GetObjectID
The GetObjectID function retrieves the unique identifier (ID) of a specified object or unit in the game world. This function can be used to obtain the ID of any object, including non-player characters (NPCs), players, and other entities. The object ID is a crucial piece of information for various gameplay mechanics, such as identifying specific entities, tracking interactions, and managing game state.
Parameters
object: The object identifier (GUID) or unit identifier (such as "player", "target", "focus", etc.) for which to retrieve the ID.
Returns
id: The unique identifier (ID) of the specified object.
Example Usage in Lua
Here is a detailed example of how to use the GetObjectID function in Lua, including multiple scenarios and the use of the GetObjectName function to retrieve the name of the objects.
local api = ...
-- Function to print the ID and name of the player
function PrintPlayerIDAndName()
local player = "player"
local playerID = api.GetObjectID(player)
local playerName = api.GetObjectName(player)
print("Player ID: " .. playerID)
print("Player Name: " .. playerName)
end
-- Function to print the ID and name of the target
function PrintTargetIDAndName()
local target = "target"
local targetID = api.GetObjectID(target)
local targetName = api.GetObjectName(target)
print("Target ID: " .. targetID)
print("Target Name: " .. targetName)
end
-- Function to print the ID and name of the focus
function PrintFocusIDAndName()
local focus = "focus"
local focusID = api.GetObjectID(focus)
local focusName = api.GetObjectName(focus)
print("Focus ID: " .. focusID)
print("Focus Name: " .. focusName)
end
-- Function to print the ID and name of an NPC by GUID
function PrintNPCIDAndName(npcGUID)
local npcID = api.GetObjectID(npcGUID)
local npcName = api.GetObjectName(npcGUID)
print("NPC ID: " .. npcID)
print("NPC Name: " .. npcName)
end
-- Call the functions
PrintPlayerIDAndName()
PrintTargetIDAndName()
PrintFocusIDAndName()
-- Example NPC GUID (replace with an actual GUID in your game)
local exampleNPCGUID = "1234-5678-9012-3456"
PrintNPCIDAndName(exampleNPCGUID)