-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstranded.nut
1025 lines (852 loc) · 25.8 KB
/
stranded.nut
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
/**
* STRANDED by Neil a.k.a. LuKeM
* Move, build, and barricade. Scavenge for food and water. How long can you survive?
*/
//-------------------------------------------------------------------------------------------
IncludeScript("VSLib");
// Variables
::UsedSpawnLocations <- {};
::HasRelocated <- {};
::Food <- {};
::Water <- {};
::SurvRoundTime <- 0;
::LastWeaponFireTime <- {};
::SpawnTimes <- {};
::AttackingBots <- [];
::CanTrackPlayers <- true;
::CurrentDifficulty <- null;
::PLAYER_HUD <- {};
::PLAYER_HUD[1] <- { pos = {x=0, y=0}, hud = HUD_RIGHT_TOP };
::PLAYER_HUD[2] <- { pos = {x=150, y=0}, hud = HUD_LEFT_TOP };
::PLAYER_HUD[3] <- { pos = {x=300, y=0}, hud = HUD_RIGHT_BOT };
::PLAYER_HUD[4] <- { pos = {x=450, y=0}, hud = HUD_LEFT_BOT };
const WATER = 0;
const FOOD = 1;
const FOOD_MODEL = "models/props_junk/garbage_cerealbox01a_fullsheet.mdl";
const WATER_MODEL = "models/props_interiors/waterbottle.mdl";
const NUTRIENT_CHANCE = 4; /** Percent chance of a nutrient spawning */
const FOOD_CHANCE = 40; /** Percent chance of food spawning (water spawn rate thus will be 100 - FOOD_CHANCE) */
const MAX_NUTRIENTS = 40; /** Maximum number of nutrients that can exist on the map */
::SpawnedNutrients <- 0;
::InventoryHUD <- null; /** The HUD menu item */
::HasDisplayedWarning <- {}; /** Has a hint been displayed during the round? */
::RandSoundsList <- [
"Event.HunterAlert",
"Event.JockeyAlert",
"Event.SmokerAlert",
"Event.BoomerAlert",
"Event.AmbientMob",
"Event.ChargerAlert",
"Event.LoneSurvivor",
"Event.MobSignal1_Fairgrounds",
"Event.ZombieChoir",
"Zombie.Alert",
"Zombie.Rage",
"Zombie.RageAtVictim",
"Zombie.BulletImpact",
"Zombie.IgniteScream",
"WoodenDoor.Break"
]
::WeaponSpawnNames <- {
weapon_adrenaline_spawn = 0
weapon_ammo_spawn = 0
weapon_autoshotgun_spawn = 0
weapon_chainsaw_spawn = 0
weapon_defibrillator_spawn = 0
weapon_first_aid_kit_spawn = 0
weapon_gascan_spawn = 0
weapon_grenade_launcher_spawn = 0
weapon_hunting_rifle_spawn = 0
weapon_item_spawn = 0
weapon_melee_spawn = 0
weapon_molotov_spawn = 0
weapon_pain_pills_spawn = 0
weapon_pipe_bomb_spawn = 0
weapon_pistol_magnum_spawn = 0
weapon_pistol_spawn = 0
weapon_pumpshotgun_spawn = 0
weapon_rifle_ak47_spawn = 0
weapon_rifle_desert_spawn = 0
weapon_rifle_m60_spawn = 0
weapon_rifle_spawn = 0
weapon_scavenge_item_spawn = 0
weapon_shotgun_chrome_spawn = 0
weapon_shotgun_spas_spawn = 0
weapon_smg_silenced_spawn = 0
weapon_smg_spawn = 0
weapon_sniper_military_spawn = 0
weapon_spawn = 0
weapon_upgradepack_explosive_spawn = 0
weapon_upgradepack_incendiary_spawn = 0
weapon_vomitjar_spawn = 0
}
// Set up mutation options
MutationOptions <-
{
ActiveChallenge = 1
CommonLimit = 150
NumReservedWanderers = 150
AlwaysAllowWanderers = true
MegaMobSize = 0
MobSpawnSize = 0
MobMaxSize = 0
WanderingZombieDensityModifier = 0.01
MaxSpecials = 3
TankLimit = 0
WitchLimit = 0
BoomerLimit = 0
ChargerLimit = 0
HunterLimit = 0
JockeyLimit = 0
SpitterLimit = 0
SmokerLimit = 0
SpecialRespawnInterval = 0
TotalSpecials = 0
cm_NoSurvivorBots = true
AllowCrescendoEvents = false
ZombieTankHealth = 300
ClearedWandererRespawnChance = 60
}
DirectorOptions <-
{
weaponsToRemove =
{
weapon_pistol = 0
weapon_pistol_magnum = 0
weapon_pipe_bomb = 0
weapon_vomitjar = 0
weapon_upgradepack_incendiary = 0
weapon_upgradepack_explosive = 0
weapon_ammo_pack = 0
upgrade_item = 0
ammo = 0
weapon_bile_bomb = 0
//weapon_molotov = 0
}
function AllowWeaponSpawn(classname)
{
if (classname in weaponsToRemove)
return false;
if (Utils.GetRandNumber(1, 5) >= 4)
return false;
return true;
}
function ShouldAvoidItem(classname)
{
if (classname in weaponsToRemove)
return true;
return false;
}
function GetDefaultItem(idx)
{
return 0;
}
}
// Change difficulty related settings
function Notifications::OnDifficulty::ModDifficulty(diff)
{
::CurrentDifficulty <- diff;
}
// Kill infected that have decap'd
function Notifications::OnInfectedHurt::DetectDecap(infected, attacker, params)
{
local hitgroup = EasyLogic.GetEventInt(params, "hitgroup");
if (attacker.GetPlayerType() == Z_SURVIVOR && ((hitgroup >= 0 && hitgroup <= 3) || hitgroup == 6 || hitgroup == 7))
infected.SetHealth(0);
}
// Calculated infacted damage and lowers it
function EasyLogic::OnDamage::infected ( victim, attacker, damageDone, damageTable )
{
if (victim.GetIndex() == attacker.GetIndex() || !victim || !attacker || victim.GetIndex() <= 64)
return;
if (damageTable.DamageType == 8 || damageTable.DamageType == 2056)
return damageDone;
return floor(damageDone.tofloat() / 12.0);
}
// Leap of faith for infected
function Notifications::OnHurt::LeapOfFaith(victim, attacker, params)
{
if (victim && attacker && victim.GetPlayerType() == Z_SURVIVOR && victim.GetCurrentAttacker() != null && victim.IsPressingShove() && Utils.GetRandNumber(1, 6) == 3)
attacker.Stagger();
}
// calculates player damage and multiplies it (to make infected much stronger)
function EasyLogic::OnDamage::player ( victim, attacker, damageDone, damageTable )
{
if (!victim || !attacker || victim.GetIndex() == attacker.GetIndex() || damageTable.DamageType == 131072)
return;
switch(victim.GetPlayerType())
{
case Z_SURVIVOR:
{
if (attacker.GetClassname() == "infected")
return Utils.GetRandNumber(30, 60);
else if (attacker.IsPlayerEntityValid())
{
switch (attacker.GetPlayerType())
{
case Z_SURVIVOR:
break;
case Z_SPITTER:
return Utils.GetRandNumber(2, 5);
case Z_HUNTER:
return Utils.GetRandNumber(5, 10);
case Z_CHARGER:
return Utils.GetRandNumber(10, 15);
case Z_BOOMER:
return Utils.GetRandNumber(1, 5);
case Z_SMOKER:
return Utils.GetRandNumber(10, 15);
case Z_JOCKEY:
return Utils.GetRandNumber(10, 15);
default:
return Utils.GetRandNumber(30, 60);
}
}
break;
}
}
}
// Timer that resets Valve pickup system (in case players lose it due to bad pickup etc)
::ResetValvePickups <- function (player)
{
if (!player.IsPlayerEntityValid())
return false;
player.BeginValvePickupObjects();
player.ValvePickupPickupRange(200.0);
}
// Relocate survivor players on spawn
function Notifications::OnSpawn::RelocatePlayers ( player, params )
{
if (player.GetPlayerType() != Z_SURVIVOR)
return;
player.PlaySound("Event.SurvivalStart");
Timers.AddTimer(10.0, true, ResetValvePickups, player);
local pos = player.GetLocation();
local ents = Objects.OfClassname("prop_physics");
// Try to acquire a good, random spawn location
for (local i = 0; i < 50; i++)
{
local vsent = ents[Utils.GetRandNumber(0, ents.len() - 1)];
local entpos = vsent.GetLocation();
local spawn = true;
// prevent spawning too close to each other
foreach (idx, n in UsedSpawnLocations)
{
local obj = Entity(idx);
if (Utils.CalculateDistance(entpos, obj.GetLocation()) <= 1200.0)
{
spawn = false;
break;
}
}
if (spawn && Utils.CalculateDistance(pos, entpos) > 500.0 && !(vsent.GetIndex() in UsedSpawnLocations))
{
if ("LastRoundSpawns" in getroottable() && player.GetIndex() in LastRoundSpawns && Utils.CalculateDistance(entpos, LastRoundSpawns[player.GetIndex()]) < 500.0)
continue;
if (!("LastRoundSpawns" in getroottable()))
::LastRoundSpawns <- {};
::LastRoundSpawns[player.GetIndex()] <- entpos;
UsedSpawnLocations[vsent.GetIndex()] <- true;
player.SetLocation(entpos);
// Check to make sure that a line can be traced from the eyes to the feet
if (!player.CanTraceToLocation(player.GetLocation()))
{
printf("[Stranded] Invalid spawn detected for %s. Respawning...", player.GetName());
continue;
}
return;
}
}
local spawnPos = player.GetSpawnLocation();
if (spawnPos)
player.SetLocation(spawnPos);
printf("[Stranded] Found no suitable spawn location for %s, spawning at default location", player.GetName());
}
::EndSimulatedPanicEvent <- function(params)
{
local survs = Players.AliveSurvivors();
foreach (infected in Objects.OfClassname("infected"))
{
local reset = true;
local infloc = infected.GetLocation();
foreach (surv in survs)
if (infected.CanTraceToOtherEntity(surv))
{
reset = false;
break;
}
if (reset)
infected.BotReset();
}
}
// Attract zombies when non-melee wep is fired
function OnGameEvent_weapon_fire ( params )
{
local player = EasyLogic.GetPlayersFromEvent(params).entity;
local idx = player.GetIndex();
if (player.GetPlayerType() != Z_SURVIVOR)
return;
local wep = player.GetActiveWeapon();
local wepclass = wep.GetClassname();
if (wepclass == "weapon_pipe_bomb")
{
player.AttachParticle("gas_fireball", 2.0);
Utils.PlaySoundToAll("BaseGrenade.Explode");
local infected = null;
while (infected = Entities.FindByClassnameWithin(infected, "infected", player.GetLocation(), Utils.GetRandNumber(1200, 2000)))
{
local vsent = Entity(infected);
vsent.BotReset();
}
::CanTrackPlayers <- false;
Timers.AddTimer(6.0, false, @(n) ::CanTrackPlayers <- true);
return;
}
if (!Utils.IsValidFireWeapon(wepclass) || wepclass.find("silenced") != null)
return;
if (!(idx in ::LastWeaponFireTime))
::LastWeaponFireTime[idx] <- 0;
if (Time() - ::LastWeaponFireTime[idx] < 30)
return;
printf("[Stranded] Simulated panic event started");
::LastWeaponFireTime[idx] <- Time();
Timers.AddTimerByName("PanicTimer" + idx, 45.0, false, ::EndSimulatedPanicEvent);
Utils.PlaySoundToAll("Event.AmbientMob");
local infected = null;
while (infected = Entities.FindByClassnameWithin(infected, "infected", player.GetLocation(), Utils.GetRandNumber(584, 2500)))
{
local vsent = Entity(infected);
vsent.BotAttack(player);
}
// Display a temporary hint
if ( !(idx in HasDisplayedWarning) )
{
local gun = player.GetActiveWeapon();
Utils.SetEntityHint( Entity(gun), "Loud noises attract zombies", "icon_skull", 0, false, 10.0, 0 );
HasDisplayedWarning[idx] <- true;
}
}
// Punish/notify players based on their current nutrient count
::CalcNutrientResults <- function(player, nutrient, tbl, idx, hud)
{
tbl[idx] -= 1;
// Notifications
if (tbl[idx] == 5)
{
if (nutrient == WATER)
Utils.SayToAll("%s is extremely thirsty.", player.GetName());
else if (nutrient == FOOD)
Utils.SayToAll("%s is extremely hungry.", player.GetName());
}
else if (tbl[idx] == 1)
{
if (nutrient == WATER)
Utils.SayToAll("%s is about to die of thirst!", player.GetName());
else if (nutrient == FOOD)
Utils.SayToAll("%s is about to die of hunger!", player.GetName());
}
else if (tbl[idx] <= 0)
{
if (nutrient == WATER)
{
local fullhp = player.GetHealth();
local newBuffer = fullhp - 15;
player.SetReviveCount(1);
player.SetRawHealth(0);
player.SetHealthBuffer(newBuffer);
if (newBuffer <= 0)
player.Kill();
}
else if (nutrient == FOOD)
player.Incapacitate();
}
if (Food[idx] <= 5 || Water[idx] <= 5)
hud.StartBlinking();
else
hud.StopBlinking();
}
// Remove nutrients from total (this is a timer)
::RemoveNutrients <- function(params)
{
local player = params.p;
local nutrient = params.t;
if (!player.IsPlayerEntityValid())
return false;
if (player.IsDead())
return;
local pid = player.GetIndex();
local hud = HUD.Get(PLAYER_HUD[pid].hud);
if (nutrient == FOOD)
{
CalcNutrientResults(player, FOOD, Food, pid, hud);
hud.SetValue("food", (Food[pid] < 0 ? 0 : Food[pid]));
}
else if (nutrient == WATER)
{
CalcNutrientResults(player, WATER, Water, pid, hud);
hud.SetValue("water", (Water[pid] < 0 ? 0 : Water[pid]));
}
}
// Set up the player's HUD on spawn
function Notifications::OnPostSpawn::SetupPlayer(player, params)
{
if (player.GetPlayerType() != Z_SURVIVOR)
return;
local pid = player.GetIndex();
printf("[Stranded] Player %d spawned", pid);
Food[pid] <- 100;
Water[pid] <- 100;
local player_hud = HUD.Item("{name}\nFood: {food} Water: {water}\nVisibility: [{visible}]");
player_hud.SetValue("name", player.GetName());
player_hud.SetValue("food", Food[pid]);
player_hud.SetValue("water", Water[pid]);
player_hud.SetValue("visible", "");
player_hud.AttachTo(PLAYER_HUD[pid].hud);
player_hud.ChangeHUDNative(PLAYER_HUD[pid].pos.x, PLAYER_HUD[pid].pos.y, 140, 72, 640, 480);
Timers.AddTimer(10.0 + Utils.GetRandNumber(-1, 3), true, RemoveNutrients, { p = player, t = FOOD });
Timers.AddTimer(5.0 + Utils.GetRandNumber(-1, 3), true, RemoveNutrients, { p = player, t = WATER });
player.SetFlashlight(false);
player.Give("pipe_bomb");
SpawnTimes[pid] <- Time();
// Precache particles
player.AttachParticle("gas_fireball", 0.1);
}
// Provide a !respawn function in case they get stuck somewhere
function ChatTriggers::respawn(player, args, text)
{
local idx = player.GetIndex();
if (idx in HasRelocated)
{
Utils.SayToAllDel("You have already respawned once this round.");
return;
}
if ((Time() - SpawnTimes[idx]) > 60.0)
{
Utils.SayToAllDel("You can only respawn during the first 60 seconds after spawning.");
return;
}
HasRelocated[idx] <- true;
Notifications.OnSpawn.RelocatePlayers ( player, null );
Utils.SayToAllDel("%s has relocated!", player.GetName());
}
// Returns the round time different
::GetRoundTimeDiff <- function()
{
return floor(Time() - ::SurvRoundTime);
}
// Returns the current round time as a formatted string
::GetRoundTime <- function ()
{
local timediff = GetRoundTimeDiff();
local timetable = Utils.GetTimeTable( timediff );
return format("%02d:%02d:%02d", timetable.hours, timetable.minutes, timetable.seconds);
}
// Gets the old round time
::GetOldRoundTime <- function()
{
local fileName = SessionState.MapName + "_strandedtimes.dat";
local oldTime = FileToString(fileName);
// If the file doesn't exist, create it.
if (oldTime == null)
{
StringToFile( fileName, "0" );
oldTime = 0;
}
return oldTime.tointeger();
}
// Resets the countdown when survivors are dead, and saves if it's the best time
function Notifications::OnSurvivorsDead::ResetAndSave ( params )
{
local fileName = SessionState.MapName + "_strandedtimes.dat";
local oldTime = ::GetOldRoundTime();
local newTime = ::GetRoundTimeDiff();
if (newTime > 60)
newTime += 60;
local timetable = Utils.GetTimeTable( oldTime );
local strOldTimeFormat = format("%02d:%02d:%02d", timetable.hours, timetable.minutes, timetable.seconds);
// Save the best time
if (newTime > oldTime)
{
Utils.PlaySoundToAll("Event.ScenarioWin_L4D1");
Utils.SayToAll("CONGRATULATIONS! NEW HIGH SCORE!");
Utils.SayToAll("Old survival time was %s.", strOldTimeFormat);
Utils.SayToAll("New survival time is %s!", ::GetRoundTime());
StringToFile( fileName, newTime.tostring() );
}
else
{
Utils.PlaySoundToAll("Event.ScavengeOvertimeStart");
Utils.SayToAll("Sorry Survivors! You didn't beat your old time of %s.", strOldTimeFormat);
}
// Make the current time static as the screen fades out
local timebox = HUD.Get(HUD_MID_TOP);
if (timebox)
{
timebox.SetValue("time", ::GetRoundTime());
timebox.StartBlinking();
}
}
// Remove saferoom doors
function Notifications::OnRoundStart::RemoveSaferoomDoors ( params )
{
printf("[Stranded] Locking ending saferoom doors");
local function ForceCloseDoor()
{
foreach (door in Objects.OfClassname("prop_door_rotating_checkpoint"))
if (GetFlowPercentForPosition(door.GetLocation(), false) > 50.0)
door.Input("Close");
}
foreach (door in Objects.OfClassname("prop_door_rotating_checkpoint"))
{
if (GetFlowPercentForPosition(door.GetLocation(), false) > 50.0)
{
door.Input("Close");
door.Input("Lock");
door.ConnectOutput("OnOpen", ForceCloseDoor);
}
}
}
// Mod wep spawns to hold only 1 gun
function Notifications::OnRoundStart::ChangeWepSpawns ( params )
{
// Wrap inside a timer so that the engine does not suspend the query
local function TimerChangeWepSpawns(args)
{
foreach (idx, v in ::WeaponSpawnNames)
foreach (wep in Objects.OfClassname(idx))
wep.SetKeyValue("count", 1);
}
Timers.AddTimer(0.1, false, TimerChangeWepSpawns);
}
// Calculates misc slow poll things
::CalculateSlowPoll <- function(params)
{
printf("%d commons left", Director.GetCommonInfectedCount());
if (Director.GetCommonInfectedCount() <= floor(SessionOptions.CommonLimit / 1.5))
{
}
}
// Spawns Zombies
::ZombieSpawn <- function(params)
{
if (::CurrentDifficulty == EASY)
{
printf("[Stranded] Low difficulty detected; SI will not spawn");
return false;
}
local survs = Players.AliveSurvivors();
local humanCount = survs.len();
if (humanCount == 0)
humanCount = 1;
local randInf = 0;
if (::CurrentDifficulty == NORMAL)
randInf = Utils.GetRandNumber(Z_HUNTER, Z_CHARGER);
else
randInf = Utils.GetRandNumber(Z_SMOKER, Z_WITCH);
if (survs.len() > 0)
// Spawn a random zombie type near a random survivor
Utils.SpawnZombieNearPlayer( Utils.GetRandValueFromArray(survs), randInf, 1000.0, 800.0 );
local time = null;
switch (humanCount)
{
case 1:
time = 80;
break;
case 2:
time = 60;
break;
case 3:
time = 50;
break;
case 4:
time = 40;
break;
default:
time = 120.0;
break;
}
Timers.AddTimer(time, false, ZombieSpawn);
}
// Attach hints to physics props, play sounds, and spawn SI
function Notifications::OnRoundStart::DoRandomStuff ( params )
{
Timers.AddTimer(35.0, true, @(params) Utils.PlaySoundToAll(::RandSoundsList[Utils.GetRandNumber(0, ::RandSoundsList.len())]));
Timers.AddTimer(100.0, false, ZombieSpawn);
if (Convars.GetStr("z_difficulty") == EXPERT)
Timers.AddTimer(900.0, true, @(n) Utils.SpawnZombieNearPlayer( Players.AnyAliveSurvivor(), TANK, 1000.0, 800.0 ) );
Timers.AddTimer(10.0, true, CalculateSlowPoll);
foreach (entity in Objects.OfClassname("prop_physics"))
if (entity.GetName().find("ENT_NO_PICKUP") == null)
Utils.SetEntityHint(entity, "Press USE to lift this object", "icon_arrow_plain_white_up", 200, true);
}
// Restarts the countdown at the beginning of a round
function Notifications::OnRoundStart::BeginCountdown ( params )
{
printf("[Stranded] New Round Started");
::SurvRoundTime <- Time();
local hudtimer = HUD.Item("Survival Time:\n{time}");
hudtimer.SetValue("time", GetRoundTime);
hudtimer.AttachTo(HUD_MID_TOP);
hudtimer.ChangeHUDNative(0, 90, 120, 47, 640, 480);
hudtimer.SetTextPosition(TextAlign.Center);
}
// Spawns food water nearby
function VSLib::EasyLogic::Update::SpawnFoodWater()
{
if (Utils.GetRandNumber(1, 100) <= NUTRIENT_CHANCE && ::SpawnedNutrients < MAX_NUTRIENTS)
{
local pos = Utils.GetNearbyLocationRadius( Players.AnyAliveSurvivor(), 800.0, 5000.0 );
if (pos)
{
local item = null;
local mdl = null;
local txt = null;
if (Utils.GetRandNumber(1, 100) < FOOD_CHANCE )
{
item = "food";
mdl = FOOD_MODEL;
txt = "Grab some food";
}
else
{
item = "water";
mdl = WATER_MODEL;
txt = "Pickup water";
}
::SpawnedNutrients++;
local ent = Utils.SpawnInventoryItem( item, mdl, pos );
local hint = Utils.SetEntityHint(ent, txt, "icon_alert", 512);
ent.GetScriptScope()["hint"] <- hint;
}
}
}
// This updater is a "mini director" that calculates the following:
// - Alerts infected that are close to visible survivors
// - Global vision/hearing info is updated based on if survivors
// are crouching, shift-walking, etc and how the modifiers affect
// infected visibility.
//
function VSLib::EasyLogic::Update::MiniDirector()
{
if (!::CanTrackPlayers)
return;
local survs = Players.AliveSurvivors();
// Custom visibility detection
foreach (surv in survs)
{
local pos = surv.GetLocation();
local btnState = 2 - ((surv.IsPressingDuck() > 0).tointeger() + (surv.IsPressingWalk() > 0).tointeger());
local seeRadius = 128.0 + 256.0 * btnState.tofloat();
// Slow walk system
if (btnState == 0)
surv.SetFriction(1.25);
else
surv.SetFriction(1.0);
// Update player visibility
local hud = HUD.Get(PLAYER_HUD[surv.GetIndex()].hud);
if (hud)
hud.SetValue("visible", Utils.BuildProgressBar(12, btnState, 2));
local infected = null;
while (infected = Entities.FindByClassnameWithin (infected, "infected", pos, seeRadius))
{
local inf = Entity(infected);
// Check if this infected can "see" the player
if (inf.CanTraceToOtherEntity(surv, 40))
{
if (!(inf in AttackingBots))
{
AttackingBots.push(inf);
inf.BotAttack(surv);
}
}
}
}
// Reset all SI that are far away from all survivors
foreach (SI in Players.Infected())
{
local CanSmell = false;
foreach (surv in survs)
{
if (Utils.GetDistBetweenEntities(SI, surv) < 1400.0)
{
CanSmell = true;
break;
}
}
if (!CanSmell)
SI.ChangeBotEyes(false);
else
SI.ChangeBotEyes(true);
}
// Reset attacking bots which are far away
foreach (idx, infected in AttackingBots)
{
local reset = true;
if (infected.IsEntityValid())
{
foreach (surv in survs)
if (Utils.GetDistBetweenEntities(infected, surv) < 1500.0)
{
reset = false;
break;
}
}
else
{
AttackingBots.remove(idx);
continue;
}
if (reset)
{
infected.BotReset();
AttackingBots.remove(idx);
}
}
}
function Notifications::OnPickupInvItem::NotifyPickup(survivor, itemName, itemEnt)
{
Utils.SayToAll("%s picked up some %s. Type !inv to access your inventory.", survivor.GetName(), itemName);
local scope = ent.GetScriptScope();
if ("hint" in scope)
scope["hint"].Kill();
::SpawnedNutrients--;
}
// Transfers an item from one inv to another
::TransferItem <- function (player, index, value)
{
foreach (client in Players.All())
{
if (client.GetName() != value)
continue;
if (Utils.CalculateDistance(player.GetLocation(), client.GetLocation()) > 200.0)
{
Utils.SayToAll("Cannot give the item; the player is too far away.");
break;
}
local inv1 = player.GetInventoryTable();
inv1[::LastItemToTransfer] -= 1;
local inv2 = client.GetInventoryTable();
if (!(::LastItemToTransfer in inv2))
inv2[::LastItemToTransfer] <- 0;
inv2[::LastItemToTransfer] += 1;
Utils.PlaySoundToAll("ambient.electrical_zap_5");
Utils.SayToAll("%s gave %s to %s.", player.GetName(), ::LastItemToTransfer, client.GetName());
break;
}
}
// Constructs the Give menu
::GiveInvItem <- function (player, item)
{
::LastItemToTransfer <- item;
InventoryHUD <- HUD.Menu(player.GetName() + "\nGive to player:\n\n{options}");
local count = 0;
foreach (client in Players.AliveSurvivors())
if (!client.IsBot() && client.GetName() != "" && client.GetIndex() != player.GetIndex())
{
count++;
InventoryHUD.AddOption(client.GetName(), TransferItem);
}
InventoryHUD.AddOption("Cancel", HUDDoNothing);
if (count > 0)
{
InventoryHUD.DisplayMenu(player, HUD_TICKER, true);
InventoryHUD.OverrideButtons(BUTTON_WALK, BUTTON_SHOVE);
}
else
Utils.SayToAllDel("Cannot give any item at the moment. Please try again later!");
}
// Does nothing.
::HUDDoNothing <- function(player, index, value)
{
}
// Consumes food from inventory
::EatFoodInv <- function(player, index, value)
{
::Food[player.GetIndex()] <- 100;
local inv = player.GetInventoryTable();
inv["food"] -= 1;
Utils.SayToAll("%s ate some food!", player.GetName());
}
// Opens Give menu
::GiveFoodInv <- function(player, index, value)
{
GiveInvItem(player, "food");
}
// Open secondary Inv
::EatFood <- function(player, index, value)
{
InventoryHUD <- HUD.Menu(player.GetName() + "\n[Item] Food:\n\n{options}");
InventoryHUD.AddOption("Eat", EatFoodInv);
InventoryHUD.AddOption("Give", GiveFoodInv);
InventoryHUD.AddOption("Cancel", HUDDoNothing);
InventoryHUD.DisplayMenu(player, HUD_TICKER, true);
InventoryHUD.OverrideButtons(BUTTON_WALK, BUTTON_SHOVE);
}
// Opens Give menu
::GiveWaterInv <- function(player, index, value)
{
GiveInvItem(player, "water");
}
// Consumes water from inv
::DrinkWaterInv <- function(player, index, value)
{
::Water[player.GetIndex()] <- 100;
local inv = player.GetInventoryTable();
inv["water"] -= 1;
// Reset B&W
player.SetReviveCount(0);
Utils.SayToAll("%s drank some water!", player.GetName());
}
// Opens drink menu
::DrinkWater <- function(player, index, value)
{
InventoryHUD <- HUD.Menu(player.GetName() + "\n[Item] Water:\n\n{options}");
InventoryHUD.AddOption("Drink", DrinkWaterInv);
InventoryHUD.AddOption("Give", GiveWaterInv);
InventoryHUD.AddOption("Cancel", HUDDoNothing);
InventoryHUD.DisplayMenu(player, HUD_TICKER, true);
InventoryHUD.OverrideButtons(BUTTON_WALK, BUTTON_SHOVE);
}
// Opens !inv
function EasyLogic::Triggers::inv ( player, args, text )
{
if (::InventoryHUD != null)
{
Utils.SayToAllDel("%s: A round stats menu is already open.", player.GetName());
return;
}
local inv = player.GetInventoryTable();
InventoryHUD <- HUD.Menu("Inventory:\n" + player.GetName() + "\n\n{options}");
local count = 0;
foreach (item, value in inv)
{
if (value <= 0)
continue;
count++;
if (item == "food")
InventoryHUD.AddOption("Food (x" + value + ")", EatFood);
else if (item == "water")
InventoryHUD.AddOption("Water (x" + value + ")", DrinkWater);
}
if (count <= 0)