The Object table works with every object in GameServer. aIndex is the object index: players are in the range Object.GetUserRange(), monsters / NPCs are in Object.GetMonsterRange(). The functions that iterate over lists (ForEach...) are on the page Iterating objects (Iterating and counting objects).

Write functions on a player (SetPower, Warp, Kill...) require the character to be in game; for monsters they are blocked only when the script is in restricted mode. See the page General rules for functions.

Index ranges

Object.GetUserRange

Returns the first and last index of the area reserved for players.

Object.GetUserRange() -> min, max

No parameters. Short names: GetMinUserIndex() (returns min) and GetMaxUserIndex() (returns max).

local first, last = Object.GetUserRange()

Object.GetMonsterRange

Returns the first and last index of the area reserved for monsters / NPCs.

Object.GetMonsterRange() -> min, max

No parameters. Short names: GetMinMonsterIndex(), GetMaxMonsterIndex().

local first, last = Object.GetMonsterRange()

Object.GetSummonRange

Returns the first and last index of the area reserved for summoned monsters.

Object.GetSummonRange() -> min, max

No parameters.

local first, last = Object.GetSummonRange()

Object.GetMaxIndex

Returns the largest object index.

Object.GetMaxIndex() -> integer

No parameters. Short name: GetMaxIndex.

local top = Object.GetMaxIndex()

Object.GetMaxItem

Returns the maximum number of items that can lie on the ground of a map.

Object.GetMaxItem() -> integer

No parameters.

local n = Object.GetMaxItem()

Object information

Object.GetType

Returns the object type.

Object.GetType(aIndex) -> integer
ParameterTypeDescription
aIndexintegerObject index

Returns: 0 none (empty slot / left the game), 1 player, 2 monster, 3 NPC, 5 item on the ground (constants OBJECT_NONE, OBJECT_USER, OBJECT_MONSTER, OBJECT_NPC, OBJECT_ITEM). Short name: GetObjectType.

if Object.GetType(aIndex) == OBJECT_USER then ... end

Object.GetConnectStatus

Returns the connection state of the object.

Object.GetConnectStatus(aIndex) -> integer
ParameterTypeDescription
aIndexintegerObject index

Returns: the state code (see the constants OBJECT_OFFLINE, OBJECT_CONNECTED, OBJECT_LOGGED, OBJECT_ONLINE); 0 if the index is invalid. Short name: GetObjectConnected.

if Object.GetConnectStatus(aIndex) == OBJECT_ONLINE then ... end

Object.GetName

Returns the name of the object (character or monster).

Object.GetName(aIndex) -> string
ParameterTypeDescription
aIndexintegerObject index

Returns: the name; an empty string if there is none. Short name: GetObjectName.

local name = Object.GetName(aIndex)

Object.GetClass

Returns the character class (for players) or the monster code (for monsters / NPCs).

Object.GetClass(aIndex) -> integer
ParameterTypeDescription
aIndexintegerObject index

Returns: the class code / monster code; -1 if there is no object. Short name: GetObjectClass.

if Object.GetClass(aIndex) == CLASS_DK then ... end

Object.GetMap

Returns the number of the map the object is standing on.

Object.GetMap(aIndex) -> integer
ParameterTypeDescription
aIndexintegerObject index

Returns: the map number (MAP_* constants); 0 if invalid. Short name: GetObjectMap.

if Object.GetMap(aIndex) == MAP_LORENCIA then ... end

Object.GetX

Returns the X coordinate of the object.

Object.GetX(aIndex) -> integer
ParameterTypeDescription
aIndexintegerObject index

Returns: the X coordinate; 0 if invalid. Short name: GetObjectMapX.

local x, y = Object.GetX(aIndex), Object.GetY(aIndex)

Object.GetY

Returns the Y coordinate of the object.

Object.GetY(aIndex) -> integer
ParameterTypeDescription
aIndexintegerObject index

Returns: the Y coordinate; 0 if invalid. Short name: GetObjectMapY.

local y = Object.GetY(aIndex)

Object.GetDirection

Returns the direction the object is facing.

Object.GetDirection(aIndex) -> integer
ParameterTypeDescription
aIndexintegerObject index

Returns: the direction (a number); 0 if invalid.

local dir = Object.GetDirection(aIndex)

Object.IsLive

Checks whether the character / monster is alive.

Object.IsLive(aIndex) -> boolean
ParameterTypeDescription
aIndexintegerIndex of an existing character or monster

Returns: true if alive; false if dead or nonexistent. The short name GetObjectLive(aIndex) returns 1 / 0.

if not Object.IsLive(aIndex) then return end

Object.GetTarget

Returns the target that a monster or character is attacking.

Object.GetTarget(aIndex) -> integer
ParameterTypeDescription
aIndexintegerMonster or player index

Returns: the target index; -1 if there is none.

local target = Object.GetTarget(monsterIndex)

HP / MP / SD / AG

The power parameter selects the stat type: 0 HP (POWER_LIFE), 1 MP (POWER_MANA), 2 SD (POWER_SHIELD), 3 AG (POWER_STAMINA).

Object.GetPower

Returns the current value of HP / MP / SD / AG.

Object.GetPower(aIndex, power) -> number
ParameterTypeDescription
aIndexintegerCharacter or monster index
powerinteger0 HP, 1 MP, 2 SD, 3 AG

Returns: the current value; 0 if the parameters are wrong. Short names: GetObjectLife, GetObjectMana, GetObjectBP, GetObjectShield.

local hp = Object.GetPower(aIndex, POWER_LIFE)

Object.GetMaxPower

Returns the maximum value (base + added part) of HP / MP / SD / AG.

Object.GetMaxPower(aIndex, power) -> number
ParameterTypeDescription
aIndexintegerCharacter or monster index
powerinteger0 HP, 1 MP, 2 SD, 3 AG

Returns: the maximum value; 0 if the parameters are wrong. Short names: GetObjectMaxLife, GetObjectMaxMana, GetObjectMaxBP, GetObjectMaxShield.

local max = Object.GetMaxPower(aIndex, POWER_LIFE)

Object.GetAddPower

Returns the added part of the maximum HP / MP / SD / AG.

Object.GetAddPower(aIndex, power) -> number
ParameterTypeDescription
aIndexintegerCharacter or monster index
powerinteger0 HP, 1 MP, 2 SD, 3 AG

Returns: the added part; 0 if the parameters are wrong.

local add = Object.GetAddPower(aIndex, POWER_MANA)

Object.SetPower

Sets the current value of HP / MP / SD / AG and sends it to the client.

Object.SetPower(aIndex, power, value) -> boolean
ParameterTypeDescription
aIndexintegerCharacter or monster index
powerinteger0 HP, 1 MP, 2 SD, 3 AG
valueintegerNew value; clamped between 0 and the maximum value

Returns: true if set; false if the object is invalid, write permission is missing, or the parameters are wrong. Short names: SetObjectLife, SetObjectMana, SetObjectBP, SetObjectShield (they take aIndex, value).

Object.SetPower(aIndex, POWER_LIFE, Object.GetMaxPower(aIndex, POWER_LIFE))  -- restore HP to full

Object.SetMaxPower

Sets the maximum value of HP / MP / SD / AG. The change is temporary: the next stat recalculation (Player.ReCalc, changing items...) recomputes it.

Object.SetMaxPower(aIndex, power, value) -> boolean
ParameterTypeDescription
aIndexintegerCharacter or monster index
powerinteger0 HP, 1 MP, 2 SD, 3 AG
valueintegerNew maximum value (1 or more)

Returns: true if set; false if invalid. If the current value is greater than the new maximum, it is lowered to the maximum. Short names: SetObjectMaxLife, SetObjectMaxMana, SetObjectMaxBP, SetObjectMaxShield.

Object.SetMaxPower(monsterIndex, POWER_LIFE, 500000)

Combat stats

Object.GetCombatStat

Reads a combat stat by name.

Object.GetCombatStat(aIndex, name) -> number
ParameterTypeDescription
aIndexintegerCharacter or monster index
namestringStat name (case-insensitive), see the list below

Returns: the stat value; 0 if the name is not in the list or the object is invalid.

Supported names:

  • Physical damage: AttackDamageMin, AttackDamageMax, AttackDamageMinRight, AttackDamageMaxRight, AttackDamageMinLeft, AttackDamageMaxLeft
  • Magic / curse: MagicDamageMin, MagicDamageMax, CurseDamageMin, CurseDamageMax
  • Rate / speed: AttackRating, AttackRatingPvP, AttackSpeed, MagicSpeed, MoveSpeed
  • Defense: Defense, DefensePvP, DefenseRating, DefenseRatingPvP, MagicDefense
  • Special damage: CriticalDamage, ExcellentDamage, DoubleDamage, DamageDecrease, ReflectDamage, SkillDamage, DamageAdd
  • Elemental: ElementalDefense, ElementalDamageMin, ElementalDamageMax, ElementalAttackRating, ElementalDefenseRating
  • Effect resistance: DebuffResistance, DebuffDefense
local def = Object.GetCombatStat(aIndex, "Defense")

Object.SetCombatStat

Sets a combat stat by name. The change is temporary: the next stat recalculation overwrites it.

Object.SetCombatStat(aIndex, name, value) -> boolean
ParameterTypeDescription
aIndexintegerCharacter or monster index
namestringStat name (same list as Object.GetCombatStat)
valueintegerNew value (signed 32-bit integer)

Returns: true if set; false if the name is wrong, the object is invalid, or write permission is missing.

Object.SetCombatStat(aIndex, "AttackSpeed", 200)

Actions

Object.Warp

Teleports the object to other coordinates within the same map. To change maps use Player.MoveTo.

Object.Warp(aIndex, x, y) -> boolean
ParameterTypeDescription
aIndexintegerCharacter or monster index
xintegerX coordinate (clamped to 0 - 255)
yintegerY coordinate (clamped to 0 - 255)

Returns: true if a teleport was requested; false if the parameters are wrong or it is blocked (player not in game, restricted mode). Equivalent short names: SetObjectMapX(aIndex, x), SetObjectMapY(aIndex, y).

Object.Warp(aIndex, 130, 130)

Object.Kill

Kills a character or monster.

Object.Kill(aIndex) -> boolean
ParameterTypeDescription
aIndexintegerCharacter or monster index

Returns: true if killed; false if the object is already dead, invalid, or write permission is missing. Short name: SetObjectLive(aIndex, 0).

Object.Kill(monsterIndex)

Object.ViewportCreate

Refreshes how the object is displayed to the people around it (resends the appearance information, including Gens, guild and castle siege information).

Object.ViewportCreate(aIndex)
ParameterTypeDescription
aIndexintegerCharacter or monster index

Returns: no return value.

Object.ViewportCreate(aIndex)

Object.ViewportDestroy

Closes the object's viewport (removes the object from the screens of the people around it).

Object.ViewportDestroy(aIndex)
ParameterTypeDescription
aIndexintegerCharacter or monster index

Returns: no return value.

How it works: if the object is in game, GameServer removes it from the visible list of each surrounding object (except items on the ground) and then clears its own visible list. Afterwards the object's viewport is recalculated in later loops, so use this function only when you fully understand its effect; normally there is no need to call it.

Object.ViewportDestroy(aIndex)