Skip to content

Object Search & Validation

gObjFind(name)

Finds a connected player by character name. Returns GameObject or nil.

local target = gObjFind("SomePlayer")
if target then
    LogAdd(LOG_BLUE, "Found " .. target.Name .. " at map " .. target.Map)
end

gObjCalcDistance(lpObj, lpTarget) / gObjCalcDistance(x, y, tx, ty)

Calculates the distance between two objects or two coordinate pairs.

  • Returns: number (-1 if invalid pointers)
local dist = gObjCalcDistance(player, target)
if dist <= 3 then
    LogAdd(LOG_GREEN, "Target is within melee range.")
end

-- Coordinate version
local dist2 = gObjCalcDistance(100, 100, 105, 105)

FindMonsterClassInVP(lpObj, class, distance)

Checks if a monster of the given class exists in the object's viewport within the given distance.

  • Returns: boolean
if FindMonsterClassInVP(player, 275, 10) then
    LogAdd(LOG_RED, "Boss monster nearby!")
end

FindMonsterCharacterInVP(lpObj, bIndex)

Checks if a specific object index exists in the object's viewport.

  • Returns: boolean
if FindMonsterCharacterInVP(monster, player.Index) then
    LogAdd(LOG_RED, "Player is visible to the monster.")
end

gObjIsConnected(aIndex) / gObjIsConnected(aIndex, dbNumber)

Returns true if the object at the given index is connected. The two-parameter version also checks the database number.

if gObjIsConnected(aIndex) then
    LogAdd(LOG_GREEN, "Player is online.")
end

gObjIsConnectedGP(aIndex)

Returns true if the object is connected at the GamePlay state.

if gObjIsConnectedGP(aIndex) then
    -- Player is fully in-game
end

gObjIsConnectedGS(aIndex)

Returns true if the object is connected at the GameServer state.

if gObjIsConnectedGS(aIndex) then
    -- Player is connected to game server
end

gObjIsNameValid(aIndex, name)

Validates that the object at aIndex has the given character name.

  • Returns: boolean
if gObjIsNameValid(aIndex, "MyCharacter") then
    LogAdd(LOG_GREEN, "Name matches.")
end

gObjIsAccountValid(aIndex, account, accountIndex, [login])

Validates the account name and index for the given object.

  • Returns: boolean
gObjIsAccountValid(aIndex, "myaccount", 12345)

gObjSearchDuplicateItem(lpObj) / gObjSearchDuplicateItem(lpObj, serial)

Searches for duplicate items in the player's inventory. The single-parameter version checks all items; the two-parameter version checks a specific serial.

  • Returns: boolean
if gObjSearchDuplicateItem(player) then
    LogAdd(LOG_RED, "Duplicate items found!")
end