Skip to content

GetObjectName

The GetObjectName function retrieves the name of a specified object or unit in the game world. This function can be used to obtain the name of any object, including non-player characters (NPCs), players, and other entities. The object name is useful for displaying information to the player, debugging, and various gameplay mechanics.

Parameters

  • object: The object identifier (GUID) or unit identifier (such as "player", "target", "focus", etc.) for which to retrieve the name.

Returns

  • name: The name of the specified object.

Example Usage in Lua

Here is a more extensive example of how to use the GetObjectName function in Lua, including the initialization of the api variable and iterating over multiple objects.

local api = ...

-- Function to print the names of all objects of a specific type
function PrintObjectNamesByType(objectType)
    local objects = api.GetObjectsByType(objectType)
    for index, obj in ipairs(objects) do
        if obj then
            local objectName = api.GetObjectName(obj)
            print("Object# " .. index .. " Name: " .. objectName)
        end
    end
end

-- Example usage: Print the names of all NPCs (assuming object type 8 represents NPCs)
PrintObjectNamesByType(8)

-- Function to print the name of the player
function PrintPlayerName()
    local player = "player"
    local playerName = api.GetObjectName(player)
    print("Player Name: " .. playerName)
end

-- Function to print the name of the target
function PrintTargetName()
    local target = "target"
    local targetName = api.GetObjectName(target)
    print("Target Name: " .. targetName)
end

-- Function to print the name of the focus
function PrintFocusName()
    local focus = "focus"
    local focusName = api.GetObjectName(focus)
    print("Focus Name: " .. focusName)
end

-- Call the functions
PrintPlayerName()
PrintTargetName()
PrintFocusName()