GetObjectType
The GetObjectType function retrieves the type of a specified object in the game world. Object types can include various categories such as players, NPCs, items, and other entities. Knowing the type of an object can be useful for filtering and handling objects based on their category.
Parameters
object: The object identifier (GUID) or unit identifier (such as "player", "target", "focus", etc.) for which to retrieve the type.
Returns
type: The type of the specified object. The specific values representing different types are typically documented in the game's API reference.
Example Usage in Lua
Here is an example of how to use the GetObjectType function in Lua, including a tie-in with the GetObjectsByType function to demonstrate filtering objects by type.
local api = ...
-- Function to print the type of the player
function PrintPlayerType()
local player = "player"
local playerType = api.GetObjectType(player)
print("Player Type: " .. playerType)
end
-- Function to print the types of all objects of a specific type
function PrintObjectTypesByType(objectType)
local objects = api.GetObjectsByType(objectType)
for index, obj in ipairs(objects) do
if obj then
local objectType = api.GetObjectType(obj)
local objectName = api.GetObjectName(obj)
print("Object# " .. index .. " Name: " .. objectName .. " Type: " .. objectType)
end
end
end
-- Example usage: Print the type of the player
PrintPlayerType()
-- Example usage: Print the types of all NPCs (assuming object type 8 represents NPCs)
PrintObjectTypesByType(8)