-
Notifications
You must be signed in to change notification settings - Fork 2
/
_zm_perks.gsc
2033 lines (1683 loc) · 54.7 KB
/
_zm_perks.gsc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#using scripts\codescripts\struct;
#using scripts\shared\array_shared;
#using scripts\shared\clientfield_shared;
#using scripts\shared\demo_shared;
#using scripts\shared\flag_shared;
#using scripts\shared\laststand_shared;
#using scripts\shared\trigger_shared;
#using scripts\shared\util_shared;
#using scripts\shared\visionset_mgr_shared;
#insert scripts\shared\shared.gsh;
#insert scripts\shared\version.gsh;
#using scripts\shared\ai\zombie_utility;
#using scripts\zm\_util;
#using scripts\zm\_zm;
#using scripts\zm\_bb;
#using scripts\zm\_zm_audio;
#using scripts\zm\_zm_bgb;
#using scripts\zm\_zm_equipment;
#using scripts\zm\_zm_laststand;
#using scripts\zm\_zm_magicbox;
#using scripts\zm\_zm_pers_upgrades_functions;
#using scripts\zm\_zm_power;
#using scripts\zm\_zm_score;
#using scripts\zm\_zm_stats;
#using scripts\zm\_zm_utility;
#using scripts\zm\_zm_weapons;
#insert scripts\zm\_zm_perks.gsh;
#insert scripts\zm\_zm_utility.gsh;
#precache( "fx", "_t6/misc/fx_zombie_cola_dtap_on" );
#precache( "fx", "_t6/misc/fx_zombie_cola_jugg_on" );
#precache( "fx", "_t6/misc/fx_zombie_cola_on" );
#namespace zm_perks;
function init()
{
level.perk_purchase_limit = 4;
// Register the perk client field
perks_register_clientfield();
if(!level.enable_magic)
{
return;
}
initialize_custom_perk_arrays();
//sets up spawned perk machines.
perk_machine_spawn_init();
vending_weapon_upgrade_trigger = [];
// Perks-a-cola vending machine use triggers
vending_triggers = GetEntArray( "zombie_vending", "targetname" );
//level flag::init( "solo_game" );
if ( vending_triggers.size < 1 )
{
return;
}
level.machine_assets = [];
//Perks machine
if( !isDefined( level.custom_vending_precaching ) )
{
level.custom_vending_precaching = &default_vending_precaching;
}
[[ level.custom_vending_precaching ]]();
zombie_utility::set_zombie_var( "zombie_perk_cost", 2000 );
array::thread_all( vending_triggers, &vending_trigger_think );
array::thread_all( vending_triggers, &electric_perks_dialog );
if ( level._custom_perks.size > 0 )
{
a_keys = GetArrayKeys( level._custom_perks );
for ( i = 0; i < a_keys.size; i++ )
{
if ( isdefined( level._custom_perks[ a_keys[ i ] ].perk_machine_thread ) )
{
level thread [[ level._custom_perks[ a_keys[ i ] ].perk_machine_thread ]]();
}
if( isdefined( level._custom_perks[ a_keys[ i ] ].perk_machine_power_override_thread ) )//Quick Revive uses this
{
level thread [[ level._custom_perks[ a_keys[ i ] ].perk_machine_power_override_thread ]]();
}
else if( isdefined( level._custom_perks[ a_keys[ i ] ].alias ) && isdefined( level._custom_perks[ a_keys[ i ] ].radiant_machine_name ) && isdefined( level._custom_perks[ a_keys[ i ] ].machine_light_effect ) )
{
level thread perk_machine_think( a_keys[ i ], level._custom_perks[ a_keys[ i ] ] );
}
}
}
if ( isdefined( level.quantum_bomb_register_result_func ) )
{
[[level.quantum_bomb_register_result_func]]( "give_nearest_perk", &quantum_bomb_give_nearest_perk_result, 10, &quantum_bomb_give_nearest_perk_validation );
}
level thread perk_hostmigration();
}
function perk_machine_think( str_key, s_custom_perk )
{
str_endon = str_key + PERK_END_POWER_THREAD;
level endon( str_endon );//Support endon for any perk machine
str_on = s_custom_perk.alias + "_on";
str_off = s_custom_perk.alias + "_off";
str_notify = str_key + "_power_on";
while ( true )
{
machine = getentarray( s_custom_perk.radiant_machine_name, "targetname");
machine_triggers = GetEntArray( s_custom_perk.radiant_machine_name, "target" );
for( i = 0; i < machine.size; i++ )
{
machine[i] SetModel(level.machine_assets[str_key].off_model);
machine[i] Solid();
}
level thread zm_perks::do_initial_power_off_callback( machine, str_key );
array::thread_all( machine_triggers, &zm_perks::set_power_on, false );
level waittill( str_on );
for( i = 0; i < machine.size; i++ )
{
machine[i] SetModel(level.machine_assets[str_key].on_model);
machine[i] vibrate((0,-100,0), 0.3, 0.4, 3);
machine[i] playsound("zmb_perks_power_on");
machine[i] thread zm_perks::perk_fx( s_custom_perk.machine_light_effect );
machine[i] thread zm_perks::play_loop_on_machine();
}
level notify( str_notify );
array::thread_all( machine_triggers, &zm_perks::set_power_on, true );
if( isdefined( level.machine_assets[ str_key ].power_on_callback ) )
{
array::thread_all( machine, level.machine_assets[ str_key ].power_on_callback );
}
level waittill( str_off );
if( isdefined( level.machine_assets[ str_key ].power_off_callback ) )
{
array::thread_all( machine, level.machine_assets[ str_key ].power_off_callback );
}
array::thread_all( machine, &zm_perks::turn_perk_off );
}
}
//
// Precaches all machines
//
// "weapon" - 1st person Bottle when drinking
// icon - Texture for when perk is active
// model - Perk Machine on/off versions
// fx - machine on
// sound
function default_vending_precaching()
{
// precache all custom perks
if ( level._custom_perks.size > 0 )
{
a_keys = GetArrayKeys( level._custom_perks );
for ( i = 0; i < a_keys.size; i++ )
{
if ( isdefined( level._custom_perks[ a_keys[ i ] ].precache_func ) )
{
level [[ level._custom_perks[ a_keys[ i ] ].precache_func ]]();
}
}
}
}
//############################################################################
// P E R K M A C H I N E S
//############################################################################
//
// Threads to turn the machines to their ON state.
//
function do_initial_power_off_callback( machine_array, perkname )
{
if( !isdefined( level.machine_assets[ perkname ] ) )
{
return;
}
if( !isdefined( level.machine_assets[ perkname ].power_off_callback ) )
{
return;
}
WAIT_SERVER_FRAME; // wait to prevent setting the clientflag before it has been initialized
array::thread_all( machine_array, level.machine_assets[ perkname ].power_off_callback );
}
function use_solo_revive()
{
if( isdefined(level.override_use_solo_revive) )
{
return [[level.override_use_solo_revive]]();
}
players = GetPlayers();
solo_mode = 0;
if ( players.size == 1 || IS_TRUE( level.force_solo_quick_revive ) )
{
solo_mode = 1;
}
level.using_solo_revive = solo_mode;
return solo_mode;
}
//
//
function set_power_on( state )
{
self.power_on = state;
}
//
//
function turn_perk_off(ishidden)
{
self notify( "stop_loopsound" );
if ( !IS_TRUE( self.b_keep_when_turned_off ) )
{
newMachine = Spawn( "script_model", self.origin );
newMachine.angles = self.angles;
newMachine.targetname = self.targetname;
if(IS_TRUE(ishidden))
{
newMachine.ishidden = true;
newMachine Ghost();
newMachine NotSolid();
}
self Delete();
}
else
{
// If b_keep_when_turned_off, turn off the fx on the machine but don't delete it.
zm_perks::perk_fx( undefined, true );
}
}
function play_loop_on_machine()
{
if( isdefined( level.sndPerksacolaLoopOverride ) )
return;
sound_ent = spawn( "script_origin", self.origin );
sound_ent playloopsound("zmb_perks_machine_loop");
sound_ent LinkTo( self );
self waittill( "stop_loopsound" );
sound_ent UnLink();
sound_ent delete();
}
//
//
function perk_fx( fx, turnOffFx )
{
if( isdefined( turnOffFx ) )
{
self.perk_fx = false;
if ( IS_TRUE( self.b_keep_when_turned_off ) && ( isdefined( self.s_fxloc )))
{
self.s_fxloc Delete();
}
}
else
{
wait(3);
if ( !isdefined(self) )
return;
if ( !IS_TRUE( self.b_keep_when_turned_off ))
{
if ( isdefined( self ) && !IS_TRUE(self.perk_fx) )
{
playfxontag( level._effect[ fx ], self, "tag_origin" );
self.perk_fx = true;
}
}
else
{
if ( isdefined( self ) && ( !isdefined( self.s_fxloc )))
{
self.s_fxloc = util::spawn_model( "tag_origin", self.origin );
playfxontag( level._effect[ fx ], self.s_fxloc, "tag_origin" );
self.perk_fx = true;
}
}
}
}
function electric_perks_dialog()
{
self endon("death");
// TODO: This hack allows the thread to start after the gametype init has had a chance to run
wait 0.01;
//TODO TEMP Disable Revive in Solo games
level flag::wait_till( "start_zombie_round_logic" );
players = GetPlayers();
if ( players.size == 1 )
{
return;
}
self endon ("warning_dialog");
level endon("switch_flipped");
timer =0;
while(1)
{
wait(0.5);
players = GetPlayers();
for(i = 0; i < players.size; i++)
{
if(!isDefined(players[i] ))
{
continue;
}
dist = distancesquared(players[i].origin, self.origin );
if(dist > 70*70)
{
timer = 0;
continue;
}
if(dist < 70*70 && timer < 3)
{
wait(0.5);
timer ++;
}
if(dist < 70*70 && timer == 3)
{
if(!isDefined(players[i] ))
{
continue;
}
players[i] thread zm_utility::do_player_vo("vox_start", 5);
wait(3);
self notify ("warning_dialog");
}
}
}
}
function reset_vending_hint_string()
{
perk = self.script_noteworthy;
solo = zm_perks::use_solo_revive();
if( isdefined( level._custom_perks ) )
{
if ( isdefined( level._custom_perks[ perk ] ) && isdefined( level._custom_perks[ perk ].cost ) && isdefined( level._custom_perks[ perk ].hint_string ) )
{
//will convert function override to string / int value as needed.
if( IsFunctionPtr( level._custom_perks[ perk ].cost ) )
{
n_cost = [[level._custom_perks[ perk ].cost]]();
}
else
{
n_cost = level._custom_perks[ perk ].cost;
}
self SetHintString( level._custom_perks[ perk ].hint_string, n_cost );
}
}
}
function vending_trigger_can_player_use( player )
{
if (player laststand::player_is_in_laststand() || IS_TRUE( player.intermission ) )
{
return false;
}
if(player zm_utility::in_revive_trigger())
{
return false;
}
if( !player zm_magicbox::can_buy_weapon() )
{
return false;
}
if( player isThrowingGrenade() )
{
return false;
}
if( player isSwitchingWeapons() )
{
return false;
}
if( IS_DRINKING(player.is_drinking) )
{
return false;
}
return true;
}
//
//
function vending_trigger_think()
{
self endon( "death" );
// TODO: This hack allows the thread to start after the gametype init has had a chance to run
wait 0.01;
//self thread turn_cola_off();
perk = self.script_noteworthy;
solo = false;
start_on = false;
level.revive_machine_is_solo = false;
//TODO TEMP Disable Revive in Solo games
if ( isdefined( perk ) && perk == PERK_QUICK_REVIVE )
{
level flag::wait_till( "start_zombie_round_logic" );
solo = use_solo_revive();
self endon("stop_quickrevive_logic");
level.quick_revive_trigger = self;
if (solo)
{
if (!IS_TRUE(level.revive_machine_is_solo))
{
// Quick Revive turned off at start
if ( !IS_TRUE( level.initial_quick_revive_power_off ) )
{
start_on = true;
}
players = GetPlayers();
foreach ( player in players )
{
if(!isDefined(player.lives))
player.lives = 0;
}
level zm::set_default_laststand_pistol( true );
}
level.revive_machine_is_solo = true;
}
}
//if ( !solo )
{
self SetHintString( &"ZOMBIE_NEED_POWER" );
}
self SetCursorHint( "HINT_NOICON" );
self UseTriggerRequireLookAt();
cost = level.zombie_vars["zombie_perk_cost"];
if ( isdefined( level._custom_perks[ perk ] ) && isdefined( level._custom_perks[ perk ].cost ) )
{
if( IsInt( level._custom_perks[ perk ].cost ) )
{
cost = level._custom_perks[ perk ].cost;
}
else
{
cost = [[ level._custom_perks[ perk ].cost ]]();
}
}
self.cost = cost;
if ( !start_on )
{
notify_name = perk + "_power_on";
level waittill( notify_name );
}
start_on = false;
if(!isdefined(level._perkmachinenetworkchoke))
{
level._perkmachinenetworkchoke = 0;
}
else
{
level._perkmachinenetworkchoke ++;
}
for(i = 0; i < level._perkmachinenetworkchoke; i ++)
{
util::wait_network_frame();
}
//Turn on music timer
self thread zm_audio::sndPerksJingles_Timer();
self thread check_player_has_perk(perk);
if ( isdefined( level._custom_perks[ perk ] ) && isdefined( level._custom_perks[ perk ].hint_string ) )
{
self SetHintString( level._custom_perks[ perk ].hint_string, cost );
}
for( ;; )
{
self waittill( "trigger", player );
index = zm_utility::get_player_index(player);
if ( !vending_trigger_can_player_use( player ) )
{
wait( 0.1 );
continue;
}
if ( player HasPerk( perk ) || player has_perk_paused( perk ) )
{
cheat = false;
if ( cheat != true )
{
//player iprintln( "Already using Perk: " + perk );
self playsound("evt_perk_deny");
player zm_audio::create_and_play_dialog( "general", "sigh" );
continue;
}
}
if( isdefined( level.custom_perk_validation ) )
{
valid = self [[ level.custom_perk_validation ]]( player );
if( !valid )
{
continue;
}
}
current_cost = self.cost;
// If the persistent upgrade "double_points" is active, the cost is halved
if( player zm_pers_upgrades_functions::is_pers_double_points_active() )
{
current_cost = player zm_pers_upgrades_functions::pers_upgrade_double_points_cost( current_cost );
}
if( !player zm_score::can_player_purchase( current_cost ) )
{
//player iprintln( "Not enough points to buy Perk: " + perk );
self playsound("evt_perk_deny");
player zm_audio::create_and_play_dialog( "general", "outofmoney" );
continue;
}
if ( !player zm_utility::can_player_purchase_perk() )
{
//player iprintln( "Too many perks already to buy Perk: " + perk );
self playsound("evt_perk_deny");
// COLLIN: do we have a VO that would work for this? if not we'll leave it at just the deny sound
player zm_audio::create_and_play_dialog( "general", "sigh" );
continue;
}
sound = "evt_bottle_dispense";
playsoundatposition(sound, self.origin);
player zm_score::minus_to_player_score( current_cost );
perkHash = -1;
if (isDefined(level._custom_perks[ perk ]) && isDefined(level._custom_perks[ perk ].hash_id))
{
perkHash = level._custom_perks[ perk ].hash_id;
}
player RecordMapEvent(ZM_MAP_EVENT_PERK_MACHINE_USED, GetTime(), self.origin, level.round_number, perkHash);
player.perk_purchased = perk;
player notify( "perk_purchased", perk );
self thread zm_audio::sndPerksJingles_Player(1);
self thread vending_trigger_post_think( player, perk );
}
}
function vending_trigger_post_think( player, perk )
{
player endon( "disconnect" );
player endon( "end_game" );
player endon( "perk_abort_drinking" );
// do the drink animation
gun = player perk_give_bottle_begin( perk );
evt = player util::waittill_any_return( "fake_death", "death", "player_downed", "weapon_change_complete", "perk_abort_drinking", "disconnect" );
// once they start drinking they get the perk - if the machine is disabled in mid drink they will have it disabled
if (evt == "weapon_change_complete" )
{
player thread wait_give_perk( perk, true );
}
// restore player controls and movement
player perk_give_bottle_end( gun, perk );
// TODO: race condition?
if ( player laststand::player_is_in_laststand() || IS_TRUE( player.intermission ) )
{
return;
}
player notify("burp");
// Only in classic mode - Update the "cash_back" persistent unlock
if( IS_TRUE(level.pers_upgrade_cash_back) )
{
player zm_pers_upgrades_functions::cash_back_player_drinks_perk();
}
// Another persistent player ability
if( IS_TRUE(level.pers_upgrade_perk_lose) )
{
player thread zm_pers_upgrades_functions::pers_upgrade_perk_lose_bought();
}
if ( isDefined( level.perk_bought_func ) )
{
player [[ level.perk_bought_func ]]( perk );
}
player.perk_purchased = undefined;
// Check If Perk Machine Was Powered Down While Drinking, Is So Pause The Perks
//-----------------------------------------------------------------------------
if ( !IS_TRUE( self.power_on ) )
{
wait 1;
perk_pause( self.script_noteworthy );
}
//player iprintln( "Bought Perk: " + perk );
}
//*****************************************************************************
//*****************************************************************************
// unlocked_perk_upgrade( perk )
// {
// ch_ref = string(tablelookup( "mp/challengeTable_zmPerk.csv", 12, perk, 7 ));
// ch_max = int(tablelookup( "mp/challengeTable_zmPerk.csv", 12, perk, 4 ));
// ch_progress = self getdstat( "challengeStats", ch_ref, "challengeProgress" );
//
// if( ch_progress >= ch_max )
// {
// return true;
// }
// return false;
// }
function wait_give_perk( perk, bought )
{
self endon( "player_downed" );
self endon( "disconnect" );
self endon( "end_game" );
self endon( "perk_abort_drinking" );
self util::waittill_any_timeout(0.5, "burp", "player_downed", "disconnect", "end_game", "perk_abort_drinking" );
self give_perk( perk, bought );
}
function return_retained_perks()
{
if ( isdefined(self._retain_perks_array) )
{
keys = getarraykeys( self._retain_perks_array );
foreach( perk in keys )
{
if ( IS_TRUE(self._retain_perks_array[perk]) )
self give_perk( perk, false );
}
}
}
//*****************************************************************************
//*****************************************************************************
function give_perk_presentation( perk )
{
self endon( "player_downed" );
self endon( "disconnect" );
self endon( "end_game" );
self endon( "perk_abort_drinking" );
//AUDIO: Ayers - Sending Perk Name over to audio common script to play VOX
self zm_audio::playerExert( "burp" );
if ( IS_TRUE( level.remove_perk_vo_delay ) )
{
self zm_audio::create_and_play_dialog( "perk", perk );
}
else
{
self util::delay(1.5, undefined, &zm_audio::create_and_play_dialog, "perk", perk );
}
self setblur( 9, 0.1 );
wait(0.1);
self setblur(0, 0.1);
//earthquake (0.4, 0.2, self.origin, 100);
}
function give_perk( perk, bought )
{
self SetPerk( perk );
self.num_perks++;
if( IS_TRUE(bought) )
{
self thread give_perk_presentation( perk );
self notify( "perk_bought", perk );
self zm_stats::increment_challenge_stat( "SURVIVALIST_BUY_PERK" );
}
if ( isdefined( level._custom_perks[ perk ] ) && isdefined( level._custom_perks[ perk ].player_thread_give ) )
{
self thread [[ level._custom_perks[ perk ].player_thread_give ]]();
}
self set_perk_clientfield( perk, PERK_STATE_OWNED );
demo::bookmark( "zm_player_perk", gettime(), self );
//stat tracking
self zm_stats::increment_client_stat( "perks_drank" );
self zm_stats::increment_client_stat( perk + "_drank" );
self zm_stats::increment_player_stat( perk + "_drank" );
self zm_stats::increment_player_stat( "perks_drank" );
//Happy Hour achievement tracking
if(!isDefined(self.perk_history))
{
self.perk_history = [];
}
array::add(self.perk_history,perk,false);
if ( !isdefined( self.perks_active ) )
{
self.perks_active = [];
}
ARRAY_ADD( self.perks_active, perk );
self notify("perk_acquired");
self thread perk_think( perk );
}
//*****************************************************************************
// Increment player max health if its the jugg perk
//*****************************************************************************
// self = player
function perk_set_max_health_if_jugg( str_perk, set_preMaxHealth, clamp_health_to_max_health )
{
n_max_total_health = undefined;
// Is it the Jugg (or upgraded) Perk?
switch ( str_perk )
{
case PERK_JUGGERNOG:
if( set_preMaxHealth )
{
self.preMaxHealth = self.maxhealth;
}
n_max_total_health = self.maxhealth + level.zombie_vars["zombie_perk_juggernaut_health"];
break;
// Is if the Jugg persistent upgrade?
case "jugg_upgrade":
if( set_preMaxHealth )
{
self.preMaxHealth = self.maxhealth;
}
// If we have jugg
if( self HasPerk(PERK_JUGGERNOG) )
{
n_max_total_health += level.zombie_vars["zombie_perk_juggernaut_health"];
}
else
{
n_max_total_health = level.zombie_vars["player_base_health"];
}
break;
case "health_reboot":
// This doesn't seem like the ideal place to do this, but many things call this function to set player health
// Give players more health in the early rounds
n_max_total_health = level.zombie_vars["player_base_health"];
if( isdefined(self.n_player_health_boost) )
{
n_max_total_health += self.n_player_health_boost;
}
if ( self HasPerk( PERK_JUGGERNOG ) )
{
n_max_total_health += level.zombie_vars["zombie_perk_juggernaut_health"];
}
}
// Was the health upgraded by Jugg?
if( isdefined(n_max_total_health) )
{
// If the PERSISTENT Jugg upgrade is active, add the extra health
if( self zm_pers_upgrades_functions::pers_jugg_active() )
{
n_max_total_health = n_max_total_health + level.pers_jugg_upgrade_health_bonus;
}
self.maxhealth = n_max_total_health;
self SetMaxHealth( n_max_total_health );
if( isdefined(clamp_health_to_max_health) && (clamp_health_to_max_health == true) )
{
if( self.health > self.maxhealth )
{
self.health = self.maxhealth;
}
}
}
}
//*****************************************************************************
//*****************************************************************************
function check_player_has_perk(perk)
{
self endon( "death" );
dist = 128 * 128;
while(true)
{
players = GetPlayers();
for( i = 0; i < players.size; i++ )
{
if(DistanceSquared( players[i].origin, self.origin ) < dist)
{
if(!players[i] HasPerk(perk) &&
self vending_trigger_can_player_use( players[i] ) &&
!players[i] has_perk_paused(perk) &&
!(players[i] zm_utility::in_revive_trigger()) &&
!(zm_equipment::is_equipment_that_blocks_purchase( players[i] getcurrentweapon() ) ) &&
(!players[i] zm_equipment::hacker_active()))
{
self setinvisibletoplayer(players[i], false);
}
else
{
self SetInvisibleToPlayer(players[i], true);
}
}
}
wait(0.1);
}
}
function vending_set_hintstring( perk )
{
switch( perk )
{
case "specialty_armorvest":
break;
}
}
function perk_think( perk )
{
self endon("disconnect");
perk_str = perk + "_stop";
result = self util::waittill_any_return( "fake_death", "death", "player_downed", perk_str );
// give the bgb system a chance to override losing the perk, or to do something triggered by the loss of the perk
while( self bgb::lost_perk_override( perk ) )
{
result = self util::waittill_any_return( "fake_death", "death", "player_downed", perk_str );
}
do_retain = true;
if( use_solo_revive() && perk == PERK_QUICK_REVIVE)
{
do_retain = false;
}
if( do_retain )
{
if ( isdefined(self._retain_perks) && self._retain_perks )
{
return;
}
else if ( isdefined( self._retain_perks_array ) && IS_TRUE( self._retain_perks_array[ perk ] ) )
{
return;
}
}
self UnsetPerk( perk );
self.num_perks--;
// turn off perk when perk is paused, if custom func is set
if ( isdefined( level._custom_perks[ perk ] ) && isdefined( level._custom_perks[ perk ].player_thread_take ) )
{
self thread [[ level._custom_perks[ perk ].player_thread_take ]]( false, perk_str, result );
}
self set_perk_clientfield( perk, PERK_STATE_NOT_OWNED );
//self perk_hud_destroy( perk );
self.perk_purchased = undefined;
//self iprintln( "Perk Lost: " + perk );
if ( isdefined( level.perk_lost_func ) )
{
self [[ level.perk_lost_func ]]( perk );
}
if ( isdefined( self.perks_active ) && IsInArray( self.perks_active, perk ) )
{
ArrayRemoveValue( self.perks_active, perk, false );
}
self notify( "perk_lost" );
}
function set_perk_clientfield( perk, state )
{
if ( isdefined( level._custom_perks[ perk ] ) && isdefined( level._custom_perks[ perk ].clientfield_set ) )
{
self [[ level._custom_perks[ perk ].clientfield_set ]]( state );
}
}
function perk_hud_destroy( perk )
{
self.perk_hud[ perk ] zm_utility::destroy_hud();
self.perk_hud[ perk ] = undefined;
}
function perk_hud_grey( perk, grey_on_off )
{
if ( grey_on_off )
self.perk_hud[ perk ].alpha = 0.3;
else
self.perk_hud[ perk ].alpha = 1.0;
}
function perk_give_bottle_begin( perk )
{
self zm_utility::increment_is_drinking();
self zm_utility::disable_player_move_states(true);
original_weapon = self GetCurrentWeapon();
weapon = "";