Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creator: AelitePrime and Wizard
- --Script Name: Zombie Script
- --Website: http://phasorscripts.wordpress.com/
- --Xfire: eliteprime14789x, and th3w1zard3
- --Version: 4.0
- --Reason for Update: Phasor Update
- -- General infection settings
- frag_nade = true -- Block Frag Grenades?
- plasma_nade = true -- Block Plasma Grenades?
- -- Gravity Rifle Info
- gravity = {}
- vehicles = {}
- activetime = {}
- ------
- -- Team Variables
- zombie_team = 1 -- 0 is red, 1 is blue
- human_team = 0
- join_team = zombie_team -- the team that people will join if a game is currently running
- -- Last Man Variables
- lastman_speed = 2.0 -- last man speed
- lastman_dmgmodifier = 2.0 -- damage modifier for the last man (on top of human damage)
- lastman_invistime = 20 -- in seconds
- last_man_next_zombie = true -- if this value is true the last man standing becomes the next zombie, if not it's random
- lastman_invulnerable = 5 -- time (in seconds) the last man is invulnerable for: replace with nil to disable
- -- Speed Variables
- zombie_speed = 3.0 -- zombie speed
- human_speed = 1.6 -- speed when not infected
- -- Alpha Zombie Variables
- alphazombie_frag_count = 0 -- number of frag nades they spawn with
- alphazombie_plasma_count = 0 -- number of plasma nades they spawn with
- alphazombie_clip_count = 0 -- number of shots in clip (loaded ammo)
- alphazombie_ammo_count = 0 -- backpack ammo they get (unloaded ammo)
- alphazombie_battery_count = 0 -- stored as a percent (0 to 1, do NOT go over or under)
- -- Zombie Variables
- zombie_count = 1 -- if value is less than 1 is it used as a percentage, more than or equal to one is absolute count
- max_zombie_count = 2 -- this caps what the zombie count would be w/ ratio (nil is disable)
- zombie_frag_count = 0 -- number of frag nades they spawn with
- zombie_plasma_count = 0 -- number of plasma nades they spawn with
- zombie_clip_count = 0 -- number of shots in clip for zombies once there are not only alpha zombies (loaded ammo)
- zombie_ammo_count = 0 -- backpack ammo zombies once there are not only alpha zombies (unloaded ammo)
- zombie_battery_count = 0 -- stored as a percent (0 to 1, do NOT go over or under)
- -- Damage Variable
- human_dmgmodifier = 1.5 -- damage modifier for humans.
- -- Invis Variables
- time_invis = 1 -- In seconds, how long the zombie/human should be invis when they crouch.
- -- Booleans
- zombie_instant_kill = true -- if this is set to true then a zombie melee will kill a human with one hit every time.
- infect_on_fall = true -- if this is set to true then people who die from fall damage will become zombies.
- infect_on_guardians = false -- if this is set to true then people who get killed by the guardians will become zombies.
- infect_on_suicide = true -- if this is set to true then people who kill themselves will become a zombie.
- infect_on_betray = true -- if this is set to true then people who betray their teammates will become a zombie.
- humans_allowed_in_vehis = false -- if this is set to false then humans cannot enter vehicles
- zombies_allowed_in_vehis = true -- if this is set to false then zombies cannot enter vehicles.
- zombies_invisible_on_crouch = true -- if this is set to true then zombies will be invisible when they crouch.
- humans_invisible_on_crouch = false -- if this is set to true then humans will become invisible when they crouch.
- --Zombie weapons.
- -- Note: If you decide the player holds a flag or a ball, make sure the secondary, tertiary, and quarternary fields are "".
- -- DO NOT make zombies hold multiple weapons if you want them to hold an oddball or a flag. If you do it will not work right, and it's entirely your fault.
- zombie_weapon = {} -- don't touch this
- zombie_weapon[1] = "weapons\\shotgun\\shotgun" -- Primary weapon for zombies
- zombie_weapon[2] = "" -- Secondary weapon for zombies.
- zombie_weapon[3] = "" -- Tertiary weapon for zombies.
- zombie_weapon[4] = "" -- Quarternary weapon for zombies.
- -- Game messages
- zombie_message = "YOU'RE A ZOMBIE! Melee Human Flesh!"
- human_message = "YOU'RE A HUMAN. Kill Zombies w/ VEHICLES!"
- rejoin_message = "Please don't leave and rejoin. You've been put back onto your last team."
- infected_message = " has been eaten alive!"
- teamkill_message = "What Are You Doing, Nigga. Don't team kill..."
- blockteamchange_message = "You're not allowed to change team."
- zombieinvis_message = "The zombies are invisible for 20 seconds!"
- timer_team_change_msg = "Thank you. The game will now continue"
- in_hill_too_long_msg = " has been infected because they were in the hill too long!"
- koth_additional_welcome_msg = "The hill is a safezone! Use it for quick getaways!"
- lastman_message = "%s is the last human alive and is invisible for %.0f seconds!"
- nozombiesleftmessage = "There are no zombies left. Someone needs to change team, otherwise a random player will be forced to."
- zombie_backtap_message = "Nice backtap!"
- human_backtap_message = "%s slaughtered you from behind." -- lol
- -- Don't modify below variables unless you know what you're doing
- cur_zombie_count = 0
- cur_human_count = 0
- alpha_zombie_count = 0
- human_time = {}
- cur_players = 0
- cur_last_man = nil
- last_man_hash = 0
- processid = 0
- game_started = false
- allow_change = false
- map_reset_boolean = false
- flagball_weap = {}
- last_hill_time = {}
- hash_table = {}
- inhill_time = {}
- speed_count = {}
- function GetRequiredVersion()
- return 200
- end
- function OnScriptLoad(process, game, persistent)
- processid = process
- Persistent = persistent
- GetGameAddresses(game)
- ScriptLoad()
- end
- function OnNewGame(map)
- if Persistent then
- ScriptLoad()
- end
- -- reset our variables
- cur_zombie_count = 0
- cur_human_count = 0
- cur_players = 0
- map = map
- -- the game hasn't started yet, will once timer runs down
- game_started = false
- if new_game_timer == nil then
- new_game_timer = registertimer(1000, "NewGameTimer")
- end
- if map == "putput" or map == "longest" or map == "beavercreek" then
- zombie_speed = 1.5
- lastman_speed = 1.25
- end
- end
- function OnGameEnd(stage)
- game_started = false
- if stage == 1 then
- if humantimer then
- removetimer(humantimer)
- humantimer = nil
- end
- if new_game_timer then
- removetimer(new_game_timer)
- new_game_timer = nil
- end
- if crouch_timer then
- removetimer(crouch_timer)
- crouch_timer = nil
- end
- if speedtimer then
- removetimer(speedtimer)
- speedtimer = nil
- end
- end
- end
- function OnServerCommand(player, command)
- local allow = nil
- local cmd = tokenizecmdstring(command)
- local tokencount = #cmd
- if tokencount > 0 then
- if cmd[1] == "sv_changeteam" and tokencount == 2 then
- local player = cmd[2]
- player = rresolveplayer(player)
- if getplayer(player) then
- local cur_team = getteam(player)
- if cur_team == zombie_team then
- makehuman(player, true)
- privatesay(player, human_message)
- elseif cur_team ~= zombie_team then
- makezombie(player, true)
- privatesay(player, zombie_message)
- end
- --sendresponse("The player's team has been changed.", player)
- else
- sendresponse("The specified player is invalid", player)
- end
- allow = false
- elseif cmd[1] == "sv_map_reset" or cmd[1] == "sv_script_reload" then
- map_reset_boolean = true
- for i = 0,15 do
- local m_player = getplayer(i)
- if m_player then
- local m_objectId = getplayerobjectid(i)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- local team = getteam(i)
- if team == zombie_team then
- if m_objectId then
- destroyobject(m_objectId)
- end
- end
- end
- end
- end
- end
- end
- end
- return allow
- end
- function OnPlayerJoin(player)
- speed_count[player] = 0
- -- update the player counts
- cur_players = cur_players + 1
- local team = getteam(player)
- -- onteamdecision isn't called for ffa gametypes
- if not team_play then
- -- initialize the destination team as the join team
- local dest_team = join_team
- -- make sure the game is started
- if game_started then
- -- if no zombies make them human
- if cur_players == 0 then
- -- change the destination team to human if cur_players 0 (doesn't matter if join_team is humanteam)
- dest_team = human_team
- -- check if there are zombies but no humans
- elseif cur_zombie_count > 0 and cur_human_count == 0 then
- -- change the destination team to human if condition met (doesn't matter if join_team is humanteam)
- dest_team = human_team
- end
- end
- -- we need to overwrite the 'team' variable being passed to onplayerjoin
- if dest_team == zombie_team then
- team = zombie_team
- elseif tonumber(dest_team) then
- team = 2
- end
- end
- local thisTeamSize = 0 -- used so we don't create empty teams for rejoining players
- if team == zombie_team then
- cur_zombie_count = cur_zombie_count + 1
- thisTeamSize = cur_zombie_count
- else
- cur_human_count = cur_human_count + 1
- thisTeamSize = cur_human_count
- end
- alpha_zombie_count = getalphacount()
- local thisHash = gethash(player)
- local alreadyExists = false
- -- check if the player has joined this game previously
- for k,v in pairs(hash_table) do
- if thisHash == k then
- if thisTeamSize > 1 then
- if v ~= team then
- --check what team they currently are (only added for ffa gametypes)
- if team == zombie_team then
- makehuman(player, false)
- else
- makezombie(player, false)
- end
- end
- privatesay(player, rejoin_message)
- team = v
- end
- alreadyExists = true
- break
- end
- end
- -- add team entry for this hash
- if alreadyExists == false then
- hash_table[thisHash] = team
- end
- -- make sure the game is started
- if game_started == true then
- -- check if the player is a zombie
- if team == zombie_team then
- --we don't need to update the counters since they're already on the zombieteam
- makezombie(player, false, true)
- --send them the zombie message
- privatesay(player, zombie_message)
- else
- -- if we're at last man, make this player a zombie
- if cur_last_man then
- --make this person a zombie (they're currently a human)
- makezombie(player, true)
- --send them the zombie message
- privatesay(player, zombie_message)
- else
- --make this person a human (they're currently a zombie)
- makehuman(player, false, true)
- --send them the human message
- privatesay(player, human_message)
- end
- end
- registertimer(0,"checkgamestate",-1)
- end
- end
- function OnPlayerLeave(player)
- speed_count[player] = 0
- gravity[player] = nil
- local team = getteam(player)
- --check if they're a zombie
- if game_started and team == zombie_team then
- --get their object struct
- local m_objectId = getplayerobjectid(player)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then -- make sure the player is alive
- for i = 0,3 do -- loop through all their weapons (primary through quartenary)
- --get their weapon's ID
- local weapID = readdword(m_object + 0x2F8 + i*4)
- if weapID then
- --get their weapon's struct
- local weap = getobject(weapID)
- --make sure the weapon exists
- if weap then
- --weapon needs to be destroyed
- registertimer(0, "destroyweaps", weapID)
- destroyobject(weapID)
- end
- end
- end
- end
- end
- --take one away from the current zombie count
- cur_zombie_count = cur_zombie_count - 1
- elseif team ~= zombie_team then
- --take one away from the current human count
- cur_human_count = cur_human_count - 1
- end
- -- if last man is leaving, reset it
- if cur_last_man == player then
- cur_last_man = nil
- end
- --minus one from current players
- cur_players = cur_players - 1
- --check the current game state (the player that left might have been the last man or the only zombie)
- registertimer(0,"checkgamestate",-1)
- -- update team within table
- local thisHash = gethash(player)
- hash_table[thisHash] = team
- end
- function OnPlayerSpawn(player)
- --get the player's team
- local team = getteam(player)
- --check if the player is a zombie
- if team == zombie_team then
- --get the player's object ID
- local m_objectId = getplayerobjectid(player)
- if m_objectId == nil then
- return
- end
- --get the player's object struct
- local m_object = getobject(m_objectId)
- --make sure the player is alive (off chance that there's a glitch in phasor)
- if m_object then
- -- set nade counts
- writebyte(m_object + 0x31E, zombie_frag_count)
- writebyte(m_object + 0x31F, zombie_plasma_count)
- -- set the ammo
- local clipcount = alphazombie_clip_count
- local ammocount = alphazombie_ammo_count
- local batterycount = alphazombie_battery_count
- -- set ammo counts for zombies when others have been infected
- if cur_zombie_count > alpha_zombie_count then
- clipcount = zombie_clip_count
- ammocount = zombie_ammo_count
- batterycount = zombie_battery_count
- else -- set alpha nades
- writebyte(m_object + 0x31E, alphazombie_frag_count)
- writebyte(m_object + 0x31F, alphazombie_plasma_count)
- end
- --check if the starting equipment is generic
- if starting_equipment == "Generic" then
- -- initialize this boolean as false
- local bool = false
- for i=0,3 do --loop through the player's weapons (primary through quartenary)
- --get the player's weapon's ID
- local m_weaponId = readdword(m_object + 0x2F8 + i*4)
- if m_weaponId == nil then
- return
- end
- --check if the zombie weapon is an oddball or a flag
- if oddball_or_flag then
- --make sure the boolean is still false and the player's weapon exists.
- if bool == false and getobject(m_weaponId) then
- --get the weapon's tagname
- local tagName = getobjecttag(m_weaponId)
- --make sure the weapon's tagname is the zombie weapon (oddball/flag)
- if tagName == oddball_or_flag then
- --store the weapon's ID in the flagball_weap table
- flagball_weap[player] = m_weaponId
- --set bool to true
- bool = true
- end
- end
- --zombie weapon is not a flag or a ball
- elseif m_weaponId then
- --get the weapon's struct
- local m_weapon = getobject(m_weaponId)
- --make sure the weapon exists
- if m_weapon then
- -- set the ammo
- writeword(m_weapon + 0x2B6, ammocount)
- writeword(m_weapon + 0x2B8, clipcount)
- -- set the battery (math.abs is absolute value meaning it takes the opposite of battery count (meaning 0 needs to be 1 and 1 needs to be 0))
- writefloat(m_weapon + 0x240, math.abs(batterycount - 1))
- -- force it to sync
- updateammo(m_weaponId)
- end
- end
- end
- -- check if we still need to assign leftover weapons to zombies (tertiary and quartenary weapons)
- if (zombie_weapon[3] and zombie_weapon[3] ~= "") then -- make sure the script user isn't retarded
- --assign the leftover weapons to the playerr
- if getplayer(player) then
- table = {player, clipcount, ammocount, batterycount}
- registertimer(0, "AssignLeftoverZombieWeapons", table)
- end
- end
- elseif starting_equipment == "Custom" then
- --assign the correct weapons to the player
- if getplayer(player) then
- table = {player, clipcount, ammocount, batterycount}
- registertimer(0, "AssignZombieWeapons", table)
- end
- end
- end
- end
- --check if the gametype is slayer
- if gametype == "Slayer" then
- local m_player = getplayer(player)
- --check if we're at the last_man
- if m_player == nil then
- return
- end
- if cur_last_man then
- --write the navpoint to the current last man
- writeword(m_player + 0x88, cur_last_man)
- else
- --there is no last man so put a nav above this player's head
- writeword(m_player + 0x88, player)
- end
- end
- end
- function OnPlayerSpawnEnd(player)
- if getteam(player) == 1 then -- blue team
- for i = 0,3 do
- local m_objectId = getplayerobjectid(player)
- local m_object = getobject(m_objectId)
- if m_object then
- local weapID = readdword(m_object + 0x2F8 + i*4)
- local weap = getobject(weapID)
- if weap then
- destroyobject(weapID)
- end
- end
- end
- local gun = createobject(gettagid("weap", "weapons\\shotgun\\shotgun"), 0, 1, false, 0, 0, 0)
- if getobject(gun) then
- assignweapon(player, gun)
- end
- registertimer(100, 'delay', player)
- end
- end
- function delay(id, count, player)
- if getplayer(player) then
- local m_objectId = getplayerobjectid(player)
- local m_object = getobject(m_objectId)
- if m_object then
- for i = 0, 3 do
- local m_weaponId = readdword(m_object + 0x2F8 + i*4)
- if m_weaponId then
- local m_weapon = getobject(m_weaponId)
- if m_weapon then
- writeword(m_weapon + 0x2B6, 0)
- writeword(m_weapon + 0x2B8, 0)
- writefloat(m_weapon + 0x240, math.abs(0 - 1))
- updateammo(m_weaponId)
- end
- end
- end
- end
- end
- return false
- end
- function OnObjectCreationAttempt(mapId, parentId, player)
- local tag_name, tag_type = gettaginfo(mapId)
- if gametype == "CTF" then
- if tag_name == "weapons\\flag\\flag" then
- local m_objectId = readdword(ctf_globals + 0x8)
- registertimer(0, "PutUnderMap", m_objectId)
- return
- end
- end
- if getplayer(player) then
- if getteam(player) == zombie_team then
- if tag_type == "proj" then
- return false
- end
- end
- end
- return nil
- end
- function OnObjectInteraction(player, objId, mapId)
- local tagName,tagType = gettaginfo(mapId)
- if tagName == "weapons\\flag\\flag" then
- return false
- end
- if getteam(player) == zombie_team then
- if tagName == "weapons\\frag grenade\\frag grenade" or tagName == "weapons\\plasma grenade\\plasma grenade" then
- return false
- end
- end
- if game_started == true then
- if tagType == "weap" then
- if getteam(player) == zombie_team then
- return false
- end
- if tagName == oddball_or_flag then
- return false
- end
- end
- if getteam(player) == zombie_team then
- if tagType == "eqip" then
- if tagName == "powerups\\active camouflage" then
- if getplayer(player) then
- local m_playerObjId = readdword(getplayer(player) + 0x34)
- local m_object = getobject(m_playerObjId)
- if m_object then
- local camoFlag = readdword(m_object + 0x204)
- if camoFlag ~= 0x51 then
- local doInvis = getrandomnumber(1, 11)
- if doInvis > 5 then
- for x = 0,15 do
- if getplayer(x) then
- local team = getteam(x)
- if team == zombie_team then
- applycamo(x, 30.00)
- end
- end
- end
- say(zombieinvis_message)
- end
- end
- end
- end
- return true
- elseif tagName == "powerups\\over shield" then
- return true
- end
- return false
- end
- end
- end
- return true
- end
- function OnPlayerKill(killer, victim, mode)
- if getplayer(victim) then
- gravity[victim] = nil
- end
- if getplayer(victim) then
- speed_count[victim] = 0
- end
- -- make sure this kill doesn't add to the score so that the game won't end prematurely
- if gametype == "Slayer" and killer and getplayer(killer) then writedword(slayer_globals + 0x40 + killer*4, 0) end
- -- make sure the game is started
- if game_started then
- -- get the victim's team
- local team = getteam(victim)
- if mode == 0 then -- server kill
- elseif mode == 1 and not map_reset_boolean then -- fall damage
- -- if this is true then a person who dies from falling will be infected
- if infect_on_fall then
- --chech if the team is the human team
- if tonumber(team) and team ~= zombie_team then
- --get the victim's name
- local name = getname(victim)
- --send the victim the infected message
- say(name .. infected_message)
- --make the victim a zombie
- registertimer(100, "makezombiedelay", {victim, false})
- end
- end
- elseif mode == 2 then -- killed by guardians
- -- if this is true then a person who dies from the guardians will be infected
- if infect_on_guardians then
- --check if the victim's team is the human team
- if tonumber(team) and team ~= zombie_team then
- --get the victim's name
- local name = getname(victim)
- --send the victim the infected message
- say(name .. infected_message)
- --make the victim a zombie
- registertimer(100, "makezombiedelay", {victim, false})
- end
- end
- elseif mode == 3 then -- killed by vehicle
- elseif mode == 4 then -- killed by another player
- --get the killer's team
- local killer_team = getteam(killer)
- -- check to see if a zombie killed them
- if tonumber(killer_team) and killer_team == zombie_team and tonumber(team) and team ~= zombie_team then
- --get the victim's name
- name = getname(victim)
- --send the victim the infected message
- say(name .. infected_message)
- --make the victim a zombie
- registertimer(100, "makezombiedelay", {victim, false})
- privatesay(victim, zombie_message)
- elseif killer_team ~= zombie_team and team == zombie_team then
- local hash = gethash(killer)
- human_time[hash] = tonumber(human_time[hash]) + 10
- end
- elseif mode == 5 then -- betrayed
- --if this is true then a person who betrays will be infected
- if infect_on_betray then
- --get the killer's team
- local killer_team = getteam(killer)
- --check if the killer is a human
- if tonumber(killer_team) and killer_team ~= zombie_team then
- --get the betrayer's name
- name = getname(killer)
- --send the betrayer the infected message
- say(tostring(name) .. infected_message)
- --make the betrayer a zombie
- registertimer(100, "makezombiedelay", {killer, true})
- end
- end
- elseif mode == 6 then -- suicide
- --if this is true then a person who suicides will be come a zombie
- if infect_on_suicide then
- -- if they're human, make them zombies
- if tonumber(team) and team ~= zombie_team then
- --get the suicider's name
- name = getname(victim)
- --they're not going to end their life that easily
- say(name .. infected_message)
- --make the suicider a zombie
- registertimer(100, "makezombiedelay", {victim, false})
- end
- end
- end
- -- this next block of code gets rid of any weapons a zombie is holding
- if tonumber(team) and team == zombie_team then
- local m_player = getplayer(victim) --get the player's struct
- if m_player == nil then
- return
- end
- local m_object = getobject(readdword(m_player + 0x34)) -- get the player's object struct
- --there's an off chance that the player might be dead (phasor bug) can't hurt to add this check
- if m_object then
- for i = 0,3 do -- loop through the player's weapons (primary to quartenary)
- local weapID = readdword(m_object + 0x2F8 + i*4)
- if weapID then
- local weap = getobject(weapID)
- --make sure the weapon exists
- if weap then
- --destroy their weapons
- registertimer(0, "destroyweaps", weapID)
- destroyobject(weapID)
- end
- end
- end
- end
- end
- end
- registertimer(200,"checkgamestate",victim)
- end
- function OnTeamDecision(team)
- local dest_team = join_team
- if game_started then
- if cur_players == 0 then -- if no zombies make them human
- dest_team = human_team
- elseif cur_zombie_count > 0 and cur_human_count == 0 then
- dest_team = human_team
- end
- end
- return dest_team
- end
- function OnTeamChange(player, old_team, dest_team, relevant)
- if relevant == 1 or relevant == true then
- if not allow_change then
- privatesay(player, blockteamchange_message)
- elseif allow_change and old_team == zombie_team then
- -- this is so memory is updated for processing
- -- when relevant is 0 OnTeamChange is called once the changes
- -- have been committed
- setspeed(player, zombie_speed)
- ChangeTeam(player, 1)
- end
- -- we don't let people change team
- elseif (relevant == 0 or relevant == false) and dest_team ~= team then -- we can't stop the person changing teams, bein done by an admin
- -- update team counts
- if dest_team == zombie_team then
- cur_human_count = cur_human_count - 1
- cur_zombie_count = cur_zombie_count + 1
- elseif dest_team ~= zombie_team then
- cur_human_count = cur_human_count + 1
- cur_zombie_count = cur_zombie_count - 1
- end
- -- they're allowed to change if the timer is active, if it is disable it
- if allow_change == true and dest_team == zombie_team then
- allow_change = false
- --remove change timer
- if player_change_timer then
- removetimer(player_change_timer)
- player_change_timer = nil
- end
- say(timer_team_change_msg)
- end
- -- check if the game has started yet
- if game_started == true then
- -- set attributes
- if dest_team == zombie_team then
- makezombie(player, false)
- elseif dest_team ~= zombie_team then
- makehuman(player, false)
- end
- registertimer(0,"checkgamestate",player)
- end
- -- update team withf
- local thisHash = gethash(player)
- hash_table[thisHash] = dest_team
- end
- return allow_change
- end
- function OnDamageApplication(receiving, causing, tagid, hit, backtap)
- if backtap then
- if causing and receiving then
- local r_object = getobject(receiving)
- local c_object = getobject(causing)
- if r_object and c_object then
- local causer = objectaddrtoplayer(c_object)
- local receiver = objectaddrtoplayer(r_object)
- if causer and receiver then
- local c_team = getteam(causer)
- local r_team = getteam(receiver)
- if c_team == zombie_team and r_team == human_team then
- privatesay(causer, zombie_backtap_message)
- privatesay(receiver, string.format(human_backtap_message,getname(causer)))
- end
- end
- end
- end
- end
- end
- function OnDamageLookup(receiver, causer, mapId, tagdata)
- local tagname = gettaginfo(mapId)
- if causing and receiving then
- local c_object = getobject(causing)
- local r_object = getobject(receiving)
- if c_object and r_object then
- local causer = objectaddrtoplayer(c_object)
- local receiver = objectaddrtoplayer(r_object)
- if causer and receiver then
- local c_team = getteam(causer)
- local r_team = getteam(receiver)
- if not team_play and r_team == c_team and causer ~= receiver then
- return false
- end
- if c_team then
- local tagname, tagtype = gettaginfo(mapId)
- if string.find(tagname, "melee") then
- odl_multiplier(500.0)
- end
- if c_team ~= zombie_team then
- if cur_last_man then
- modifier = lastman_dmgmodifier
- else
- modifier = human_dmgmodifier
- end
- if tagtype == "jpt!" then
- odl_multiplier(modifier)
- end
- elseif c_team == zombie_team then
- if not team_play and c_team == r_team and causer ~= receiver then
- privatesay(causer, "Do not hit your own team.")
- return false
- end
- end
- end
- end
- end
- end
- local tagname = gettaginfo(mapId)
- local rplayer, cplayer = nil, nil
- if receiver ~= nil then
- if getobject(receiver) then
- if tonumber(receiver) then
- local rplayer = objectidtoplayer(receiver)
- end
- end
- end
- if causer ~= nil then
- if getobject(causer) then
- if tonumber(causer) then
- local cplayer = objectidtoplayer(causer)
- end
- end
- end
- if cplayer and rplayer ~= nil then
- if getteam(cplayer) == getteam(rplayer) then
- return false
- end
- end
- if tagname == "weapons\\plasma rifle\\bolt" then
- local player = objectidtoplayer(causer)
- if player then
- local m_causer = getobject(causer)
- local m_receiver = getobject(receiver)
- if m_receiver and m_causer then
- local mapId = readdword(m_receiver)
- local tagname, tagtype = gettaginfo(mapId)
- if tagtype == "vehi" then
- if gravity[player] then
- gravity[player] = nil
- writebit(m_receiver + 0x10, 5, 0)
- local x_aim = readfloat(m_causer, 0x230)
- local y_aim = readfloat(m_causer, 0x234)
- local z_aim = readfloat(m_causer, 0x238)
- local vel = 1
- writefloat(m_receiver, 0x68, vel * math.sin(x_aim))
- writefloat(m_receiver, 0x6C, vel * math.sin(y_aim))
- writefloat(m_receiver, 0x70, vel * math.sin(z_aim))
- registertimer(10, "ActiveVehicle", {receiver, player})
- else
- local bool
- for p,r in pairs(gravity) do
- if r == receiver then
- bool = true
- end
- end
- if not bool then
- gravity[player] = receiver
- vehicles[receiver] = player
- writebit(m_receiver + 0x10, 5, 0)
- local m_player = getplayer(player)
- local xy_aim = readfloat(m_player, 0x138)
- local z_aim = readfloat(m_player, 0x13C)
- local dist = 4
- local x = readfloat(m_causer, 0x5C)
- local y = readfloat(m_causer, 0x60)
- local z = readfloat(m_causer, 0x64)
- writefloat(m_receiver, 0x5C, x + dist * math.cos(xy_aim))
- writefloat(m_receiver, 0x60, y + dist * math.sin(xy_aim))
- writefloat(m_receiver, 0x64, z + dist * math.sin(z_aim) + 0.5)
- writefloat(m_receiver, 0x68, 0)
- writefloat(m_receiver, 0x6C, 0)
- writefloat(m_receiver, 0x70, 0)
- local angular_velocity_x = readfloat(m_receiver, 0x8C)
- local angular_velocity_y = readfloat(m_receiver, 0x90)
- local angular_velocity_z = readfloat(m_receiver, 0x94)
- writefloat(m_receiver, 0x8C, .2)
- writefloat(m_receiver, 0x90, .3)
- writefloat(m_receiver, 0x94, .05)
- end
- end
- end
- end
- end
- elseif tagname == "globals\\vehicle_collision" then
- if vehicles[causer] then
- local m_player = getplayer(vehicles[causer])
- if m_player then
- local objId = readdword(m_player, 0x34)
- applydmgtag(receiver, gettagid("jpt!", "weapons\\rocket launcher\\explosion"), 500, objId)
- return false
- end
- end
- end
- end
- function OnVehicleEntry(player, m_vehicleId, seat, mapId, relevant)
- if game_started and relevant == true then
- if getplayer(player) == nil then
- return nil
- end
- local team = getteam(player)
- if (team == zombie_team and zombies_allowed_in_vehis) or (team ~= zombie_team and humans_allowed_in_vehis) then
- return true
- end
- end
- return false
- end
- function OnClientUpdate(player)
- local m_object = getplayerobjectid(player)
- local flashlight = readbyte(getobject(m_object), 0x206)
- if flashlight == 8 then
- OnFlashlightToggle(player)
- end
- local m_player = getplayer(player)
- if m_player == nil then
- return
- end
- local m_objectId = getplayerobjectid(player)
- if m_objectId == nil then
- return
- end
- local m_object = getobject(m_objectId)
- if m_object then
- local hash = gethash(player)
- local team = getteam(player)
- if team == zombie_team and oddball_or_flag then
- local shooting = readbit(m_object + 0x209, 4)
- local nading2 = readbit(m_object + 0x209, 2)
- local nading = readbit(m_object + 0x209, 3)
- if shooting == true or nading == true then
- weapID = flagball_weap[player]
- if m_player then
- if weapID then
- if getobject(weapID) then
- assignweapon(player, weapID)
- end
- end
- end
- end
- end
- -- this block of code sets the player's score according to what it should be.
- if tonumber(human_time[hash]) then
- if gametype == "KOTH" then
- local time = timetoword(tonumber(human_time[hash])*30)
- local hill_time = readword(m_player, 0xC4)
- if tonumber(hill_time) then
- writewordsigned(m_player, 0xC4, time)
- end
- elseif gametype == "CTF" then
- local player_score = readdword(m_player + 0xC8)
- if tonumber(player_score) then
- writedwordsigned(m_player, 0xC8, human_time[hash])
- end
- elseif gametype == "Slayer" then
- writedwordsigned(slayer_globals, 0x40 + player * 4, human_time[hash])
- end
- else
- human_time[hash] = 0
- end
- end
- --continually write 0 to these addresses
- if gametype == "KOTH" then
- writedword(team_koth_score_array + 0x0, 0)
- writedword(team_koth_score_array + 0x4, 0)
- elseif gametype == "CTF" then
- writedword(ctf_globals + 0x10, 0)
- writedword(ctf_globals + 0x14, 0)
- elseif gametype == "Slayer" then
- writedword(slayer_globals + 0x0, 0)
- writedword(slayer_globals + 0x4, 0)
- end
- --this makes sure that people won't camp in unreachable places.
- local x,y,z = getobjectcoords(m_objectId)
- local team = getteam(player)
- if map == "damnation" and team ~= zombie_team then
- if object_in_sphere(m_objectId, 1.99, 9.03, 7.82, 5) then
- kill(player)
- privatesay(player, "Do not camp in unreachable spots!")
- elseif object_in_sphere(m_objectId, 11.4, 11.21, 10.51, 5) then
- kill(player)
- privatesay(player, "Do not camp in unreachable spots!")
- end
- elseif map == "icefields" and team ~= zombie_team then
- if object_in_sphere(m_objectId, -31.27, 42.44, 11.48, 5) then
- kill(player)
- privatesay(player, "Do not camp in unreachable spots!")
- elseif object_in_sphere(m_objectId, -71.29, 70.83, 6.67, 10) then
- kill(player)
- privatesay(player, "Do not camp in unreachable spots!")
- elseif object_in_sphere(m_objectId, -17.28, 19.63, 11.55, 5) then
- kill(player)
- privatesay(player, "Do not camp in unreachable spots!")
- end
- end
- local vehiId = gravity[player]
- if vehiId then
- local m_player = getplayer(player)
- local objId = readdword(m_player, 0x34)
- local m_object = getobject(objId)
- local m_vehicle = getobject(vehiId)
- local x_aim = readfloat(m_object, 0x230)
- local y_aim = readfloat(m_object, 0x234)
- local z_aim = readfloat(m_object, 0x238)
- local x = readfloat(m_object, 0x5C)
- local y = readfloat(m_object, 0x60)
- local z = readfloat(m_object, 0x64)
- local dist = 4
- writefloat(m_vehicle, 0x5C, x + dist * math.sin(x_aim))
- writefloat(m_vehicle, 0x60, y + dist * math.sin(y_aim))
- writefloat(m_vehicle, 0x64, z + dist * math.sin(z_aim) + 0.5)
- writefloat(m_vehicle, 0x68, 0)
- writefloat(m_vehicle, 0x6C, 0)
- writefloat(m_vehicle, 0x70, 0.01285)
- end
- end
- -- called when all players are zombies (no shit)
- function all_players_zombies(player)
- -- if there is a last man, store their hash
- if player ~= nil and player ~= -1 and getplayer(player) then
- last_man_hash = gethash(player)
- -- write the hash to file
- local file = io.open("lasthash_" .. processid .. ".tmp", "w")
- if (file ~= nil) then
- file:write(tostring(last_man_hash))
- file:close()
- end
- end
- -- move onto the next map
- svcmd("sv_map_next")
- end
- --basically this timer assigns the tertiary and quarternary weapons to zombies if specified at the top
- --this is needed since onweaponassignment isn't called for tertiary and quartenary weapons
- function AssignLeftoverZombieWeapons(id, count, table)
- local player = table[1]
- local clipcount = table[2]
- local ammocount = table[3]
- local batterycount = table[4]
- if getplayer(player) == nil then
- return
- end
- local m_objectId = getplayerobjectid(player)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- local m_weaponId = createobject(gettagid("weap", zombie_weapon[3]), 0, 0, false, 5, 5, 2)
- if m_weaponId then
- local m_weapon = getobject(m_weaponId)
- if m_weapon then
- -- set the ammo
- writeword(m_weapon, 0x2B6, ammocount)
- writeword(m_weapon, 0x2B8, clipcount)
- writefloat(m_weapon, 0x240, math.abs(batterycount - 1))
- -- force it to sync
- updateammo(m_weaponId)
- end
- end
- --make sure the script user isn't retarded so we don't get errors
- if zombie_weapon[4] and zombie_weapon[4] ~= "" then
- --create the quarternary weapon
- local m_weaponId = createobject(gettagid("weap", zombie_weapon[4]), 0, 0, false, 5, 5, 2)
- --make sure createobject didn't screw up
- if m_weaponId then
- --assign the weapon to the player
- assignweapon(player, m_weaponId)
- --make sure we can safely set the ammo
- local m_weapon = getobject(m_weaponId)
- if m_weapon then
- -- set the ammo
- writeword(m_weapon, 0x2B6, ammocount)
- writeword(m_weapon, 0x2B8, clipcount)
- writefloat(m_weapon, 0x240, math.abs(batterycount - 1))
- -- force it to sync
- updateammo(m_weaponId)
- end
- end
- end
- end
- end
- return false
- end
- --this function is called when a gametype is 'custom'
- --this function will delete the player's weapons and reassign the weapon's specified at the top
- function AssignZombieWeapons(id, count, table)
- local player = table[1]
- local clipcount = table[2]
- local ammocount = table[3]
- local batterycount = table[4]
- if getplayer(player) == nil then
- return
- end
- local m_objectId = getplayerobjectid(player)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- --count is increased everytime the timer is called
- if count == 1 then
- for i = 0,3 do -- this is used to remove any weapons they already have
- local m_weaponId = readdword(m_object + 0x2F8 + i*4)
- if m_weaponId then
- local m_weapon = getobject(m_weaponId)
- if m_weapon then
- destroyobject(m_weaponId)
- end
- end
- end
- end
- local i = count
- if zombie_weapon and zombie_weapon[i] and zombie_weapon[i] ~= "" then
- local m_weaponId = createobject(gettagid("weap", zombie_weapon[i]), 0, 0, false, 1, 1, 1)
- if m_weaponId ~= 0xFFFFFFFF then
- assignweapon(player, m_weaponId)
- if oddball_or_flag then
- flagball_weap[player] = m_weaponId
- else
- local m_weapon = getobject(m_weaponId)
- if m_weapon then
- -- set the ammo
- writeword(m_weapon, 0x2B6, ammocount)
- writeword(m_weapon, 0x2B8, clipcount)
- writefloat(m_weapon, 0x240, 1)
- -- force it to sync
- updateammo(m_weaponId)
- end
- end
- end
- end
- if count < 4 then return 1 else return 0 end
- end
- end
- return false
- end
- function ChangeTeam(player, forcekill, team, updatecounters)
- if player and forcekill and team then
- changeteam(player, forcekill, team)
- elseif player and forcekill then
- changeteam(player, forcekill)
- else
- changeteam(player, 1)
- end
- if team ~= cur_team then
- OnFFATeamChange(player, cur_team, team, updatecounters)
- end
- end
- function checkgamestate(id, count, player)
- -- check if the game has started yet
- if game_started == true then
- local zombie_count = getzombiesize()
- local human_count = gethumansize()
- -- if no humans, but there are zombies, end the game
- if human_count == 0 and zombie_count > 0 then
- all_players_zombies(player)
- elseif human_count > 1 and zombie_count == 0 then
- noZombiesLeft()
- elseif human_count == 1 and zombie_count > 0 and not cur_last_man then
- onlastman()
- elseif cur_last_man and zombie_count == 0 then
- makehuman(cur_last_man, false)
- cur_last_man = nil
- elseif cur_last_man and human_count > 1 then
- if gametype == "Slayer" then takenavsaway() end
- makehuman(cur_last_man, false)
- cur_last_man = nil
- end
- end
- return false
- end
- -- this function searches through current players and selects a random one
- function ChooseRandomPlayer(excludeTeam)
- -- loop through all 16 possible spots and add to table
- local t = getplayertable(excludeTeam)
- if #t > 0 then
- -- generate a random number that we will use to select a player
- local r = getrandomnumber(1, #t+1)
- return t[r]
- else
- return nil
- end
- end
- --I made this function because there's a bug with destroyobject in phasor version 058X
- --basically all it does is move the objects under the map lol
- function destroyweaps(id, count, m_weaponId)
- if m_weaponId then
- local m_weapon = getobject(m_weaponId)
- if m_weapon then
- writefloat(m_weapon + 0x5C, readfloat(m_weapon + 0x5C) - 1000)
- end
- end
- return false
- end
- function DelayWriteCoords(id, count)
- writefloat(readdword(ctf_globals + 0x0), 0x8, readfloat(readdword(ctf_globals + 0x0), 0x8) - 100)
- writefloat(readdword(ctf_globals + 0x4), 0x8, readfloat(readdword(ctf_globals + 0x4), 0x8) - 100)
- return false
- end
- function endian(address, offset, length)
- local data_table = {}
- local data = ""
- for i=0,length do
- local hex = string.format("%X", readbyte(address + offset + i))
- if tonumber(hex, 16) < 16 then
- hex = 0 .. hex
- end
- table.insert(data_table, hex)
- end
- for k,v in pairs(data_table) do
- data = v .. data
- end
- return data
- end
- --gets the number of alpha zombies
- function getalphacount()
- -- recalculate how many "alpha" zombies there are
- if zombie_count < 1 then
- alpha_zombie_count = round((cur_players * zombie_count) + 0.5)
- else
- alpha_zombie_count = zombie_count
- end
- if alpha_zombie_count > max_zombie_count then
- alpha_zombie_count = max_zombie_count
- end
- return alpha_zombie_count
- end
- function GetGameAddresses(game)
- if game == "PC" then
- map_pointer = 0x63525c
- ctf_globals = 0x639B98
- slayer_globals = 0x63A0E8
- oddball_globals = 0x639E58
- gametype_base = 0x671340
- ctf_flag_stolen = 0x639BB4
- ball_holder_addr = 0x639F1C
- team_oddball_score_array = 0x639E9C
- oddball_score_array = 0x639E5C
- koth_move_timer = 0x639D78
- team_koth_score_array = 0x639BD0
- team_race_score_array = 0x63A028
- machine_pointer = 0x745BA0
- flag_respawn_addr = 0x488A7E
- inhill_addr = 0x639C50
- else
- map_pointer = 0x5B927C
- ctf_globals = 0x5BDBB8
- slayer_globals = 0x5BE108
- oddball_globals = 0x5BDEB8
- gametype_base = 0x5F5498
- ctf_flag_stolen = 0x5BD8B4
- ball_holder_addr = 0x5BDF3C
- team_oddball_score_array = 0x5BDE9C
- oddball_score_array = 0x5BDE5C
- koth_move_timer = 0x5BDD78
- team_koth_score_array = 0x5BDBF0
- team_race_score_array = 0x5BD028
- machine_pointer = 0x6C7980
- flag_respawn_addr = 0x4638EE
- inhill_addr = 0x5BDC70
- end
- end
- function gethumansize()
- local size = 0
- for i = 0,15 do
- if getplayer(i) then
- local team = getteam(i)
- if team ~= zombie_team then
- size = size + 1
- end
- end
- end
- return size
- end
- function getplayertable(excludeTeam)
- local players = ""
- for i=0,15 do
- if getplayer(i) and getteam(i) ~= excludeTeam then
- if players == nil then
- players = i .. ","
- else
- players = players .. i .. ","
- end
- end
- end
- return tokenizestring(players, ",")
- end
- function getzombiesize()
- local size = 0
- for i = 0,15 do
- if getplayer(i) then
- local team = getteam(i)
- if team == zombie_team then
- size = size + 1
- end
- end
- end
- return size
- end
- function HumanTimer(id, count)
- if map_reset_boolean == true then
- map_reset_boolean = false
- end
- if game_started == true then
- for i = 0,15 do
- if getplayer(i) then
- local m_player = getplayer(i)
- local hash = gethash(i)
- local team = readbyte(m_player + 0x20)
- local m_objectId = getplayerobjectid(i)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if team ~= zombie_team then
- if m_object then
- if tonumber(human_time[hash]) then
- human_time[hash] = tonumber(human_time[hash]) + 1
- else
- human_time[hash] = 1
- end
- end
- end
- end
- if gametype == "KOTH" then
- local m_objectId = getplayerobjectid(i)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if PlayerInHill(i) == true and m_object then
- if inhill_time[hash] == nil then
- inhill_time[hash] = 0
- writebit(m_object, 0x10, 7, 1)
- if team ~= zombie_team then
- say(getname(i) .. " must leave the hill in 10 seconds or they will be infected!")
- else
- say(getname(i) .. " must leave the hill in 10 seconds or they will be killed!")
- end
- elseif inhill_time[hash] >= 10 then
- if team ~= zombie_team then
- makezombie(i, true)
- say(getname(i) .. in_hill_too_long_msg)
- else
- kill(i)
- say(getname(i) .. " has been killed because they were in the hill too long!")
- end
- inhill_time[hash] = nil
- elseif team ~= zombie_team then
- privatesay(i, "You have " .. math.abs(inhill_time[hash] - 10) .. " seconds to leave the hill!")
- inhill_time[hash] = inhill_time[hash] + 1
- end
- elseif m_object then
- inhill_time[hash] = nil
- writebit(m_object, 0x10, 7, 0)
- end
- end
- end
- end
- end
- end
- return true
- end
- function invisCrouch(id, count)
- if not zombies_invisible_on_crouch and not humans_invisible_on_crouch then crouch_timer = nil return false end
- for i = 0,15 do
- if getplayer(i) then
- local m_objectId = getplayerobjectid(i)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- local obj_crouch = readbyte(m_object + 0x2A0)
- if obj_crouch == 3 then
- local team = readbyte(getplayer(i) + 0x20)
- if (team == zombie_team and zombies_invisible_on_crouch) or (team ~= zombie_team and humans_invisible_on_crouch) then
- applycamo(i, time_invis)
- end
- end
- end
- end
- end
- end
- return true
- end
- --called when a player needs to be a human
- function makehuman(player, forcekill, updatecounters)
- if getplayer(player) then
- -- change the player's speed
- setspeed(player, human_speed)
- local team = getteam(player)
- if team == zombie_team then
- if team_play then
- ChangeTeam(player, forcekill)
- else
- ChangeTeam(player, forcekill, nil, updatecounters)
- end
- end
- end
- end
- --called when a player needs to be made a zombie
- function makezombie(player, forcekill, updatecounters)
- if getplayer(player) then
- -- change the player's speed
- setspeed(player, zombie_speed)
- local team = getteam(player)
- if team ~= zombie_team then
- if team_play then
- ChangeTeam(player, forcekill)
- else
- ChangeTeam(player, forcekill, nil, updatecounters)
- end
- end
- end
- end
- function makezombiedelay(id, count, arg)
- makezombie(arg[1], arg[2])
- end
- function NewGameTimer(id, count)
- if count == 10 then
- say("The game is starting...")
- if cur_players ~= 0 then
- local newgame_zombie_count = 0
- -- by default make all players human
- for x=0,15 do
- if getplayer(x) then
- local thisTeam = getteam(x)
- local hash = gethash(x)
- if thisTeam then
- if thisTeam == zombie_team then
- ChangeTeam(x, 0)
- end
- human_time[hash] = 0
- end
- end
- end
- local possible_count = cur_players
- -- make players zombie until the count has been met
- local finalZombies = 0
- if zombie_count >= 1 then
- finalZombies = zombie_count
- else
- finalZombies = round((possible_count * zombie_count) + 0.5)
- end
- -- make last man zombie
- local last_man_index = -1
- -- check if the last man is to be made a zombie
- -- if so find who was last man
- if last_man_next_zombie == true and cur_players > 1 then
- -- loop through all hashes and check if any match the last man
- for i=0,15 do
- if getplayer(i) then
- local hash = gethash(i)
- if last_man_hash == hash then
- -- make them a zombie and save their info
- makezombie(i, true)
- newgame_zombie_count = 1
- last_man_index = i
- break
- end
- end
- end
- end
- -- reset last man
- last_man_hash = 0
- if finalZombies == cur_players then -- if 0 players they will be human
- finalZombies = finalZombies - 1
- elseif finalZombies > possible_count then -- fix the count
- finalZombies = possible_count
- elseif max_zombie_count and finalZombies > max_zombie_count then -- cap the zombie count
- finalZombies = max_zombie_count
- elseif finalZombies < 0 then
- finalZombies = 0
- end
- -- set counters such that ChangeTeam wont end the game
- cur_zombie_count = 16
- cur_human_count = 16
- -- loop through the players, randomly selecting ones to become
- -- zombies
- while (newgame_zombie_count < finalZombies) do
- -- randomly choose a player
- local newzomb = ChooseRandomPlayer(zombie_team)
- if newzomb == nil then
- break
- elseif newzomb ~= last_man_index then
- makezombie(newzomb, true)
- newgame_zombie_count = newgame_zombie_count + 1
- end
- end
- -- fix the team counters
- cur_zombie_count = newgame_zombie_count
- cur_human_count = cur_players - finalZombies
- -- reset the map
- svcmd("sv_map_reset")
- -- loop through and tell players which team they're on
- for i=0,15 do
- if getplayer(i) then
- local pteam = getteam(i)
- if pteam then
- -- check if they're a zombie
- if pteam == zombie_team then
- privatesay(i, zombie_message)
- else
- if not team_play then makehuman(i) end
- privatesay(i, human_message)
- end
- end
- end
- end
- end
- game_started = true
- new_game_timer = nil
- return false -- remove timer
- else
- say("The game will start in " .. 10 - count .. " second(s).")
- return true -- keep timer
- end
- end
- -- there are no zombies left
- function noZombiesLeft()
- if team_play then
- if player_change_timer == nil then
- allow_change = true
- say(nozombiesleftmessage)
- player_change_timer = registertimer(1000, "PlayerChangeTimer")
- end
- else
- -- pick a human and make them zombie.
- local newZomb = ChooseRandomPlayer(zombie_team)
- if newZomb then
- makezombie(newZomb, true)
- privatesay(newZomb, zombie_message)
- end
- end
- end
- --called to check if an object is in a virtual sphere
- --i use this to check if a person is in a unreachable spot.
- function object_in_sphere(m_objectId, X, Y, Z, R)
- local Pass = false
- if getobject(m_objectId) then
- local x,y,z = getobjectcoords(m_objectId)
- if (X - x)^2 + (Y - y)^2 + (Z - z)^2 <= R then
- Pass = true
- end
- end
- return Pass
- end
- function OnFFATeamChange(player, cur_team, dest_team, updatecounters)
- -- update team counts
- if not updatecounters then
- if dest_team == zombie_team then
- cur_human_count = cur_human_count - 1
- cur_zombie_count = cur_zombie_count + 1
- elseif dest_team ~= zombie_team then
- cur_human_count = cur_human_count + 1
- cur_zombie_count = cur_zombie_count - 1
- end
- end
- -- check if the game has started yet
- if game_started == true then
- registertimer(0,"checkgamestate",player)
- end
- -- update team with
- local thisHash = gethash(player)
- hash_table[thisHash] = dest_team
- end
- -- called when a last man exists
- function onlastman()
- -- lookup the last man
- for x=0,15 do
- if getplayer(x) then
- local team = getteam(x)
- if team ~= zombie_team and team then
- cur_last_man = x
- if gametype == "Slayer" then WriteNavsToZombies(x) end
- -- give the last man speed and extra ammo
- setspeed(x, lastman_speed)
- -- find the last man's weapons
- local m_player = getplayer(x)
- if m_player then
- local m_ObjId = readdword(m_player + 0x34)
- if m_ObjId then
- -- find the player's object
- local m_object = getobject(m_ObjId)
- if m_object then
- if lastman_invulnerable and lastman_invulnerable > 0 then
- -- setup the invulnerable timer
- writebit(m_object + 0x10, 7, 1)
- registertimer(lastman_invulnerable * 1000, "RemoveLastmanProtection", m_object)
- end
- -- give all weapons 600 ammo
- for i=0,3 do
- local m_weaponId = readdword(m_object + 0x2F8 + (i*4))
- if m_weaponId ~= 0xffffffff then
- -- get the weapons memory address
- local m_weapon = getobject(m_weaponId)
- if m_weapon then
- -- set the ammo
- writeword(m_weapon, 0x2B6, 600)
- end
- end
- end
- end
- end
- end
- end
- end
- end
- if cur_last_man then
- local lastman_name = getname(cur_last_man)
- local msg = string.format(lastman_message, tostring(lastman_name), lastman_invistime)
- say(msg)
- applycamo(cur_last_man, lastman_invistime)
- end
- end
- function PlayerChangeTimer(id, count)
- if count ~= 10 then
- local zombsize = cur_zombie_count
- if allow_change == false or zombsize > 0 then
- allow_change = false
- if team_play then say("Thank you, the game can continue.") end
- player_change_timer = nil
- return false
- end
- say("In " .. 10 - count .. " seconds a player will be forced to become a zombie.")
- return true
- else -- timer up, force team change
- allow_change = false
- -- pick a human and make them zombie.
- local newZomb = ChooseRandomPlayer(zombie_team)
- if newZomb then
- makezombie(newZomb, true)
- privatesay(newZomb, zombie_message)
- end
- player_change_timer = nil
- return false
- end
- end
- function PlayerInHill(player)
- player = tonumber(player)
- local bool = false
- local m_player = getplayer(player)
- if m_player then
- local InHill = readbyte(team_koth_score_array + player + 0x80)
- if InHill == 1 then
- bool = true
- end
- end
- return bool
- end
- function PutUnderMap(id, count, m_objectId)
- local m_object = getobject(m_objectId)
- if m_object then
- local x,y,z = getobjectcoords(m_objectId)
- movobjectcoords(m_objectId, x, y, z - 20)
- end
- return false
- end
- function sendresponse(message, player)
- if message == "" then
- return
- end
- player = tonumber(player)
- if tonumber(player) and player ~= nil and player ~= -1 and player >= 0 and player < 16 then
- sendconsoletext(player, message)
- else
- hprintf(message)
- end
- end
- function ScriptLoad()
- if Persistent then
- cur_zombie_count = 0
- cur_human_count = 0
- alpha_zombie_count = 0
- human_time = {}
- cur_players = 0
- cur_last_man = nil
- last_man_hash = 0
- processid = 0
- game_started = false
- allow_change = false
- flagball_weap = {}
- last_hill_time = {}
- hash_table = {}
- inhill_time = {}
- end
- for i = 1,4 do
- if zombie_weapon[i] == "weapons\\ball\\ball" or zombie_weapon[i] == "weapons\\flag\\flag" then
- oddball_or_flag = zombie_weapon[i]
- end
- end
- gametype = readbyte(gametype_base + 0x30)
- if gametype == 1 then
- gametype = "CTF"
- writedword(flag_respawn_addr + 0x0, 0xFFFFFFFF)
- registertimer(0, "DelayWriteCoords")
- elseif gametype == 2 then
- gametype = "Slayer"
- writebyte(gametype_base + 0x58, 3)
- if speedtimer == nil then
- speedtimer = registertimer(1000, "SpeedTimer")
- end
- elseif gametype == 4 then
- gametype = "KOTH"
- end
- -- assume a game is running
- game_started = true
- team_play = readbyte(gametype_base + 0x34) -- Confirmed. (Off = 0) (On = 1)
- if team_play == 1 then
- team_play = true
- else
- team_play = false
- zombie_team = 0
- end
- starting_equipment = readbit(gametype_base + 0x38, 2) -- Generic = 0, Custom = 1
- if starting_equipment == 1 then
- starting_equipment = "Generic"
- else
- starting_equipment = "Custom"
- end
- if humantimer == nil then
- humantimer = registertimer(1000, "HumanTimer")
- end
- if crouch_timer == nil then
- crouch_timer = registertimer(200, "invisCrouch")
- end
- -- recalculate team counters
- cur_zombie_count = getzombiesize()
- cur_human_count = gethumansize()
- cur_players = cur_zombie_count + cur_human_count
- -- recalculate how many "alpha" zombies there are
- alpha_zombie_count = getalphacount()
- -- load the last man hash (if there is one)
- local file = io.open("lasthash_" .. processid .. ".tmp", "r")
- if file then
- -- read the ip
- last_man_hash = file:read("*line")
- file:close()
- -- delete the file
- os.remove("lasthash_" .. processid .. ".tmp")
- end
- registertimer(0,"checkgamestate")
- end
- function SpeedTimer(id, count)
- for i = 0,15 do
- if getplayer(i) then
- local team = getteam(i)
- if team == zombie_team then
- setspeed(i, zombie_speed)
- elseif cur_last_man == i then
- setspeed(i, lastman_speed)
- else
- setspeed(i, human_speed)
- end
- end
- end
- return true
- end
- function RemoveLastmanProtection(id, count, m_object)
- writebit(m_object, 0x10, 7, 0)
- return false
- end
- --rounds the number
- function round(num)
- under = math.floor(num)
- upper = math.floor(num) + 1
- underV = -(under - num)
- upperV = upper - num
- if (upperV > underV) then
- return under
- else
- return upper
- end
- end
- --called when the lastman no longer exists
- function takenavsaway()
- for i = 0,15 do
- local m_player = getplayer(i)
- if m_player then
- writeword(m_player + 0x88, i)
- end
- end
- end
- function timetoword(time)
- if time == -1 or time == "-1" then
- return -1
- elseif tonumber(time) then
- local returntime = ""
- local seconds = tonumber(time)
- local days = math.floor(seconds/86400)
- seconds = seconds - days*86400
- local hours = math.floor(seconds/3600)
- seconds = seconds - hours*3600
- local minutes = math.floor(seconds/60)
- seconds = seconds - minutes*60
- if seconds ~= 0 then
- returntime = seconds .. "s"
- end
- if minutes ~= 0 then
- if returntime == "" then
- returntime = minutes .. "m"
- else
- returntime = minutes .. "m " .. returntime
- end
- end
- if hours ~= 0 then
- if returntime == "" then
- returntime = hours .. "h"
- else
- returntime = hours .. "h " .. returntime
- end
- end
- if days ~= 0 then
- if returntime == "" then
- returntime = days .. "d"
- else
- returntime = days .. "d " .. returntime
- end
- end
- if returntime == "" then
- returntime = "0s"
- end
- return returntime
- end
- end
- function todec(number)
- return tonumber(number, 16)
- end
- --this function writes navpoints to zombies which will point to the last man
- function WriteNavsToZombies(cur_last_man)
- for i = 0,15 do
- if getplayer(i) then
- local team = getteam(i)
- if team == zombie_team then
- local m_player = getplayer(i)
- if m_player then
- local slayer_target = readword(m_player, 0x88)
- if slayer_target < 16 and slayer_target > -1 then
- writeword(m_player, 0x88, cur_last_man)
- end
- end
- end
- end
- end
- end
- function writewordsigned(address, offset, value)
- if value and value > 0x7FFF then
- local max = 0xFFFF
- local difference = max - value
- value = -1 - difference
- end
- writeword(address + offset, value)
- end
- function writedwordsigned(address, offset, value)
- if value and value > 0x7FFFFFFF then
- local max = 0xFFFFFFFF
- local difference = max - value
- value = -1 - difference
- end
- writedword(address + offset, value)
- end
- function OnFlashlightToggle(player)
- if getplayer(player) then
- if speed_count[player] == 0 then
- registertimer(10, "speedtimerstart", player)
- end
- end
- end
- function speedtimerstart(id, count, player)
- if getplayer(player) then
- if getteam(player) == zombie_team then
- setspeed(player, zombie_speed + 1)
- elseif getteam(player) == human_team then
- setspeed(player, human_speed + 1)
- end
- speed_count[player] = speed_count[player] + 1
- registertimer(3000, "speedtimerstop", player)
- end
- return false
- end
- function speedtimerstop(id, count, player)
- if getplayer(player) then
- if getteam(player) == zombie_team then
- setspeed(player, zombie_speed)
- elseif getteam(player) == human_team then
- setspeed(player, human_speed)
- end
- end
- return false
- end
- function ActiveVehicle(id, count, info)
- local vehiId = info[1]
- local player = info[2]
- local m_vehicle = getobject(vehiId)
- if m_vehicle then
- if vehicles[vehiId] == player then
- if getplayer(player) then
- local vx = readfloat(m_vehicle, 0x68)
- local vy = readfloat(m_vehicle, 0x6C)
- local vz = readfloat(m_vehicle, 0x70)
- local velocity = math.sqrt(vx ^ 2 + vy ^ 2 + vz ^ 2)
- if velocity == 0 then
- activetime[vehiId] = activetime[vehiId] or 100 - 1
- if activetime[vehiId] <= 0 then
- vehicles[vehiId] = nil
- return false
- end
- end
- end
- else
- return false
- end
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement