Skip to content

Mob

The Mob object represents a mob entity in the game world.

Functions

mob:is_valid() -> boolean

Validates the object exists in the game world. Always call this before using other methods.


mob:get_id() -> number | nil

Returns the mob template ID or nil if unavailable.


mob:get_position() -> table | nil

Returns position as a table with x and y fields, or nil if unavailable.

lua
local pos = mob:get_position()
if pos then
    -- pos.x, pos.y
end

mob:get_name() -> string | nil

Returns the mob name or nil if unavailable.


mob:is_elite() -> boolean | nil

Returns true if the mob is an elite boss, or nil if unavailable.

Example

lua
-- Find closest mob to player
local player = core.object_manager.get_local_player()
local map = core.object_manager.get_current_map()

if player and player:is_valid() and map and map:is_valid() then
    local player_pos = player:get_position()
    local closest_mob = nil
    local closest_dist = math.huge

    for _, mob in ipairs(map:get_mobs()) do
        if mob and mob:is_valid() then
            local mob_pos = mob:get_position()
            if mob_pos then
                local dist = math.sqrt(
                    (mob_pos.x - player_pos.x)^2 +
                    (mob_pos.y - player_pos.y)^2
                )
                if dist < closest_dist then
                    closest_dist = dist
                    closest_mob = mob
                end
            end
        end
    end

    if closest_mob then
        core.log("Closest: " .. (closest_mob:get_name() or "Unknown"))
    end
end