Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Global Vehicle Meta-Ids v2 (Utility Script for scripting with SAPP, not a game-play script)
- -- by H® Shaft and Giraffe (could not have done this script without Giraffes help)
- -- This script will display a list of vehicle meta-ids in the map, along with vehicle names (if there is one)
- -- Works with BOTH protected and unprotected Halo PC/CE maps!
- -- Purpose of this script?
- -- This script is a utility script to aid in script and game development
- -- using a lua script, you can spawn any vehicle, in any game type, or replace any vehicle with another vehicle, or block from spawning
- -- But, you will first need the meta-id of those vehicles you wish to spawn, replace or block
- -- This will display and log (see USAGE below):
- -- 1) a complete list of all vehicle meta-id listed in the map,
- -- 2) list of all vehicle meta-id listed in the globals tag, or -
- -- 3) a single vehicle meta-id into sapps log file with the map name
- -- Usage - Type the command (without quotes):
- -- 1) "all_vehicles" |- to see and save a list of all vehicle meta-ids in the map
- -- 2) "global_vehicles" |- to see and save a list of all vehicle meta-ids in the globals tag
- -- 3) "this_vehicle" |- to see and save a single meta-id of the vehicle you are IN
- -- Sample Output ("global_vehicles") Displayed on screen, and logged into sapp.log:
- -- There are 6 vehicles listed in the map bloodgulch (PC/CE):
- -- Vehicle # 1: Meta ID: 3822322272 Name: Warthog
- -- Vehicle # 2: Meta ID: 3837199171 Name: Ghost
- -- Vehicle # 3: Meta ID: 3830907619 Name: Scorpion
- -- Vehicle # 4: Meta ID: 3846177740 Name: Warthog
- -- Vehicle # 5: Meta ID: 3899197173 Name: Banshee
- -- Vehicle # 6: Meta ID: 3842311057 Name: Gun Turret
- -- Map Globals
- -- Each map has a standard list of SIX vehicle 'slots', this is the "stock" slot list (Globals Tag).
- -- This slot list matches the multiplayer gametype 'vehicle options' screen, in the halo lobby 'Edit Gametypes' section:
- -- Slot 1: Warthog
- -- Slot 2: Ghost
- -- Slot 3: Scorpion
- -- Slot 4: Rocket Warthog
- -- Slot 5: Banshee
- -- Slot 6: Gun Turret
- -- Notes:
- -- 'Stock' PC/CE maps always follow the above order, BUT, - not all "custom" Halo CE maps follow the above order.
- -- The Custom map's author may have 'mixed the slot order', or - may not have used all six slots in the scenario, or
- -- 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)
- -- Slots 1, 2 & 4 are the vehicles typically setup for RACE gametypes, and others will not 'usually' spawn during race games.
- -- 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)
- -- "Custom Maps" use meta-ids that are unique to each map, so the meta-id can only be used for each unique "Custom" map.
- -- Vehicles in CE and Protected CE Maps:
- -- "names" of vehicles could be wrong IF:
- -- the maps author did not add tag a name for a "custom" vehicle, or used another vehicles "name" or model
- -- such as calling a "hornet" a "banshee"
- -- using the wrong id: such as using the warthog hud message text id# in the ghost vehicle tag (or custom vehicle tag)
- -- 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
- -- sapp api version
- api_version = "1.9.0.0"
- function OnScriptLoad()
- register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
- vehicle_index = {}
- end
- function OnPlayerChat(PlayerIndex, Message)
- local response = nil
- local Message = string.lower(Message)
- map_name = get_var(0,"$map")
- -- | retrieve and show/save the meta-id list for the entire map
- if (Message == "all_vehicles") then
- response = false
- if (get_var(0, "$gt") ~= "n/a") then
- local tag_array = read_dword(0x40440000)
- local tag_count = read_word(0x4044000C)
- local veh_index = 1
- vehicle_index[map_name] = {}
- execute_command('log_note "These are the vehicles listed in the entire map:"')
- say(PlayerIndex,"These are the vehicles listed in the entire map:")
- for i=0,tag_count-1 do
- local tag = tag_array + i*32
- if (read_dword(tag) == 0x76656869) then
- local vehicle_metaid = read_dword(tag + 0xC)
- if (vehicle_metaid ~= 0xFFFFFFFF) then
- local vehicle_name_tag = get_vehicle_name(vehicle_metaid)
- vehicle_index[map_name][1] = veh_index
- vehicle_index[map_name][2] = vehicle_metaid
- vehicle_index[map_name][3] = vehicle_name_tag
- 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]))
- say(PlayerIndex, str0)
- execute_command("log_note \""..str0.."\"")
- veh_index = veh_index + 1
- end
- end
- end
- end
- end
- -- | retrieve and show/save the meta-id list for map from globals tag
- if (Message == "global_vehicles") then
- response = false
- if (get_var(0, "$gt") ~= "n/a") then
- local globals_tag = lookup_tag("matg", "globals\\globals")
- local globals_data = read_dword(globals_tag + 0x14)
- local mp_info_data = read_dword(globals_data + 0x168)
- local vehicles_count = read_dword(mp_info_data + 0x20)
- local vehicles_data = read_dword(mp_info_data + 0x24)
- vehicle_index[map_name] = {}
- if vehicles_count > 0 then
- local str1 = string.format("There are %s vehicles listed in the map globals %s:", tostring(vehicles_count),tostring(map_name))
- execute_command("log_note \""..str1.."\"")
- say(PlayerIndex,str1)
- local veh_index = 1
- for i=0,vehicles_count-1 do
- local vehicle_metaid = read_dword(vehicles_data + i*16 + 0xC)
- if (vehicle_metaid ~= 0xFFFFFFFF) then
- local vehicle_name_tag = get_vehicle_name(vehicle_metaid)
- vehicle_index[map_name][1] = veh_index
- vehicle_index[map_name][2] = vehicle_metaid
- vehicle_index[map_name][3] = vehicle_name_tag
- 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]))
- say(PlayerIndex, str2)
- execute_command("log_note \""..str2.."\"")
- veh_index = veh_index + 1
- end
- end
- say(PlayerIndex, "This list was saved in the sapp log file.")
- else
- local str3 = string.format("There are no vehicles listed in %s, or there was an error.", tostring(map_name))
- say(PlayerIndex, str3)
- execute_command("log_note \""..str3.."\"")
- end
- end
- end
- -- | retrieve and show/save the meta-id for your current vehicle (you must be in a vehicle)
- if (Message == "this_vehicle") then
- response = false
- if (get_var(0, "$gt") ~= "n/a") then
- if isinvehicle(PlayerIndex) then
- local player_object = get_dynamic_player(PlayerIndex)
- local vehicle_id = read_dword(player_object + 0x11C)
- local veh_object = get_object_memory(vehicle_id)
- if (veh_object ~= 0) then
- local vehicle_metaid = read_dword(veh_object)
- if (vehicle_metaid ~= 0xFFFFFFFF) then
- local vehicle_name_tag = get_vehicle_name(vehicle_metaid)
- local data = string.format("Map: %s Vehicle MetaId: %s Name or Tag: %s", tostring(map_name),tostring(vehicle_metaid), tostring(vehicle_name_tag))
- execute_command("log_note \""..data.."\"")
- say(PlayerIndex, data)
- say(PlayerIndex, "This vehicle's meta-id was saved in the sapp log file.")
- else
- say(PlayerIndex, "Sorry, there was an error, no meta-data available.")
- end
- end
- else
- say(PlayerIndex, "You must be in a vehicle to retrieve it's meta-data.")
- end
- end
- end
- return response
- end
- function get_vehicle_name(MetaID) -- Thanks to Giraffe!
- if (MetaID == 0xFFFFFFFF) then
- return "NULL METAID"
- else
- local globals_tag = lookup_tag("matg", "globals\\globals")
- local globals_data = read_dword(globals_tag + 0x14)
- local interface_bitmaps_data = read_dword(globals_data + 0x144)
- local hud_globals_metaid = read_dword(interface_bitmaps_data + 0x6C)
- local hud_globals_tag = lookup_tag(hud_globals_metaid)
- local hud_globals_data = read_dword(hud_globals_tag + 0x14)
- local hud_icon_messages_metaid = read_dword(hud_globals_data + 0xC0)
- local hud_icon_messages_tag = lookup_tag(hud_icon_messages_metaid)
- local hud_icon_messages_data = read_dword(hud_icon_messages_tag + 0x14)
- local string_references_count = read_dword(hud_icon_messages_data)
- local string_references_data = read_dword(hud_icon_messages_data + 0x4)
- local strings = {}
- for i=0,string_references_count-1 do
- local bytes = read_dword(string_references_data + i*20)
- local string_data = read_dword(string_references_data + i*20 + 0xC)
- local string = ''
- for j=0,bytes-3,2 do
- string = string .. string.char(read_char(string_data +j))
- end
- strings[i] = string
- end
- local vehicle_tag = lookup_tag(MetaID)
- local vehicle_data = read_dword(vehicle_tag + 0x14)
- local hud_text_message_index = read_short(vehicle_data + 0x13C)
- if(strings[hud_text_message_index] ~= nil) then
- return strings[hud_text_message_index]
- else
- return strings[0]
- end
- end
- end
- function isinvehicle(PlayerIndex)
- local player_object = get_dynamic_player(PlayerIndex)
- if player_object ~= 0 then
- local vehicleId = read_dword(player_object + 0x11C)
- if vehicleId == 0xFFFFFFFF then
- return false
- else
- return true
- end
- else
- return false
- end
- end
- function OnScriptUnload()
- vehicle_index = {}
- end
- function OnError(Message)
- print(debug.traceback())
- end
- -- Created by H® Shaft, special thanks to Giraffe
- -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement