Advertisement
HR_Shaft

Roaming Slayer Targets v1 - for Phasor v2+

Jul 6th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.95 KB | None | 0 0
  1. --[[ ### Roaming Slayer Targets v1 ###]]--
  2. --[[ ###   by H® Shaft for Phasor  ###]]--
  3.  
  4. -- puts a target over the head of each player in the game, which blinks/rotates between players
  5. -- Gametype notes:
  6. -- The slayer gametype MUST have "kill in order" set, AND objectives indicators set to "nav points"
  7. -- This script is ONLY compatible with Team Slayer and Free for All Slayer for both Halo PC and Halo CE.
  8. -- Premade gametypes for pc and ce games: FFA 15 kills, Team 25 kills - Link:
  9.  
  10. -- http://www.mediafire.com/download/pkfvby8dtzez552/roaming_target_gametypes.zip
  11.  
  12. -- don't edit --
  13. roaming_targets = {}
  14. team_change = {}
  15. playerscore = {}
  16. teamscore = {}
  17. map_reset = false
  18. team_play = false
  19. game_started = false
  20. showtargets = nil
  21. cur_players = 0
  22. timerCount = 0
  23. score_limit = 100
  24.  
  25. --                          edit or add map name        edit true/false
  26. -- Roaming Targets          Map:                        Boolean:   true = enable, false = disable
  27. roaming_targets.            beavercreek         =       false
  28. roaming_targets.            bloodgulch          =       true               
  29. roaming_targets.            boardingaction      =       false              
  30. roaming_targets.            carousel            =       false
  31. roaming_targets.            chillout            =       false              
  32. roaming_targets.            damnation           =       false              
  33. roaming_targets.            dangercanyon        =       true               
  34. roaming_targets.            deathisland         =       true           
  35. roaming_targets.            gephyrophobia       =       true               
  36. roaming_targets.            hangemhigh          =       false              
  37. roaming_targets.            icefields           =       true               
  38. roaming_targets.            infinity            =       true               
  39. roaming_targets.            longest             =       false              
  40. roaming_targets.            prisoner            =       false              
  41. roaming_targets.            putput              =       false
  42. roaming_targets.            ratrace             =       true               
  43. roaming_targets.            sidewinder          =       false              
  44. roaming_targets.            timberland          =       true               
  45. roaming_targets.            wizard              =       false
  46.  
  47. function GetRequiredVersion()
  48.     return 200
  49. end
  50.  
  51. function OnScriptLoad(process, game, persistent)
  52.     GAME = game
  53.     GetGameAddresses(game)
  54.     Persistent = persistent
  55.     ScriptLoad()
  56. end
  57.  
  58. function ApplyPatches()
  59.     writebyte(slayer_score_patch, 0xEB)
  60.     writebyte(slayer_score_patch2, 0xEB)   
  61. end
  62.  
  63. function OnScriptUnload()
  64.     writebyte(slayer_score_patch, 0x74)
  65.     writebyte(slayer_score_patch2, 0x75)
  66. end
  67.  
  68. function OnNewGame(map)
  69.     ScriptLoad()   
  70.     team_play = getteamplay()
  71.     gametype = readbyte(gametype_base + 0x30)
  72.     game_started = false
  73.    
  74.     if not new_game_timer then
  75.         new_game_timer = registertimer(0, "NewGameTimer")
  76.     end
  77. end
  78.  
  79. function NewGameTimer(id, count)
  80.     if map_reset == true then
  81.         map_reset = false
  82.     end
  83.    
  84.     game_started = true
  85.     team_play = getteamplay()
  86.     score_limit = readbyte(gametype_base + 0x58)
  87.    
  88.     if team_play then
  89.         teamscore[0] = 0
  90.         teamscore[1] = 0                   
  91.     end
  92.    
  93.     for i = 0,15 do
  94.         if getplayer(i) then
  95.             playerscore[i] = 0
  96.             team_change[i] = false
  97.             cur_players = cur_players + 1
  98.             stats_base = (stats_globals + i*0x30)
  99.         end
  100.     end
  101.  
  102.     if not updatescores and game_started then
  103.         updatescores = registertimer(100, "Update_Scores")
  104.     end
  105.    
  106.     new_game_timer = nil   
  107.     return false
  108. end
  109.  
  110. function OnPlayerJoin(player)
  111.     if getplayer(player) then
  112.         cur_players = cur_players + 1
  113.         team_change[player] = false
  114.         playerscore[player] = 0
  115.         if gametype == 2 then
  116.             if map_name then roaming_targets[map_name] = roaming_targets[map_name] or false end
  117.             if roaming_targets[map_name] and game_started and cur_players > 0 and not showtargets then
  118.                 score_limit = readbyte(gametype_base + 0x58)
  119.                 showtargets = registertimer(250, "Show_Targets")
  120.             end
  121.         end    
  122.     end
  123. end
  124.  
  125. function OnPlayerLeave(player)
  126.     if getplayer(player) then
  127.         cur_players = cur_players - 1
  128.         team_change[player] = {}
  129.         playerscore[player] = 0
  130.         if cur_players < 1 and showtargets then
  131.             showtargets = nil
  132.         end        
  133.     end
  134. end
  135.  
  136. function ScriptLoad()
  137.     if Persistent then
  138.         cur_players = 0
  139.         timerCount = 0
  140.         team_change = {}
  141.         playerscore = {}
  142.         teamscore = {}     
  143.         game_started = false
  144.         team_play = false      
  145.         if not new_game_timer then
  146.             new_game_timer = registertimer(0, "NewGameTimer")
  147.         end        
  148.     end
  149.    
  150.     GetGameAddresses(game)
  151.     ApplyPatches()
  152.     showtargets = nil
  153.     game_started = false
  154.     team_play = false  
  155.     team_play = getteamplay()
  156.     gametype = readbyte(gametype_base + 0x30)
  157.     cur_players = readword(network_base, 0x1A0)
  158.    
  159.     if gametype == 2 then
  160.         if map_name then roaming_targets[map_name] = roaming_targets[map_name] or false end
  161.         if roaming_targets[map_name] then
  162.             score_limit = readbyte(gametype_base + 0x58)
  163.             showtargets = registertimer(250, "Show_Targets")
  164.         end
  165.     end
  166.    
  167.     for i = 0,15 do
  168.         if getplayer(i) then
  169.             playerscore[i] = 0
  170.             team_change[i] = false
  171.             cur_players = cur_players + 1
  172.             stats_base = (stats_globals + i*0x30)
  173.         end
  174.     end
  175.    
  176.     if not new_game_timer then
  177.         new_game_timer = registertimer(0, "NewGameTimer")
  178.     end    
  179.    
  180. end
  181.  
  182. function OnServerCommand(player, command)
  183.     local allow = nil
  184.     local cmd = tokenizecmdstring(command)
  185.     local tokencount = #cmd
  186.    
  187.     if tokencount > 0 then
  188.    
  189.         if cmd[1] == "sv_map_reset" then
  190.             map_reset = true
  191.             showtargets = nil          
  192.             if team_play then
  193.                 teamscore[0] = 0
  194.                 teamscore[1] = 0
  195.                 for i=0,15 do  
  196.                     if getplayer(i) then
  197.                         playerscore[i] = 0
  198.                     end
  199.                 end
  200.             else
  201.                 for i=0,15 do  
  202.                     if getplayer(i) then
  203.                         playerscore[i] = 0
  204.                     end
  205.                 end            
  206.             end
  207.             ScriptLoad()               
  208.             for i=0,15 do  
  209.                 if getplayer(i) then
  210.                     kill(i)
  211.                 end
  212.             end        
  213.             allow = true
  214.            
  215.         elseif cmd[1] == "sv_script_reload" then
  216.             map_reset = true
  217.             showtargets = nil
  218.             writedword(gametime_base + 0x10, 0)
  219.             map_reset = true
  220.             showtargets = nil          
  221.             if team_play then
  222.                 teamscore[0] = 0
  223.                 teamscore[1] = 0
  224.                 Write_Team_Score(0, teamscore[0])
  225.                 Write_Team_Score(1, teamscore[1])              
  226.                 for i=0,15 do  
  227.                     if getplayer(i) then
  228.                         local m_player = getplayer(i)
  229.                         playerscore[i] = 0
  230.                         Write_Player_Score(i, playerscore[i])
  231.                         stats_base = (stats_globals + i*0x30)
  232.                         writeword(stats_base + 0x8, 0) -- kills
  233.                         writeword(stats_base + 0x10, 0) -- assists
  234.                         writeword(stats_base + 0x1A, 0) -- deaths
  235.                        
  236.                         writeword(getplayer(i) + 0x9C, 0) -- kills
  237.                         writeword(getplayer(i) + 0xA4, 0) -- assists
  238.                         writeword(getplayer(i) + 0xAE, 0) -- deaths                
  239.        
  240.                         writeword(m_player + 0x9C, 0) -- kills
  241.                         writeword(m_player + 0xA4, 0) -- assists
  242.                         writeword(m_player + 0xAE, 0) -- deaths
  243.                                
  244.                     end
  245.                 end
  246.             else
  247.                 for i=0,15 do  
  248.                     if getplayer(i) then
  249.                         local m_player = getplayer(i)
  250.                         playerscore[i] = 0
  251.                         Write_Player_Score(i, playerscore[i])
  252.                         stats_base = (stats_globals + i*0x30)
  253.                         writeword(stats_base + 0x8, 0) -- kills
  254.                         writeword(stats_base + 0x10, 0) -- assists
  255.                         writeword(stats_base + 0x1A, 0) -- deaths
  256.                        
  257.                         writeword(getplayer(i) + 0x9C, 0) -- kills
  258.                         writeword(getplayer(i) + 0xA4, 0) -- assists
  259.                         writeword(getplayer(i) + 0xAE, 0) -- deaths                
  260.        
  261.                         writeword(m_player + 0x9C, 0) -- kills
  262.                         writeword(m_player + 0xA4, 0) -- assists
  263.                         writeword(m_player + 0xAE, 0) -- deaths                
  264.                     end
  265.                 end            
  266.             end
  267.             ScriptLoad()
  268.             --privatesay(player, "**RELOAD** The game has been reset and scripts reloaded. ")
  269.             for i=0,15 do  
  270.                 if getplayer(i) then
  271.                     kill(i)
  272.                     playerscore[i] = 0
  273.                     --privatesay(i, "The game has been reset. ")
  274.                 end
  275.             end
  276.             svcmd("sv_map_reset")  
  277.             allow = true
  278.         end
  279.        
  280.     end
  281.    
  282.     return allow
  283. end
  284.  
  285. function OnPlayerKill(killer, victim, mode)
  286.  
  287.     if game_started then
  288.        
  289.         if mode == 1 then -- player was killed by falling or team-change
  290.        
  291.             if getplayer(victim) then
  292.                 local vname = getname(victim)  
  293.                 if not team_change[victim] and not map_reset then
  294.                     say(vname .. " fell and died.")
  295.                     return false
  296.                 elseif team_change[victim] and not map_reset then
  297.                     team_change[victim] = false
  298.                     say(vname .. " changed teams.")
  299.                     return false                       
  300.                 end
  301.             end        
  302.        
  303.         elseif mode == 4 then -- player was killed by another player
  304.  
  305.             if getplayer(killer) then
  306.                 local kteam = getteam(killer)
  307.                 playerscore[killer] = playerscore[killer] + 1
  308.                 if team_play then kteam = getteam(killer) teamscore[kteam] = teamscore[kteam] + 1 end
  309.             end
  310.  
  311.         elseif mode == 5 then -- player was killed/betrayed by teammate
  312.        
  313.             if getplayer(killer) then
  314.                 local kteam = getteam(killer)
  315.                 -- prevents negative score sabotage, but deducts 1 point per betray if score > 0
  316.                 if (playerscore[killer] - 1) >= 0 then playerscore[killer] = playerscore[killer] - 1 end
  317.                 if team_play then if (teamscore[kteam] - 1) >= 0 then teamscore[kteam] = teamscore[kteam] - 1 end end
  318.             end
  319.    
  320.         elseif mode == 6 then --suicides - killer is victim/self
  321.  
  322.             if getplayer(victim) then
  323.                 local vteam = getteam(victim)
  324.                 -- prevents negative score sabotage, but deducts 1 point per suicide if score > 0
  325.                 if (playerscore[victim] - 1) >= 0 then playerscore[victim] = playerscore[victim] - 1 end
  326.                 if team_play then if (teamscore[vteam] - 1) >= 0 then teamscore[vteam] = teamscore[vteam] - 1 end end              
  327.             end
  328.            
  329.         end
  330.        
  331.     end
  332. end
  333.  
  334. function OnClientUpdate(player)
  335.     if getplayer(player) then
  336.    
  337.         if not team_play then
  338.             local score = playerscore[player]
  339.             if score ~= nil then
  340.                 -- monitors and initiates FFA game win announcement
  341.                 if score >= score_limit and game_started then
  342.                     game_started = false
  343.                     announcewin = registertimer(0, "AnnounceWin", player)
  344.                 end
  345.             end
  346.            
  347.         elseif team_play then
  348.             local team = getteam(player)
  349.             local score = teamscore[team]
  350.             -- monitors and initiates Team game win announcement
  351.             if score >= score_limit and game_started then
  352.                 game_started = false
  353.                 announcewin = registertimer(0, "AnnounceWin", player)
  354.             end
  355.         end
  356.        
  357.     end
  358. end
  359.  
  360. function AnnounceWin(id, count, player)
  361.     -- announces game winner
  362.     if player and game_started == false then
  363.         local name = getname(player)   
  364.         svcmd("sv_map_next")
  365.         if not team_play then
  366.             say(name .. " WINS THE GAME! ")
  367.         else   
  368.             local team = getteam(player)
  369.             if team == 0 then team = "RED TEAM" elseif team == 1 then team = "BLUE TEAM" end
  370.             say(team .. " WINS THE GAME! ")
  371.         end    
  372.     end    
  373.     return false
  374. end
  375.    
  376. function Update_Scores(id, count)
  377.     -- continuous score updating
  378.     if not team_play then
  379.         for i = 0,15 do
  380.             if getplayer(i) then
  381.                 local team = getteam(i) -- in FFA, each player is a team
  382.                 if playerscore[i] == nil or playerscore[i] < 0 then playerscore[i] = 0 end
  383.                 Write_Player_Score(i, playerscore[i])
  384.             end
  385.         end    
  386.     else
  387.         for i = 0,15 do
  388.             if getplayer(i) then
  389.                 if playerscore[i] == nil or playerscore[i] < 0 then playerscore[i] = 0 end
  390.                 Write_Player_Score(i, playerscore[i])
  391.             end
  392.         end
  393.         if teamscore[0] == nil or teamscore[0] < 0 then teamscore[0] = 0 end
  394.         if teamscore[1] == nil or teamscore[1] < 0 then teamscore[1] = 0 end
  395.         Write_Team_Score(0, teamscore[0])
  396.         Write_Team_Score(1, teamscore[1])
  397.     end
  398.     return true
  399. end                
  400.  
  401. function Write_Player_Score(player, score)
  402.     -- writes the players score
  403.     if gametype == 2 then
  404.         if player then
  405.             writedword(slayer_globals + 0x40 + player*4, score)
  406.         end
  407.     end
  408. end
  409.  
  410. function Write_Team_Score(team, score)
  411.     -- writes the team score
  412.     if gametype == 2 then
  413.         writedword(slayer_globals + team*4, score)
  414.     end    
  415. end
  416.  
  417. function GetGameAddresses(game)
  418.     if game == "PC" or GAME == "PC" then
  419.         map_name = readstring(0x698F21)
  420.         gametype_base = 0x671340
  421.         network_base = 0x745BA8
  422.         gametime_base = 0x671420
  423.         slayer_globals = 0x63A0E8
  424.         slayer_score_patch = 0x48F428
  425.         slayer_score_patch2 = 0x48F23E
  426.         stats_globals = 0x639898
  427.     else
  428.         map_name = readstring(0x61D151)
  429.         gametype_base = 0x5F5498
  430.         network_base = 0x6C7988
  431.         gametime_base = 0x5F55BC
  432.         slayer_globals = 0x5BE108
  433.         slayer_score_patch = 0x469CF8
  434.         slayer_score_patch2 = 0x4691CE
  435.         stats_globals = 0x5BD8B8
  436.     end
  437. end
  438.  
  439. function getteamplay()
  440.     if readbyte(gametype_base + 0x34) == 1 then
  441.         return true
  442.     else
  443.         return false
  444.     end
  445. end
  446.  
  447. function Show_Targets(id, count)
  448.     Roaming_Targets()
  449.     return true
  450. end
  451.  
  452. function Roaming_Targets()
  453.     local response = nil
  454.     if game_started and cur_players > 0 and gametype == 2 then
  455.         if team_play then
  456.             local target = SelectRoamingPlayer(player)
  457.             if target then
  458.                 local team = getteam(target)
  459.                 for i = 0,15 do
  460.                     if getplayer(i) and getplayer(i) ~= getplayer(target) and getteam(i) ~= team then
  461.                         writeword(getplayer(i) + 0x88, target)
  462.                     end                
  463.                 end
  464.                 response = true
  465.             else
  466.                 response = false
  467.             end
  468.         else
  469.             local target = SelectRoamingPlayer(player)
  470.             if target then
  471.                 for i = 0,15 do
  472.                     if getplayer(i) and getplayer(i) ~= getplayer(target) then
  473.                         writeword(getplayer(i) + 0x88, target)
  474.                     end                
  475.                 end
  476.                 response = true
  477.             else
  478.                 response = false
  479.             end
  480.         end
  481.     end
  482.     return response
  483. end
  484. -- inspired by a different original from Aelite while working on targets for flying hogs, thanks!
  485. function SelectRoamingPlayer(player)
  486.     local target = {}
  487.     for i=0,15 do
  488.         if getplayer(i) then
  489.             table.insert(target, i)
  490.         end
  491.     end
  492.     if #target >= 1 then
  493.         if (timerCount > #target) then
  494.             timerCount = 0
  495.         else
  496.             timerCount = timerCount + 1
  497.         end
  498.         return target[timerCount]
  499.     end
  500. end
  501.  
  502. function OnTeamChange(player, old_team, new_team, relevant)
  503.     -- prevent unbalancing teams by team change
  504.     local response = nil
  505.     if getplayer(player) then
  506.    
  507.         local newteam = "New Team"
  508.         local oldteam = "Old Team"
  509.        
  510.         if not team_play then response = false return response end
  511.        
  512.         if new_team == 0 then
  513.             oldteam = "Blue Team"
  514.             newteam = "Red Team"       
  515.         elseif new_team == 1 then
  516.             oldteam = "Red Team"
  517.             newteam = "Blue Team"      
  518.         end        
  519.        
  520.         if relevant == true or relevant == 1 then
  521.             if getteamsize(old_team) == getteamsize(new_team) then
  522.                 privatesay(player, "You cannot change teams.")
  523.                 response = false
  524.             elseif getteamsize(old_team) + 1 == getteamsize(new_team) then
  525.                 privatesay(player, "You cannot change teams.")
  526.                 response = false
  527.             elseif getteamsize(old_team) == getteamsize(new_team) + 1 then
  528.                 privatesay(player, "You cannot change teams.")
  529.                 response = false
  530.             elseif getteamsize(old_team) > getteamsize(new_team) then
  531.                 team_change[player] = true
  532.                 -- transfer player score to new team score, and deduct new player score from old team score
  533.                 if team_play then
  534.                     teamscore[new_team] = teamscore[new_team] + playerscore[player]
  535.                     teamscore[old_team] = teamscore[old_team] - playerscore[player]
  536.                 end
  537.                 say(getname(player) .. " switched to the "  .. newteam)
  538.                 response = true
  539.             elseif getteamsize(old_team) < getteamsize(new_team) then
  540.                 team_change[player] = true
  541.                 -- transfer player score to new team score, and deduct new player score from old team score
  542.                 if team_play then
  543.                     teamscore[new_team] = teamscore[new_team] + playerscore[player]
  544.                     teamscore[old_team] = teamscore[old_team] - playerscore[player]
  545.                 end                            
  546.                 say(getname(player) .. " switched to the "  .. newteam)
  547.                 response = true
  548.             end
  549.         elseif relevant == false or relevant == 0 then
  550.             team_change[player] = true
  551.             -- transfer player score to new team score, and deduct new player score from old team score
  552.             if team_play then
  553.                 teamscore[new_team] = teamscore[new_team] + playerscore[player]
  554.                 teamscore[old_team] = teamscore[old_team] - playerscore[player]
  555.             end        
  556.             say(getname(player) .. " was team-switched by the server to the " .. newteam .. ".")
  557.             response = true
  558.         end
  559.        
  560.     end
  561.     return response
  562. end
  563.  
  564. function OnGameEnd(stage)
  565.     if stage == 1 then
  566.         game_started = false
  567.         if announcewin then
  568.             announcewin = nil
  569.         end    
  570.         if showtargets then
  571.             showtargets = nil
  572.         end
  573.         if updatescores then
  574.             updatescores = nil
  575.         end
  576.         if new_game_timer then
  577.             new_game_timer = nil
  578.         end
  579.     end
  580. end
  581.  
  582. -- Created by H® Shaft.
  583. -- Thanks to Oxide, AelitePrime, Nugget & Wizard.
  584. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  585. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement