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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
|
include( 'player_class/player_base.lua' )
include( 'player_class/player_zombie.lua' )
include( 'map_defaults.lua' )
include( 'resource.lua' )
include( 'enums.lua' )
include( 'items.lua' )
include( 'events.lua' )
include( 'shared.lua' )
include( 'moddable.lua' )
include( 'ply_extension.lua' )
include( 'tables.lua' )
include( 'weather.lua' )
AddCSLuaFile( 'player_class/player_base.lua' )
AddCSLuaFile( 'player_class/player_zombie.lua' )
AddCSLuaFile( 'animations.lua' )
AddCSLuaFile( 'enums.lua' )
AddCSLuaFile( 'items.lua' )
AddCSLuaFile( 'shared.lua' )
AddCSLuaFile( 'moddable.lua' )
AddCSLuaFile( 'cl_notice.lua' )
AddCSLuaFile( 'cl_hudstains.lua' )
AddCSLuaFile( 'cl_targetid.lua' )
AddCSLuaFile( 'cl_spawnmenu.lua' )
AddCSLuaFile( 'cl_inventory.lua' )
AddCSLuaFile( 'cl_init.lua' )
AddCSLuaFile( 'cl_postprocess.lua' )
AddCSLuaFile( 'cl_scoreboard.lua' )
AddCSLuaFile( 'ply_extension.lua' )
AddCSLuaFile( 'tables.lua' )
AddCSLuaFile( 'weather.lua' )
AddCSLuaFile( 'vgui/vgui_panelbase.lua' )
AddCSLuaFile( 'vgui/vgui_dialogue.lua' )
AddCSLuaFile( 'vgui/vgui_shopmenu.lua' )
AddCSLuaFile( 'vgui/vgui_classpicker.lua' )
AddCSLuaFile( 'vgui/vgui_zombieclasses.lua' )
AddCSLuaFile( 'vgui/vgui_itempanel.lua' )
AddCSLuaFile( 'vgui/vgui_helpmenu.lua' )
AddCSLuaFile( 'vgui/vgui_endgame.lua' )
AddCSLuaFile( 'vgui/vgui_itemdisplay.lua' )
AddCSLuaFile( 'vgui/vgui_playerdisplay.lua' )
AddCSLuaFile( 'vgui/vgui_playerpanel.lua' )
AddCSLuaFile( 'vgui/vgui_panelsheet.lua' )
AddCSLuaFile( 'vgui/vgui_goodmodelpanel.lua' )
AddCSLuaFile( 'vgui/vgui_categorybutton.lua' )
AddCSLuaFile( 'vgui/vgui_sidebutton.lua' )
AddCSLuaFile( 'vgui/vgui_scroller.lua' )
util.AddNetworkString( "InventorySynch" )
util.AddNetworkString( "StashSynch" )
util.AddNetworkString( "StatsSynch" )
util.AddNetworkString( "ItemPlacerSynch" )
util.AddNetworkString( "WeatherSynch" )
function GM:Initialize()
GAMEMODE.NextZombieThink = CurTime() + GetConVar( "sv_redead_setup_time" ):GetInt()
GAMEMODE.RandomLoot = {}
GAMEMODE.PlayerIDs = {}
GAMEMODE.Lords = {}
GAMEMODE.Wave = 1
GAMEMODE.NextWave = CurTime() + 60 * GetConVar( "sv_redead_wave_length" ):GetInt()
local length = #GAMEMODE.Waves * ( GetConVar( "sv_redead_wave_length" ):GetInt() * 60 )
for i=1, #GAMEMODE.Waves - 1 do
local remain = length - i * GetConVar( "sv_redead_wave_length" ):GetInt() * 60
local num = i * GetConVar( "sv_redead_wave_length" ):GetInt()
timer.Simple( remain, function() for k,v in pairs( team.GetPlayers( TEAM_ARMY ) ) do v:Notice( num .. " minutes until evac arrives", GAMEMODE.Colors.White, 5 ) end end )
end
timer.Simple( GetConVar( "sv_redead_setup_time" ):GetInt(), function() for k,v in pairs( player.GetAll() ) do v:Notice( "The undead onslaught has begun", GAMEMODE.Colors.White, 5 ) end end )
timer.Simple( GetConVar( "sv_redead_setup_time" ):GetInt() - 5, function() for k,v in pairs( team.GetPlayers( TEAM_ARMY ) ) do v:Notice( "Press F4 if you want to be the zombie lord", GAMEMODE.Colors.White, 5 ) end end )
timer.Simple( GetConVar( "sv_redead_setup_time" ):GetInt() + 5, function() GAMEMODE:PickLord() GAMEMODE.EarlyPick = true end )
timer.Simple( length - 60, function()
if GetGlobalBool( "GameOver", false ) then return end
GAMEMODE.EvacAlert = true
for k,v in pairs( player.GetAll() ) do
v:ClientSound( GAMEMODE.LastMinute )
v:Notice( "The evac chopper is en route", GAMEMODE.Colors.White, 5 )
end
end )
timer.Simple( length - 40, function()
if GetGlobalBool( "GameOver", false ) then return end
for k,v in pairs( team.GetPlayers( TEAM_ARMY ) ) do
v:Notice( "The evac chopper has arrived", GAMEMODE.Colors.White, 5 )
v:Notice( "You have 45 seconds to reach the evac zone", GAMEMODE.Colors.White, 5, 2 )
v:Notice( "The location has been marked", GAMEMODE.Colors.White, 5, 4 )
end
if IsValid( GAMEMODE.Antidote ) then
GAMEMODE.Antidote:SetOverride()
end
GAMEMODE:SpawnEvac()
end )
timer.Simple( length + 5, function() GAMEMODE:CheckGameOver( true ) end )
GAMEMODE:WeatherInit()
if math.random( 1, 10 ) == 1 then
GAMEMODE.RandomEvent = CurTime() + ( 60 * math.Rand( 1.5, 3.5 ) )
end
end
GM.Breakables = {}
GM.WoodLocations = {}
GM.WoodCount = 1
GM.WoodPercent = 1
GM.SpawnCounter = 0
GM.LordExists = false
GM.EarlyPick = false
function GM:InitPostEntity()
GAMEMODE.Trader = ents.Create( "info_trader" )
GAMEMODE.Trader:Spawn()
GAMEMODE.SpecialTrader = ents.Create( "info_trader" )
GAMEMODE.SpecialTrader:SetSpecial( true )
GAMEMODE.SpecialTrader:Spawn()
local badshit = ents.FindByClass( "npc_*" )
badshit = table.Add( badshit, ents.FindByClass( "weapon_*" ) )
badshit = table.Add( badshit, ents.FindByClass( "prop_ragdoll" ) )
badshit = table.Add( badshit, ents.FindByClass( "item_*" ) )
badshit = table.Add( badshit, ents.FindByClass( "point_servercommand" ) )
badshit = table.Add( badshit, ents.FindByClass( "env_entity_maker" ) )
badshit = table.Add( badshit, ents.FindByClass( "point_template" ) )
badshit = table.Add( badshit, ents.FindByClass( "game_text" ) )
for k,v in pairs( ents.FindByClass( "prop_phys*" ) ) do
if string.find( v:GetModel(), "explosive" ) or string.find( v:GetModel(), "propane" ) or string.find( v:GetModel(), "gascan" ) or string.find( v:GetModel(), "gib" ) then
table.insert( badshit, v )
end
local phys = v:GetPhysicsObject()
if IsValid( phys ) and table.HasValue( { "wood", "wood_crate", "wood_furniture", "wood_plank", "default" }, phys:GetMaterial() ) and phys:GetMass() > 8 then
table.insert( GAMEMODE.WoodLocations, { Pos = v:GetPos(), Ang = v:GetAngles(), Model = v:GetModel(), Health = v:Health() } )
GAMEMODE.WoodCount = GAMEMODE.WoodCount + 1
v.IsWooden = true
if v:Health() == 0 then
v:SetHealth( 100 )
end
if phys:IsAsleep() then
phys:Wake()
end
end
end
for k,v in pairs( badshit ) do
v:Remove()
end
GAMEMODE.WoodPercent = math.floor( table.Count( ents.FindByClass( "prop_phys*" ) ) * GAMEMODE.WoodPercentage )
for k,v in pairs( ents.FindByClass( "prop_phys*" ) ) do
local tbl = item.GetByModel( v:GetModel() )
local phys = v:GetPhysicsObject()
if tbl or ( IsValid( phys ) and phys:GetMass() <= 3 ) then
v:Remove()
end
end
GAMEMODE:LoadAllEnts()
local tbl = ents.FindByClass( "prop_door_rotating" )
tbl = table.Add( tbl, ents.FindByClass( "func_breakable*" ) )
tbl = table.Add( tbl, ents.FindByClass( "func_door*" ) )
GAMEMODE.Breakables = tbl
GAMEMODE.NPCSpawns = ents.FindByClass( "info_npcspawn" )
local num = #ents.FindByClass( "point_radiation" )
if num < 5 then return end
for i=1, math.floor( num * GAMEMODE.RadiationAmount ) do
local rad = table.Random( ents.FindByClass( "point_radiation" ) )
while !rad:IsActive() do
rad = table.Random( ents.FindByClass( "point_radiation" ) )
end
rad:SetActive( false )
end
end
function GM:SaveAllEnts()
MsgN( "Saving ReDead map config data..." )
local enttbl = {
info_player_zombie = {},
info_player_army = {},
info_lootspawn = {},
info_npcspawn = {},
info_evac = {},
point_stash = {},
point_radiation = {},
prop_physics = {}
}
for k,v in pairs( enttbl ) do
for c,d in pairs( ents.FindByClass( k ) ) do
if k == "prop_physics" then
if d.AdminPlaced then
local phys = d:GetPhysicsObject()
if IsValid( phys ) then
table.insert( enttbl[k], { d:GetPos(), d:GetModel(), d:GetAngles(), phys:IsMoveable() } )
end
end
elseif d.AdminPlaced then
table.insert( enttbl[k], d:GetPos() )
end
end
end
file.Write( "redead/" .. string.lower( game.GetMap() ) .. "_json.txt", util.TableToJSON( enttbl ) )
end
function GM:LoadAllEnts()
MsgN( "Loading ReDead map config data..." )
local read = file.Read( "redead/" .. string.lower( game.GetMap() ) .. "_json.txt", "DATA" )
if not read then
MsgN( "No map config data found for " .. game.GetMap() .. "." )
return
end
local config = util.JSONToTable( read )
if not config then
MsgN( "ERROR: ReDead map config data file was empty!" )
return
end
MsgN( "Loaded ReDead map config data successfully!" )
for k,v in pairs( config ) do
if v[1] then
if k == "prop_physics" then
for c,d in pairs( v ) do
local function spawnent()
local ent = ents.Create( k )
ent:SetPos( d[1] )
ent:SetModel( d[2] )
ent:SetAngles( d[3] )
ent:SetSkin( math.random( 0, 6 ) )
ent:Spawn()
ent.AdminPlaced = true
local phys = ent:GetPhysicsObject()
if IsValid( phys ) and not d[4] then
phys:EnableMotion( false )
end
end
timer.Simple( c * 0.1, function() spawnent() end )
end
else
for c,d in pairs( ents.FindByClass( k ) ) do
d:Remove()
end
for c,d in pairs( v ) do
if k != "point_radiation" and k != "info_lootspawn" and k != "info_npcspawn" then
local function spawnent()
local ent = ents.Create( k )
ent:SetPos( d )
ent:Spawn()
ent.AdminPlaced = true
end
timer.Simple( c * 0.1, function() spawnent() end )
else
local ent = ents.Create( k )
ent:SetPos( d )
ent:Spawn()
ent.AdminPlaced = true
end
end
end
end
end
end
function GM:AddToZombieList( ply )
if team.NumPlayers( TEAM_ZOMBIES ) > 0 then
ply:ClientSound( "HL1/fvox/buzz.wav", 100 )
ply:Notice( "You cannot be the zombie lord now", GAMEMODE.Colors.Red, 5 )
return
end
if not table.HasValue( GAMEMODE.Lords, ply ) and not GAMEMODE.LordExists then
table.insert( GAMEMODE.Lords, ply )
local snd = table.Random( GAMEMODE.AmbientScream )
ply:ClientSound( snd, 100 )
ply:Notice( "You have volunteered to be the zombie lord", GAMEMODE.Colors.White, 5 )
end
end
function GM:PickLord( force )
if table.Count( player.GetAll() ) < GetConVar( "sv_redead_minimum_players" ):GetInt() and not force then
for k,v in pairs( player.GetAll() ) do
v:Notice( "A zombie lord cannot be chosen at this time", GAMEMODE.Colors.White, 5 )
end
return
end
local tbl = team.GetPlayers( TEAM_ZOMBIES )
for k,v in pairs( GAMEMODE.Lords ) do
if IsValid( v ) then
table.insert( tbl, v )
end
end
if table.Count( tbl ) < 1 then
tbl = team.GetPlayers( TEAM_ARMY )
end
local ply = table.Random( tbl )
local snd = table.Random( GAMEMODE.AmbientScream )
ply:ClientSound( snd, 100 )
if ply:Team() == TEAM_ZOMBIES then
ply:Notice( "You have become the zombie lord", GAMEMODE.Colors.White, 5 )
timer.Simple( 3, function() ply:Gib() ply:SetLord( true ) end )
else
ply:Notice( "You will become the zombie lord", GAMEMODE.Colors.White, 5 )
timer.Simple( 3, function() ply:SetTeam( TEAM_ZOMBIES ) ply:SetPlayerClass( CLASS_RUNNER ) ply:SetCash( 0 ) ply:Gib() ply:SetLord( true ) end )
end
for k,v in pairs( player.GetAll() ) do
if v != ply and not force then
v:Notice( "A zombie lord has been chosen", GAMEMODE.Colors.White, 5 )
end
end
GAMEMODE.LordExists = true
end
function GM:RespawnAntidote()
if IsValid( ents.FindByClass( "sent_antidote" )[1] ) and ents.FindByClass( "sent_antidote" )[1]:CuresLeft() > 0 then return end
if #ents.FindByClass( "info_lootspawn" ) < 3 then return end
local ent = table.Random( ents.FindByClass( "info_lootspawn" ) )
local pos = ent:GetPos()
local close = true
while close do
ent = table.Random( ents.FindByClass( "info_lootspawn" ) )
pos = ent:GetPos()
close = false
for k,v in pairs( ents.FindByClass( "sent_antidote" ) ) do
if v:GetPos():Distance( pos ) < 500 then
close = true
end
end
end
local ant = ents.Create( "sent_antidote" )
ant:SetPos( pos )
ant:Spawn()
GAMEMODE.Antidote = ant
for k,v in pairs( team.GetPlayers( TEAM_ARMY ) ) do
v:Notice( "The antidote resupply location has changed", GAMEMODE.Colors.White, 5 )
end
end
function GM:SpawnEvac()
local pos = Vector(0,0,0)
if #ents.FindByClass( "info_evac" ) < 1 then
local loot = ents.FindByClass( "info_lootspawn" )
if #loot < 1 then
MsgN( "ERROR: Map not configured properly." )
return
end
local prop = table.Random( loot )
pos = prop:GetPos()
else
local point = table.Random( ents.FindByClass( "info_evac" ) )
pos = point:GetPos()
end
local evac = ents.Create( "point_evac" )
evac:SetPos( pos )
evac:Spawn()
end
function GM:GetGeneratedLoot()
local tbl = {}
for k,v in pairs( GAMEMODE.RandomLoot ) do
if IsValid( v ) then
table.insert( tbl, v )
end
end
for k,v in pairs( GAMEMODE.RandomLoot ) do
if not IsValid( v ) then
table.remove( tbl, k )
return tbl
end
end
return tbl
end
function GM:LootThink()
for k,v in pairs( ents.FindByClass( "prop_phys*" ) ) do
if v.Removal and v.Removal < CurTime() and IsValid( v ) then
v:Remove()
end
end
if #ents.FindByClass( "info_lootspawn" ) < 10 then return end
local amt = math.floor( GAMEMODE.MaxLoot * #ents.FindByClass( "info_lootspawn" ) )
local total = 0
local loots = GAMEMODE:GetGeneratedLoot()
local num = amt - #loots
if num > 0 then
local tbl = { ITEM_SUPPLY, ITEM_LOOT, ITEM_AMMO, ITEM_MISC, ITEM_SPECIAL, ITEM_WPN_COMMON, ITEM_WPN_SPECIAL, ITEM_EXPLOSIVE }
local chancetbl = { 0.60, 0.70, 0.70, 0.95, 0.05, 0.03, 0.02, 0.10 }
for i=1, num do
local ent = table.Random( ents.FindByClass( "info_lootspawn" ) )
local pos = ent:GetPos()
local rnd = math.Rand(0,1)
local choice = math.random( 1, table.Count( tbl ) )
while rnd > chancetbl[ choice ] do
rnd = math.Rand(0,1)
choice = math.random( 1, table.Count( tbl ) )
end
local rand = item.RandomItem( tbl[choice] )
local proptype = "prop_physics"
if rand.TypeOverride then
proptype = rand.TypeOverride
end
local loot = ents.Create( proptype )
loot:SetPos( pos + Vector(0,0,5) )
loot:SetAngles( VectorRand():Angle() )
if rand.DropModel then
loot:SetModel( rand.DropModel )
else
loot:SetModel( rand.Model )
end
loot:Spawn()
loot.RandomLoot = true
loot.IsItem = true
if not rand.CollisionOverride then
loot:SetCollisionGroup( COLLISION_GROUP_WEAPON )
end
table.insert( GAMEMODE.RandomLoot, loot )
end
end
end
function GM:WoodThink()
if table.Count( GAMEMODE.WoodLocations ) < 1 then return end
if GAMEMODE.WoodCount < GAMEMODE.WoodPercent then
local tbl = table.Random( GAMEMODE.WoodLocations )
local prop = ents.Create( "prop_physics" )
prop:SetPos( tbl.Pos )
prop:SetAngles( tbl.Ang )
prop:SetModel( tbl.Model )
prop:SetHealth( math.Clamp( tbl.Health, 50, 500 ) )
prop:Spawn()
prop.IsWooden = true
GAMEMODE.WoodCount = GAMEMODE.WoodCount + 1
elseif GAMEMODE.WoodCount > GAMEMODE.WoodPercent then
local ent = table.Random( ents.FindByClass( "prop_phys*" ) )
local phys = ent:GetPhysicsObject()
if IsValid( phys ) and not ent.IsItem and ent.IsWooden then
ent:Remove()
GAMEMODE.WoodCount = GAMEMODE.WoodCount - 1
end
end
end
function GM:EventThink()
if not GAMEMODE.RandomEvent then
GAMEMODE.RandomEvent = CurTime() + ( 60 * math.Rand( 3.5, 9.5 ) )
end
if GAMEMODE.RandomEvent and GAMEMODE.RandomEvent < CurTime() then
local ev = event.GetRandom()
while ( ( ev.Type == EVENT_WEATHER and GAMEMODE.WeatherHappened ) or ev.Chance < math.Rand(0,1) ) do
ev = event.GetRandom()
end
if ev.Type == EVENT_WEATHER then
GAMEMODE.WeatherHappened = true
end
ev.Start()
GAMEMODE.Event = ev
GAMEMODE.RandomEvent = nil
end
if GAMEMODE.Event then
GAMEMODE.Event:Think()
if GAMEMODE.Event:EndThink() then
GAMEMODE.Event:End()
GAMEMODE.Event = nil
end
end
end
function GM:WaveThink()
if GAMEMODE.NextWave < CurTime() then
GAMEMODE.NextWave = CurTime() + 60 * GetConVar( "sv_redead_wave_length" ):GetInt()
GAMEMODE.Wave = GAMEMODE.Wave + 1
if GAMEMODE.Wave > #GAMEMODE.Waves then return end
for k,v in pairs( player.GetAll() ) do
v:Notice( "New undead mutations have been spotted", GAMEMODE.Colors.White, 5 )
v:ClientSound( table.Random( GAMEMODE.AmbientScream ) )
end
end
end
function GM:GetZombieClass()
local rand = math.Rand(0,1)
local class = table.Random( GAMEMODE.Waves[ GAMEMODE.Wave ] or { "npc_nb_common" } )
while #GAMEMODE.Waves[ GAMEMODE.Wave ] != 1 and rand > GAMEMODE.SpawnChance[ class ] do
rand = math.Rand(0,1)
class = table.Random( GAMEMODE.Waves[ GAMEMODE.Wave ] or { "npc_nb_common" } )
end
return class
end
function GM:NPCRespawnThink()
for k,v in pairs( ( GAMEMODE.NPCSpawns or {} ) ) do
if IsValid( v ) then
local box = ents.FindInBox( v:GetPos() + Vector( -32, -32, 0 ), v:GetPos() + Vector( 32, 32, 64 ) )
local can = true
for k,v in pairs( box ) do
if v.NextBot then
can = false
end
end
if can and GAMEMODE.SpawnCounter > 0 then
local ent = ents.Create( GAMEMODE:GetZombieClass() )
ent:SetPos( v:GetPos() )
ent:Spawn()
GAMEMODE.SpawnCounter = GAMEMODE.SpawnCounter - 1
end
end
end
end
function GM:NPCThink()
if GAMEMODE.Wave > #GAMEMODE.Waves then return end
local tbl = ents.FindByClass( "npc_nb*" )
if #tbl < GetConVar( "sv_redead_max_zombies" ):GetInt() and #tbl < GetConVar( "sv_redead_zombies_per_player" ):GetInt() * team.NumPlayers( TEAM_ARMY ) then
local total = math.Round( GetConVar( "sv_redead_zombies_per_player" ):GetInt() * team.NumPlayers( TEAM_ARMY ) + GetConVar( "sv_redead_zombies_per_player_zombie" ):GetFloat() * team.NumPlayers( TEAM_ZOMBIES ) )
local num = math.Clamp( total, 1, math.Min( GetConVar( "sv_redead_max_zombies" ):GetInt() - #tbl, total ) )
GAMEMODE.SpawnCounter = num
--[[for i=1, num do
local tbl = ents.FindByClass( "info_npcspawn" )
if #tbl < 1 then return end
local spawn = table.Random( tbl )
local vec = VectorRand() * 5
vec.z = 1
local ent = ents.Create( GAMEMODE:GetZombieClass() )
ent:SetPos( spawn:GetPos() + vec )
ent:Spawn()
end]]
end
end
function GM:Think()
if ( GAMEMODE.NextGameThink or 0 ) < CurTime() then
if ( GAMEMODE.NextZombieThink or 0 ) < CurTime() then
GAMEMODE:NPCThink()
GAMEMODE.NextZombieThink = CurTime() + GetConVar( "sv_redead_wave_time" ):GetInt()
end
GAMEMODE:NPCRespawnThink()
GAMEMODE:RespawnAntidote()
GAMEMODE:EventThink()
GAMEMODE:LootThink()
GAMEMODE:WoodThink()
GAMEMODE:WaveThink()
GAMEMODE:WeatherThink()
GAMEMODE:CheckGameOver( false )
GAMEMODE.NextGameThink = CurTime() + 1
end
for k,v in pairs( player.GetAll() ) do
if v:Team() != TEAM_UNASSIGNED then
v:Think()
end
end
end
function GM:PhysgunPickup( ply, ent )
if ply:IsAdmin() or ply:IsSuperAdmin() then return true end
if ent:IsPlayer() then return false end
if not ent.Placer or ent.Placer != ply then return false end
return true
end
function GM:PlayerDisconnected( pl )
if pl:Alive() then
pl:DropLoot()
end
if not table.HasValue( GAMEMODE.PlayerIDs, pl:SteamID() ) then
table.insert( GAMEMODE.PlayerIDs, pl:SteamID() )
end
if pl:IsLord() then
GAMEMODE.LordExists = false
end
end
function GM:PlayerInitialSpawn( pl )
pl:GiveAmmo( 200, "Pistol", false )
if table.HasValue( GAMEMODE.PlayerIDs, pl:SteamID() ) then
pl:SetTeam( TEAM_ZOMBIES )
elseif pl:IsBot() then
pl:SetTeam( TEAM_ARMY )
pl:Spawn()
else
pl:SetTeam( TEAM_UNASSIGNED )
pl:Spectate( OBS_MODE_ROAMING )
end
end
function GM:PlayerSpawn( pl )
if pl:Team() == TEAM_UNASSIGNED then
pl:Spectate( OBS_MODE_ROAMING )
pl:SetPos( pl:GetPos() + Vector( 0, 0, 50 ) )
return
end
GAMEMODE:RespawnAntidote()
if pl:Team() == TEAM_ARMY then
local music = table.Random( GAMEMODE.OpeningMusic )
pl:ClientSound( music, 100 )
end
pl:NoticeOnce( "Press F1 to view the help menu", GAMEMODE.Colors.Blue, 7, 15 )
pl:NoticeOnce( "Press F2 to buy items and weapons", GAMEMODE.Colors.Blue, 7, 17 )
pl:NoticeOnce( "Press F3 to activate the panic button", GAMEMODE.Colors.Blue, 7, 19 )
pl:InitializeInventory()
pl:OnSpawn()
pl:OnLoadout()
local oldhands = pl:GetHands()
if IsValid( oldhands ) then
oldhands:Remove()
end
local hands = ents.Create( "gmod_hands" )
if IsValid( hands ) then
hands:DoSetup( pl )
hands:Spawn()
end
end
function GM:PlayerSetModel( pl )
end
function GM:PlayerLoadout( pl )
end
function GM:PlayerJoinTeam( ply, teamid )
local oldteam = ply:Team()
if ply:Alive() and ply:Team() != TEAM_UNASSIGNED then return end
if teamid != TEAM_UNASSIGNED and ply:Team() == TEAM_UNASSIGNED then
ply:UnSpectate()
end
if teamid == TEAM_SPECTATOR or teamid == TEAM_UNASSIGNED then
teamid = TEAM_ARMY
end
ply:SetTeam( teamid )
if ply.NextSpawn and ply.NextSpawn > CurTime() then
ply.NextSpawn = CurTime() + 5
else
ply:Spawn()
end
end
function GM:PlayerSwitchFlashlight( ply, on )
return ply:Team() == TEAM_ARMY
end
function GM:GetFallDamage( ply, speed )
if ply:Team() == TEAM_ZOMBIES then
return 5
end
local pain = speed * 0.12
ply:AddStamina( math.floor( pain * -0.25 ) )
return pain
end
function GM:PlayerDeathSound()
return true
end
function GM:CanPlayerSuicide( ply )
return false
end
function GM:KeyRelease( ply, key )
if ply:Team() != TEAM_ARMY then return end
if key == IN_JUMP then
ply:AddStamina( -2 )
end
if key != IN_USE then return end
local trace = {}
trace.start = ply:GetShootPos()
trace.endpos = trace.start + ply:GetAimVector() * 80
trace.filter = ply
local tr = util.TraceLine( trace )
if IsValid( tr.Entity ) and tr.Entity:GetClass() == "prop_physics" then
if IsValid( ply.Stash ) then
ply.Stash:OnExit( ply )
return true
end
ply:AddToInventory( tr.Entity )
return true
elseif IsValid( tr.Entity ) and tr.Entity:GetClass() == "point_stash" then
if IsValid( ply.Stash ) then
ply.Stash:OnExit( ply )
else
tr.Entity:OnUsed( ply )
end
elseif not IsValid( tr.Entity ) then
if IsValid( ply.Stash ) then
ply.Stash:OnExit( ply )
end
end
return true
end
function GM:PropBreak( att, prop )
local phys = prop:GetPhysicsObject()
if IsValid( phys ) and prop:GetModel() != "models/props_debris/wood_board04a.mdl" then
if prop.IsWooden or (ent:GetMaterialType() == MAT_WOOD) then
GAMEMODE:SpawnChunk( prop:LocalToWorld( prop:OBBCenter() ) )
GAMEMODE.WoodCount = GAMEMODE.WoodCount - 1
end
end
end
function GM:SpawnChunk( pos )
local ent = ents.Create( "prop_physics" )
ent:SetPos( pos )
ent:SetModel( "models/props_debris/wood_chunk04a.mdl" )
ent:SetCollisionGroup( COLLISION_GROUP_WEAPON )
ent:Spawn()
ent.IsItem = true
end
function GM:AllowPlayerPickup( ply, ent )
local tbl = item.GetByModel( ent:GetModel() )
if tbl and tbl.AllowPickup then
return true
end
return false
end
function GM:PlayerUse( ply, entity )
if ply:Team() == TEAM_ARMY and ( ply.LastUse or 0 ) < CurTime() then
if table.HasValue( { "sent_propane_canister", "sent_propane_tank", "sent_fuel_diesel", "sent_fuel_gas" }, entity:GetClass() ) then
ply.LastUse = CurTime() + 0.5
if not IsValid( ply.HeldObject ) and not IsValid( entity.Holder ) then
ply:PickupObject( entity )
ply.HeldObject = entity
entity.Holder = ply
entity:SetCollisionGroup( COLLISION_GROUP_WEAPON )
elseif entity == ply.HeldObject then
ply:DropObject( entity )
ply.HeldObject = nil
entity.Holder = nil
entity:SetCollisionGroup( COLLISION_GROUP_NONE )
end
end
return true
end
if ply:Team() != TEAM_ZOMBIES then return false end
local trace = {}
trace.start = ply:GetShootPos()
trace.endpos = trace.start + ply:GetAimVector() * 80
trace.filter = ply
local tr = util.TraceLine( trace )
if entity:GetClass() == "prop_door_rotating" or entity:GetClass() == "func_button" then
return false
end
return true
end
function GM:EntityTakeDamage( ent, dmginfo )
if ent.IsWooden then
ent.WoodHealth = ( ent.WoodHealth or 150 ) - dmginfo:GetDamage()
if ent.WoodHealth < 1 then
ent:Fire( "break", 0, 0 )
end
end
if not ent:IsPlayer() and ent:IsOnFire() then
ent:Extinguish()
end
if not ent:IsPlayer() and ent.IsItem then
dmginfo:ScaleDamage( 0 )
return
end
local attacker = dmginfo:GetAttacker()
if ent:IsPlayer() and ent:Team() == TEAM_ARMY and IsValid( attacker ) and ( attacker:IsNPC() or ( ( attacker:IsPlayer() and attacker:Team() == TEAM_ZOMBIES ) or ( attacker:IsPlayer() and attacker == ent ) ) ) then
if ent:Health() <= 50 then
ent:NoticeOnce( "Your health has dropped below 30%", GAMEMODE.Colors.Red, 5 )
ent:NoticeOnce( "Health doesn't regenerate when below 30%", GAMEMODE.Colors.Blue, 5, 2 )
end
if dmginfo:IsDamageType( DMG_BURN ) then
ent:ViewBounce( 30 )
else
ent:ViewBounce( 25 )
ent:RadioSound( VO_PAIN )
ent:DrawBlood()
end
if ent:GetPlayerClass() == CLASS_COMMANDO then
dmginfo:ScaleDamage( GetConVar( "sv_redead_dmg_scale" ):GetFloat() * 0.85 )
else
dmginfo:ScaleDamage( GetConVar( "sv_redead_dmg_scale" ):GetFloat() )
end
if dmginfo:IsExplosionDamage() and attacker:Team() == TEAM_ZOMBIES then
dmginfo:ScaleDamage( 0 )
else
ent:AddStat( "Damage", math.Round( dmginfo:GetDamage() ) )
--[[if attacker:IsPlayer() then
attacker:AddZedDamage( math.Round( dmginfo:GetDamage() ) )
end]]
end
elseif ent:IsPlayer() and ent:Team() == TEAM_ZOMBIES and IsValid( attacker ) and attacker:IsPlayer() and dmginfo:GetDamage() > 30 then
sound.Play( table.Random( GAMEMODE.GoreBullet ), ent:GetPos() + Vector(0,0,50), 75, math.random( 90, 110 ), 0.8 )
end
return self.BaseClass:EntityTakeDamage( ent, dmginfo )
end
function GM:ScaleNPCDamage( npc, hitgroup, dmginfo ) // obsolete!
if hitgroup == HITGROUP_HEAD then
npc:EmitSound( "Player.DamageHeadShot" )
npc:SetHeadshotter( dmginfo:GetAttacker(), true )
local effectdata = EffectData()
effectdata:SetOrigin( dmginfo:GetDamagePosition() )
util.Effect( "headshot", effectdata, true, true )
dmginfo:ScaleDamage( math.Rand( 2.50, 3.00 ) )
dmginfo:GetAttacker():NoticeOnce( "Headshot combos earn you more " .. GAMEMODE.CurrencyName .. "s", GAMEMODE.Colors.Blue, 5 )
dmginfo:GetAttacker():AddHeadshot()
elseif hitgroup == HITGROUP_CHEST then
dmginfo:ScaleDamage( 1.25 )
npc:SetHeadshotter( dmginfo:GetAttacker(), false )
dmginfo:GetAttacker():ResetHeadshots()
elseif hitgroup == HITGROUP_STOMACH then
dmginfo:ScaleDamage( 0.75 )
npc:SetHeadshotter( dmginfo:GetAttacker(), false )
dmginfo:GetAttacker():ResetHeadshots()
else
dmginfo:ScaleDamage( 0.50 )
npc:SetHeadshotter( dmginfo:GetAttacker(), false )
dmginfo:GetAttacker():ResetHeadshots()
end
return dmginfo
end
function GM:ScalePlayerDamage( ply, hitgroup, dmginfo )
if IsValid( ply.Stash ) then
return
end
if hitgroup == HITGROUP_HEAD then
ply:EmitSound( "Player.DamageHeadShot" )
ply:ViewBounce( 25 )
dmginfo:ScaleDamage( 1.75 * GetConVar( "sv_redead_dmg_scale" ):GetFloat() )
return
elseif hitgroup == HITGROUP_CHEST then
ply:ViewBounce( 15 )
dmginfo:ScaleDamage( 1.50 * GetConVar( "sv_redead_dmg_scale" ):GetFloat() )
return
elseif hitgroup == HITGROUP_STOMACH then
dmginfo:ScaleDamage( 1.25 * GetConVar( "sv_redead_dmg_scale" ):GetFloat() )
else
dmginfo:ScaleDamage( 0.50 * GetConVar( "sv_redead_dmg_scale" ):GetFloat() )
end
ply:ViewBounce( ( dmginfo:GetDamage() / 20 ) * 10 )
end
function GM:PlayerShouldTakeDamage( ply, attacker )
if ply:Team() == TEAM_UNASSIGNED then return false end
if IsValid( attacker ) and attacker:IsPlayer() and attacker != ply then
return ( ply:Team() != attacker:Team() or GetConVar( "sv_redead_team_dmg" ):GetBool() )
end
return true
end
function GM:OnDamagedByExplosion( ply, dmginfo )
if dmginfo:GetDamage() > 25 then
ply:SetBleeding( true )
end
ply:SetDSP( 35, false )
umsg.Start( "GrenadeHit", ply )
umsg.End()
end
function GM:PlayerDeathThink( ply )
if ply.NextSpawn and ply.NextSpawn > CurTime() then return end
if ply:KeyDown( IN_JUMP ) or ply:KeyDown( IN_ATTACK ) or ply:KeyDown( IN_ATTACK2 ) then
ply:Spawn()
end
end
function GM:DoPlayerDeath( ply, attacker, dmginfo )
ply:OnDeath()
if ply:Team() == TEAM_ARMY then
if team.NumPlayers( TEAM_ZOMBIES ) < 1 then
ply:AddStat( "Martyr" )
end
local music = table.Random( GAMEMODE.DeathMusic )
ply:ClientSound( music, 100 )
ply:RadioSound( VO_DEATH )
ply:SetTeam( TEAM_ZOMBIES )
if not GAMEMODE.LordExists and GAMEMODE.EarlyPick then
GAMEMODE:PickLord( true )
end
if IsValid( attacker ) and attacker:IsPlayer() and attacker != ply then
attacker:AddZedDamage( 50 )
end
elseif ply:Team() == TEAM_ZOMBIES then
if IsValid( attacker ) and attacker:IsPlayer() then
attacker:AddCash( GAMEMODE.PlayerZombieKillValue )
attacker:AddFrags( 1 )
end
if ply:IsLord() and ply:GetZedDamage() >= GAMEMODE.RedemptionDamage then
ply:SetTeam( TEAM_ARMY )
ply:Notice( "Prepare to respawn as a human", GAMEMODE.Colors.Blue, 5, 2 )
end
end
if dmginfo:IsExplosionDamage() then
ply:SetModel( table.Random( GAMEMODE.Corpses ) )
local ed = EffectData()
ed:SetOrigin( ply:GetPos() )
util.Effect( "gore_explosion", ed, true, true )
end
ply:CreateRagdoll()
end
function GM:SynchStats()
net.Start( "StatsSynch" )
net.WriteInt( table.Count( player.GetAll() ), 8 )
for k,v in pairs( player.GetAll() ) do
net.WriteEntity( v )
net.WriteTable( v:GetStats() )
end
net.Broadcast()
end
function GM:EndGame( winner )
GAMEMODE:SynchStats()
SetGlobalBool( "GameOver", true )
SetGlobalInt( "WinningTeam", winner )
for k,v in pairs( player.GetAll() ) do
if winner == TEAM_ZOMBIES then
v:NoticeOnce( "The undead have overwhelmed " .. team.GetName( TEAM_ARMY ) , GAMEMODE.Colors.White, 7, 2 )
elseif team.NumPlayers( TEAM_ARMY ) > 0 then
v:NoticeOnce( team.GetName( TEAM_ARMY ) .. " has successfully evacuated", GAMEMODE.Colors.White, 7, 2 )
end
if v:Team() == winner and winner == TEAM_ARMY then
local music = table.Random( GAMEMODE.WinMusic )
v:ClientSound( music, 100 )
v:GodEnable()
else
local music = table.Random( GAMEMODE.LoseMusic )
v:ClientSound( music, 100 )
end
v:NoticeOnce( "Next map: " .. game.GetMapNext() , GAMEMODE.Colors.White, 7, 4 )
end
timer.Simple( GetConVar( "sv_redead_post_game_time" ):GetInt(), function() game.LoadNextMap() end )
end
function GM:CheckGameOver( canend )
if GetGlobalBool( "GameOver", false ) then return end
if team.NumPlayers( TEAM_ARMY ) < 1 and team.NumPlayers( TEAM_ZOMBIES ) > 0 then
GAMEMODE:EndGame( TEAM_ZOMBIES )
elseif GAMEMODE.Wave > #GAMEMODE.Waves and canend then
for k,v in pairs( team.GetPlayers( TEAM_ARMY ) ) do
if not v:IsEvacuated() then
v:Notice( "The evac chopper left without you", GAMEMODE.Colors.Red, 5 )
v:SetTeam( TEAM_ZOMBIES )
end
end
GAMEMODE:EndGame( TEAM_ARMY )
end
end
function GM:ShowHelp( ply )
ply:SendLua( "GAMEMODE:ShowHelp()" )
end
function GM:ShowTeam( ply )
if ply:Team() == TEAM_ZOMBIES then
ply:SendLua( "GAMEMODE:ShowZombieClasses()" )
return
end
if not ply:Alive() then return end
if ply:IsIndoors() then
ply:Notice( "You cannot use your radio indoors", GAMEMODE.Colors.Red )
else
if ply:GetPlayerClass() == CLASS_SPECIALIST then
if IsValid( ply.Stash ) then
GAMEMODE.SpecialTrader:OnExit( ply )
else
if GAMEMODE.RadioBlock and GAMEMODE.RadioBlock > CurTime() then
ply:Notice( "Radio communications are offline", GAMEMODE.Colors.Red )
return
end
GAMEMODE.SpecialTrader:OnUsed( ply )
end
else
if IsValid( ply.Stash ) then
GAMEMODE.Trader:OnExit( ply )
else
if GAMEMODE.RadioBlock and GAMEMODE.RadioBlock > CurTime() then
ply:Notice( "Radio communications are offline", GAMEMODE.Colors.Red )
return
end
GAMEMODE.Trader:OnUsed( ply )
end
end
end
end
function GM:ShowSpare1( ply )
GAMEMODE:PanicButton( ply )
end
function GM:ShowSpare2( ply )
GAMEMODE:AddToZombieList( ply )
end
function GM:PanicButton( ply )
if ( ply.Panic or 0 ) > CurTime() or ply:Team() == TEAM_ZOMBIES then return end
ply.Panic = CurTime() + 0.5
local panic = { { ply:IsBleeding(), { "Bandage" }, "bleeding" },
{ ply:GetRadiation() > 0, { "Vodka", "Moonshine Vodka", "Anti-Rad" }, "irradiated" },
{ ply:Health() < 50, { "Advanced Medikit", "Basic Medikit", "Canned Food" }, "severely wounded" },
{ ply:Health() < 100, { "Basic Medikit", "Canned Food" }, "wounded" },
{ ply:GetStamina() < 100, { "Energy Drink" }, "fatigued" },
{ ply:GetStamina() < 100, { "Water" }, "fatigued" } }
for k,v in pairs( panic ) do
if v[1] then
for c,d in pairs( v[2] ) do
local tbl = item.GetByName( d )
if tbl and ply:HasItem( tbl.ID ) then
tbl.Functions[ 1 ]( ply, tbl.ID )
ply:Notice( "Panic button detected that you were " .. v[3], GAMEMODE.Colors.Blue )
return
end
end
end
end
ply:Notice( "Panic button did not detect any usable items", GAMEMODE.Colors.Red )
ply:ClientSound( "items/suitchargeno1.wav" )
end
function DropItem( ply, cmd, args )
local id = tonumber( args[1] )
local count = math.Clamp( tonumber( args[2] ), 1, 100 )
if not ply:HasItem( id ) then return end
local tbl = item.GetByID( id )
if count == 1 then
if ply:HasItem( id ) then
local makeprop = true
if tbl.DropFunction then
makeprop = tbl.DropFunction( ply, id, true )
end
if makeprop then
local prop = ents.Create( "prop_physics" )
prop:SetPos( ply:GetItemDropPos() )
prop:SetAngles( ply:GetAimVector():Angle() )
if tbl.DropModel then
prop:SetModel( tbl.DropModel )
else
prop:SetModel( tbl.Model )
end
prop:SetCollisionGroup( COLLISION_GROUP_WEAPON )
prop:Spawn()
prop.IsItem = true
prop.Removal = CurTime() + 5 * 60
end
ply:RemoveFromInventory( id, true )
ply:EmitSound( Sound( "items/ammopickup.wav" ) )
end
return
end
local itemcount = math.min( ply:GetItemCount( id ), count )
local loot = ents.Create( "sent_lootbag" )
for i=1, itemcount do
loot:AddItem( id )
end
loot:SetAngles( ply:GetAimVector():Angle() )
loot:SetPos( ply:GetItemDropPos() )
loot:SetRemoval( 60 * 5 )
loot:Spawn()
//loot:SetUser( ply )
ply:EmitSound( Sound( "items/ammopickup.wav" ) )
ply:RemoveMultipleFromInventory( loot:GetItems() )
if tbl.DropFunction then
tbl.DropFunction( ply, id )
end
end
concommand.Add( "inv_drop", DropItem )
function UseItem( ply, cmd, args )
local id = tonumber( args[1] )
local pos = tonumber( args[2] )
if ply:HasItem( id ) then
local tbl = item.GetByID( id )
if not tbl.Functions[pos] then return end
tbl.Functions[pos]( ply, id )
end
end
concommand.Add( "inv_action", UseItem )
function TakeItem( ply, cmd, args )
local id = tonumber( args[1] )
local count = math.Clamp( tonumber( args[2] ), 1, 100 )
if not IsValid( ply.Stash ) or not table.HasValue( ply.Stash:GetItems(), id ) or string.find( ply.Stash:GetClass(), "npc" ) then return end
local tbl = item.GetByID( id )
if count == 1 then
ply:AddIDToInventory( id )
ply.Stash:RemoveItem( id )
return
end
local items = {}
if IsValid( ply.Stash ) then
for i=1, count do
if table.HasValue( ply.Stash:GetItems(), id ) then
table.insert( items, id )
ply.Stash:RemoveItem( id )
end
end
ply:AddMultipleToInventory( items )
ply:EmitSound( Sound( "items/itempickup.wav" ) )
end
end
concommand.Add( "inv_take", TakeItem )
function StoreItem( ply, cmd, args )
local id = tonumber( args[1] )
local count = math.Clamp( tonumber( args[2] ), 1, 100 )
if not IsValid( ply.Stash ) or not ply:HasItem( id ) then return end
local tbl = item.GetByID( id )
if count == 1 then
ply.Stash:AddItem( id )
ply:RemoveFromInventory( id )
ply:EmitSound( Sound( "c4.disarmfinish" ) )
if tbl.DropFunction then
tbl.DropFunction( ply, id )
end
return
end
local items = {}
for i=1, count do
if ply:HasItem( id ) then
table.insert( items, id )
ply.Stash:AddItem( id )
end
end
ply:RemoveMultipleFromInventory( items )
ply:EmitSound( Sound( "c4.disarmfinish" ) )
if tbl.DropFunction then
tbl.DropFunction( ply, id )
end
end
concommand.Add( "inv_store", StoreItem )
function SellbackItem( ply, cmd, args )
if not IsValid( ply ) then return end
local id = tonumber( args[1] )
if not table.HasValue( ply:GetShipment(), id ) then return end
local tbl = item.GetByID( id )
ply:AddCash( tbl.Price )
ply:RemoveFromShipment( id )
end
concommand.Add( "inv_refund", SellbackItem )
function OrderShipment( ply, cmd, args )
ply:SendShipment()
end
concommand.Add( "ordershipment", OrderShipment )
function BuyItem( ply, cmd, args )
local id = tonumber( args[1] )
local count = tonumber( args[2] )
if not IsValid( ply.Stash ) or not ply.Stash:GetClass() == "info_trader" or not table.HasValue( ply.Stash:GetItems(), id ) or count < 0 then return end
local tbl = item.GetByID( id )
if tbl.Price > ply:GetCash() then
return
end
if tbl.Price > ply:GetStat( "Pricey" ) then
ply:SetStat( "Pricey", tbl.Price )
end
if count == 1 then
ply:AddToShipment( { id } )
ply:AddCash( -tbl.Price )
return
end
if ( tbl.Price * count ) > ply:GetCash() then
return
end
local items = {}
for i=1, count do
table.insert( items, id )
end
ply:AddToShipment( items )
ply:AddCash( -tbl.Price * count )
end
concommand.Add( "inv_buy", BuyItem )
function DropCash( ply, cmd, args )
local amt = tonumber( args[1] )
if amt > ply:GetCash() or amt < 5 then return end
ply:AddCash( -amt )
local money = ents.Create( "sent_cash" )
money:SetPos( ply:GetItemDropPos() )
money:Spawn()
money:SetCash( amt )
end
concommand.Add( "cash_drop", DropCash )
function StashCash( ply, cmd, args )
local amt = tonumber( args[1] )
if not IsValid( ply.Stash ) or amt > ply:GetCash() or amt < 5 or string.find( ply.Stash:GetClass(), "npc" ) then return end
ply:AddCash( -amt )
ply:SynchCash( ply.Stash:GetCash() + amt )
ply.Stash:SetCash( ply.Stash:GetCash() + amt )
end
concommand.Add( "cash_stash", StashCash )
function TakeCash( ply, cmd, args )
local amt = tonumber( args[1] )
if not IsValid( ply.Stash ) or amt > ply.Stash:GetCash() or amt < 5 or string.find( ply.Stash:GetClass(), "npc" ) then return end
ply:AddCash( amt )
ply:SynchCash( ply.Stash:GetCash() - amt )
ply.Stash:SetCash( ply.Stash:GetCash() - amt )
end
concommand.Add( "cash_take", TakeCash )
function SetPlyClass( ply, cmd, args )
local class = tonumber( args[1] )
if not GAMEMODE.ClassLogos[ class ] then return end
if ply:Team() == TEAM_ARMY then return end
if ply:Team() == TEAM_ZOMBIES then
ply.NextClass = class
else
ply:SetPlayerClass( class )
end
end
concommand.Add( "changeclass", SetPlyClass )
function SaveGameItems( ply, cmd, args )
if ( !ply:IsAdmin() or !ply:IsSuperAdmin() ) then return end
GAMEMODE:SaveAllEnts()
end
concommand.Add( "sv_redead_save_map_config", SaveGameItems )
function MapSetupMode( ply, cmd, args )
if not IsValid( ply ) then
for k, ply in pairs( player.GetAll() ) do
if ply:IsAdmin() or ply:IsSuperAdmin() then
ply:Give( "rad_itemplacer" )
ply:Give( "rad_propplacer" )
ply:Give( "weapon_physgun" )
end
end
return
end
if ply:IsAdmin() or ply:IsSuperAdmin() then
ply:Give( "rad_itemplacer" )
ply:Give( "rad_propplacer" )
ply:Give( "weapon_physgun" )
ply:AddCash( 500 )
end
end
concommand.Add( "sv_redead_dev_mode", MapSetupMode )
function ItemListing( ply, cmd, args )
if IsValid( ply ) and ply:IsAdmin() then
local itemlist = item.GetList()
for k,v in pairs( itemlist ) do
print( v.ID .. ": " .. v.Name )
end
end
end
concommand.Add( "sv_redead_dev_itemlist", ItemListing )
function TestItem( ply, cmd, args )
if IsValid( ply ) and ply:IsAdmin() then
local id = tonumber( args[1] )
local tbl = item.GetByID( id )
if tbl then
ply:AddIDToInventory( id )
end
end
end
concommand.Add( "sv_redead_dev_give", TestItem )
|