Advertisement
it300

Zombies 4.0 Public

May 20th, 2017
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.28 KB | None | 0 0
  1. -- Zombies by: Skylace aka Devieth
  2. -- Version 4.0 for Sapp 10+
  3. -- Website: http://pastebin.com/u/it300
  4.  
  5.  
  6. -- Team setup
  7. human_team, zombie_team = 0, 1
  8.  
  9. -- Speed setup
  10. human_speed = 1
  11. last_speed = 1.5
  12. zombie_speed = 1.75
  13. boost_ammount = 0.5
  14. sprint_time = 2
  15.  
  16. -- Damage
  17. z_damage_modify = 3 -- Zombies vs Humans (Melle = 1 hit kill *unless enemy player has os*)
  18. h_damage_modify = 1.4 -- Humans vs Zombies (Pistol = 4sk to body)
  19. s_damage_modify = 1.6 -- Humans w/ Sniper vs Zombies (Sniper = 1st)
  20. l_damage_modify = 1.7 -- Last man vs Zombies (Pistol = 3sk to body)
  21.  
  22. -- Spawning
  23. zombie_spawn_time = 0
  24. human_spawn_time = 3
  25.  
  26. -- Scoring
  27. score_per_kill = 5
  28. score_per_infect = 15
  29. score_per_combo = 1 -- This * combo count
  30. score_per_spree = 2 -- This * Spree count
  31. human_score_per_second = 1
  32. zombie_score_per_second = 0.2
  33.  
  34. -- Weapon(s)
  35. zombie_weapons, human_weapons = {}, {}
  36. zombie_weapons[1] = "weapons\\ball\\ball" -- Primary
  37. zombie_weapons[2] = nil -- Cannot set if Primary is the ball or flag.
  38. zombie_weapons[3] = nil -- Set the extras to nil if you want them to be unused.
  39. zombie_weapons[4] = nil -- You cannot set the human weapon as the ball or flag.
  40. human_weapons[1] = "weapons\\pistol\\pistol" -- Primary
  41. human_weapons[2] = nil
  42. human_weapons[3] = nil
  43. human_weapons[4] = nil
  44.  
  45. -- Other
  46. last_camo_time = 15
  47. last_is_next_zombie = true
  48. disable_vehicles = true
  49.  
  50. -- Kill messages
  51. infect_msg = "infected"
  52. suicide_msg = "couldn't take the pressure!"
  53. unknown_msg = "was infected due to a mysterious force."
  54.  
  55. -- Other messages
  56. human_again_msg = "has become human again for killing %s humans!"
  57. game_over_msg = "All humans have been infected!!! The game will now end..."
  58. no_more_zombies_msg = "There are no more zombies!"
  59. no_zombies_countdown_msg = "A random player will become a zombie in"
  60. lastman_msg = "is the last person alive, find them and eat their brains!!!"
  61.  
  62. -- Required
  63. api_version = "1.10.0.0"
  64. svcmd = execute_command_sequence
  65. score, sprint, player_weapon_id = {}, {}, {}
  66. h_count, z_count, count = 0, 0, 0
  67. nozomz,last_name = false, nil
  68. msg = nil
  69.  
  70. function OnScriptLoad()
  71.     gameinfo_header = read_dword(sig_scan("A1????????8B480C894D00") + 0x1)
  72.     register_callback(cb['EVENT_GAME_START'], "OnGameStart")
  73.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  74.     register_callback(cb['EVENT_DAMAGE_APPLICATION'], "OnDamageApplication")
  75.     register_callback(cb['EVENT_WEAPON_DROP'], "OnWeaponDrop")
  76.     register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
  77.     register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
  78.     register_callback(cb['EVENT_SPAWN'], "OnPlayerSpawn")
  79.     register_callback(cb['EVENT_DIE'], "OnPlayerDeath")
  80.     register_callback(cb['EVENT_TICK'], "OnEventTick")
  81.     server_setup()
  82. end
  83.  
  84.  
  85. function OnScriptUnload()
  86.     for i = 1,#player_weapon_id do
  87.         destroy_object(player_weapon_id[i])
  88.     end
  89. end
  90.  
  91. function OnDamageApplication(PlayerIndex, Causer, MetaID, Damage, HitString, Backtap)
  92.     if tonumber(Causer) ~= 0 and game_active then
  93.         if get_team(Causer) ~= get_team(PlayerIndex) then
  94.             if get_team(Causer) == zombie_team then
  95.                 if not last then
  96.                     Damage = Damage * z_damage_modify
  97.                 end
  98.             else
  99.                 if not last then
  100.                     local weapon = get_tag(PlayerIndex)
  101.                     if weapon == "weapons\\sniper rifle\\sniper rifle" then
  102.                         Damage = Damage * s_damage_modify
  103.                     else
  104.                         Damage = Damage * h_damage_modify
  105.                     end
  106.                 else
  107.                     Damage = Damage * l_damage_modify
  108.                 end
  109.             end
  110.         else
  111.             if tonumber(Causer) ~= tonumber(PlayerIndex) then
  112.                 Damage = 0
  113.             end
  114.         end
  115.     end
  116.     return true, Damage
  117. end
  118.  
  119. function OnGameStart()
  120.     gameinfo_base = read_dword(gameinfo_header)
  121.     game_active, last, join_call = false, false, false
  122.     for i = 1,16 do
  123.         sprint[i], score[i], player_weapon_id[i] = sprint_time * 30, 0, nil
  124.     end
  125. end
  126.  
  127. function OnGameEnd()
  128.     game_active = false
  129. end
  130.  
  131. function OnPlayerSpawn(PlayerIndex)
  132.     if game_active then
  133.         apply_player_weapons(PlayerIndex)
  134.     end
  135. end
  136.  
  137. function OnPlayerJoin(PlayerIndex)
  138.     local players = tonumber(get_var(PlayerIndex, "$pn"))
  139.     if game_active ~= true then
  140.         set_team(PlayerIndex, human_team, false)
  141.         if players > 1 then
  142.             if join_call == false then
  143.                 join_call = true
  144.                 timer(1000, "start_game_timer")
  145.             end
  146.         else
  147.             say(PlayerIndex, "Please wait for more players to join.")
  148.         end
  149.     else
  150.         set_navs()
  151.         if players > 1 then
  152.             set_team(PlayerIndex, zombie_team, false)
  153.             timer(100, "check_game_state")
  154.         else
  155.             game_active = false
  156.             say(PlayerIndex, "The game has been stopped, not enough players.")
  157.         end
  158.     end
  159. end
  160.  
  161. function OnPlayerLeave(PlayerIndex)
  162.     timer(100, "check_game_state")
  163. end
  164.  
  165. function OnPlayerDeath(VictimIndex, KillerIndex)
  166.     if game_active then
  167.         local VictimIndex, KillerIndex = tonumber(VictimIndex), tonumber(KillerIndex) -- Making sure they are numbers.
  168.         local victim_name, victim_team = get_var(VictimIndex, "$name"), get_team(VictimIndex) -- Victim name & team
  169.         if KillerIndex > 0 then -- Players
  170.             local killer_name, killer_team = get_var(KillerIndex, "$name"), get_team(KillerIndex) -- Killer name & team
  171.             if VictimIndex ~= KillerIndex then -- PvP
  172.                 if killer_team == zombie_team and victim_team == human_team then -- Zombie vs Human
  173.                     set_team(VictimIndex, zombie_team, false)
  174.                     say_all(killer_name .. " " .. infect_msg .. " " .. victim_name)
  175.                 end
  176.                 set_player_score(1, KillerIndex, false)
  177.             else -- Suicide
  178.                 if victim_team == human_team then
  179.                     set_team(VictimIndex, zombie_team, false)
  180.                     say_all(victim_name .. " " .. suicide_msg)
  181.                 end
  182.                 set_player_score(1, KillerIndex, true)
  183.             end
  184.         elseif KillerIndex == 0 then -- Guardians
  185.             if victim_team == human_team then
  186.                 set_team(VictimIndex, zombie_team, false)
  187.                 say_all(victim_name .. " " .. unknown_msg)
  188.             end
  189.         elseif KillerIndex == -1 then
  190.             if victim_team == human_team then
  191.                 set_team(VictimIndex, zombie_team, false)
  192.                 say_all(victim_name .. " " .. unknown_msg)
  193.             end
  194.         end
  195.         set_spawn_time(VictimIndex)
  196.         timer(100, "check_game_state")
  197.     end
  198. end
  199.  
  200. function OnWeaponDrop(PlayerIndex, Slot)
  201.     if get_team(PlayerIndex) == zombie_team then
  202.         if player_weapon_id[tonumber(PlayerIndex)] then
  203.             assign_weapon(player_weapon_id[tonumber(PlayerIndex)], PlayerIndex)
  204.         end
  205.     end
  206. end
  207.  
  208. function OnEventTick()
  209.     for i = 0,16 do
  210.         if player_present(i) then
  211.             if player_alive(i) and game_active then
  212.                 local zero = math.fmod(read_dword(gameinfo_base + 0xC), 15)
  213.                 local crouch, team = read_byte(get_dynamic_player(i) + 0x2A0), get_team(i)
  214.                 local flashlight = read_bit(get_dynamic_player(i) + 0x206, 3)
  215.                 if team == zombie_team then if crouch == 3 then camo(i, 1) end end -- Crouch camo for zombies
  216.                 if flashlight == 1 then
  217.                     if math.floor(sprint[i]) > 0 then
  218.                         if zero == 0 then set_player_speeds(i, team, true) end
  219.                         sprint[i] = math.floor(sprint[i] - 1)
  220.                     else
  221.                         if zero == 0 then set_player_speeds(i, team, false) end
  222.                     end
  223.                 else
  224.                     if sprint[i] < (sprint_time * 30) then
  225.                         sprint[i] = sprint[i] + 0.05
  226.                     end
  227.                     if zero == 0 then set_player_speeds(i, team, false) end
  228.                 end
  229.                 if zero == 0 then set_player_score(0, i, team) end
  230.             end
  231.             if msg ~= nil then
  232.                 for x = 0,10 do rprint(i, " ") end
  233.                 rprint(i, "|c"..msg)
  234.                 for x = 0,12 do rprint(i, " ") end
  235.             end
  236.         end
  237.     end
  238. end
  239.  
  240. function set_player_speeds(PlayerIndex, team, boost)
  241.     if team == zombie_team then
  242.         local speed = zombie_speed
  243.         if boost then speed = speed + boost_ammount end
  244.         set_speed(PlayerIndex, speed)
  245.     else
  246.         if not last then
  247.             local speed = human_speed
  248.             if boost then speed = speed + boost_ammount end
  249.             set_speed(PlayerIndex, speed)
  250.         else
  251.             local speed = last_speed
  252.             if boost then speed = speed + boost_ammount end
  253.             set_speed(PlayerIndex, speed)
  254.         end
  255.     end
  256. end
  257.  
  258. function start_game_timer()
  259.     local allow_return, present = true, false
  260.     count = count + 1
  261.     msg = "The game will start in " .. 6 - count
  262.     if count >= 6 then
  263.         if last_is_next_zombie then
  264.             if last_name ~= nil then
  265.                 for i = 1,16 do
  266.                     if player_present(i) then
  267.                         if get_var(i, "$name") == last_name then
  268.                             present, last_name = true, nil
  269.                             set_team(i, zombie_team, false)
  270.                             break
  271.                         end
  272.                     end
  273.                 end
  274.             end
  275.         end
  276.         if present == false then
  277.             get_random_player(zombie_team, false)
  278.         end
  279.         count, allow_return = 0, false
  280.         svcmd("sv_map_reset")
  281.         msg = "The game has started!"
  282.         timer(50, "activate")
  283.         timer(1500, "remove_msg")
  284.     end
  285.     return allow_return
  286. end
  287.  
  288. function activate() set_navs() check_game_state() game_active = true end -- Set naves above players own heads.
  289. function remove_msg() msg = nil end
  290.  
  291. function get_random_player(NewTeam, ForceKill)
  292.     local players, Count = {}, 0
  293.     for i = 1,16 do
  294.         if player_present(i) then
  295.             if get_team(i) ~= NewTeam then
  296.                 Count = Count + 1
  297.                 players[Count] = i
  298.     end end end
  299.     if #players >= 1 then
  300.         local PlayerIndex = players[rand(1,#players)]
  301.         set_team(PlayerIndex, NewTeam, ForceKill)
  302.     end
  303. end
  304.  
  305. function check_game_state()
  306.     get_counts()
  307.     if game_active and t_count > 1 then
  308.         if h_count > 1 and z_count == 0 then
  309.             if not nozomz then
  310.                 nozomz = true
  311.                 timer(1000, "no_zombies_left")
  312.                 say_all(no_more_zombies_msg)
  313.             end
  314.         elseif h_count == 1 and z_count >= 1 then
  315.             timer(500, "on_last_man")
  316.         elseif h_count >= 2 and z_count >= 1 then
  317.             last = false
  318.         elseif h_count == 0 and z_count >= 1 then
  319.             svcmd("sv_map_next")
  320.             say_all(game_over_msg)
  321.         end
  322.     end
  323. end
  324.  
  325. function no_zombies_left()
  326.     local allow_return = true
  327.     count = count + 1
  328.     say_all(no_zombies_countdown_msg.. " " .. 3-count)
  329.     if count >= 3 then
  330.         get_random_player(zombie_team, true)
  331.         timer(100, "reset")
  332.         count, allow_return = 0, false
  333.     end
  334.     return allow_return
  335. end
  336.  
  337. function reset() nozomz = false end
  338.  
  339. function on_last_man() -- There is only one human, lets give him the tools to concure.
  340.     last = true
  341.     for i = 1,16 do
  342.         if player_present(i) then
  343.             if get_team(i) == human_team and get_var(i,"$name") ~= last_name then
  344.                 last_name = get_var(i,"$name")
  345.                 camo(i, last_camo_time)
  346.                 say_all(last_name .. " " .. lastman_msg)
  347.                 set_navs(i)
  348.                 break
  349.             end
  350.         end
  351.     end
  352. end
  353.  
  354. function get_counts()
  355.     if human_team == 0 then
  356.         h_count, z_count = tonumber(get_var(0, "$reds")), tonumber(get_var(0, "$blues"))
  357.     else
  358.         h_count, z_count = tonumber(get_var(0, "$blues")), tonumber(get_var(0, "$reds"))
  359.     end
  360.     t_count = h_count + z_count
  361. end
  362.  
  363. function set_player_score(Mode, PlayerIndex, etc)
  364.     if Mode ~= 0 then
  365.         if etc then -- etc = bool | Punish asshole humans.
  366.             if score[tonumber(PlayerIndex)] > 100 then
  367.                 score[tonumber(PlayerIndex)] = score[tonumber(PlayerIndex)] - 100
  368.             end
  369.         else
  370.             local combo, spree = tonumber(get_var(PlayerIndex, "$combo")), tonumber(get_var(PlayerIndex, "$streak"))
  371.             local combo_score, spree_score = combo * score_per_combo, 0
  372.             if math.fmod(spree, 5) == 0 then
  373.                 spree_score = spree * score_per_spree
  374.             end
  375.             if get_team(PlayerIndex) == human_team then
  376.                 score[tonumber(PlayerIndex)] = score[tonumber(PlayerIndex)] + (score_per_kill + combo_score + spree_score)
  377.             else
  378.                 score[tonumber(PlayerIndex)] = score[tonumber(PlayerIndex)] + (score_per_infect + combo_score + spree_score)
  379.             end
  380.         end
  381.     else
  382.         if etc == zombie_team then -- etc = team | Apply team scores per second (while alive.)
  383.             score[tonumber(PlayerIndex)] = score[tonumber(PlayerIndex)] + (zombie_score_per_second / 2)
  384.         else
  385.             score[tonumber(PlayerIndex)] = score[tonumber(PlayerIndex)] + (human_score_per_second / 2)
  386.         end
  387.         svcmd("team_score 2 0;score " .. PlayerIndex .. " " .. math.floor(tonumber(score[tonumber(PlayerIndex)])))
  388.     end
  389. end
  390.  
  391. function apply_player_weapons(PlayerIndex)
  392.     local weapons = zombie_weapons
  393.     svcmd("wdel "..PlayerIndex.." 5")
  394.     if get_team(PlayerIndex) == human_team then weapons = human_weapons end
  395.     if weapons[1] == "weapons\\ball\\ball" or weapons[1] == "weapons\\flag\\flag" then
  396.         if player_weapon_id[tonumber(PlayerIndex)] ~= nil then
  397.             assign_weapon(player_weapon_id[tonumber(PlayerIndex)], PlayerIndex)
  398.         else
  399.             local m_object = get_dynamic_player(PlayerIndex)
  400.             local x,y,z = read_vector3d(m_object + 0x5C)
  401.             local m_weaponId = spawn_object("weap",weapons[1],x,y,z+1,0.0, GetTag("weap", weapons[1]))
  402.             player_weapon_id[tonumber(PlayerIndex)] = m_weaponId
  403.             assign_weapon(m_weaponId, PlayerIndex)
  404.         end
  405.     else
  406.         for i = 1,4 do
  407.             if weapons[i] ~= nil then
  408.                 local m_weaponId = spawn_object("weap",(weapons[i]),1,1,1,0, GetTag("weap", (weapons[i])))
  409.                 assign_weapon(m_weaponId, PlayerIndex)
  410.             end
  411.         end
  412.     end
  413.     if get_team(PlayerIndex) == zombie_team then
  414.         svcmd("ammo " .. PlayerIndex .. " 0 5;mag " .. PlayerIndex .. " 0 5;nades " .. PlayerIndex .. " 0 0")
  415.     end
  416. end
  417.  
  418. function set_spawn_time(PlayerIndex)
  419.     if player_present(PlayerIndex) then
  420.         local m_player = get_player(PlayerIndex)
  421.         if get_team(PlayerIndex) == zombie_team then
  422.             write_dword(m_player + 0x2C, zombie_spawn_time * 30)
  423.         else
  424.             write_dword(m_player + 0x2C, human_spawn_time * 30)
  425.         end
  426.     end
  427. end
  428.  
  429. function GetTag(class,path) -- Thanks to 002
  430.     local tagarray = read_dword(0x40440000)
  431.     for i=0,read_word(0x4044000C)-1 do
  432.         local tag = tagarray + i * 0x20
  433.         local tagclass = string.reverse(string.sub(read_string(tag),1,4))
  434.         if(tagclass == class) then
  435.             if(read_string(read_dword(tag + 0x10)) == path) then
  436.                 return read_dword(tag + 0xC)
  437.             end
  438.         end
  439.     end
  440.     return nil
  441. end
  442.  
  443. function get_team(PlayerIndex)
  444.     local m_player = get_player(PlayerIndex)
  445.     if m_player ~= 0 then
  446.         return read_byte(m_player + 0x20)
  447.     end
  448.     return nil
  449. end
  450.  
  451. function set_team(PlayerIndex, NewTeam, ForceKill)
  452.     local m_player = get_player(PlayerIndex)
  453.     if m_player ~= 0 then
  454.         write_byte(m_player + 0x20, NewTeam)
  455.         if ForceKill then kill(PlayerIndex) end
  456.     end
  457. end
  458.  
  459. function set_speed(PlayerIndex, Speed)
  460.     local m_player = get_player(PlayerIndex)
  461.     if m_player then
  462.         write_float(m_player + 0x6c, Speed)
  463.     end
  464. end
  465.  
  466. function get_tag(PlayerIndex)
  467.     local m_object = get_dynamic_player(PlayerIndex)
  468.     if m_object ~= 0 then
  469.         local weapon_address = get_object_memory(read_dword(m_object + 0x118))
  470.         if weapon_address ~= 0 then
  471.             local weapon_tag = lookup_tag(read_dword(weapon_address))
  472.             if weapon_tag then
  473.                 return read_string(read_dword(weapon_tag + 0x10))
  474.             end
  475.         end
  476.     end
  477. end
  478.  
  479. function set_navs(PlayerIndex)
  480.     for i = 1,16 do
  481.         if player_present(i) then
  482.             local m_player = get_player(i)
  483.             local player = to_real_index(i)
  484.             if m_player ~= 0 then
  485.                 if PlayerIndex ~= nil then
  486.                     write_word(m_player + 0x88, to_real_index(PlayerIndex))
  487.                 else
  488.                     write_word(m_player + 0x88, player)
  489.                 end
  490.             end
  491.         end
  492.     end
  493. end
  494.  
  495. function server_setup()
  496.     gameinfo_base = read_dword(gameinfo_header)
  497.     join_call, last_name, nozomz = false, nil, false
  498.     local disable_team = zombie_team + 1
  499.     for i = 1,#tags do
  500.         svcmd("disable_object '".. tags[i][1] .."' "..disable_team)
  501.     end
  502.     for i = 1,16 do
  503.         sprint[i], score[i] = sprint_time * 30, 0
  504.         if player_present(i) then
  505.             set_team(i, human_team, false)
  506.         end
  507.     end
  508.     if tonumber(get_var(0, "$pn")) > 1 then
  509.         timer(1000, "start_game_timer")
  510.     end
  511.     if disable_vehicles then svcmd("disable_all_vehicles 0 1") end
  512.     svcmd("block_tc enabled;disable_object 'weapons\\ball\\ball' 0;disable_object 'weapons\\flag\\flag' 0")
  513. end
  514.  
  515. -- Weapon tags + powerup tags for spawning ammo packs
  516. tags = {
  517. {"weapons\\sniper rifle\\sniper rifle", "powerups\\sniper rifle ammo\\sniper rifle ammo"},
  518. {"weapons\\pistol\\pistol", "powerups\\pistol ammo\\pistol ammo"},
  519. {"weapons\\assault rifle\\assault rifle", "powerups\\assault rifle ammo\\assault rifle ammo"},
  520. {"weapons\\shotgun\\shotgun", "powerups\\shotgun ammo\\shotgun ammo"},
  521. {"weapons\\flamethrower\\flamethrower", "powerups\\flamethrower ammo\\flamethrower ammo"},
  522. {"weapons\\rocket launcher\\rocket launcher", "powerups\\rocket launcher ammo\\rocket launcher ammo"},
  523. {"weapons\\needler\\mp_needler", "powerups\\needler ammo\\needler ammo"},
  524. {"weapons\\plasma rifle\\plasma rifle", "weapons\\plasma grenade\\plasma grenade"},
  525. {"weapons\\plasma_cannon\\plasma_cannon", "weapons\\plasma grenade\\plasma grenade"},
  526. {"weapons\\plasma pistol\\plasma pistol", "powerups\\over shield"},
  527. {"weapons\\plasma grenade\\plasma grenade", "weapons\\plasma grenade\\plasma grenade"},
  528. {"weapons\\frag grenade\\frag grenade", "weapons\\frag grenade\\frag grenade"}
  529. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement