Advertisement
HR_Shaft

Driver Bonus v2 for Team Race for SAPP version 10

May 26th, 2017
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.90 KB | None | 0 0
  1. -- Driver Bonus v2 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. -- Update: Added driver must have a gunner to get a driver bonus.
  7.  
  8. -- 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).
  9. -- 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.
  10. -- 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.
  11. -- 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.
  12. -- If the game is one point away from being won, this does not ensure the driver (and not the gunner) gets the lap - halo decides that.
  13.  
  14.  
  15. -- Assist message shown to all when a driver in a multi-seat vehicle receives an ASSIST driving bonus.
  16. ASSIST_MESSAGE = "was given +2 ASSISTS driving bonus! Get 10 for +1 score!"
  17.  
  18. -- Score message shown to all when a driver in a multi-seat vehicle receives a SCORE driving bonus.
  19. SCORE_MESSAGE = "was given +1 SCORE/lap driving bonus!"
  20.  
  21.  
  22. -- don't edit --
  23. api_version = "1.10.0.0"
  24.  
  25. function OnScriptLoad()
  26.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  27.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  28.     register_callback(cb['EVENT_SCORE'], "OnPlayerScore")
  29.     if get_var(0, "$gt") ~= "n/a" then
  30.         game_started = true
  31.         team_play = getteamplay()      
  32.     else
  33.         game_started = false
  34.         team_play = false
  35.     end
  36. end
  37.  
  38. function OnNewGame()
  39.     game_started = true
  40.     team_play = getteamplay()
  41. end
  42.  
  43. function OnGameEnd()
  44.     game_started = false
  45. end
  46.  
  47. function OnPlayerScore(PlayerIndex)
  48.     if (get_var(0,"$gt") == "race") and (team_play == true) then
  49.         if isinvehicle(PlayerIndex) and PlayerIsDriver(PlayerIndex) then
  50.             local player_object = get_dynamic_player(PlayerIndex)
  51.             if (player_object ~= 0) then
  52.                 local vehicleId = read_dword(player_object + 0x11C)    
  53.                 local veh_name = string.lower(GetPlayerVehicleTagName(PlayerIndex))
  54.                 if (veh_name ~= nil) then
  55.                     if string.find(veh_name, "snowh") or string.find(veh_name, "civi") or string.find(veh_name, "wart") or
  56.                         string.find(veh_name, "hawg") or string.find(veh_name, "puma") or string.find(veh_name, "booger") or
  57.                         string.find(veh_name, "gaus") then 
  58.                         local driver = get_var(PlayerIndex,"$name")
  59.                         local Assists = tonumber(get_var(PlayerIndex, "$assists"))
  60.                         if (Assists +2 <= 9) and VehicleHasGunner(vehicleId) then      
  61.                             execute_command("assists me +2", PlayerIndex)
  62.                             rprint(PlayerIndex, "|rDRIVER BONUS: +2 assists!")
  63.                             rprint(PlayerIndex, " ")
  64.                             for i=1,16 do
  65.                                 if player_present(i) then
  66.                                     say(i, driver .. " " .. ASSIST_MESSAGE)
  67.                                 end
  68.                             end
  69.                         elseif (Assists +2 >= 10) and VehicleHasGunner(vehicleId) then 
  70.                             execute_command("score me +1", PlayerIndex)
  71.                             rprint(PlayerIndex, "|rDRIVER BONUS: +1 score!")   
  72.                             rprint(PlayerIndex, " ")       
  73.                             execute_command("assists me 0", PlayerIndex)
  74.                             for i=1,16 do
  75.                                 if player_present(i) then
  76.                                     say(i, driver .. " " .. SCORE_MESSAGE)
  77.                                 end
  78.                             end
  79.                         end
  80.                     end
  81.                 end
  82.             end    
  83.         end
  84.     end
  85. end
  86.  
  87. function getteamplay()
  88.     if get_var(0,"$ffa") == "0" then
  89.         return true
  90.     else
  91.         return false
  92.     end
  93. end
  94.  
  95. function isinvehicle(PlayerIndex)
  96.     local player_object = get_dynamic_player(PlayerIndex)
  97.     if player_object ~= 0 then
  98.         local vehicleId = read_dword(player_object + 0x11C)
  99.         if vehicleId == 0xFFFFFFFF then
  100.             return false
  101.         else
  102.             return true
  103.         end
  104.     else
  105.         return false
  106.     end
  107. end
  108.  
  109. function PlayerIsDriver(PlayerIndex)
  110.     if (player_alive(PlayerIndex) == false) then return false end
  111.     local player_object = get_dynamic_player(PlayerIndex)
  112.     local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
  113.     local vehicleId = read_dword(player_object + 0x11C)
  114.     if (vehicleId == 0xFFFFFFFF) then return false end
  115.     local obj_id = get_object_memory(vehicleId)
  116.     return read_dword(obj_id + 0x324) == player_object_id
  117. end
  118.  
  119. function VehicleHasGunner(VehicleID)
  120.     local vehicle_object = get_object_memory(VehicleID)
  121.     if (vehicle_object == 0) then return false end
  122.     return read_dword(vehicle_object + 0x328) ~= 0xFFFFFFFF
  123. end
  124.  
  125. function GetPlayerVehicleTagName(PlayerIndex)
  126.     if isinvehicle(PlayerIndex) and game_started then
  127.         local player_object = get_dynamic_player(PlayerIndex)
  128.         local vehicleId = read_dword(player_object + 0x11C)
  129.         local vehicle_obj = get_object_memory(vehicleId)
  130.         if (vehicle_obj ~= 0) then
  131.             local vehicle_metaid = read_dword(vehicle_obj)     
  132.             local veh_name = get_vehicle_name(vehicle_metaid)
  133.             if (veh_name ~= nil and veh_name ~= "NULL METAID") then
  134.                 return veh_name
  135.             else
  136.                 return nil
  137.             end
  138.         end
  139.     end
  140. end
  141.  
  142. function get_vehicle_name(MetaID) -- Thanks to Giraffe!
  143.     if (MetaID == 0xFFFFFFFF) then
  144.         return "NULL METAID"
  145.     else
  146.         local globals_tag = lookup_tag("matg", "globals\\globals")
  147.         local globals_data = read_dword(globals_tag + 0x14)
  148.         local interface_bitmaps_data = read_dword(globals_data + 0x144)
  149.         local hud_globals_metaid = read_dword(interface_bitmaps_data + 0x6C)
  150.         local hud_globals_tag = lookup_tag(hud_globals_metaid)
  151.         local hud_globals_data = read_dword(hud_globals_tag + 0x14)
  152.         local hud_icon_messages_metaid = read_dword(hud_globals_data + 0xC0)
  153.         local hud_icon_messages_tag = lookup_tag(hud_icon_messages_metaid)
  154.         local hud_icon_messages_data = read_dword(hud_icon_messages_tag + 0x14)
  155.         local string_references_count = read_dword(hud_icon_messages_data)
  156.         local string_references_data = read_dword(hud_icon_messages_data + 0x4)
  157.         local strings = {}
  158.         for i=0,string_references_count-1 do
  159.             local bytes = read_dword(string_references_data + i*20)
  160.             local string_data = read_dword(string_references_data + i*20 + 0xC)
  161.             local string = ''
  162.             for j=0,bytes-3,2 do
  163.                 string = string .. string.char(read_char(string_data +j))
  164.             end
  165.             strings[i] = string
  166.         end
  167.         local vehicle_tag = lookup_tag(MetaID)
  168.         local vehicle_data = read_dword(vehicle_tag + 0x14)
  169.         local hud_text_message_index = read_short(vehicle_data + 0x13C)
  170.         if(strings[hud_text_message_index] ~= nil) then
  171.             return strings[hud_text_message_index]
  172.         else
  173.             return strings[0]
  174.         end
  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
  184. -- Email: debtproblems@hotmail.com
  185.  
  186. -- The player -db-GoNe/Juhleek - a well spoken liar, cheat.
  187. -- -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