Advertisement
HR_Shaft

Driver Bonus for Team Race for SAPP version 10+

May 16th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.35 KB | None | 0 0
  1. -- Driver Bonus for Team Race for SAPP version 10+
  2. -- by H® Shaft
  3.  
  4. -- Designed for TEAM RACE, Halo PC/CE, for SAPP version 10
  5. -- * NOT compatibible with earlier sapp versions
  6.  
  7. -- When a DRIVER of a multi-seat vehicle 'scores a lap' in a team race game, they will be given 2 ASSISTS and a message is shown to all (ASSIST_MESSAGE).
  8. -- When the DRIVER reaches 10 assists they will be given an extra +1 SCORE/lap and a message is shown to all (SCORE_MESSAGE) and their assists are reset to 0.
  9. -- will only work if player is in a multi-seat vehicle, such as a warthog.  Will not work in solo vehicles: tanks, ghosts, banshees, turrets, jets, etc.
  10. -- Why? This will help balance out driver/gunner scoring. Commonly in race, the GUNNER, and NOT the DRIVER, will win the game when they have the SAME score.
  11. -- If the game is one point away from being won, this does not ensure the driver gets the lap - halo decides that.
  12.  
  13.  
  14. -- Assist message shown to all when a driver in a multi-seat vehicle receives an ASSIST driving bonus.
  15. ASSIST_MESSAGE = "was given +2 ASSISTS driving bonus! Get 10 for +1 score!"
  16.  
  17. -- Score message shown to all when a driver in a multi-seat vehicle receives a SCORE driving bonus.
  18. SCORE_MESSAGE = "was given +1 SCORE/lap driving bonus!"
  19.  
  20. -- don't edit --
  21. api_version = "1.10.0.0"
  22.  
  23. function OnScriptLoad()
  24.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  25.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  26.     register_callback(cb['EVENT_SCORE'], "OnPlayerScore")
  27.     if get_var(0, "$gt") ~= "n/a" then
  28.         game_started = true
  29.         team_play = getteamplay()      
  30.     else
  31.         game_started = false
  32.         team_play = false
  33.     end
  34. end
  35.  
  36. function OnNewGame()
  37.     game_started = true
  38.     team_play = getteamplay()
  39. end
  40.  
  41. function OnGameEnd()
  42.     game_started = false
  43. end
  44.  
  45. function OnPlayerScore(PlayerIndex)
  46.     if (get_var(0,"$gt") == "race") and (team_play == true) then
  47.         if isinvehicle(PlayerIndex) and PlayerIsDriver(PlayerIndex) then
  48.             local veh_name = string.lower(GetPlayerVehicleTagName(PlayerIndex))
  49.             if (veh_name ~= nil) then
  50.                 if string.find(veh_name, "snowh") or string.find(veh_name, "civi") or string.find(veh_name, "wart") or
  51.                     string.find(veh_name, "hawg") or string.find(veh_name, "puma") or string.find(veh_name, "booger") or
  52.                     string.find(veh_name, "gaus") then 
  53.                     local driver = get_var(PlayerIndex,"$name")
  54.                     local Assists = tonumber(get_var(PlayerIndex, "$assists"))
  55.                     if (Assists +2 <= 9) then      
  56.                         execute_command("assists me +2", PlayerIndex)
  57.                         rprint(PlayerIndex, "|rDRIVER BONUS: +2 assists!")
  58.                         rprint(PlayerIndex, " ")
  59.                         for i=1,16 do
  60.                             if player_present(i) then
  61.                                 say(i, driver .. " " .. ASSIST_MESSAGE)
  62.                             end
  63.                         end
  64.                     elseif (Assists +2 >= 10) then 
  65.                         execute_command("score me +1", PlayerIndex)
  66.                         rprint(PlayerIndex, "|rDRIVER BONUS: +1 score!")   
  67.                         rprint(PlayerIndex, " ")       
  68.                         execute_command("assists me 0", PlayerIndex)
  69.                         for i=1,16 do
  70.                             if player_present(i) then
  71.                                 say(i, driver .. " " .. SCORE_MESSAGE)
  72.                             end
  73.                         end
  74.                     end
  75.                 end
  76.             end        
  77.         end
  78.     end
  79. end
  80.  
  81. function getteamplay()
  82.     if get_var(0,"$ffa") == "0" then
  83.         return true
  84.     else
  85.         return false
  86.     end
  87. end
  88.  
  89. function isinvehicle(PlayerIndex)
  90.     local player_object = get_dynamic_player(PlayerIndex)
  91.     if player_object ~= 0 then
  92.         local vehicleId = read_dword(player_object + 0x11C)
  93.         if vehicleId == 0xFFFFFFFF then
  94.             return false
  95.         else
  96.             return true
  97.         end
  98.     else
  99.         return false
  100.     end
  101. end
  102.  
  103. function PlayerIsDriver(PlayerIndex)
  104.     if (player_alive(PlayerIndex) == false) then return false end
  105.     local player_object = get_dynamic_player(PlayerIndex)
  106.     local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
  107.     local vehicleId = read_dword(player_object + 0x11C)
  108.     if (vehicleId == 0xFFFFFFFF) then return false end
  109.     local obj_id = get_object_memory(vehicleId)
  110.     return read_dword(obj_id + 0x324) == player_object_id
  111. end
  112.  
  113. function GetPlayerVehicleTagName(PlayerIndex)
  114.     if isinvehicle(PlayerIndex) and game_started then
  115.         local player_object = get_dynamic_player(PlayerIndex)
  116.         local vehicleId = read_dword(player_object + 0x11C)
  117.         local vehicle_obj = get_object_memory(vehicleId)
  118.         if (vehicle_obj ~= 0) then
  119.             local vehicle_metaid = read_dword(vehicle_obj)     
  120.             local veh_name = get_vehicle_name(vehicle_metaid)
  121.             if (veh_name ~= nil and veh_name ~= "NULL METAID") then
  122.                 return veh_name
  123.             else
  124.                 return nil
  125.             end
  126.         end
  127.     end
  128. end
  129.  
  130. function get_vehicle_name(MetaID) -- Thanks to Giraffe!
  131.     if (MetaID == 0xFFFFFFFF) then
  132.         return "NULL METAID"
  133.     else
  134.         local globals_tag = lookup_tag("matg", "globals\\globals")
  135.         local globals_data = read_dword(globals_tag + 0x14)
  136.         local interface_bitmaps_data = read_dword(globals_data + 0x144)
  137.         local hud_globals_metaid = read_dword(interface_bitmaps_data + 0x6C)
  138.         local hud_globals_tag = lookup_tag(hud_globals_metaid)
  139.         local hud_globals_data = read_dword(hud_globals_tag + 0x14)
  140.         local hud_icon_messages_metaid = read_dword(hud_globals_data + 0xC0)
  141.         local hud_icon_messages_tag = lookup_tag(hud_icon_messages_metaid)
  142.         local hud_icon_messages_data = read_dword(hud_icon_messages_tag + 0x14)
  143.         local string_references_count = read_dword(hud_icon_messages_data)
  144.         local string_references_data = read_dword(hud_icon_messages_data + 0x4)
  145.         local strings = {}
  146.         for i=0,string_references_count-1 do
  147.             local bytes = read_dword(string_references_data + i*20)
  148.             local string_data = read_dword(string_references_data + i*20 + 0xC)
  149.             local string = ''
  150.             for j=0,bytes-3,2 do
  151.                 string = string .. string.char(read_char(string_data +j))
  152.             end
  153.             strings[i] = string
  154.         end
  155.         local vehicle_tag = lookup_tag(MetaID)
  156.         local vehicle_data = read_dword(vehicle_tag + 0x14)
  157.         local hud_text_message_index = read_short(vehicle_data + 0x13C)
  158.         if(strings[hud_text_message_index] ~= nil) then
  159.             return strings[hud_text_message_index]
  160.         else
  161.             return strings[0]
  162.         end
  163.     end
  164. end
  165.  
  166. function OnError(Message)
  167.     print(debug.traceback())
  168. end
  169.  
  170. -- Created by H® Shaft
  171. -- Visit http://halorace.org/forum/index.php
  172. -- Email: debtproblems@hotmail.com
  173.  
  174. -- The player -db-GoNe/Juhleek - a well spoken liar, cheat.
  175. -- -db- is: "diverging from the believable" - How ironic. A race clan where admins use rcon to favor themselves to win.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement