Advertisement
HR_Shaft

Global Vehicle Meta-Ids for Sapp

Nov 25th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.34 KB | None | 0 0
  1. -- Global Vehicle Meta-Ids  (Utility Script for scripting with SAPP, not a game-play script)
  2. -- by H® Shaft
  3.  
  4. -- edited 11/26/2016 corrected an omitted map name
  5.  
  6. -- This script will display a list of vehicle meta-ids listed in the maps global tag
  7. -- Works with BOTH protected and unprotected Halo PC/CE maps
  8. -- This will display and log: 1) a meta-id list, or: 2) a single vehicle meta-id into sapps log file with the map name
  9. -- see USAGE below.
  10.  
  11. -- Usage:
  12.     -- to see and save a list of all global vehicle meta-ids, type: "all_vehicles" (without quotes)
  13.     -- to see and save the meta-id of the vehicle you are IN, type "this_vehicle" (without quotes)
  14.    
  15. -- Sample Output (all_vehicles) Displayed on screen, and logged into sapp.log:
  16.     -- There are 6 vehicles listed in the map bloodgulch (PC/CE):
  17.     -- Vehicle # 1: Meta ID: 3822322272
  18.     -- Vehicle # 2: Meta ID: 3837199171
  19.     -- Vehicle # 3: Meta ID: 3830907619
  20.     -- Vehicle # 4: Meta ID: 3846177740
  21.     -- Vehicle # 5: Meta ID: 3899197173
  22.     -- Vehicle # 6: Meta ID: 3842311057
  23.  
  24.  
  25. -- Each map has a standard list of SIX vehicle 'slots', this is the "stock" slot list.
  26. -- This slot list matches the multiplayer gametype 'vehicle options' screen, in the halo lobby 'Edit Gametypes' section:
  27.  
  28. -- Slot 1: Warthog
  29. -- Slot 2: Ghost
  30. -- Slot 3: Scorpion
  31. -- Slot 4: Rocket Warthog
  32. -- Slot 5: Banshee
  33. -- Slot 6: Gun Turret
  34.  
  35. -- Notes:
  36. -- 'Stock' PC/CE maps always follow the above order, BUT, - not all "custom" Halo CE maps follow the above order.  
  37. -- The Custom map's author may have 'mixed the slot order', or - may not have used all six slots, or
  38. -- 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 output
  39. -- Slots 1, 2 & 4 are the vehicles typically setup for RACE gametypes, and others will not 'usually' spawn during race games.
  40. -- Stock PC/CE maps use the same meta-ids for each slot for both PC and CE stock maps (Warthog meta-id for PC and CE is 3822322272)
  41. -- "Custom Maps" use meta-ids that are unique to each map.
  42.            
  43. -- sapp api version
  44. api_version = "1.9.0.0"
  45.  
  46. function OnScriptLoad()
  47.     register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
  48.     vehicle_index = {}
  49. end
  50.  
  51. function OnPlayerChat(PlayerIndex, Message)
  52.     local response = nil   
  53.     local Message = string.lower(Message)
  54.     map_name = get_var(0,"$map")   
  55.  
  56.     -- | retrieve and show/save the meta-id list for map from globals tag
  57.     if (Message == "all_vehicles") then
  58.         response = false
  59.         if (get_var(0, "$gt") ~= "n/a") then
  60.             local globals_tag = lookup_tag("matg", "globals\\globals")
  61.             local globals_data = read_dword(globals_tag + 0x14)
  62.             local mp_info_data = read_dword(globals_data + 0x168)
  63.             local vehicles_count = read_dword(mp_info_data + 0x20)
  64.             local vehicles_data = read_dword(mp_info_data + 0x24)
  65.             vehicle_index[map_name] = {}
  66.             if vehicles_count > 0 then
  67.                 local str1 = string.format("There are %s vehicles listed in the map %s:", tostring(vehicles_count),tostring(map_name))
  68.                 execute_command("log_note \""..str1.."\"")
  69.                 say(PlayerIndex,str1)
  70.                 local veh_index = 1
  71.                 for i=0,vehicles_count-1 do
  72.                     local vehicle_metaid = read_dword(vehicles_data + i*16 + 0xC)
  73.                     if (vehicle_metaid ~= 0) then
  74.                         vehicle_index[map_name][1] = veh_index
  75.                         vehicle_index[map_name][2] = vehicle_metaid
  76.                         local str2 = string.format("Vehicle #%s: Meta ID: %s", tostring(vehicle_index[map_name][1]), tostring(vehicle_index[map_name][2])) 
  77.                         say(PlayerIndex, str2)
  78.                         execute_command("log_note \""..str2.."\"")
  79.                         veh_index = veh_index + 1
  80.                     end
  81.                 end
  82.                 say(PlayerIndex, "This list was saved in the sapp log file.")
  83.             else
  84.                 local str3 = string.format("There are no vehicles listed in %s, or there was an error.", tostring(map_name))
  85.                 say(PlayerIndex, str3)
  86.                 execute_command("log_note \""..str3.."\"")
  87.             end
  88.         end
  89.     end
  90.    
  91.     -- | retrieve and show/save the meta-id for your current vehicle (you must be in a vehicle)
  92.     if (Message == "this_vehicle") then
  93.         response = false
  94.         if isinvehicle(PlayerIndex) then
  95.             local player_object = get_dynamic_player(PlayerIndex)
  96.             local vehicle_id = read_dword(player_object + 0x11C)
  97.             local veh_object = get_object_memory(vehicle_id)
  98.             if (veh_object ~= 0) then
  99.                 local vehicle_metaid = read_dword(veh_object)
  100.                 if (vehicle_metaid ~= 0) then
  101.                     local data = string.format("Map: %s  Vehicle MetaId: %s", tostring(map_name),tostring(vehicle_metaid))     
  102.                     execute_command("log_note \""..data.."\"")     
  103.                     say(PlayerIndex, data)
  104.                     say(PlayerIndex, "This vehicle's meta-id was saved in the sapp log file.")
  105.                 else
  106.                     say(PlayerIndex, "Sorry, there was an error, no meta-data available.")
  107.                 end
  108.             end
  109.         else
  110.             say(PlayerIndex, "You must be in a vehicle to retrieve it's meta-data.")
  111.         end
  112.     end
  113.    
  114.     return response
  115. end
  116.  
  117. function isinvehicle(PlayerIndex)
  118.     local player_object = get_dynamic_player(PlayerIndex)
  119.     if player_object ~= 0 then
  120.         local vehicleId = read_dword(player_object + 0x11C)
  121.         if vehicleId == 0xFFFFFFFF then
  122.             return false
  123.         else
  124.             return true
  125.         end
  126.     else
  127.         return false
  128.     end
  129. end
  130.  
  131. function OnScriptUnload()
  132.     vehicle_index = {}
  133. end
  134.  
  135. function OnError(Message)
  136.     print(debug.traceback())
  137. end
  138.  
  139. -- Created by H® Shaft, special thanks to Giraffe
  140. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement