· 8 years ago · Jun 16, 2018, 04:38 AM
1-- General infection settings
2zombie_team = 1 -- 0 is red, 1 is blue
3human_team = 1 - zombie_team
4zombie_speed = 2 -- zombie speed
5lastman_speed = 1.5 -- last man speed
6lastman_dmgmodifier = 1.5 -- damage modifier for the last man (on top of human damage)
7lastman_invistime = 10 -- in seconds
8human_speed = 1.0 -- speed when not infected
9zombie_count = 0.17 -- if value is less than 1 is it used as a percentage, more than or equal to one is absolute count
10last_man_next_zombie = true -- if this value is true the last man standing becomes the next zombie, if not it's random
11max_zombie_count = 1 -- this caps what the zombie count would be w/ ratio (nil is disable)
12lastman_invulnerable = 5 -- time (in seconds) the last man is invulnerable for: replace with nil to disable
13alphazombie_frag_count = 0 -- number of frag nades they spawn with
14alphazombie_plasma_count = 0 -- number of plasma nades they spawn with
15zombie_frag_count = 0 -- number of frag nades they spawn with
16zombie_plasma_count = 0 -- number of plasma nades they spawn with
17alphazombie_clip_count = 12 -- number of shots in clip
18alphazombie_ammo_count = 0 -- backpack ammo they get
19zombie_clip_count = 0 -- number of shots in clip for zombies once there are not only alpha zombies
20zombie_ammo_count = 0 -- backpack ammo zombies once there are not only alpha zombies
21
22-- Game messages
23zombie_message = "YOU'RE A ZOMBIE. KILL THE HUMANS!"
24human_message = "You're a human, survive."
25rejoin_message = "Please don't leave and rejoin. You've been put back onto your last team."
26infected_message = " has been infected by a retarded zombie!"
27teamkill_message = "Don't team kill..."
28blockteamchange_message = "You're not allowed to change team."
29zombieinvis_message = "The zombies are invisible for 20 seconds!"
30timer_team_change_msg = "Thank you. The game will now continue"
31
32-- Don't modify below variables unless you know what you're doing
33cur_zombie_count = 0
34cur_human_count = 0
35alpha_zombie_count = 0
36cur_players = 0
37cur_last_man = nil
38last_man_hash = 0
39processid = 0
40game_started = false
41allow_change = false
42hash_table = {}
43new_game_timer = 0
44player_change_timer = 0
45
46-- This function is required for scripts to run on Phasor (including and after 01.00.03.104)
47-- You should return the minimum required version of Phasor
48-- Official releases:
49-- 01.00.03.104 - 3104
50-- 01.00.10.057 - 10057
51function GetRequiredVersion()
52 return 10057
53end
54
55-- called when the script is loaded
56function OnScriptLoad(process)
57
58 processid = process
59
60 -- assume a game is running
61 game_started = true
62
63 -- recalculate team counters
64 cur_zombie_count = getteamsize(zombie_team)
65 cur_human_count = getteamsize(human_team)
66 cur_players = cur_zombie_count + cur_human_count
67
68 -- recalculate how many "alpha" zombies there are
69 alpha_zombie_count = getalphacount()
70
71 -- load the last man hash (if there is one)
72 local file = io.open("lasthash_" .. processid .. ".tmp", "r")
73
74 if (file ~= nil) then
75
76 -- read the hash
77 last_man_hash = file:read("*line")
78
79 file:close()
80
81 -- delete the file
82 os.remove("lasthash_" .. processid .. ".tmp")
83 end
84end
85
86-- called when the script is unloaded
87-- Do not return a value
88function OnScriptUnload()
89
90end
91
92-- called when a game is starting (before any players join)
93-- Do not return a value.
94function OnNewGame(map)
95
96 -- reset our variables
97 cur_zombie_count = 0
98 cur_human_count = 0
99 cur_players = 0
100
101 -- the game hasn't started yet, will once timer runs down
102 game_started = false
103 new_game_timer = registertimer(2000, "NewGameTimer")
104end
105
106-- called when a game is ending
107-- Do not return a value.
108function OnGameEnd(mode)
109 -- mode 1 = score menu (F1) is being displayed to clients, they are still ingame
110 -- mode 2 = post game menu appeared
111 -- mode 3 = players can quit via the post game score card
112
113 -- remove the new game timer (if still active)
114 if mode == 1 then
115 removetimer(new_game_timer)
116 end
117end
118
119-- Called when there is chat within the server
120-- It must return a value which indicates whether or not the chat is sent.
121function OnServerChat(player, chattype, message)
122 return 1
123end
124
125-- Called when a server command is being executed
126-- It must return a value which indicates whether or not the command should be processed
127-- Note: It is only called when an authenticated (and allowed) player attempts to use the command.
128-- player is -1 when being executed via the server console.
129function OnServerCommand(player, command)
130 local allow = 1
131 local tokencount = getcmdtokencount(command)
132 if tokencount > 0 then
133 local cmd = getcmdtoken(command, 0)
134 if cmd == "sv_changeteam" and tokencount == 2 then
135 local player = getcmdtoken(command, 1)
136 player = rresolveplayer(player)
137 if getplayer(player) ~= nil then
138 local cur_team = getteam(player)
139 if cur_team == zombie_team then
140 makehuman(player, true)
141 privatesay(player, human_message)
142 elseif cur_team == human_team then
143 makezombie(player, true)
144 privatesay(player, zombie_message)
145 end
146 hprintf("The player's team has been changed.")
147 else
148 hprintf("The specified player is invalid")
149 end
150
151 allow = 0
152 end
153 end
154 return allow
155end
156
157-- Called when a player's team is being chosen as the join the server.
158-- It must return a value which indicates the team the player is to be put on.
159-- Note: this function being called doesn't guarantee that the player will be able to successfully join.
160function OnTeamDecision(cur_team)
161 local dest_team = zombie_team
162
163 if game_started then
164 if cur_players == 0 then -- if no zombies make them human
165 dest_team = human_team
166 elseif cur_zombie_count > 0 and cur_human_count == 0 then
167 dest_team = human_team
168 end
169 end
170
171 return dest_team
172end
173
174-- Called when a player joins the server.
175-- Do not return a value.
176function OnPlayerJoin(player, team)
177
178 -- update the player counts
179 cur_players = cur_players + 1
180
181 local thisTeamSize = 0 -- used so we don't create empty teams for rejoining players
182 if team == zombie_team then
183 cur_zombie_count = cur_zombie_count + 1
184 thisTeamSize = cur_zombie_count
185 else
186 cur_human_count = cur_human_count + 1
187 thisTeamSize = cur_human_count
188 end
189
190 alpha_zombie_count = getalphacount()
191
192 local thisHash = gethash(player)
193 local alreadyExists = false
194
195 -- check if the player has joined this game previously
196 for k,v in pairs(hash_table) do
197 if thisHash == k then
198
199 if thisTeamSize > 1 then
200 if v ~= team then changeteam(player, 0) end
201
202 --privatesay(player, rejoin_message)
203 team = v
204 end
205 alreadyExists = true
206
207 break
208 end
209 end
210
211 -- add team entry for this hash
212 if alreadyExists == false then
213 hash_table[thisHash] = team
214 end
215
216 if game_started == true then
217
218 -- check if the player is a zombie
219 if team == zombie_team then
220 makezombie(player, false)
221 privatesay(player, zombie_message)
222 else
223 -- if we're at last man, make this player a zombie
224 if cur_last_man ~= nil then
225 makezombie(player, true)
226 privatesay(player, zombie_message)
227 else
228 makehuman(player, false)
229 privatesay(player, human_message)
230 end
231 end
232 checkgamestate(-1)
233 end
234end
235
236-- Called when a player the server.
237-- Do not return a value.
238function OnPlayerLeave(player, team)
239 if team == zombie_team then
240 cur_zombie_count = cur_zombie_count - 1
241 elseif team == human_team then
242 cur_human_count = cur_human_count - 1
243 end
244
245 -- if last man is leaving, reset it
246 if cur_last_man == player then
247 cur_last_man = nil
248 end
249
250 cur_players = cur_players - 1
251
252 checkgamestate(-1)
253
254 -- update team within table
255 local thisHash = gethash(player)
256 hash_table[thisHash] = team
257end
258
259-- called when a player kills another, 'killer' is the index of the killing player, 'victim' is the index of the dead player
260-- Do not return a value.
261function OnPlayerKill(killer, victim, mode)
262
263 if game_started then
264
265 if mode == 0 then -- server kill
266 elseif mode == 1 then -- fall damage
267 elseif mode == 2 then -- killed by guardians
268 elseif mode == 3 then -- killed by vehicle
269 elseif mode == 4 then -- killed by another player
270
271 local killer_team = getteam(killer)
272 local victim_team = getteam(victim)
273
274 -- check to see if a zombie killed them
275 if killer_team == zombie_team and victim_team == human_team then
276 name = getname(victim)
277 say(name .. infected_message)
278 makezombie(victim, false)
279 --privatesay(victim, zombie_message)
280 end
281
282 elseif mode == 5 then -- betrayed
283 --privatesay(killer, teamkill_message)
284 elseif mode == 6 then -- suicide
285 -- if they're human, make them zombies
286 local team = getteam(victim)
287 if team == human_team then
288 name = getname(victim)
289 say(name .. infected_message)
290 makezombie(victim, false)
291 --privatesay(victim, zombie_message)
292 end
293 end
294 end
295end
296
297-- called when a player gets a double kill, killing spree etc
298-- see Phasor documentation for multiplier values
299function OnKillMultiplier(player, multiplier)
300end
301
302-- Called when a player s (after object is created, before players are notified)
303-- Do not return a value
304function OnPlayerSpawn(player, m_objectId)
305
306 local team = getteam(player)
307
308 if team == zombie_team then
309
310 local m_objectId = getplayerobjectid(player)
311 local m_object = getobject(m_objectId)
312 if m_object ~= nil then
313 -- set nade counts
314 writebyte(m_object, 0x31E, zombie_frag_count)
315 writebyte(m_object, 0x31F, zombie_plasma_count)
316
317 -- set the ammo
318 local clipcount = alphazombie_clip_count
319 local ammocount = alphazombie_ammo_count
320
321 -- set ammo counts for zombies when others have been infected
322 if cur_zombie_count > alpha_zombie_count then
323 clipcount = zombie_clip_count
324 ammocount = zombie_ammo_count
325 else -- set alpha nades
326 writebyte(m_object, 0x31E, alphazombie_frag_count)
327 writebyte(m_object, 0x31F, alphazombie_plasma_count)
328 end
329
330 for i=0,3 do
331 local m_weaponId = readdword(m_object, 0x2F8 + (i*4))
332 if m_weaponId ~= 0xffffffff then
333 local m_weapon = getobject(m_weaponId)
334 if m_weapon ~= nil then
335 -- set the ammo
336 writeword(m_weapon, 0x2B6, ammocount)
337 writeword(m_weapon, 0x2B8, clipcount)
338 -- force it to sync
339 updateammo(m_weaponId)
340 end
341 end
342 end
343 end
344 end
345end
346
347-- Called after clients have been notified of a player spawn
348-- Do not return a value
349function OnPlayerSpawnEnd(player, m_objectId)
350
351end
352
353-- Called when a player is attempting to .
354-- A value must be returned. The return value indicates whether or not the player is allowed the change team.
355-- Notes: If relevant is 1 the return value is considered, if it's 0 then the return value is ignored.
356function OnTeamChange(relevant, player, team, dest_team)
357 if relevant == 1 then
358
359 if allow_change == false then
360 privatesay(player, blockteamchange_message)
361 elseif dest_team == zombie_team then
362 -- this is so memory is updated for processing
363 -- when relevant is 0 OnTeamChange is called once the changes
364 -- have been committed
365 changeteam(player, 1)
366 end
367
368 -- we don't let people change team
369 return 0
370
371
372 elseif dest_team ~= team then -- we can't stop the person changing teams, bein done by an admin
373
374 -- update team counts
375 if dest_team == zombie_team then
376 cur_human_count = cur_human_count - 1
377 cur_zombie_count = cur_zombie_count + 1
378 elseif dest_team == human_team then
379 cur_human_count = cur_human_count + 1
380 cur_zombie_count = cur_zombie_count - 1
381 end
382
383 -- they're allowed to change if the timer is active, if it is disable it
384 if allow_change == true and dest_team == zombie_team then
385
386 allow_change = false
387 -- remove change timer
388 removetimer(player_change_timer)
389 player_change_timer = 0
390
391 say(timer_team_change_msg)
392 end
393
394 -- check if the game has started yet
395 if game_started == true then
396
397 -- set attributes
398 if dest_team == zombie_team then
399 makezombie(player, false)
400 elseif dest_team == human_team then
401 makehuman(player, false)
402 end
403
404 checkgamestate(player)
405 end
406
407 -- update team within table
408 local thisHash = gethash(player)
409 hash_table[thisHash] = dest_team
410 end
411
412 return 1
413end
414
415function OnClientUpdate(player, m_objectId)
416 --local x, y, z = getobjectcoords(m_objectId)
417 --local output = string.format("%.2f %.2f %.2f", x,y,z)
418 --hprintf(output)
419end
420
421
422-- Called when a player interacts with an object
423-- It can be called while attempting to pick the object up
424-- It is also called when standing above an object so can be called various times quickly
425function OnObjectInteraction(player, m_ObjectId, tagType, tagName)
426
427 local response = 1
428
429 if game_started == true then
430
431 -- regardless of the team, stop people taking the flag
432 if tagType == "weap" then
433 if tagName == "weapons\\flag\\flag" then
434 response = 0
435 end
436 end
437
438 if response == 1 then
439
440 local team = getteam(player)
441
442 if team == zombie_team then
443
444 -- we want to stop zombies picking up weapons
445 if tagType == "weap" then
446 response = 0
447 elseif tagType == "eqip" then
448
449 if tagName == "weapons\\frag grenade\\frag grenade" or tagName == "weapons\\plasma grenade\\plasma grenade" then
450 response = 0 -- don't let them pick the nades
451 elseif tagName == "powerups\\active camouflage" then
452
453 -- check if the picking player is already invisible
454 local m_player = getplayer(player)
455 if m_player ~= nil then
456
457 local m_playerObjId = readdword(m_player, 0x34)
458 local m_object = getobject(m_playerObjId)
459 if m_object ~= nil then
460
461 local camoFlag = readdword(m_object, 0x204)
462 if camoFlag ~= 0x51 then
463
464 -- check if zombies are to be made invisible
465 local doInvis = getrandomnumber(1, 10)
466
467 if doInvis > 5 then
468
469 -- make the whole zombie team invis for 20 seconds
470 for x = 0,15 do
471
472 local team = getteam(x)
473
474 if team == zombie_team and x ~= player then
475 --hprintf("applying camo to player " .. x)
476 applycamo(x, 30.00)
477 end
478 end
479
480 say(zombieinvis_message)
481 end
482 end
483 end
484 end
485 end
486 end
487 end
488 end
489 end
490 return response
491end
492
493-- Called when a player attempts to reload their weapon.
494-- A value must be returned. The return value indicates whether or not the player is allowed to reload.
495-- Notes: If player is -1 then the weapon being reload wasn't located (it could be a vehicle's weapon)
496function OnWeaponReload(player, weapon)
497 return 1
498end
499
500-- Called when a player attempts to enter a vehicle.
501-- A value must be returned. The return value indicates whether or not the player is allowed to enter.
502function OnVehicleEntry(relevant, player, vehicleId, vehicle_tag, seat)
503
504 local response = 1
505 if game_started and relevant == 1 then
506
507 local team = getteam(player)
508 if team == zombie_team then
509 response = 0
510 end
511 end
512
513 return response
514end
515
516function OnVehicleEject(player, forceEject)
517 return 1
518end
519
520-- Called when damage is being done to an object.
521-- This doesn't always need to be a player.
522-- Do not return a value
523function OnDamageLookup(receiving_obj, causing_obj, tagdata, tagname)
524
525 -- Resolve the object ids into player ids
526 -- Remember, the damage doesn't always need to be done by a player.
527 local receiver = objecttoplayer(receiving_obj)
528 local causer = objecttoplayer(causing_obj)
529
530 -- We want to amplify human damage, so make sure the causer is human
531 if causer ~= nil then
532
533 local c_team = getteam(causer)
534 -- Make sure the team was found
535 if c_team ~= nil then
536
537 -- Check if it's a human causing the damage
538 if c_team == human_team then
539
540 -- It's human damage, read the current damage the weapon has
541 local min_dmg = readfloat(tagdata, 0x1D0)
542 local max_dmg_min = readfloat(tagdata, 0x1D4)
543 local max_dmg_max = readfloat(tagdata, 0x1D8)
544
545 -- This is used to increase human damage (for last man)
546 local modifier = 1.0
547
548 -- Check if we're up to last man
549 if cur_last_man ~= nil then
550 -- Change the damage modifier to the last man's
551 modifier = lastman_dmgmodifier
552 end
553
554 -- Change the damage that will be done
555 writefloat(tagdata, 0x1D0, min_dmg * 2 * modifier)
556 writefloat(tagdata, 0x1D4, max_dmg_min * 2 * modifier)
557 writefloat(tagdata, 0x1D8, max_dmg_max * 2 * modifier)
558
559 -- It's a zombie causing the damage
560 elseif c_team == zombie_team then
561
562 -- check if it is melee damage, if so increase it to instant kill
563 local found = string.find(tagname, "melee", -5)
564
565 -- We only want to increase zombie's melee damage
566 if found ~= nil then
567
568 -- make melee instant kill
569 writefloat(tagdata, 0x1D0, 500)
570 writefloat(tagdata, 0x1D4, 500)
571 writefloat(tagdata, 0x1D8, 500)
572
573 end
574 end
575 end
576 end
577end
578
579-- Called when a player is being assigned a weapon (usually when they spawn)
580-- A value must be returned. The return value is the id of the weapon they're to spawn with. Return zero if the weapon shouldn't change.
581-- Notes: This is called for all weapon spawns the player has
582-- This is also called with player 255 when vehicles are being assigned weapons.
583-- This is only considered if in gametype, the weapon set is 'generic' if not this has no effect.
584function OnWeaponAssignment(player, object, count, tag)
585
586 local actualWeapon = 0
587 local team = getteam(player)
588
589 if team == zombie_team then
590 -- we only want zombies to have shotguns
591 actualWeapon = lookuptag("weap", "weapons\\shotgun\\shotgun")
592
593 else
594 -- we only want humans to have shotguns and pistols
595 if count == 0 then
596 actualWeapon = lookuptag("weap", "weapons\\shotgun\\shotgun")
597 elseif count == 1 then
598 actualWeapon = lookuptag("weap", "weapons\\pistol\\pistol")
599 end
600 end
601
602 return actualWeapon
603end
604
605-- Called when an object is created
606-- Do not return a value.
607function OnObjectCreation(m_objectId, player_owner, tag)
608
609end
610
611-- The below functions are used internally within the Lua script
612function NewGameTimer(id, count)
613
614 if count == 5 then
615
616 say("The game is starting...")
617
618 if cur_players ~= 0 then
619
620 local newgame_zombie_count = 0
621
622 -- by default make all players human
623 for x=0,15 do
624 local thisTeam = getteam(x)
625 if thisTeam ~= nil then
626 if thisTeam == zombie_team then
627 changeteam(x, 0)
628 end
629 end
630 end
631
632 local possible_count = cur_players
633
634 -- make players zombie until the count has been met
635 local finalZombies = 0
636
637 if zombie_count >= 1 then
638 finalZombies = zombie_count
639 else
640 finalZombies = round((possible_count * zombie_count) + 0.5)
641 end
642
643 -- make last man zombie
644 local last_man_index = -1
645
646 -- check if the last man is to be made a zombie
647 -- if so find who was last man
648 if last_man_next_zombie == true and cur_players > 1 then
649
650 -- loop through all hashes and check if any match the last man
651 for i=0,15 do
652 local hash = gethash(i)
653
654 if hash ~= nil then
655 if last_man_hash == hash then
656
657 -- make them a zombie and save their info
658 makezombie(i, true)
659 newgame_zombie_count = 1
660 last_man_index = i
661
662 break
663 end
664 end
665 end
666 end
667
668 -- reset last man
669 last_man_hash = 0
670
671 --hprintf("Expecting " .. finalZombies .. " zombies. Cur players " .. cur_players .. " possibles " .. possible_count)
672
673 if finalZombies == cur_players then -- if 0 players they will be human
674 finalZombies = finalZombies - 1
675 elseif finalZombies > possible_count then -- fix the count
676 finalZombies = possible_count
677 elseif max_zombie_count ~= nil and finalZombies > max_zombie_count then -- cap the zombie count
678 finalZombies = max_zombie_count
679 elseif finalZombies < 0 then
680 finalZombies = 0
681 end
682
683 -- set counters such that changeteam wont end the game
684 cur_zombie_count = 16
685 cur_human_count = 16
686
687 --hprintf("Expecting " .. finalZombies .. " zombies. Cur players " .. cur_players .. " possibles " .. possible_count)
688
689 -- loop through the players, randomly selecting ones to become
690 -- zombies
691 while (newgame_zombie_count < finalZombies) do
692
693 -- randomly choose a player
694 local newzomb = ChooseRandomPlayer(zombie_team)
695
696 if newzomb == nil then
697 break
698 elseif newzomb ~= last_man_index then
699
700 makezombie(newzomb, true)
701 newgame_zombie_count = newgame_zombie_count + 1
702 end
703 end
704
705 -- fix the team counters
706 cur_zombie_count = newgame_zombie_count
707 cur_human_count = cur_players - finalZombies
708
709 -- reset the map
710 svcmd("sv_map_reset")
711
712 -- loop through and tell players which team they're on
713 for i=0,15 do
714
715 local pteam = getteam(i)
716 if pteam ~= nil then
717 -- check if they're a zombie
718 if pteam == zombie_team then
719 privatesay(i, zombie_message)
720 else
721 privatesay(i, human_message)
722 end
723 end
724 end
725
726 end
727
728 game_started = true
729
730 return 0 -- remove timer
731 else
732 say("The game will start in " .. 10 - 2*count .. " seconds.")
733
734 return 1 -- keep timer
735 end
736end
737
738function PlayerChangeTimer(id, count)
739 if count ~= 10 then
740
741 local zombsize = cur_zombie_count
742
743 if allow_change == false or zombsize > 0 then
744
745 allow_change = false
746
747 say("Thank you, the game can continue.")
748
749 return 0
750 end
751
752 say("In " .. 10 - count .. " seconds a player will be forced to become a zombie.")
753
754 return 1
755 else -- timer up, force team change
756
757 allow_change = false
758
759 -- pick a human and make them zombie.
760 local newZomb = ChooseRandomPlayer(zombie_team)
761
762 if newZomb ~= nil then
763 makezombie(newZomb, true)
764 privatesay(player, zombie_message)
765 end
766
767 return 0
768 end
769end
770
771-- this function searches through current players and selects a random one
772function ChooseRandomPlayer(excludeTeam)
773
774 local t = {}
775
776 -- loop through all 16 possible spots and add to table
777 for i=0,15 do
778
779 -- check if the player exists
780 local team = getteam(i)
781
782 if team ~= nil and team ~= excludeTeam then
783 table.insert(t, i)
784 end
785
786 end
787
788 if #t > 0 then
789 -- generate a random number that we will use to select a player
790 local tableCount = table.getn(t)
791 local r = getrandomnumber(1, tableCount+1)
792 return t[r]
793 else
794 return nil
795 end
796end
797
798function RemoveLastmanProtection(id, count, m_object)
799 writebit(m_object, 0x10, 7, 0)
800 return 0
801end
802
803-- there are no zombies left
804function noZombiesLeft()
805
806 allow_change = true
807 say("There are no zombies left. Someone needs to change team, otherwise a random player will be forced to.")
808 player_change_timer = registertimer(1000, "PlayerChangeTimer")
809
810end
811
812-- called when its the last man
813function onlastman()
814
815 -- lookup the last man
816 for x=0,15 do
817 local team = getteam(x)
818
819 if team == human_team then
820
821 cur_last_man = x
822 -- give the last man speed and extra ammo
823 setspeed(x, lastman_speed)
824
825 -- find the last man's weapons
826 local m_player = getplayer(x)
827
828 if m_player ~= nil then
829 local m_ObjId = readdword(m_player, 0x34)
830
831 -- find the player's object
832 local m_object = getobject(m_ObjId)
833
834 if m_object ~= nil then
835
836 if lastman_invulnerable ~= nil and lastman_invulnerable > 0 then
837 -- setup the invulnerable timer
838 writebit(m_object, 0x10, 7, 1)
839 registertimer(lastman_invulnerable * 1000, "RemoveLastmanProtection", m_object)
840 end
841
842 -- give all weapons 600 ammo
843 for i=0,3 do
844 local m_weaponId = readdword(m_object, 0x2F8 + (i*4))
845
846 if m_weaponId ~= 0xffffffff then
847
848 -- get the weapons memory address
849 local m_weapon = getobject(m_weaponId)
850
851 if m_weapon ~= nil then
852 -- set the ammo
853 writeword(m_weapon, 0x2B6, 600)
854 end
855 end
856 end
857 end
858 end
859 end
860 end
861
862 if cur_last_man ~= nil then
863
864 local lastman_name = getname(cur_last_man)
865 local msg = string.format("%s is the last man alive and is invisible for %.0f seconds!", lastman_name, lastman_invistime)
866 say(msg)
867 applycamo(cur_last_man, lastman_invistime)
868 end
869
870
871end
872
873-- checks the game state, for last man, all zombies etc
874-- called onteamchange, player join and leave
875function checkgamestate(player)
876
877 -- check if the game has started yet
878 if game_started == true then
879
880 local zombie_count = cur_zombie_count
881 local human_count = cur_human_count
882 --hprintf("zombie count " .. zombie_count)
883 --hprintf("human count " .. human_count)
884
885 -- if no humans, but there are zombies, end the game
886 if human_count == 0 and zombie_count > 0 then
887 all_players_zombies(player)
888 elseif human_count > 1 and zombie_count == 0 then
889 noZombiesLeft()
890 elseif human_count == 1 and zombie_count > 0 and cur_last_man == nil then
891 onlastman()
892 elseif cur_last_man ~= nil and zombie_count == 0 then
893 makehuman(cur_last_man, false)
894 cur_last_man = nil
895 end
896 end
897end
898
899-- called when all players are zombies (no shit)
900function all_players_zombies(player)
901
902 -- if there is a last man, store their hash
903 if player ~= -1 then
904 last_man_hash = gethash(player)
905 -- write the hash to file
906 local file = io.open("lasthash_" .. processid .. ".tmp", "w")
907
908 if (file ~= nil) then
909 file:write(last_man_hash)
910 file:close()
911 end
912 end
913
914 -- move onto the next map
915 svcmd("sv_map_next")
916end
917
918function makezombie(player, forcekill)
919
920 -- change the player's speed
921 setspeed(player, zombie_speed)
922
923 local team = getteam(player)
924 if team == human_team then
925 changeteam(player, forcekill)
926 end
927end
928
929function makehuman(player, forcekill)
930 -- change the player's speed
931 setspeed(player, human_speed)
932
933 local team = getteam(player)
934 if team == zombie_team then
935 changeteam(player, forcekill)
936 end
937end
938
939function getalphacount()
940 -- recalculate how many "alpha" zombies there are
941 if zombie_count < 1 then
942 alpha_zombie_count = round((cur_players * zombie_count) + 0.5)
943 else
944 alpha_zombie_count = zombie_count
945 end
946
947 if alpha_zombie_count > max_zombie_count then
948 alpha_zombie_count = max_zombie_count
949 end
950 return alpha_zombie_count
951end
952
953
954function round(num)
955 under = math.floor(num)
956 upper = math.floor(num) + 1
957 underV = -(under - num)
958 upperV = upper - num
959 if (upperV > underV) then
960 return under
961 else
962 return upper
963 end
964end