跳转至

对象搜索与验证

gObjFind(name)

通过角色名查找已连接的玩家。返回 GameObjectnil

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)

计算两个对象或两个坐标对之间的距离。

  • 返回值: number(指针无效时返回 -1)
local dist = gObjCalcDistance(player, target)
if dist <= 3 then
    LogAdd(LOG_GREEN, "Target is within melee range.")
end

-- 坐标版本
local dist2 = gObjCalcDistance(100, 100, 105, 105)

FindMonsterClassInVP(lpObj, class, distance)

检查对象视野中指定距离内是否存在指定类别的怪物。

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

FindMonsterCharacterInVP(lpObj, bIndex)

检查对象视野中是否存在指定的对象索引。

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

gObjIsConnected(aIndex) / gObjIsConnected(aIndex, dbNumber)

指定索引的对象已连接时返回 true。双参数版本还会检查数据库编号。

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

gObjIsConnectedGP(aIndex)

对象处于 GamePlay 状态时返回 true

if gObjIsConnectedGP(aIndex) then
    -- 玩家已完全进入游戏
end

gObjIsConnectedGS(aIndex)

对象处于 GameServer 连接状态时返回 true

if gObjIsConnectedGS(aIndex) then
    -- 玩家已连接到游戏服务器
end

gObjIsNameValid(aIndex, name)

验证指定 aIndex 的对象是否拥有给定的角色名。

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

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

验证指定对象的账号名和账号索引。

  • 返回值: boolean
gObjIsAccountValid(aIndex, "myaccount", 12345)

gObjSearchDuplicateItem(lpObj) / gObjSearchDuplicateItem(lpObj, serial)

搜索玩家背包中的重复物品。单参数版本检查所有物品;双参数版本检查指定序列号。

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