Advertisement
HR_Shaft

Roaming FFA Slayer Targets v1 for SAPP

Mar 16th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.32 KB | None | 0 0
  1. -- Roaming FFA Slayer Targets v1 for SAPP
  2. -- by H® Shaft
  3.  
  4. -- *** Roaming FFA Slayer Targets is designed for 3 or more players for Free-For-All SLAYER game-types ONLY ***
  5.  
  6. -- Puts a target over the head of other players in the game, which blinks/roams between all living players.  
  7. -- Targets reduce the ability to hide or camp during slayer on large or multilevel maps.
  8. -- If you kill another player, even if they DON'T have a target - you STILL get a point.
  9. -- Normal death messages are blocked, and show the killers score as normal, but to shown to ALL players:
  10. -- "sehé°° was killed by H® Shaft (12)"   << "12" shows that H® Shaft has 12 kills
  11. -- Enable or disable targets per map, and add your own map (see line 267) in LoadDefaults() near the bottom
  12.  
  13. -- Gametype notes:
  14. -- The slayer gametype MUST have "kill in order" set, AND objective indicators set to "nav points"
  15. -- This script is ONLY compatible with Free for All Slayer gametypes for both Halo PC/CE.
  16.  
  17. -- *** if loaded during a non-slayer map, it will skip the map and notify you by console and record it in the sapp log ***
  18. -- *** if script is reloaded during game play, it resets all player scores, and re-starts rotating targets if 2 or more players ***
  19.  
  20.  
  21. -- sapp api version
  22. api_version = "1.9.0.0"
  23.  
  24. -- don't edit --
  25. team_play = false
  26. game_started = false
  27. cur_players = 0
  28. timerCount = 0
  29.  
  30. function OnScriptLoad()
  31.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  32.     register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
  33.     register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
  34.     register_callback(cb['EVENT_DIE'], "OnPlayerDie")
  35.     register_callback(cb['EVENT_COMMAND'], "OnServerCommand")  
  36.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  37.    
  38.     disable_killmsg_addr = sig_scan("8B42348A8C28D500000084C9") + 3
  39.     original_code_1 = read_dword(disable_killmsg_addr)
  40.     safe_write(true)
  41.     write_dword(disable_killmsg_addr, 0x03EB01B1)
  42.     safe_write(false)  
  43.     map_name = get_var(0,"$map")
  44.     LoadDefaults()
  45.     LoadScript()
  46.  
  47.     if halo_type == "PC" then
  48.         gametime_base = 0x671420   
  49.     elseif halo_type == "CE" then
  50.         gametime_base = 0x5F55BC   
  51.     end
  52. end
  53.  
  54. function OnScriptUnload()
  55.     safe_write(true)
  56.     write_dword(disable_killmsg_addr, original_code_1)
  57.     safe_write(false)
  58.     enable_targets = {}
  59. end
  60.  
  61. function OnNewGame()
  62.     game_started = true
  63.     map_name = get_var(0,"$map")
  64.     gametype = get_var(0, "$gt")
  65.     team_play = getteamplay()
  66.     LoadDefaults()
  67.     LoadScript()
  68.     -- check for compatibility
  69.     if (gametype ~= "slayer") or (team_play == true) then
  70.         local mode = get_var(0,"$mode")
  71.         local str1 = string.format("**Roaming FFA Targets script isn't compatible with %s gametype, ONLY FFA SLAYER game types. Skipping map.", tostring(mode))
  72.         execute_command("log_note \""..str1.."\"")
  73.         cprint(str1)
  74.         execute_command("sv_map_next")
  75.     end
  76. end
  77.  
  78. function LoadScript()
  79.     game_started = true
  80.     team_play = getteamplay()
  81.     gametype = get_var(0, "$gt")
  82.     map_name = get_var(0,"$map")
  83.     cur_players = 0
  84.     timerCount = 0 
  85.     if map_name then enable_targets[map_name] = enable_targets[map_name] or false end
  86.     for i = 1,16 do
  87.         if player_present(i) then
  88.             cur_players = cur_players + 1          
  89.         end
  90.     end
  91.     if game_started and gametype == "slayer" then
  92.         if enable_targets[map_name] then
  93.             if not showtargets then
  94.                 if cur_players > 2 then
  95.                     showtargets = timer(300, "Show_Targets")
  96.                 end
  97.             end    
  98.         end
  99.     end
  100. end
  101.  
  102. function OnPlayerJoin(PlayerIndex)
  103.     cur_players = cur_players + 1          
  104.     if player_present(PlayerIndex) then
  105.         if game_started and gametype == "slayer" then
  106.             if enable_targets[map_name] then
  107.                 if not showtargets then
  108.                     if cur_players > 2 then
  109.                         showtargets = timer(300, "Show_Targets")   
  110.                     end
  111.                 end    
  112.             end
  113.         end    
  114.     end
  115. end
  116.  
  117. function OnPlayerLeave(PlayerIndex)
  118.     cur_players = cur_players - 1      
  119. end
  120.  
  121. function OnPlayerDie(PlayerIndex, KillerIndex)
  122.     -- Killer Index is: -- falling = -1, server = -1, team-switch = -1, vehicle = 0, other players = 1 or greater
  123.     if game_started then
  124.         local vname = get_var(PlayerIndex, "$name")        
  125.         local killer = tonumber(KillerIndex)
  126.        
  127.         if (killer == -1) then  -- server, falling or team change
  128.             if not map_reset then
  129.                 say_all(vname.. " died.")
  130.             end
  131.        
  132.         elseif (killer == 0) then -- vehicle
  133.             say_all(vname.. " was killed by a vehicle.")
  134.            
  135.         elseif (killer > 0) then
  136.             local kname = get_var(KillerIndex, "$name")
  137.            
  138.             if (PlayerIndex == killer) then -- suicide
  139.                 execute_command('say * "$name committed suicide."', PlayerIndex)               
  140.                
  141.             elseif (PlayerIndex ~= KillerIndex) then -- killed by another player
  142.                 if cur_players > 2 then
  143.                     execute_command("slayer_score " .. KillerIndex .. " +1")
  144.                     local playerscore = get_var(KillerIndex, "$score")
  145.                     say_all(vname.. " was killed by " .. kname .. " (" .. playerscore .. ")")
  146.                 else
  147.                     local playerscore = get_var(KillerIndex, "$score")
  148.                     say_all(vname.. " was killed by " .. kname .. " (" .. playerscore .. ")")
  149.                 end    
  150.                
  151.             else
  152.                 say_all(vname.. " was killed by the guardians. ")          
  153.             end
  154.         end
  155.  
  156.     end
  157.     if map_reset == true then
  158.         map_reset = false
  159.     end
  160. end
  161.  
  162. function getteamplay()
  163.     if get_var(0,"$ffa") == "0" then
  164.         return true
  165.     else
  166.         return false
  167.     end
  168. end
  169.  
  170. function Show_Targets()
  171.     if game_started and cur_players > 2 then
  172.         Roaming_Targets()
  173.         return true
  174.     else
  175.         return false
  176.     end
  177. end
  178.  
  179. function Roaming_Targets()
  180.     if not team_play then
  181.         local target = SelectTarget()
  182.         if target then
  183.             if player_present(target) and player_alive(target) then    
  184.                 for PlayerIndex = 1,16 do
  185.                     if player_present(PlayerIndex) and player_alive(PlayerIndex) then
  186.                         if get_player(PlayerIndex) and get_player(PlayerIndex) ~= get_player(target) then
  187.                             write_word(get_player(PlayerIndex) + 0x88, target) 
  188.                         end
  189.                     end    
  190.                 end
  191.             end    
  192.         end
  193.     end
  194. end
  195.  
  196. function SelectTarget()
  197.     local t = {}
  198.     for i=1,16 do
  199.         if player_present(i) and player_alive(i) then
  200.             local PlayerIndex = i
  201.             table.insert(t, PlayerIndex)
  202.         end
  203.     end
  204.     if #t > 0 then
  205.         if (timerCount > #t) then
  206.             timerCount = 0
  207.         else
  208.             timerCount = timerCount + 1
  209.         end    
  210.         return t[timerCount]
  211.     end
  212. end
  213.  
  214.  
  215. function OnServerCommand(PlayerIndex, Command, Environment, Password)
  216.     --  Enviroment: 0: console, 1: rcon, 2: chat, Password is the password used in the rcon, otherwise a nil
  217.     local allow = nil
  218.     local name = get_var(PlayerIndex, "$name")
  219.     if (tonumber(get_var(PlayerIndex,"$lvl"))) >= 1 then
  220.         isadmin = true
  221.     else
  222.         isadmin = false
  223.     end    
  224.     if (Environment == 1) or (Environment == 2) then
  225.         if Command ~= nil then
  226.             if isadmin then
  227.                 if Command == "sv_map_reset" then
  228.                     map_reset = true
  229.                     game_started = false           
  230.                     say_all("The game has been reset and scripts reloaded.")
  231.                     LoadDefaults()
  232.                     LoadScript()
  233.                     allow = true
  234.                 elseif Command == "reload" or Command == "/reload" then
  235.                     map_reset = true
  236.                     game_started = false
  237.                     timerCount = 0
  238.                     write_dword(gametime_base + 0x10, 0)       
  239.                     for i =1,16 do 
  240.                         if player_present(i) then
  241.                             write_dword(get_player(i) + 0x2C, 0)
  242.                             kill(i)                    
  243.                             execute_command("slayer_score " .. i .. " 0")
  244.                             execute_command("kills " .. i .. " 0")
  245.                             execute_command("assists " .. i .. " 0")
  246.                             execute_command("deaths " .. i .. " 0")                    
  247.                         end
  248.                     end
  249.                     LoadDefaults()
  250.                     LoadScript()
  251.                     say_all("The game has been reset and scripts reloaded.")                   
  252.                     allow = true
  253.                 end
  254.             else   
  255.                 allow = false
  256.             end
  257.         end
  258.     end
  259.     return allow
  260. end
  261.  
  262. function OnGameEnd()
  263.     game_started = false
  264.     cur_players = 0
  265. end
  266.  
  267. function LoadDefaults()
  268.     -- default enable/disable targets for the specified map: true = enable, false = disable
  269.     enable_targets = {
  270.         ["beavercreek"] = true,
  271.         ["bloodgulch"] = true,
  272.         ["boardingaction"] = true,
  273.         ["carousel"] = true,
  274.         ["chillout"] = true,
  275.         ["damnation"] = true,
  276.         ["dangercanyon"] = true,
  277.         ["deathisland"] = true,
  278.         ["gephyrophobia"] = true,
  279.         ["hangemhigh"] = true,
  280.         ["icefields"] = true,
  281.         ["infinity"] = true,
  282.         ["longest"] = true,
  283.         ["prisoner"] = true,
  284.         ["putput"] = true,
  285.         ["ratrace"] = true,
  286.         ["sidewinder"] = true,
  287.         ["timberland"] = true,
  288.         ["wizard"] = true,
  289.     }
  290. end
  291.  
  292. function OnError(Message)
  293.     print(debug.traceback())
  294. end
  295.  
  296. -- Created by H® Shaft
  297. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement