Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Object Tag Info Utility | by H® Shaft
- -- NOT used for games: Scripting utility to retrieve tag types, tag names, location and meta id's
- -- type the following commands in chat to retrieve and log tag information into the sapp.log and on screen
- -- COMMAND to type (without quotes):
- -- "weapon" -- | retrieve the tag info for your current (primary) weapon
- -- "vehicle" -- | retrieve the tag info for your current vehicle (you must be in a vehicle)
- -- "biped" -- | retrieve the tag info for your current biped
- -- "coord" -- | retrieve your coordinates x,y,z and rotation (yaw - the direction you are facing, not "aim")
- -- "save" -- | type "save" to export all object data to a text file in your sapp directory, (takes 15 to 45 seconds be patient)
- -- The information exported/stored will be:
- -- Object ID, Object Type, Object Tag Name, Object Coordinates (xyz), Object Yaw, Object Pitch, Object Roll, Object Rotation
- -- the file name which will be saved is "<mapname>_<gametype>_tag_info.txt" (i.e. bloodgulch_slayer_tag_info.txt)
- -- With your new exported data, you can create a custom script and move objects where you want them, or back to their origin,
- -- or block their creation, or replace them, or destroy all objects and restore them to their origin.
- -- the data exported will look like this, for each object exported using the save command:
- --[1] = "obj_id: 3799056386",
- --[2] = "obj_type: vehi",
- --[3] = "tag_name: vehicles\\warthog\\mp_warthog",
- --[4] = "meta_id: 3822322272",
- --[5] = "X: 28.961212158203",
- --[6] = "Y: -90.674217224121",
- --[7] = "Z: 0.68556469678879",
- --[8] = "yaw: -516601.1875",
- --[9] = "pitch: -4.7147543232472e+27",
- --[10] = "roll: 1.0005150372047e-33",
- --[11] = "rotation: -1.5430639405479e-32"
- -- Note: your gametype controls which weapons and vehicles spawn so you might need to make a custom gametype to spawn what you want then use that with this script
- api_version = "1.8.0.0"
- game_started = false
- Object_IDS = {}
- equipment = {}
- vehicle = {}
- biped = {}
- weapon = {}
- function OnScriptLoad()
- register_callback(cb['EVENT_GAME_START'], "OnNewGame")
- register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
- register_callback(cb['EVENT_OBJECT_SPAWN'], "OnObjectSpawn")
- register_callback(cb['EVENT_SPAWN'], "OnPlayerSpawn")
- register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
- end
- function OnScriptUnload() end
- function OnNewGame()
- game_started = true
- map_name = get_var(0,"$map")
- game_type = get_var(0,"$mode")
- end
- function OnGameEnd()
- game_started = false
- end
- function OnObjectSpawn(PlayerIndex, MapID, ParentID, ObjectID)
- table.insert(Object_IDS, ObjectID)
- return true
- end
- function OnPlayerSpawn(PlayerIndex)
- -- we want the biped to be listed in the object id's, but NOT his weapons to prevent confusion
- execute_command_sequence("nades me 0;wdel", PlayerIndex)
- end
- function PopulateTables()
- for _,id in pairs(Object_IDS) do
- local object = get_object_memory(id)
- if object ~= 0 then
- local obj_type = read_byte(object + 0xB4)
- local obj_meta = read_dword(object)
- local obj_name = read_string(read_dword(read_word(object) * 32 + 0x40440038))
- local objtype = ""
- local x, y, z = read_vector3d(object + 0x5c)
- local yaw = read_float(object + 0x76)
- local pitch = read_float(object + 0x7A)
- local roll = read_float(object + 0x7E)
- local rotation = read_float(object + 0x82)
- if obj_type == 0 then
- objtype = "bipd"
- table.insert(biped, {"obj_id: " ..id, "obj_type: " ..objtype, "tag_name: " ..obj_name, "meta_id: " ..obj_meta, "X: " ..x, "Y: " ..y, "Z: " ..z, "yaw: " ..yaw, "pitch: " .. pitch, "roll: " ..roll, "rotation: " ..rotation})
- elseif obj_type == 1 then
- objtype = "vehi"
- table.insert(vehicle, {"obj_id: " ..id, "obj_type: " ..objtype, "tag_name: " ..obj_name, "meta_id: " ..obj_meta, "X: " ..x, "Y: " ..y, "Z: " ..z, "yaw: " ..yaw, "pitch: " .. pitch, "roll: " ..roll, "rotation: " ..rotation})
- elseif obj_type == 3 then
- objtype = "eqip"
- table.insert(equipment, {"obj_id: " ..id, "obj_type: " ..objtype, "tag_name: " ..obj_name, "meta_id: " ..obj_meta, "X: " ..x, "Y: " ..y, "Z: " ..z, "yaw: " ..yaw, "pitch: " .. pitch, "roll: " ..roll, "rotation: " ..rotation})
- elseif obj_type == 2 then
- objtype = "weap"
- table.insert(weapon, {"obj_id: " ..id, "obj_type: " ..objtype, "tag_name: " ..obj_name, "meta_id: " ..obj_meta, "X: " ..x, "Y: " ..y, "Z: " ..z, "yaw: " ..yaw, "pitch: " .. pitch, "roll: " ..roll, "rotation: " ..rotation})
- end
- end
- end
- -- 15 seconds because it takes time to process table data
- timer(15000, "SaveData")
- return false
- end
- function SaveData()
- local file_name = ("sapp\\"..map_name.."_"..game_type.."_tag_info.txt")
- -- if file exists, open it.
- local file = io.open(file_name, "r")
- if file == nil then
- -- if file doesn't exist, create it, then open it.
- file = io.open(file_name, "w")
- local data = {equipment, vehicle, biped, weapon}
- tablesave(data, file_name)
- local str1 = string.format("Exported tag info file: %s", tostring(file_name))
- execute_command("log_note \""..str1.."\"")
- file:close()
- elseif file ~= nil then
- local data = {equipment, vehicle, biped, weapon}
- local str1 = string.format("Exported tag info file: %s", tostring(file_name))
- execute_command("log_note \""..str1.."\"")
- tablesave(data, file_name)
- file:close()
- end
- return false
- end
- function OnPlayerChat(PlayerIndex, Message)
- local response = nil
- local name = get_var(PlayerIndex,"$name")
- local Message = string.lower(Message)
- -- | retrieve your coordinates x,y,z and rotation (yaw) (the direction you are facing, not "aim")
- if (Message == "coord") then
- local player_object = get_dynamic_player(PlayerIndex)
- local player_static = get_player(PlayerIndex)
- local x,y,z = read_vector3d(player_object + 0x5C)
- local rotation = read_float(player_static + 0x138)
- local map_name = get_var(0,"$map")
- local data = string.format("%s,%s,%s,%s,%s", tostring(map_name),tostring(x),tostring(y),tostring(z),tostring(rotation))
- execute_command("log_note \""..data.."\"")
- say(PlayerIndex, "X: " .. x .. " Y: " .. y .. " Z: " .. z .. " R: " .. rotation)
- response = false
- end
- -- | retrieve the tag info for your current (primary) weapon
- if (Message == "weapon") then
- if isinvehicle(PlayerIndex) then
- say(PlayerIndex, "You cannot be in a vehicle to retrieve your weapon's name and data.")
- else
- local player_object = get_dynamic_player(PlayerIndex)
- local weaponId = read_dword(player_object + 0x118)
- local weap_obj = get_object_memory(weaponId)
- if weap_obj ~= 0 then
- local weap_name = "unknown"
- weap_name = read_string(read_dword(read_word(weap_obj) * 32 + 0x40440038))
- local weap_meta = read_dword(weap_obj)
- local data = string.format("Map: %s Weap Tag Name: %s MetaId: %s", tostring(map_name),tostring(weap_name),tostring(weap_meta))
- execute_command("log_note \""..data.."\"")
- say(PlayerIndex, data)
- end
- end
- response = false
- end
- -- | retrieve the tag info for your current vehicle (you must be in a vehicle)
- if (Message == "vehicle") then
- if isinvehicle(PlayerIndex) then
- local player_object = get_dynamic_player(PlayerIndex)
- local veh_id = read_dword(player_object + 0x11C)
- local veh_obj = get_object_memory(veh_id)
- if veh_obj ~= 0 then
- local veh_name = "unknown"
- veh_name = read_string(read_dword(read_word(veh_obj) * 32 + 0x40440038))
- local veh_meta = read_dword(veh_obj)
- local data = string.format("Map: %s Veh Tag Name: %s MetaId: %s", tostring(map_name),tostring(veh_name),tostring(veh_meta))
- execute_command("log_note \""..data.."\"")
- say(PlayerIndex, data)
- end
- else
- say(PlayerIndex, "You must be in a vehicle to retrieve it's name and data.")
- end
- response = false
- end
- -- | retrieve the tag info for your current biped
- if (Message == "biped") then
- if isinvehicle(PlayerIndex) then
- say(PlayerIndex, "You cannot be in a vehicle to retrieve your biped's name and data.")
- else
- local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
- local player_object = get_object_memory(player_object_id)
- if player_object ~= 0 then
- local bipd_name = "unknown"
- bipd_name = read_string(read_dword(read_word(player_object) * 32 + 0x40440038))
- local bipd_meta = read_dword(player_object)
- local data = string.format("Map: %s Biped Tag Name: %s MetaId: %s", tostring(map_name),tostring(bipd_name),tostring(bipd_meta))
- execute_command("log_note \""..data.."\"")
- say(PlayerIndex, data)
- end
- end
- response = false
- end
- -- export all object data to a text file in your sapp directory
- if (Message == "save") then
- timer(1000, "PopulateTables")
- say(PlayerIndex, "Exporting Object Tag Info: please wait 45 seconds, then check your sapp folder for the txt file export.")
- response = false
- end
- return response
- end
- -- miscellaneous functions --
- function isinvehicle(PlayerIndex)
- local player_object = get_dynamic_player(PlayerIndex)
- local vehicleId = read_dword(player_object + 0x11C)
- if vehicleId == 0xFFFFFFFF then
- return false
- else
- return true
- end
- end
- --Nuggets table save and table load and related functions
- function tablesave(t, filename)
- local file = io.open(filename, "w")
- local spaces = 0
- local function tab()
- local str = ""
- for i = 1,spaces do
- str = str .. " "
- end
- return str
- end
- local function format(t)
- spaces = spaces + 4
- local str = "{ "
- for k,v in opairs(t) do
- -- Key datatypes
- if type(k) == "string" then
- k = string.format("%q", k)
- elseif k == math.inf then
- k = "1 / 0"
- end
- k = tostring(k)
- -- Value datatypes
- if type(v) == "string" then
- v = string.format("%q", v)
- elseif v == math.inf then
- v = "1 / 0"
- end
- if type(v) == "table" then
- if tablelen(v) > 0 then
- str = str .. "\n" .. tab() .. "[" .. k .. "] = " .. format(v) .. ","
- else
- str = str .. "\n" .. tab() .. "[" .. k .. "] = {},"
- end
- else
- str = str .. "\n" .. tab() .. "[" .. k .. "] = " .. tostring(v) .. ","
- end
- end
- spaces = spaces - 4
- return string.sub(str, 1, string.len(str) - 1) .. "\n" .. tab() .. "}"
- end
- file:write("return " .. format(t))
- file:close()
- end
- function tableload(filename)
- local file = loadfile(filename)
- if file then
- return file() or {}
- end
- return {}
- end
- function tablelen(t)
- local count = 0
- for k,v in pairs(t) do
- count = count + 1
- end
- return count
- end
- function opairs(t)
- local keys = {}
- for k,v in pairs(t) do
- table.insert(keys, k)
- end
- table.sort(keys,
- function(a,b)
- if type(a) == "number" and type(b) == "number" then
- return a < b
- end
- an = string.lower(tostring(a))
- bn = string.lower(tostring(b))
- if an ~= bn then
- return an < bn
- else
- return tostring(a) < tostring(b)
- end
- end)
- local count = 1
- return function()
- if unpack(keys) then
- local key = keys[count]
- local value = t[key]
- count = count + 1
- return key,value
- end
- end
- end
- function spaces(n, delimiter)
- delimiter = delimiter or ""
- local str = ""
- for i = 1, n do
- if i == math.floor(n / 2) then
- str = str .. delimiter
- end
- str = str .. " "
- end
- return str
- end
- function OnError(Message)
- print(debug.traceback())
- end
- -- Created by H® Shaft
- -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement