Sharp Aion2 Lua SDK
API reference

entitiesLua module

Search nearby game entities and classify character classes with bundled Lua helpers.

Import this library with local entities = require("entities"). The records come from game.entities and include id, name, kind, subkind, position, distance, and alive.

entities.class_info(code)

Parameters: A character class code from game.local_character_class. Returns: {code, name, weapon, style, ranged}, or nil, "unknown character class" for any other value.

style is "melee" or "ranged", and ranged is the same answer as a boolean. weapon is the weapon type the class uses. A Novice (code 1) has no weapon yet, so its weapon, style, and ranged are nil. Each call returns a new table, so changing it does not change later results.

ClassWeaponStyleClassWeaponStyle
GladiatorGreatswordmeleeElementalistOrbranged
TemplarSwordmeleeSorcererMagicbookranged
AssassinDaggermeleeClericMaceranged
ChanterStaffmeleeRangerBowranged

The style follows the weapon's reach in the client data: Bow, Orb, Magicbook, and Mace reach 20 m, and the other four weapons reach 1.0 to 1.5 m.

entities.local_class()

Parameters: None. Returns: The entities.class_info record for the logged-in character, or nil, error when the class cannot be read.

local entities = require("entities")
local class, err = entities.local_class()
if class and class.style then
    log.info(class.name .. " fights at " .. class.style .. " range")
elseif err then
    log.warn(err)
end

entities.nearby(radius, limit)

Parameters: Optional radius defaults to 3000 world units and optional limit to 128. Returns: Entity records in an array, or nil, error.

entities.characters(radius, limit)

Parameters: The same optional radius and limit. Returns: Nearby character records, or nil, error.

entities.living(radius, limit)

Parameters: The same optional radius and limit. Returns: Nearby living character records, or nil, error.

entities.nearest(radius, predicate)

Parameters: Optional radius defaults to 3000. Optional predicate is a function that receives each record and returns a boolean. Returns: The closest matching record, nil when none match, or nil, error on a read failure. It considers at most 512 records.

local entities = require("entities")
local nearest, err = entities.nearest(2500, function(entity)
    return entity.kind == "character" and entity.alive
end)
if nearest then
    log.info(nearest.name)
elseif err then
    log.warn(err)
end