· 7 years ago · Sep 03, 2018, 04:24 AM
1-- RandomWeaponInfection
2
3-- Written by [SC]Nuggets
4-- If you have questions, comments, critiques, or evil plans to rule the world, contact [SC]Nuggets via phasor.proboards.com
5-- Enjoy!
6
7--[[
8
9In this gametype, you spawn with assigned attributes based on random number generators.
10You may not pick up any other weapon other than what you have spawned with.
11
12--]]
13
14--[[
15
16I have re-scripted my RandomWeapon script in order to make it more user-friendly.
17This version of the script is meant to make the probabilities of spawning with certain attributes easier to edit.
18If you're interested in how the code works, I have comments and such in the code below.
19If you just want this script to work and don't care how it actually works, then you can stop reading when you get to "function GetRequiredVersion".
20This is the first script I've written with intentions of others reading and trying to understand it, so let me know if I suck at it or not.
21
22--]]
23
24-- PROBABILITIES:
25
26--[[
27
28Change these values to whatever you choose.
29The percentage of probability is based on the ratio of the value you enter for a specific field and the sum of all of the values of that category.
30For example, if the sum of all of the values of the "Primary" category is 100, and the assault_rifle is set to 25, there is a 25% chance a player will spawn with an assault rifle (25/100).
31If the sum of the "Primary" category is 500 and assault_rifle is set to 25, then there's a 5% chance a player will spawn with an assault rifle (25/500).
32It's obviously easiest to just let each section add up to 100 so the values you enter for each attribute will be a percent value, but if for some reason you don't it want to, I've given you that freedom.
33Enter the values to any precision you like.
34
35--]]
36
37-- Weapon probabilities:
38
39 -- Primary:
40 plasma_pistol = 19
41 assault_rifle = 22
42 needler = 14
43 plasma_rifle = 12
44 shotgun = 10
45 pistol = 11
46 sniper = 9
47 flamethrower = 1.5
48 rocket = 1
49 fuel_rod = 0.5
50
51 -- Secondary:
52 no_weapon = 70
53 plasma_pistol_2 = 7
54 assault_rifle_2 = 7
55 needler_2 = 5
56 plasma_rifle_2 = 3
57 shotgun_2 = 3
58 pistol_2 = 2
59 sniper_2 = 1
60 flamethrower_2 = 1
61 rocket_2 = 0.75
62 fuel_rod_2 = 0.25
63
64
65-- Grenade probabilities:
66no_grenades = 75
67one_frag = 5
68two_frags = 4
69three_frags = 2
70one_plasma = 5
71two_plasmas = 4
72three_plasmas = 2
73two_of_each = 2
74four_of_each = 1
75
76-- Special probabilities:
77none = 95.5
78invisible = 0.75
79overshield = 0.75
80extra_speed = 0.75
81invis_overshield = 0.5
82invis_speed = 0.5
83overshield_speed = 0.5
84all_special = 0.25
85
86
87-- Ammo probabilities:
88normal_ammo = 75
89double_ammo = 12
90triple_ammo = 8
91ammotacular = 4.75
92infinite_ammo = 0.25
93
94
95-- Server Messages:
96welcome_message = "Random attributes will be assigned to you on each spawn."
97death_message = "Choosing random attributes..."
98
99-- Other Editable Variables:
100speed = 2.0 -- Speed value of players who spawn with extra speed
101
102-- Weapon tables: Keeps track of what players have what weapon. 1 = yes, 0 = no.
103-- Don't mess with this unless you know what you're doing.
104
105AssaultRifle = {}
106Pistol = {}
107Needler = {}
108PlasmaRifle = {}
109PlasmaPistol = {}
110FuelRod = {}
111Rocket = {}
112Flamethrower = {}
113Shotgun = {}
114Sniper = {}
115
116-- Infection Attributes:
117-- General infection settings
118zombie_team = 1 -- 0 is red, 1 is blue
119human_team = 1 - zombie_team
120zombie_speed = 1.5 -- zombie speed
121lastman_speed = 1.5 -- last man speed
122lastman_dmgmodifier = 1.5 -- damage modifier for the last man (on top of human damage)
123lastman_invistime = 10 -- in seconds
124human_speed = 1.0 -- speed when not infected
125zombie_count = 0.17 -- if value is less than 1 is it used as a percentage, more than or equal to one is absolute count
126last_man_next_zombie = true -- if this value is true the last man standing becomes the next zombie, if not it's random
127max_zombie_count = 2 -- this caps what the zombie count would be w/ ratio (nil is disable)
128lastman_invulnerable = 5 -- time (in seconds) the last man is invulnerable for: replace with nil to disable
129alphazombie_frag_count = 0 -- number of frag nades they spawn with
130alphazombie_plasma_count = 0 -- number of plasma nades they spawn with
131zombie_frag_count = 0 -- number of frag nades they spawn with
132zombie_plasma_count = 0 -- number of plasma nades they spawn with
133alphazombie_clip_count = 12 -- number of shots in clip
134alphazombie_ammo_count = 0 -- backpack ammo they get
135zombie_clip_count = 0 -- number of shots in clip for zombies once there are not only alpha zombies
136zombie_ammo_count = 0 -- backpack ammo zombies once there are not only alpha zombies
137
138-- Game messages
139zombie_message = "YOU'RE A ZOMBIE. KILL THE HUMANS!"
140human_message = "YOU'RE A HUMAN. SURVIVE."
141rejoin_message = "Please don't leave and rejoin. You've been put back onto your last team."
142infected_message = " has been infected!"
143teamkill_message = "Don't team kill..."
144blockteamchange_message = "You're not allowed to change team."
145zombieinvis_message = "The zombies are invisible for 20 seconds!"
146timer_team_change_msg = "Thank you. The game will now continue"
147
148-- Don't modify below variables unless you know what you're doing
149cur_zombie_count = 0
150cur_human_count = 0
151alpha_zombie_count = 0
152cur_players = 0
153cur_last_man = nil
154last_man_hash = 0
155processid = 0
156game_started = false
157allow_change = false
158hash_table = {}
159new_game_timer = 0
160player_change_timer = 0
161
162function GetRequiredVersion()
163
164 return 10057
165end
166
167
168function OnScriptLoad(process)
169
170 -- Create tables for each weapon and set every player's value to 0.
171
172 for i = 1, 16 do
173
174 AssaultRifle[i] = 0
175 Pistol[i] = 0
176 Needler[i] = 0
177 PlasmaRifle[i] = 0
178 PlasmaPistol[i] = 0
179 FuelRod[i] = 0
180 Rocket[i] = 0
181 Flamethrower[i] = 0
182 Shotgun[i] = 0
183 Sniper[i] = 0
184 end
185
186 processid = process
187
188 -- assume a game is running
189 game_started = true
190
191 -- recalculate team counters
192 cur_zombie_count = getteamsize(zombie_team)
193 cur_human_count = getteamsize(human_team)
194 cur_players = cur_zombie_count + cur_human_count
195
196 -- recalculate how many "alpha" zombies there are
197 alpha_zombie_count = getalphacount()
198
199 -- load the last man hash (if there is one)
200 local file = io.open("lasthash_" .. processid .. ".tmp", "r")
201
202 if (file ~= nil) then
203
204 -- read the hash
205 last_man_hash = file:read("*line")
206
207 file:close()
208
209 -- delete the file
210 os.remove("lasthash_" .. processid .. ".tmp")
211 end
212end
213
214
215function OnScriptUnload()
216
217
218end
219
220
221function OnNewGame(map)
222
223 -- reset our variables
224 cur_zombie_count = 0
225 cur_human_count = 0
226 cur_players = 0
227
228 -- the game hasn't started yet, will once timer runs down
229 game_started = false
230 new_game_timer = registertimer(2000, "NewGameTimer")
231end
232
233
234function OnGameEnd(mode)
235
236 if mode == 1 then
237 removetimer(new_game_timer)
238 end
239end
240
241function OnServerChat(player, chattype, message)
242
243 return 1
244end
245
246function OnServerCommand(player, command)
247
248 local allow = 1
249 local tokencount = getcmdtokencount(command)
250 if tokencount > 0 then
251 local cmd = getcmdtoken(command, 0)
252 if cmd == "sv_changeteam" and tokencount == 2 then
253 local player = getcmdtoken(command, 1)
254 player = rresolveplayer(player)
255 if getplayer(player) ~= nil then
256 local cur_team = getteam(player)
257 if cur_team == zombie_team then
258 makehuman(player, true)
259 privatesay(player, human_message)
260 elseif cur_team == human_team then
261 makezombie(player, true)
262 privatesay(player, zombie_message)
263 end
264 hprintf("The player's team has been changed.")
265 else
266 hprintf("The specified player is invalid")
267 end
268
269 allow = 0
270 end
271 end
272
273 return allow
274end
275
276
277function OnTeamDecision(cur_team)
278
279 local dest_team = zombie_team
280
281 if game_started then
282 if cur_players == 0 then -- if no zombies make them human
283 dest_team = human_team
284 elseif cur_zombie_count > 0 and cur_human_count == 0 then
285 dest_team = human_team
286 end
287 end
288
289 return dest_team
290end
291
292
293function OnPlayerJoin(player, team)
294
295 privatesay(player, "Randomness:")
296 privatesay(player, welcome_message)
297
298 registertimer(1000, "HelpTimer", player)
299
300 -- update the player counts
301 cur_players = cur_players + 1
302
303 local thisTeamSize = 0 -- used so we don't create empty teams for rejoining players
304 if team == zombie_team then
305 cur_zombie_count = cur_zombie_count + 1
306 thisTeamSize = cur_zombie_count
307 else
308 cur_human_count = cur_human_count + 1
309 thisTeamSize = cur_human_count
310 end
311
312 alpha_zombie_count = getalphacount()
313
314 local thisHash = gethash(player)
315 local alreadyExists = false
316
317 -- check if the player has joined this game previously
318 for k,v in pairs(hash_table) do
319 if thisHash == k then
320
321 if thisTeamSize > 1 then
322 if v ~= team then changeteam(player, 0) end
323
324 --privatesay(player, rejoin_message)
325 team = v
326 end
327 alreadyExists = true
328
329 break
330 end
331 end
332
333 -- add team entry for this hash
334 if alreadyExists == false then
335 hash_table[thisHash] = team
336 end
337
338 if game_started == true then
339
340 -- check if the player is a zombie
341 if team == zombie_team then
342 makezombie(player, false)
343 privatesay(player, zombie_message)
344 else
345 -- if we're at last man, make this player a zombie
346 if cur_last_man ~= nil then
347 makezombie(player, true)
348 privatesay(player, zombie_message)
349 else
350 makehuman(player, false)
351 privatesay(player, human_message)
352 end
353 end
354 checkgamestate(-1)
355 end
356end
357
358function OnPlayerLeave(player, team)
359
360 if team == zombie_team then
361 cur_zombie_count = cur_zombie_count - 1
362 elseif team == human_team then
363 cur_human_count = cur_human_count - 1
364 end
365
366 -- if last man is leaving, reset it
367 if cur_last_man == player then
368 cur_last_man = nil
369 end
370
371 cur_players = cur_players - 1
372
373 checkgamestate(-1)
374
375 -- update team within table
376 local thisHash = gethash(player)
377 hash_table[thisHash] = team
378end
379
380
381function OnPlayerKill(killer, victim, mode)
382
383 privatesay(victim, death_message)
384 local victimId = resolveplayer(victim)
385
386 -- Reset all weapon values of the victim to 0.
387
388 AssaultRifle[victimId] = 0
389 Pistol[victimId] = 0
390 Needler[victimId] = 0
391 PlasmaRifle[victimId] = 0
392 PlasmaPistol[victimId] = 0
393 FuelRod[victimId] = 0
394 Rocket[victimId] = 0
395 Flamethrower[victimId] = 0
396 Shotgun[victimId] = 0
397 Sniper[victimId] = 0
398
399 if game_started then
400
401 if mode == 0 then -- server kill
402 elseif mode == 1 then -- fall damage
403 local victim_team = getteam(victim)
404 if victim_team == human_team then
405 name = getname(victim)
406 say(name .. infected_message)
407 makezombie(victim, false)
408 end
409 elseif mode == 2 then -- killed by guardians
410 elseif mode == 3 then -- killed by vehicle
411 elseif mode == 4 then -- killed by another player
412
413 local killer_team = getteam(killer)
414 local victim_team = getteam(victim)
415
416 -- check to see if a zombie killed them
417 if killer_team == zombie_team and victim_team == human_team then
418 name = getname(victim)
419 say(name .. infected_message)
420 makezombie(victim, false)
421 --privatesay(victim, zombie_message)
422 end
423
424 elseif mode == 5 then -- betrayed
425 --privatesay(killer, teamkill_message)
426 elseif mode == 6 then -- suicide
427 -- if they're human, make them zombies
428 local team = getteam(victim)
429 if team == human_team then
430 name = getname(victim)
431 say(name .. infected_message)
432 makezombie(victim, false)
433 --privatesay(victim, zombie_message)
434 end
435 end
436 end
437end
438
439
440function OnKillMultiplier(player, multiplier)
441
442
443end
444
445
446function OnPlayerSpawn(player, m_objectId)
447
448 local team = getteam(player)
449
450 if team == zombie_team then
451
452 local m_objectId = getplayerobjectid(player)
453 local m_object = getobject(m_objectId)
454 if m_object ~= nil then
455 -- set nade counts
456 writebyte(m_object, 0x31E, zombie_frag_count)
457 writebyte(m_object, 0x31F, zombie_plasma_count)
458
459 -- set the ammo
460 local clipcount = alphazombie_clip_count
461 local ammocount = alphazombie_ammo_count
462
463 -- set ammo counts for zombies when others have been infected
464 if cur_zombie_count > alpha_zombie_count then
465 clipcount = zombie_clip_count
466 ammocount = zombie_ammo_count
467 else -- set alpha nades
468 writebyte(m_object, 0x31E, alphazombie_frag_count)
469 writebyte(m_object, 0x31F, alphazombie_plasma_count)
470 end
471
472 for i=0,3 do
473 local m_weaponId = readdword(m_object, 0x2F8 + (i*4))
474 if m_weaponId ~= 0xffffffff then
475 local m_weapon = getobject(m_weaponId)
476 if m_weapon ~= nil then
477 -- set the ammo
478 writeword(m_weapon, 0x2B6, ammocount)
479 writeword(m_weapon, 0x2B8, clipcount)
480 -- force it to sync
481 updateammo(m_weaponId)
482 end
483 end
484 end
485 end
486 end
487end
488
489function OnPlayerSpawnEnd(player, m_objectId)
490
491 if gethash(player) ~= nil then
492 -- GRENADES
493
494 -- Determine whether a player will spawn with grenades, and if so, what kind and how many.
495 -- Sum up all of the values entered in the probabilities.
496
497 local grenade_sum = no_grenades + one_frag + two_frags + three_frags one_plasma + two_plasmas + three_plasmas + two_of_each + four_of_each
498
499 -- Find the highest precision used out of all of the values entered.
500 -- Create array
501 local g = {no_grenades, one_frag, two_frags, three_frags, one_plasma, two_plasmas, three_plasmas, two_of_each, four_of_each}
502
503 -- Find the highest precision out of all elements of the array.
504 local g_precision = findHighestPrecision(g)
505
506 -- Be lazy.
507 local x = 10^g_precision
508
509 -- Get a random number: 0 <= grenade < (grenade_sum * 10^precision)
510 local grenade = getrandomnumber(0, (grenade_sum * x))
511
512 local team = getteam(player)
513 local m_Object = getobject(m_objectId)
514
515 -- Determine what the random number will do.
516
517 if m_Object ~= 0 then
518 if grenade >= 0 and grenade < (no_grenades * x) then
519
520 writebyte(m_Object, 0x31E, 0) -- set frag grenades to 0
521 writebyte(m_Object, 0x31F, 0) -- set plasmas to 0
522
523 elseif grenade >= (no_grenades * x) and grenade < (x * (no_grenades + one_frag)) then
524
525 if team == human_team then
526 writebyte(m_Object, 0x31E, 1) -- set frags to 1
527 writebyte(m_Object, 0x31F, 0) -- plasmas to 0
528
529 privatesay(player, "A Frag Grenade.") -- tell the player what they spawned with
530 end
531
532 elseif grenade >= (x * (no_grenades + one_frag)) and grenade < (x * (no_grenades + one_frag + one_plasma)) then
533
534 writebyte(m_Object, 0x31E, 0) -- yadayadayada
535 writebyte(m_Object, 0x31F, 1) -- yada.
536
537 privatesay(player, "A Plasma Grenade.")
538
539 elseif grenade >= (x * (no_grenades + one_frag + one_plasma)) and grenade < (x * (no_grenades + one_frag + one_plasma + two_frags)) then
540
541 if team == human_team then
542 writebyte(m_Object, 0x31E, 2)
543 writebyte(m_Object, 0x31F, 0)
544
545 privatesay(player, "Two Frag Grenades.")
546 end
547
548 elseif grenade >= (x * (no_grenades + one_frag + one_plasma + two_frags)) and grenade < (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas)) then
549
550 writebyte(m_Object, 0x31E, 0)
551 writebyte(m_Object, 0x31F, 2)
552
553 privatesay(player, "Two Plasma Grenades.")
554
555 elseif grenade >= (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas)) and grenade < (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas + two_of_each)) then
556
557 if team == human_team then
558 writebyte(m_Object, 0x31E, 2)
559 writebyte(m_Object, 0x31F, 2)
560
561 privatesay(player, "Two of each Grenade.")
562 end
563
564 elseif grenade >= (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas + two_of_each)) and grenade < (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas + two_of_each + three_frags)) then
565
566 if team == human_team then
567 writebyte(m_Object, 0x31E, 3)
568 writebyte(m_Object, 0x31F, 0)
569
570 privatesay(player, "Three Frag Grenades.")
571 end
572
573 elseif grenade >= (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas + two_of_each + three_frags)) and grenade < (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas + two_of_each + three_frags + three_plasmas)) then
574
575 writebyte(m_Object, 0x31E, 0)
576 writebyte(m_Object, 0x31F, 3)
577
578 privatesay(player, "Three Plasma Grenades.")
579
580 elseif grenade >= (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas + two_of_each)) and grenade < (grenade_sum * x) then
581
582 if team == human_team then
583 writebyte(m_Object, 0x31E, 4)
584 writebyte(m_Object, 0x31F, 4)
585
586 privatesay(player, "Four of each Grenade.")
587 end
588 end
589 end
590
591 -- SPECIAL ATTRIBUTES
592
593 if team == zombie_team then
594
595 -- Determine whether a player will spawn with camouflage, overshield, or extra speed.
596 -- Sum up the values
597
598 local special_sum = invisible + overshield + extra_speed + invis_overshield + invis_speed + overshield_speed + all_special + none
599
600 -- Find the highest precision used (see the GRENADES section for info on what's going on here).
601
602 local s = {invisible, overshield, extra_speed, invis_overshield, invis_speed, overshield_speed, all_special, none}
603 local s_precision = findHighestPrecision(s)
604 local y = 10^s_precision
605
606 local gametype_base = 0x671340
607 local gametype_game = readbyte(gametype_base, 0x30) -- Make sure this isn't an Oddball or Race gametype where speed cannot be changed
608
609 -- Determine whether this is a shields or no-shields gametype so players don't spawn with "overshield" in a no-shields gametype.
610
611 local gametype_parameters = readbyte(gametype_base, 0x38)
612 local binary = convertbase(10, 2, gametype_parameters) -- gametype_parameters is represented in binary...
613 local obj_max_shields = 0
614
615 if string.sub(binary, -4, -4) == "0" then -- ... but we only care if this is a shields or no-shields gametype (which is represented by the fourth digit from the right) Shields on = 0; Shields off = 1
616
617 obj_max_shields = 1
618 end
619
620 local special = getrandomnumber(0, (special_sum * y))
621
622 -- Put it all together and do magical stuff.
623
624 if special >= 0 and special < (invisible * y) then
625
626 applycamo(player, 0)
627 setspeed(player, 1)
628 privatesay(player, "You are invisible!")
629
630 elseif special >= (invisible * y) and special < (y * (invisible + extra_speed)) then
631
632 if gametype_game ~= 3 and gametype_game ~= 5 then -- make sure this isn't oddball or race
633 setspeed(player, speed)
634 privatesay(player, "You have increased speed!")
635 end
636
637 elseif special >= (y * (invisible + extra_speed)) and special < (y * (invisible + extra_speed + invis_speed)) then
638
639 if gametype_game ~= 3 and gametype_game ~= 5 then
640 applycamo(player, 0)
641 setspeed(player, speed)
642 privatesay(player, "You are invisible AND have increased speed!")
643 end
644
645 elseif special >= (y * (invisible + extra_speed + invis_speed)) and special < (y * (invisible + extra_speed + invis_speed + overshield)) then
646
647 if obj_max_shields ~= 0 then -- make sure players have shields in this gametype
648 applyos(player)
649 setspeed(player, 1)
650 privatesay(player, "You have overshield!")
651 else
652 setspeed(player, 1)
653 end
654
655 elseif special >= (y * (invisible + extra_speed + invis_speed + overshield)) and special < (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield)) then
656
657 if obj_max_shields ~= 0 then
658 applyos(player)
659 applycamo(player, 0)
660 setspeed(player, 1)
661 privatesay(player, "You are invisible AND have overshield!")
662 else
663 setspeed(player, 1)
664 end
665
666 elseif special >= (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield)) and special < (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield + overshield_speed)) then
667
668 if obj_max_shields ~= 0 and gametype_game ~= 3 and gametype_game ~= 5 then
669 applyos(player)
670 setspeed(player, speed)
671 privatesay(player, "You have overshield AND extra speed!")
672 else
673 setspeed(player, 1)
674 end
675
676 elseif special >= (y * (invisible + extra_speed + invis_speed + overshield+ invis_overshield + overshield_speed)) and special < (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield + overshield_speed + all_special)) then
677
678 if obj_max_shields ~= 0 and gametype_game ~= 3 and gametype_game ~= 5 then
679 applyos(player)
680 applycamo(player, 0)
681 setspeed(player, speed)
682 privatesay(player, "JACKPOT: All special attributes!")
683 else
684 setspeed(player, 1)
685 end
686
687 elseif special >= (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield + overshield_speed + all_special)) and special < (y * special_sum) then
688
689 setspeed(player, 1.0)
690 end
691 end
692
693 if team == human_team then
694
695 -- AMMO ATTRIBUTES
696
697 -- Determine whether a player will spawn with extra ammo.
698
699 local ammo_sum = normal_ammo + double_ammo + triple_ammo + ammotacular + infinite_ammo
700
701 -- Find the highest precision used (see the GRENADES section for more info on how this works).
702
703 local a = {normal_ammo, double_ammo, triple_ammo, ammotacular, infinite_ammo}
704 local a_precision = findHighestPrecision(a)
705 local z = 10^a_precision
706
707 local ammo = getrandomnumber(0, (ammo_sum * z))
708
709 local m_player = getplayer(player)
710 local ammo_multiplier = 1 -- Initialize an ammo multiplier
711
712 -- Get a player's weapons.....
713
714 if m_player ~= nil then
715
716 local m_ObjId = readdword(m_player, 0x34)
717 local m_object = getobject(m_ObjId)
718
719 if m_object ~= nil then
720 for i = 0, 3 do -- For primary, secondary, ternary, and quartary weapons do...
721
722 local m_weaponId = readdword(m_object, 0x2F8 + (i*4)) -- Get the weapon ID of each weapon (incrementing by four bytes each time)
723
724 if m_weaponId ~= nil then
725
726 local m_weapon = getobject(m_weaponId)
727
728 if m_weapon ~= nil then
729
730 -- Make sure the player isn't getting "extra ammo" in his/her plasma weapon
731
732 if PlasmaRifle[resolveplayer(player)] ~= 1 and PlasmaPistol[resolveplayer(player)] ~= 1 and FuelRod[resolveplayer(player)] ~= 1 then
733
734 -- Do all the shmexy stuff.
735
736 local weap_ammo = readword(m_weapon, 0x2B6)
737
738 if ammo >= 0 and ammo < (double_ammo * z) then
739
740 writeword(m_weapon, 0x2B6, weap_ammo * 2)
741 ammo_multiplier = 2
742
743 elseif ammo >= (double_ammo * z) and ammo < (z * (double_ammo + triple_ammo)) then
744
745 writeword(m_weapon, 0x2B6, weap_ammo * 3)
746 ammo_multiplier = 3
747
748 elseif ammo >= (z * (double_ammo + triple_ammo)) and ammo < (z * (double_ammo + triple_ammo + ammotacular)) then
749
750 writeword(m_weapon, 0x2B6, weap_ammo * 4)
751 ammo_multiplier = 4
752
753 elseif ammo >= (z * (double_ammo + triple_ammo + ammotacular)) and ammo < (z * (double_ammo + triple_ammo + ammotacular + infinite_ammo)) then
754
755 writeword(m_weapon, 0x2B6, 9999)
756 writeword(m_weapon, 0x2B8, 9999)
757 updateammo(m_weaponId)
758 ammo_multiplier = 5
759 end
760 end
761 end
762 end
763 end
764 end
765 end
766
767 -- Print the messages (if you print the messages in the loop above, the player will be spammed the same message for each weapon)
768
769 if ammo_multiplier == 2 then
770 privatesay(player, "Double Ammo!")
771 elseif ammo_multiplier == 3 then
772 privatesay(player, "Triple Ammo!")
773 elseif ammo_multiplier == 4 then
774 privatesay(player, "Ammotacular!")
775 elseif ammo_multiplier == 5 then
776 privatesay(player, "JACKPOT: INFINITE AMMO!")
777 end
778 end
779 end
780end
781
782
783function OnTeamChange(relevant, player, team, dest_team)
784
785 if relevant == 1 then
786
787 if allow_change == false then
788 privatesay(player, blockteamchange_message)
789 elseif dest_team == zombie_team then
790 -- this is so memory is updated for processing
791 -- when relevant is 0 OnTeamChange is called once the changes
792 -- have been committed
793 changeteam(player, 1)
794 end
795
796 -- we don't let people change team
797 return 0
798
799
800 elseif dest_team ~= team then -- we can't stop the person changing teams, bein done by an admin
801
802 -- update team counts
803 if dest_team == zombie_team then
804 cur_human_count = cur_human_count - 1
805 cur_zombie_count = cur_zombie_count + 1
806 elseif dest_team == human_team then
807 cur_human_count = cur_human_count + 1
808 cur_zombie_count = cur_zombie_count - 1
809 end
810
811 -- they're allowed to change if the timer is active, if it is disable it
812 if allow_change == true and dest_team == zombie_team then
813
814 allow_change = false
815 -- remove change timer
816 removetimer(player_change_timer)
817 player_change_timer = 0
818
819 say(timer_team_change_msg)
820 end
821
822 -- check if the game has started yet
823 if game_started == true then
824
825 -- set attributes
826 if dest_team == zombie_team then
827 makezombie(player, false)
828 elseif dest_team == human_team then
829 makehuman(player, false)
830 end
831
832 checkgamestate(player)
833 end
834
835 -- update team within table
836 local thisHash = gethash(player)
837 hash_table[thisHash] = dest_team
838 end
839
840 return 1
841end
842
843
844function OnObjectInteraction(player, m_ObjectId, tagType, tagName)
845
846 -- Set values of "player" so they can be accessed in the weapon arrays (since there is no "0th" element of an array in Lua)
847
848 local team = getteam(player)
849
850 --[[local player = resolveplayer(player)
851
852 if tagType == "weap" then
853
854 -- Based on weapon values, determine what weapon(s) a player can interact with.
855
856 if tagName == "weapons\\assault rifle\\assault rifle" then
857 if AssaultRifle[player] == 1 then
858
859 response = 1
860 else
861 response = 0
862 end
863
864 elseif tagName == "weapons\\pistol\\pistol" then
865 if Pistol[player] == 1 then
866
867 response = 1
868 else
869 response = 0
870 end
871
872 elseif tagName == "weapons\\plasma rifle\\plasma rifle" then
873 if PlasmaRifle[player] == 1 then
874
875 response = 1
876 else
877 response = 0
878 end
879
880 elseif tagName == "weapons\\plasma pistol\\plasma pistol" then
881 if PlasmaPistol[player] == 1 then
882
883 response = 1
884 else
885 response = 0
886 end
887
888 elseif tagName == "weapons\\needler\\mp_needler" then
889 if Needler[player] == 1 then
890
891 response = 1
892 else
893 response = 0
894 end
895
896 elseif tagName == "weapons\\flamethrower\\flamethrower" then
897 if Flamethrower[player] == 1 then
898
899 response = 1
900 else
901 response = 0
902 end
903
904 elseif tagName == "weapons\\plasma_cannon\\plasma_cannon" then
905 if FuelRod[player] == 1 then
906
907 response = 1
908 else
909 response = 0
910 end
911
912 elseif tagName == "weapons\\rocket launcher\\rocket launcher" then
913 if Rocket[player] == 1 then
914
915 response = 1
916 else
917 response = 0
918 end
919
920 elseif tagName == "weapons\\shotgun\\shotgun" then
921 if Shotgun[player] == 1 then
922
923 response = 1
924 else
925 response = 0
926 end
927
928 elseif tagName == "weapons\\sniper rifle\\sniper rifle" then
929 if Sniper[player] == 1 then
930
931 response = 1
932 else
933 response = 0
934 end
935 end
936
937 elseif tagType == "eqip" then
938
939 if tagName == "weapons\\frag grenade\\frag grenade" or tagName == "weapons\\plasma grenade\\plasma grenade" then
940
941 -- Don't let players pick up grenades.
942 response = 0
943 else
944 -- Let players pick up overshield, camo, and health.
945 response = 1
946 end
947 end--]]
948
949 local response = 1
950
951 if game_started == true then
952
953 -- regardless of the team, stop people taking the flag
954 if tagType == "weap" then
955 if tagName == "weapons\\flag\\flag" then
956 response = 0
957 end
958 end
959
960 if response == 1 then
961
962 local team = getteam(player)
963
964 if team == zombie_team then
965
966 -- we want to stop zombies picking up weapons
967 if tagType == "weap" then
968 response = 0
969 elseif tagType == "eqip" then
970
971 if tagName == "weapons\\frag grenade\\frag grenade" or tagName == "weapons\\plasma grenade\\plasma grenade" then
972 response = 0 -- don't let them pick the nades
973 elseif tagName == "powerups\\active camouflage" then
974
975 -- check if the picking player is already invisible
976 local m_player = getplayer(player)
977 if m_player ~= nil then
978
979 local m_playerObjId = readdword(m_player, 0x34)
980 local m_object = getobject(m_playerObjId)
981 if m_object ~= nil then
982
983 local camoFlag = readdword(m_object, 0x204)
984 if camoFlag ~= 0x51 then
985
986 -- check if zombies are to be made invisible
987 local doInvis = getrandomnumber(1, 10)
988
989 if doInvis > 5 then
990
991 -- make the whole zombie team invis for 20 seconds
992 for x = 0,15 do
993
994 local team = getteam(x)
995
996 if team == zombie_team and x ~= player then
997 --hprintf("applying camo to player " .. x)
998 applycamo(x, 30.00)
999 end
1000 end
1001
1002 say(zombieinvis_message)
1003 end
1004 end
1005 end
1006 end
1007 end
1008 end
1009 end
1010 end
1011 end
1012
1013 return response
1014end
1015
1016
1017function OnWeaponReload(player, weapon)
1018
1019 return 1
1020end
1021
1022
1023function OnVehicleEntry(relevant, player, vehicleId, vehicle_tag, seat)
1024
1025 local response = 1
1026 if game_started and relevant == 1 then
1027
1028 local team = getteam(player)
1029 if team == zombie_team then
1030 response = 0
1031 end
1032 end
1033
1034 return response
1035end
1036
1037
1038function OnDamageLookup(receiving_obj, causing_obj, tagdata, tagname)
1039
1040 -- Resolve the object ids into player ids
1041 -- Remember, the damage doesn't always need to be done by a player.
1042 local receiver = objecttoplayer(receiving_obj)
1043 local causer = objecttoplayer(causing_obj)
1044
1045 -- We want to amplify human damage, so make sure the causer is human
1046 if causer ~= nil then
1047
1048 local c_team = getteam(causer)
1049 -- Make sure the team was found
1050 if c_team ~= nil then
1051
1052 -- Check if it's a human causing the damage
1053 if c_team == human_team then
1054
1055 -- It's human damage, read the current damage the weapon has
1056 local min_dmg = readfloat(tagdata, 0x1D0)
1057 local max_dmg_min = readfloat(tagdata, 0x1D4)
1058 local max_dmg_max = readfloat(tagdata, 0x1D8)
1059
1060 -- This is used to increase human damage (for last man)
1061 local modifier = 1.0
1062
1063 -- Check if we're up to last man
1064 if cur_last_man ~= nil then
1065 -- Change the damage modifier to the last man's
1066 modifier = lastman_dmgmodifier
1067 end
1068
1069 -- Change the damage that will be done
1070 writefloat(tagdata, 0x1D0, min_dmg * 2 * modifier)
1071 writefloat(tagdata, 0x1D4, max_dmg_min * 2 * modifier)
1072 writefloat(tagdata, 0x1D8, max_dmg_max * 2 * modifier)
1073
1074 -- It's a zombie causing the damage
1075 elseif c_team == zombie_team then
1076
1077 -- check if it is melee damage, if so increase it to instant kill
1078 local found = string.find(tagname, "melee", -5)
1079
1080 -- We only want to increase zombie's melee damage
1081 if found ~= nil then
1082
1083 -- make melee instant kill
1084 writefloat(tagdata, 0x1D0, 500)
1085 writefloat(tagdata, 0x1D4, 500)
1086 writefloat(tagdata, 0x1D8, 500)
1087
1088 end
1089 end
1090 end
1091 end
1092end
1093
1094function OnWeaponAssignment(player, object, count, tag)
1095
1096 -- Make sure the weapon is being assigned to a player, not a vehicle
1097
1098 if player ~= 0xFFFFFFFF then
1099
1100 -- Determine what weapon(s) a player will spawn with.
1101 -- Sum it up.
1102
1103 local weap_sum = assault_rifle + pistol + needler + plasma_rifle + plasma_pistol + fuel_rod + rocket + flamethrower + shotgun + sniper
1104 local weap2_sum = no_weapon + assault_rifle_2 + pistol_2 + needler_2 + plasma_rifle_2 + plasma_pistol_2 + fuel_rod_2 + rocket_2 + flamethrower_2 + shotgun_2 + sniper_2
1105
1106 -- Find the highest precision used (see the GRENADES section for more info on how this works).
1107
1108 local w = {assault_rifle, pistol, needler, plasma_rifle, plasma_pistol, fuel_rod, rocket, flamethrower, shotgun, sniper}
1109 local w2 = {no_weapon, assault_rifle_2, pistol_2, needler_2, plasma_rifle_2, plasma_pistol_2, fuel_rod_2, rocket_2, flamethrower_2, shotgun_2, sniper_2}
1110 local precision = findHighestPrecision(w)
1111 local precision_2 = findHighestPrecision(w2)
1112 local x = 10^precision
1113 local y = 10^precision_2
1114
1115 local weapon = getrandomnumber(0, (weap_sum * x))
1116 local weapon2 = getrandomnumber(0, (weap2_sum * y))
1117
1118 -- Primary
1119
1120 if count == 0 then
1121 if weapon >= 0 and weapon < (x * plasma_pistol) then
1122
1123 actualWeapon = lookuptag("weap", "weapons\\plasma pistol\\plasma pistol")
1124 privatesay(player, "Plasma Pistol.")
1125 PlasmaPistol[resolveplayer(player)] = 1
1126
1127 elseif weapon >= (x * plasma_pistol) and weapon < (x * (plasma_pistol + assault_rifle)) then
1128
1129 actualWeapon = lookuptag("weap", "weapons\\assault rifle\\assault rifle")
1130 privatesay(player, "Assault Rifle.")
1131 AssaultRifle[resolveplayer(player)] = 1
1132
1133 elseif weapon >= (x * (plasma_pistol + assault_rifle)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle)) then
1134
1135 actualWeapon = lookuptag("weap", "weapons\\plasma rifle\\plasma rifle")
1136 privatesay(player, "Plasma Rifle.")
1137 PlasmaRifle[resolveplayer(player)] = 1
1138
1139 elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol)) then
1140
1141 actualWeapon = lookuptag("weap", "weapons\\pistol\\pistol")
1142 privatesay(player, "Pistol.")
1143 Pistol[resolveplayer(player)] = 1
1144
1145 elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun)) then
1146
1147 actualWeapon = lookuptag("weap", "weapons\\shotgun\\shotgun")
1148 privatesay(player, "Shotgun.")
1149 Shotgun[resolveplayer(player)] = 1
1150
1151 elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler)) then
1152
1153 actualWeapon = lookuptag("weap", "weapons\\needler\\mp_needler")
1154 privatesay(player, "Needler.")
1155 Needler[resolveplayer(player)] = 1
1156
1157 elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper)) then
1158
1159 actualWeapon = lookuptag("weap", "weapons\\sniper rifle\\sniper rifle")
1160 privatesay(player, "Sniper.")
1161 Sniper[resolveplayer(player)] = 1
1162
1163 elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper + flamethrower)) then
1164
1165 actualWeapon = lookuptag("weap", "weapons\\flamethrower\\flamethrower")
1166 privatesay(player, "Flamethrower.")
1167 Flamethrower[resolveplayer(player)] = 1
1168
1169 elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper + flamethrower)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper + flamethrower + rocket)) then
1170
1171 actualWeapon = lookuptag("weap", "weapons\\rocket launcher\\rocket launcher")
1172 privatesay(player, "Rocket.")
1173 Rocket[resolveplayer(player)] = 1
1174
1175 elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper + flamethrower + rocket)) and weapon < (x * weap_sum) then
1176
1177 actualWeapon = lookuptag("weap", "weapons\\plasma_cannon\\plasma_cannon")
1178 privatesay(player, "Fuel Rod.")
1179 FuelRod[resolveplayer(player)] = 1
1180 end
1181
1182 -- Secondary
1183
1184 elseif count == 1 then
1185
1186 if weapon2 >= 0 and weapon2 < (y * plasma_pistol_2) then
1187
1188 if PlasmaPistol[resolveplayer(player)] ~= 1 then -- Make sure player doesn't spawn with the same primary and secondary weapon
1189
1190 actualWeapon = lookuptag("weap", "weapons\\plasma pistol\\plasma pistol")
1191 privatesay(player, "Secondary: Plasma Pistol")
1192 PlasmaPistol[resolveplayer(player)] = 1
1193 end
1194
1195 elseif weapon2 >= (y * plasma_pistol_2) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2)) then
1196
1197 if AssaultRifle[resolveplayer(player)] ~= 1 then
1198
1199 actualWeapon = lookuptag("weap", "weapons\\assault rifle\\assault rifle")
1200 privatesay(player, "Secondary: Assault Rifle")
1201 AssaultRifle[resolveplayer(player)] = 1
1202 end
1203
1204 elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2)) then
1205
1206 if PlasmaRifle[resolveplayer(player)] ~= 1 then
1207
1208 actualWeapon = lookuptag("weap", "weapons\\plasma rifle\\plasma rifle")
1209 privatesay(player, "Secondary: Plasma Rifle")
1210 PlasmaRifle[resolveplayer(player)] = 1
1211 end
1212
1213 elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2)) then
1214
1215 if Needler[resolveplayer(player)] ~= 1 then
1216
1217 actualWeapon = lookuptag("weap", "weapons\\needler\\mp_needler")
1218 privatesay(player, "Secondary: Needler")
1219 Needler[resolveplayer(player)] = 1
1220 end
1221
1222 elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2)) then
1223
1224 if Pistol[resolveplayer(player)] ~= 1 then
1225
1226 actualWeapon = lookuptag("weap", "weapons\\pistol\\pistol")
1227 privatesay(player, "Secondary: Pistol")
1228 Pistol[resolveplayer(player)] = 1
1229 end
1230
1231 elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2)) then
1232
1233 if Shotgun[resolveplayer(player)] ~= 1 then
1234
1235 actualWeapon = lookuptag("weap", "weapons\\shotgun\\shotgun")
1236 privatesay(player, "Secondary: Shotgun")
1237 Shotgun[resolveplayer(player)] = 1
1238 end
1239
1240 elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2)) then
1241
1242 if Sniper[resolveplayer(player)] ~= 1 then
1243
1244 actualWeapon = lookuptag("weap", "weapons\\sniper rifle\\sniper rifle")
1245 privatesay(player, "Secondary: Sniper")
1246 Sniper[resolveplayer(player)] = 1
1247 end
1248
1249 elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2)) then
1250
1251 if Rocket[resolveplayer(player)] ~= 1 then
1252
1253 actualWeapon = lookuptag("weap", "weapons\\rocket launcher\\rocket launcher")
1254 privatesay(player, "Secondary: Rocket Launcher")
1255 Rocket[resolveplayer(player)] = 1
1256 end
1257
1258 elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2 + flamethrower_2)) then
1259
1260 if Flamethrower[resolveplayer(player)] ~= 1 then
1261
1262 actualWeapon = lookuptag("weap", "weapons\\flamethrower\\flamethrower")
1263 privatesay(player, "Secondary: Flamethrower")
1264 Flamethrower[resolveplayer(player)] = 1
1265 end
1266
1267 elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2 + flamethrower_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2 + flamethrower_2 + fuel_rod_2)) then
1268
1269 if FuelRod[resolveplayer(player)] ~= 1 then
1270
1271 actualWeapon = lookuptag("weap", "weapons\\plasma_cannon\\plasma_cannon")
1272 privatesay(player, "Secondary: Fuel Rod")
1273 FuelRod[resolveplayer(player)] = 1
1274 end
1275 end
1276 end
1277 end
1278
1279 return actualWeapon
1280end
1281
1282
1283function OnObjectCreation(m_objId, player_owner, tagName)
1284
1285
1286end
1287
1288function OnClientUpdate(player, m_object)
1289
1290
1291end
1292
1293function OnVehicleEject(player, forced)
1294
1295 return 1
1296end
1297
1298function findHighestPrecision(array)
1299
1300 local precision = 0 -- Initialize.
1301
1302 for i = 1, #array do -- From the first element of the array to the last, do...
1303
1304 local p = getPrecision(array[i]) -- Get the precision of each element.
1305
1306 if p > precision then
1307 precision = p -- Set the highest value found to the variable "precision".
1308 end
1309 end
1310
1311 return precision -- return it.
1312end
1313
1314function getPrecision(number)
1315
1316 local temp = math.ceil(number) -- Truncate digits after the decimal (could use math.floor here too; doesn't really matter).
1317 local count = 0 -- Initialize a count.
1318
1319 while temp ~= number do -- If these are equal, our precision has been reached.
1320
1321 number = number * 10 -- Move to the next decimal place.
1322 temp = math.ceil(number) -- Set temp to be the truncated version of this new number.
1323 count = count + 1 -- Increase the count.
1324 end
1325
1326 return count -- Return the precision of the number.
1327end
1328
1329function applyos(player)
1330
1331 boolean = false -- Initialize
1332 local hash = gethash(player)
1333
1334 if hash ~= nil then -- Make sure player exists
1335
1336 local m_player = getplayer(player)
1337
1338 if m_player ~= nil then
1339
1340 local m_objId = readdword(m_player, 0x34)
1341 local m_object = getobject(m_objId)
1342
1343 if m_object ~= nil then -- Make sure player is alive
1344
1345 -- Get player's coordinates
1346 local x = readfloat(m_object, 0x5C)
1347 local y = readfloat(m_object, 0x60)
1348 local z = readfloat(m_object, 0x64)
1349
1350 createobject("eqip", "powerups\\over shield", 0, 0, false, x, y, z) -- Create Overshield
1351
1352 boolean = true -- The application was successful
1353 end
1354 end
1355 end
1356
1357 return boolean -- Return success or failure of application
1358end
1359
1360-- This function is courtesy of Smiley's awesomeness
1361
1362function convertbase(inputbase, outputbase, input)
1363
1364 local power = 0
1365 local answer = 0
1366 local number = math.floor(input / (outputbase^power))
1367 local check = true
1368
1369 for word in string.gmatch(tostring(input), "%d") do
1370 if tonumber(word) >= inputbase then
1371 check = false
1372 break
1373 end
1374 end
1375
1376 if check == false then
1377 answer = 0
1378 else
1379 if input == 0 then
1380 answer = 0
1381 else
1382
1383 while number ~= 1 do
1384 power = power + 1
1385 number = math.floor(input / (outputbase^power))
1386 end
1387
1388 while power >= 0 do
1389 number = math.floor(input / (outputbase^power))
1390 input = input - (number * (outputbase^power))
1391 answer = answer + (number * (inputbase^power))
1392 power = power - 1
1393 end
1394 end
1395 end
1396
1397 return answer
1398end
1399
1400function HelpTimer(id, count, player)
1401
1402 if count == 15 then
1403 privatesay(player, "FAQ: Why can't I pick up weapons?")
1404 elseif count == 18 then
1405 privatesay(player, "You spawn with a random weapon set and are stuck with it until you die.")
1406 return 0
1407 end
1408
1409 return 1
1410end
1411
1412-- The below functions are used internally within the Lua script
1413function NewGameTimer(id, count)
1414
1415 if count == 5 then
1416
1417 say("The game is starting...")
1418
1419 if cur_players ~= 0 then
1420
1421 local newgame_zombie_count = 0
1422
1423 -- by default make all players human
1424 for x=0,15 do
1425 local thisTeam = getteam(x)
1426 if thisTeam ~= nil then
1427 if thisTeam == zombie_team then
1428 changeteam(x, 0)
1429 end
1430 end
1431 end
1432
1433 local possible_count = cur_players
1434
1435 -- make players zombie until the count has been met
1436 local finalZombies = 0
1437
1438 if zombie_count >= 1 then
1439 finalZombies = zombie_count
1440 else
1441 finalZombies = round((possible_count * zombie_count) + 0.5)
1442 end
1443
1444 -- make last man zombie
1445 local last_man_index = -1
1446
1447 -- check if the last man is to be made a zombie
1448 -- if so find who was last man
1449 if last_man_next_zombie == true and cur_players > 1 then
1450
1451 -- loop through all hashes and check if any match the last man
1452 for i=0,15 do
1453 local hash = gethash(i)
1454
1455 if hash ~= nil then
1456 if last_man_hash == hash then
1457
1458 -- make them a zombie and save their info
1459 makezombie(i, true)
1460 newgame_zombie_count = 1
1461 last_man_index = i
1462
1463 break
1464 end
1465 end
1466 end
1467 end
1468
1469 -- reset last man
1470 last_man_hash = 0
1471
1472 --hprintf("Expecting " .. finalZombies .. " zombies. Cur players " .. cur_players .. " possibles " .. possible_count)
1473
1474 if finalZombies == cur_players then -- if 0 players they will be human
1475 finalZombies = finalZombies - 1
1476 elseif finalZombies > possible_count then -- fix the count
1477 finalZombies = possible_count
1478 elseif max_zombie_count ~= nil and finalZombies > max_zombie_count then -- cap the zombie count
1479 finalZombies = max_zombie_count
1480 elseif finalZombies < 0 then
1481 finalZombies = 0
1482 end
1483
1484 -- set counters such that changeteam wont end the game
1485 cur_zombie_count = 16
1486 cur_human_count = 16
1487
1488 --hprintf("Expecting " .. finalZombies .. " zombies. Cur players " .. cur_players .. " possibles " .. possible_count)
1489
1490 -- loop through the players, randomly selecting ones to become
1491 -- zombies
1492 while (newgame_zombie_count < finalZombies) do
1493
1494 -- randomly choose a player
1495 local newzomb = ChooseRandomPlayer(zombie_team)
1496
1497 if newzomb == nil then
1498 break
1499 elseif newzomb ~= last_man_index then
1500
1501 makezombie(newzomb, true)
1502 newgame_zombie_count = newgame_zombie_count + 1
1503 end
1504 end
1505
1506 -- fix the team counters
1507 cur_zombie_count = newgame_zombie_count
1508 cur_human_count = cur_players - finalZombies
1509
1510 -- reset the map
1511 svcmd("sv_map_reset")
1512
1513 -- loop through and tell players which team they're on
1514 for i=0,15 do
1515
1516 local pteam = getteam(i)
1517 if pteam ~= nil then
1518 -- check if they're a zombie
1519 if pteam == zombie_team then
1520 privatesay(i, zombie_message)
1521 else
1522 privatesay(i, human_message)
1523 end
1524 end
1525 end
1526
1527 end
1528
1529 game_started = true
1530
1531 return 0 -- remove timer
1532 else
1533 say("The game will start in " .. 10 - 2*count .. " seconds.")
1534
1535 return 1 -- keep timer
1536 end
1537end
1538
1539function PlayerChangeTimer(id, count)
1540 if count ~= 10 then
1541
1542 local zombsize = cur_zombie_count
1543
1544 if allow_change == false or zombsize > 0 then
1545
1546 allow_change = false
1547
1548 say("Thank you, the game can continue.")
1549
1550 return 0
1551 end
1552
1553 say("In " .. 10 - count .. " seconds a player will be forced to become a zombie.")
1554
1555 return 1
1556 else -- timer up, force team change
1557
1558 allow_change = false
1559
1560 -- pick a human and make them zombie.
1561 local newZomb = ChooseRandomPlayer(zombie_team)
1562
1563 if newZomb ~= nil then
1564 makezombie(newZomb, true)
1565 privatesay(player, zombie_message)
1566 end
1567
1568 return 0
1569 end
1570end
1571
1572-- this function searches through current players and selects a random one
1573function ChooseRandomPlayer(excludeTeam)
1574
1575 local t = {}
1576
1577 -- loop through all 16 possible spots and add to table
1578 for i=0,15 do
1579
1580 -- check if the player exists
1581 local team = getteam(i)
1582
1583 if team ~= nil and team ~= excludeTeam then
1584 table.insert(t, i)
1585 end
1586
1587 end
1588
1589 if #t > 0 then
1590 -- generate a random number that we will use to select a player
1591 local tableCount = table.getn(t)
1592 local r = getrandomnumber(1, tableCount+1)
1593 return t[r]
1594 else
1595 return nil
1596 end
1597end
1598
1599function RemoveLastmanProtection(id, count, m_object)
1600 writebit(m_object, 0x10, 7, 0)
1601 return 0
1602end
1603
1604-- there are no zombies left
1605function noZombiesLeft()
1606
1607 allow_change = true
1608 say("There are no zombies left. Someone needs to change team, otherwise a random player will be forced to.")
1609 player_change_timer = registertimer(1000, "PlayerChangeTimer")
1610
1611end
1612
1613-- called when its the last man
1614function onlastman()
1615
1616 -- lookup the last man
1617 for x=0,15 do
1618 local team = getteam(x)
1619
1620 if team == human_team then
1621
1622 cur_last_man = x
1623 -- give the last man speed and extra ammo
1624 setspeed(x, lastman_speed)
1625
1626 -- find the last man's weapons
1627 local m_player = getplayer(x)
1628
1629 if m_player ~= nil then
1630 local m_ObjId = readdword(m_player, 0x34)
1631
1632 -- find the player's object
1633 local m_object = getobject(m_ObjId)
1634
1635 if m_object ~= nil then
1636
1637 if lastman_invulnerable ~= nil and lastman_invulnerable > 0 then
1638 -- setup the invulnerable timer
1639 writebit(m_object, 0x10, 7, 1)
1640 registertimer(lastman_invulnerable * 1000, "RemoveLastmanProtection", m_object)
1641 end
1642
1643 -- give all weapons 600 ammo
1644 for i=0,3 do
1645 local m_weaponId = readdword(m_object, 0x2F8 + (i*4))
1646
1647 if m_weaponId ~= 0xffffffff then
1648
1649 -- get the weapons memory address
1650 local m_weapon = getobject(m_weaponId)
1651
1652 if m_weapon ~= nil then
1653 -- set the ammo
1654 writeword(m_weapon, 0x2B6, 600)
1655 end
1656 end
1657 end
1658 end
1659 end
1660 end
1661 end
1662
1663 if cur_last_man ~= nil then
1664
1665 local lastman_name = getname(cur_last_man)
1666 local msg = string.format("%s is the last man alive and is invisible for %.0f seconds!", lastman_name, lastman_invistime)
1667 say(msg)
1668 applycamo(cur_last_man, lastman_invistime)
1669 end
1670
1671
1672end
1673
1674-- checks the game state, for last man, all zombies etc
1675-- called onteamchange, player join and leave
1676function checkgamestate(player)
1677
1678 -- check if the game has started yet
1679 if game_started == true then
1680
1681 local zombie_count = cur_zombie_count
1682 local human_count = cur_human_count
1683 --hprintf("zombie count " .. zombie_count)
1684 --hprintf("human count " .. human_count)
1685
1686 -- if no humans, but there are zombies, end the game
1687 if human_count == 0 and zombie_count > 0 then
1688 all_players_zombies(player)
1689 elseif human_count > 1 and zombie_count == 0 then
1690 noZombiesLeft()
1691 elseif human_count == 1 and zombie_count > 0 and cur_last_man == nil then
1692 onlastman()
1693 elseif cur_last_man ~= nil and zombie_count == 0 then
1694 makehuman(cur_last_man, false)
1695 cur_last_man = nil
1696 end
1697 end
1698end
1699
1700-- called when all players are zombies (no shit)
1701function all_players_zombies(player)
1702
1703 -- if there is a last man, store their hash
1704 if player ~= -1 then
1705 last_man_hash = gethash(player)
1706 -- write the hash to file
1707 local file = io.open("lasthash_" .. processid .. ".tmp", "w")
1708
1709 if (file ~= nil) then
1710 file:write(last_man_hash)
1711 file:close()
1712 end
1713 end
1714
1715 -- move onto the next map
1716 svcmd("sv_map_next")
1717end
1718
1719function makezombie(player, forcekill)
1720
1721 -- change the player's speed
1722 setspeed(player, zombie_speed)
1723
1724 local team = getteam(player)
1725 if team == human_team then
1726 changeteam(player, forcekill)
1727 end
1728end
1729
1730function makehuman(player, forcekill)
1731 -- change the player's speed
1732 setspeed(player, human_speed)
1733
1734 local team = getteam(player)
1735 if team == zombie_team then
1736 changeteam(player, forcekill)
1737 end
1738end
1739
1740function getalphacount()
1741 -- recalculate how many "alpha" zombies there are
1742 if zombie_count < 1 then
1743 alpha_zombie_count = round((cur_players * zombie_count) + 0.5)
1744 else
1745 alpha_zombie_count = zombie_count
1746 end
1747
1748 if alpha_zombie_count > max_zombie_count then
1749 alpha_zombie_count = max_zombie_count
1750 end
1751 return alpha_zombie_count
1752end
1753
1754
1755function round(num)
1756 under = math.floor(num)
1757 upper = math.floor(num) + 1
1758 underV = -(under - num)
1759 upperV = upper - num
1760 if (upperV > underV) then
1761 return under
1762 else
1763 return upper
1764 end
1765end