Advertisement
HR_Shaft

Global Vehicle Meta-Ids v2 for SAPP

Nov 26th, 2016
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.72 KB | None | 0 0
  1. -- Global Vehicle Meta-Ids v2  (Utility Script for scripting with SAPP, not a game-play script)
  2. -- by H® Shaft and Giraffe (could not have done this script without Giraffes help)
  3.  
  4. -- This script will display a list of vehicle meta-ids in the map, along with vehicle names (if there is one)
  5. -- Works with BOTH protected and unprotected Halo PC/CE maps!
  6.  
  7. -- Purpose of this script?
  8.     -- This script is a utility script to aid in script and game development
  9.     -- using a lua script, you can spawn any vehicle, in any game type, or replace any vehicle with another vehicle, or block from spawning
  10.     -- But, you will first need the meta-id of those vehicles you wish to spawn, replace or block
  11.  
  12. -- This will display and log (see USAGE below):
  13.     -- 1) a complete list of all vehicle meta-id listed in the map,
  14.     -- 2) list of all vehicle meta-id listed in the globals tag, or -
  15.     -- 3) a single vehicle meta-id into sapps log file with the map name
  16.  
  17. -- Usage - Type the command (without quotes):
  18.     -- 1) "all_vehicles"        |- to see and save a list of all vehicle meta-ids in the map
  19.     -- 2) "global_vehicles"     |- to see and save a list of all vehicle meta-ids in the globals tag
  20.     -- 3) "this_vehicle"        |- to see and save a single meta-id of the vehicle you are IN
  21.  
  22. -- Sample Output ("global_vehicles") Displayed on screen, and logged into sapp.log:
  23.  
  24.     -- There are 6 vehicles listed in the map bloodgulch (PC/CE):
  25.     -- Vehicle # 1: Meta ID: 3822322272 Name: Warthog
  26.     -- Vehicle # 2: Meta ID: 3837199171 Name: Ghost
  27.     -- Vehicle # 3: Meta ID: 3830907619 Name: Scorpion
  28.     -- Vehicle # 4: Meta ID: 3846177740 Name: Warthog
  29.     -- Vehicle # 5: Meta ID: 3899197173 Name: Banshee
  30.     -- Vehicle # 6: Meta ID: 3842311057 Name: Gun Turret
  31.  
  32. -- Map Globals 
  33. -- Each map has a standard list of SIX vehicle 'slots', this is the "stock" slot list (Globals Tag).
  34. -- This slot list matches the multiplayer gametype 'vehicle options' screen, in the halo lobby 'Edit Gametypes' section:
  35.  
  36. -- Slot 1: Warthog
  37. -- Slot 2: Ghost
  38. -- Slot 3: Scorpion
  39. -- Slot 4: Rocket Warthog
  40. -- Slot 5: Banshee
  41. -- Slot 6: Gun Turret
  42.  
  43. -- Notes:
  44. -- 'Stock' PC/CE maps always follow the above order, BUT, - not all "custom" Halo CE maps follow the above order.  
  45. -- The Custom map's author may have 'mixed the slot order', or - may not have used all six slots in the scenario, or
  46. -- some vehicles in the map may have been spawned by a 'built-in' halo script. If so, they may NOT all be listed in the globals output (use all_vehicles instead)
  47. -- Slots 1, 2 & 4 are the vehicles typically setup for RACE gametypes, and others will not 'usually' spawn during race games.
  48. -- Stock PC/CE maps use the same meta-ids for each slot for both PC and CE stock maps (i.e. Warthog meta-id for PC AND CE is same#: 3822322272)
  49. -- "Custom Maps" use meta-ids that are unique to each map, so the meta-id can only be used for each unique "Custom" map.
  50.  
  51. -- Vehicles in CE and Protected CE Maps:
  52.     -- "names" of vehicles could be wrong IF:
  53.     -- the maps author did not add tag a name for a "custom" vehicle, or used another vehicles "name" or model
  54.     -- such as calling a "hornet" a "banshee"
  55.     -- using the wrong id: such as using the warthog hud message text id# in the ghost vehicle tag (or custom vehicle tag)
  56.     -- vehicles may not spawn by gametype settings if author failed to add that vehicle to the globals tag, but did add it in the scenario tag
  57.                
  58. -- sapp api version
  59. api_version = "1.9.0.0"
  60.  
  61. function OnScriptLoad()
  62.     register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
  63.     vehicle_index = {}
  64. end
  65.  
  66. function OnPlayerChat(PlayerIndex, Message)
  67.     local response = nil   
  68.     local Message = string.lower(Message)
  69.     map_name = get_var(0,"$map")
  70.    
  71.     -- | retrieve and show/save the meta-id list for the entire map
  72.     if (Message == "all_vehicles") then
  73.         response = false   
  74.         if (get_var(0, "$gt") ~= "n/a") then   
  75.             local tag_array = read_dword(0x40440000)
  76.             local tag_count = read_word(0x4044000C)
  77.             local veh_index = 1
  78.             vehicle_index[map_name] = {}
  79.             execute_command('log_note "These are the vehicles listed in the entire map:"')
  80.             say(PlayerIndex,"These are the vehicles listed in the entire map:")        
  81.             for i=0,tag_count-1 do
  82.                 local tag = tag_array + i*32
  83.                 if (read_dword(tag) == 0x76656869) then
  84.                     local vehicle_metaid = read_dword(tag + 0xC)
  85.                     if (vehicle_metaid ~= 0xFFFFFFFF) then
  86.                         local vehicle_name_tag = get_vehicle_name(vehicle_metaid)
  87.                         vehicle_index[map_name][1] = veh_index
  88.                         vehicle_index[map_name][2] = vehicle_metaid
  89.                         vehicle_index[map_name][3] = vehicle_name_tag
  90.                         local str0 = string.format("Vehicle #%s: Meta ID: %s Name: %s", tostring(vehicle_index[map_name][1]), tostring(vehicle_index[map_name][2]), tostring(vehicle_index[map_name][3]))  
  91.                         say(PlayerIndex, str0)
  92.                         execute_command("log_note \""..str0.."\"")
  93.                         veh_index = veh_index + 1
  94.                     end                            
  95.                 end
  96.             end
  97.         end
  98.     end    
  99.    
  100.     -- | retrieve and show/save the meta-id list for map from globals tag
  101.     if (Message == "global_vehicles") then
  102.         response = false   
  103.         if (get_var(0, "$gt") ~= "n/a") then
  104.             local globals_tag = lookup_tag("matg", "globals\\globals")
  105.             local globals_data = read_dword(globals_tag + 0x14)
  106.             local mp_info_data = read_dword(globals_data + 0x168)
  107.             local vehicles_count = read_dword(mp_info_data + 0x20)
  108.             local vehicles_data = read_dword(mp_info_data + 0x24)
  109.             vehicle_index[map_name] = {}
  110.             if vehicles_count > 0 then
  111.                 local str1 = string.format("There are %s vehicles listed in the map globals %s:", tostring(vehicles_count),tostring(map_name))
  112.                 execute_command("log_note \""..str1.."\"")
  113.                 say(PlayerIndex,str1)
  114.                 local veh_index = 1
  115.                 for i=0,vehicles_count-1 do
  116.                     local vehicle_metaid = read_dword(vehicles_data + i*16 + 0xC)
  117.                     if (vehicle_metaid ~= 0xFFFFFFFF) then
  118.                         local vehicle_name_tag = get_vehicle_name(vehicle_metaid)
  119.                         vehicle_index[map_name][1] = veh_index
  120.                         vehicle_index[map_name][2] = vehicle_metaid
  121.                         vehicle_index[map_name][3] = vehicle_name_tag
  122.                         local str2 = string.format("Vehicle #%s: Meta ID: %s Name: %s", tostring(vehicle_index[map_name][1]), tostring(vehicle_index[map_name][2]), tostring(vehicle_index[map_name][3]))  
  123.                         say(PlayerIndex, str2)
  124.                         execute_command("log_note \""..str2.."\"")
  125.                         veh_index = veh_index + 1
  126.                     end
  127.                 end
  128.                 say(PlayerIndex, "This list was saved in the sapp log file.")
  129.             else
  130.                 local str3 = string.format("There are no vehicles listed in %s, or there was an error.", tostring(map_name))
  131.                 say(PlayerIndex, str3)
  132.                 execute_command("log_note \""..str3.."\"")
  133.             end
  134.         end
  135.     end
  136.    
  137.     -- | retrieve and show/save the meta-id for your current vehicle (you must be in a vehicle)
  138.     if (Message == "this_vehicle") then
  139.         response = false
  140.         if (get_var(0, "$gt") ~= "n/a") then
  141.             if isinvehicle(PlayerIndex) then
  142.                 local player_object = get_dynamic_player(PlayerIndex)
  143.                 local vehicle_id = read_dword(player_object + 0x11C)
  144.                 local veh_object = get_object_memory(vehicle_id)
  145.                 if (veh_object ~= 0) then
  146.                     local vehicle_metaid = read_dword(veh_object)
  147.                     if (vehicle_metaid ~= 0xFFFFFFFF) then
  148.                         local vehicle_name_tag = get_vehicle_name(vehicle_metaid)
  149.                         local data = string.format("Map: %s  Vehicle MetaId: %s Name or Tag: %s", tostring(map_name),tostring(vehicle_metaid), tostring(vehicle_name_tag))     
  150.                         execute_command("log_note \""..data.."\"")     
  151.                         say(PlayerIndex, data)
  152.                         say(PlayerIndex, "This vehicle's meta-id was saved in the sapp log file.")
  153.                     else
  154.                         say(PlayerIndex, "Sorry, there was an error, no meta-data available.")
  155.                     end
  156.                 end
  157.             else
  158.                 say(PlayerIndex, "You must be in a vehicle to retrieve it's meta-data.")
  159.             end
  160.         end    
  161.     end
  162.    
  163.     return response
  164. end
  165.  
  166. function get_vehicle_name(MetaID) -- Thanks to Giraffe!
  167.     if (MetaID == 0xFFFFFFFF) then
  168.         return "NULL METAID"
  169.     else
  170.         local globals_tag = lookup_tag("matg", "globals\\globals")
  171.         local globals_data = read_dword(globals_tag + 0x14)
  172.         local interface_bitmaps_data = read_dword(globals_data + 0x144)
  173.         local hud_globals_metaid = read_dword(interface_bitmaps_data + 0x6C)
  174.         local hud_globals_tag = lookup_tag(hud_globals_metaid)
  175.         local hud_globals_data = read_dword(hud_globals_tag + 0x14)
  176.         local hud_icon_messages_metaid = read_dword(hud_globals_data + 0xC0)
  177.         local hud_icon_messages_tag = lookup_tag(hud_icon_messages_metaid)
  178.         local hud_icon_messages_data = read_dword(hud_icon_messages_tag + 0x14)
  179.         local string_references_count = read_dword(hud_icon_messages_data)
  180.         local string_references_data = read_dword(hud_icon_messages_data + 0x4)
  181.         local strings = {}
  182.         for i=0,string_references_count-1 do
  183.             local bytes = read_dword(string_references_data + i*20)
  184.             local string_data = read_dword(string_references_data + i*20 + 0xC)
  185.             local string = ''
  186.             for j=0,bytes-3,2 do
  187.                 string = string .. string.char(read_char(string_data +j))
  188.             end
  189.             strings[i] = string
  190.         end
  191.         local vehicle_tag = lookup_tag(MetaID)
  192.         local vehicle_data = read_dword(vehicle_tag + 0x14)
  193.         local hud_text_message_index = read_short(vehicle_data + 0x13C)
  194.         if(strings[hud_text_message_index] ~= nil) then
  195.             return strings[hud_text_message_index]
  196.         else
  197.             return strings[0]
  198.         end
  199.     end
  200. end
  201.  
  202. function isinvehicle(PlayerIndex)
  203.     local player_object = get_dynamic_player(PlayerIndex)
  204.     if player_object ~= 0 then
  205.         local vehicleId = read_dword(player_object + 0x11C)
  206.         if vehicleId == 0xFFFFFFFF then
  207.             return false
  208.         else
  209.             return true
  210.         end
  211.     else
  212.         return false
  213.     end
  214. end
  215.  
  216. function OnScriptUnload()
  217.     vehicle_index = {}
  218. end
  219.  
  220. function OnError(Message)
  221.     print(debug.traceback())
  222. end
  223.  
  224. -- Created by H® Shaft, special thanks to Giraffe
  225. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement