Advertisement
HR_Shaft

Multi-Team-Vehicles v2 for SAPP

Jul 11th, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.57 KB | None | 0 0
  1. -- MTV: Multi-Team-Vehicles v2 for SAPP by H® Shaft
  2.  
  3. -- ||| Incompatible with team games ||| If attempted, the script will move to next map, and log it, and report to console.
  4.  
  5. -- Allows you to enter the enemy's vehicle during FREE-for-All (FFA) games
  6. -- Aiming reticle (crosshairs) will not turn red: Big fuggin deal, just aim and shoot!
  7. -- Gametype settings: Under 'team play options': turn off radar or enemies will show as friendly/yellow on motion sensor.
  8.  
  9. -- Created originally for Phasor by H® Shaft and AelitePrime
  10. -- Portions inspired by/taken from 002's Anti-Teamshoot, and sehé°°'s Zombie script
  11.  
  12. -- SAPP api version --
  13. api_version = "1.8.0.0"
  14. team_play = 3
  15.  
  16. function OnScriptLoad()
  17.     local tick_counter_sig = sig_scan("8B2D????????807D0000C644240600")
  18.     if(tick_counter_sig ~= 0) then
  19.         tick_counter_address = read_dword(read_dword(tick_counter_sig + 2)) + 0xC
  20.         register_callback(cb['EVENT_TICK'],"OnTick")
  21.     end
  22.     register_callback(cb['EVENT_GAME_START'],"OnNewGame")
  23.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  24.     register_callback(cb['EVENT_JOIN'],"OnPlayerJoin")
  25.     register_callback(cb['EVENT_SPAWN'],"OnPlayerSpawn")
  26.     register_callback(cb['EVENT_DIE'], "OnPlayerDeath")
  27.     register_callback(cb['EVENT_BETRAY'], "OnPlayerBetray")
  28.  
  29.     disable_killmsg_addr = sig_scan("8B42348A8C28D500000084C9") + 3
  30.     original_code_1 = read_dword(disable_killmsg_addr)
  31.     execute_command("var_add kname 3")
  32.    
  33.     safe_write(true)
  34.     write_dword(disable_killmsg_addr, 0x03EB01B1)
  35.     safe_write(false)
  36.    
  37.     if get_var(0, "$gt") ~= "n/a" then
  38.         OnNewGame()
  39.     end    
  40. end
  41.  
  42. function OnScriptUnload()
  43.     safe_write(true)
  44.     write_dword(disable_killmsg_addr, original_code_1)
  45.     safe_write(false)
  46.     execute_command("var_del kname")
  47. end
  48.  
  49. function OnNewGame()
  50.     -- team games incompatability notice for console and log
  51.     if team_play == 3 then team_play = getteamplay() end   
  52.     if (team_play == true) then
  53.         local MODE = get_var(0,"$mode")
  54.         local str1 = string.format("MTV script NOT compatible with %s gametype which is a team game! Skipping map.", tostring(MODE))
  55.         say_all(str1)
  56.         execute_command("log_note \""..str1.."\"")
  57.         cprint(str1)
  58.         execute_command("sv_map_next")
  59.     else
  60.         game_started = true
  61.         for i=1,16 do
  62.             if (player_present(i) == true) then
  63.                 write_byte(get_player(i) + 0x20, 0)
  64.                 kill(i)
  65.             end
  66.         end
  67.     end        
  68. end
  69.  
  70. function OnGameEnd()
  71.     game_started = false
  72. end
  73.  
  74. function OnPlayerDeath(PlayerIndex, KillerIndex)
  75.     if game_started then
  76.    
  77.         -- set killer index (KillerIndex)
  78.         local killer = tonumber(KillerIndex)
  79.         execute_command('var_set kname "$name" '..PlayerIndex, killer)
  80.        
  81.         -- set victim name
  82.         local victim_name = get_var(PlayerIndex,"$name")
  83.         -- when killer is 0, the victim died by a vehicle, -1 means killer is the server, fall damage, or team change which are not used here
  84.         if killer == 0 then
  85.             say_all(victim_name .. " was killed by a vehicle.")
  86.         end
  87.        
  88.         -- killed by a player if killer index > 0
  89.         if killer > 0 then
  90.             -- set killer name for death by self or another player
  91.             local killer_name = get_var(KillerIndex,"$kname")
  92.             -- suicide if player and killer are the same
  93.             if PlayerIndex == killer then
  94.                 say_all(victim_name.. " committed suicide.")
  95.             else
  96.                 -- killed by another player
  97.                 execute_command('say * "$name was killed by $kname"', PlayerIndex)
  98.             end
  99.         end
  100.        
  101.     end
  102. end
  103.  
  104. function OnPlayerBetray(PlayerIndex)
  105.     if game_started then
  106.         if player_present(PlayerIndex) then
  107.             if not team_play then
  108.                 -- since this script can cause betrays on free-for-all, if betray count is > 0, then set to 0 to prevent tk warning or kick/ban
  109.                 -- sapp remembers the tk score, even if player quits and rejoins, and between maps too
  110.                 if read_dword(get_player(PlayerIndex) + 0xC0) > 0 then
  111.                     write_dword(get_player(PlayerIndex) + 0xC0, 0)
  112.                 end
  113.                 if read_dword(get_player(PlayerIndex) + 0xE0) > 0 then
  114.                     write_dword(get_player(PlayerIndex) + 0xE0, 0)
  115.                 end
  116.             end    
  117.         end
  118.     end
  119. end
  120.  
  121. function OnPlayerSpawn(PlayerIndex)
  122.     if player_present(PlayerIndex) then
  123.         write_byte(get_player(PlayerIndex) + 0x20, 0)
  124.     end
  125. end
  126.  
  127. function OnPlayerJoin(PlayerIndex)
  128.     if player_present(PlayerIndex) then
  129.         write_byte(get_player(PlayerIndex) + 0x20, 0)
  130.     end
  131. end
  132.  
  133. function OnTick()
  134.     local tick_id = read_dword(tick_counter_address)
  135.     for i=1,16 do
  136.         local player_dyn = get_dynamic_player(i)
  137.         if (player_dyn ~= 0) then
  138.             for k=0,3 do
  139.                 local struct = player_dyn + 0x430 + 0x10 * k
  140.                 local damager_time = read_dword(struct)
  141.                 if (damager_time == tick_id) then
  142.                     local damager_pid = read_word(struct + 0xC)
  143.                     local damager_player = nil
  144.                     if (damager_pid ~= 0xFFFF) then
  145.                         damager_player = to_player_index(damager_pid)
  146.                         OnDamageLookup(i,damager_player)
  147.                     end
  148.                 end
  149.             end
  150.         end
  151.     end
  152. end
  153.  
  154. function OnDamageLookup(ReceiverIndex, CauserIndex)
  155.     if (CauserIndex and ReceiverIndex ~= CauserIndex) then
  156.         local c_team = read_word(get_player(CauserIndex) + 0x20)
  157.         local r_team = read_word(get_player(ReceiverIndex) + 0x20) 
  158.         if c_team == r_team then
  159.             local count = r_team
  160.             while (r_team == count) do
  161.                 count = count + 1
  162.                 if count > 15 then count = 0 end
  163.                 write_byte(get_player(ReceiverIndex) + 0x20, count)
  164.             end                                
  165.         end
  166.     end
  167. end
  168.  
  169. -- returns true if team game, false if ffa game
  170. function getteamplay()
  171.     if get_var(0,"$ffa") == "0" then
  172.         return true
  173.     else
  174.         return false
  175.     end
  176. end
  177.  
  178. function OnError(Message)
  179.     print(debug.traceback())
  180. end
  181.  
  182. -- Created by H® Shaft
  183. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement