This page covers four small tables: Monster (monsters), Skill (skill watching), Party (party) and Map (maps). A player's summoned monster is in Player.SummonMonster (page Player: send information and actions); the functions for iterating monsters are on the page Iterate and count objects.
Monster.Create, CreateInArea, CreateEx, Delete) are blocked when the script is in restricted mode (see the page General rules for functions).Monster
Monster.Create
Creates a temporary monster at a cell. A temporary monster does not respawn after it dies.
Monster.Create(class, map, x, y [, dir, moveRange, despawnSeconds, instance]) -> integer
| Parameter | Type | Description |
|---|---|---|
class | integer | Monster / NPC code (must exist in the monster data) |
map | integer | Map number (must exist on this GameServer) |
x, y | integer | Coordinates (clamped from 0 to 255) |
dir | integer | Direction 0 to 7; -1 (default) = random |
moveRange | integer | Movement range; -1 (default) = according to the monster data |
despawnSeconds | integer | Disappears by itself after this many seconds (maximum 30 days); 0 (default) = does not disappear by itself |
instance | integer | Instance number; -1 (default) = no instance |
Returns: the index of the monster just created; -1 on failure (wrong parameters, the monster code / map does not exist, no free slots for creating objects, restricted mode). Short name: MonsterCreate(class, map, x, y, dir).
local npc = Monster.Create(240, MAP_LORENCIA, 130, 130, 3)
if npc == -1 then Log.AddC(1, "Unable to create the NPC") end
Monster.CreateInArea
Creates several temporary monsters of the same type inside a rectangular area.
Monster.CreateInArea(class, map, x1, y1, x2, y2 [, count, despawnSeconds]) -> integer
| Parameter | Type | Description |
|---|---|---|
class | integer | Monster code |
map | integer | Map number |
x1, y1, x2, y2 | integer | The two corners of the area (clamped from 0 to 255); either corner may come first |
count | integer | Number of monsters to create, from 1 to 200 (default 1) |
despawnSeconds | integer | Disappears by itself after this many seconds (maximum 30 days); 0 (default) = does not disappear by itself |
Returns: the number of monsters actually created (may be less than count); 0 if the parameters are wrong.
local n = Monster.CreateInArea(14, MAP_DUNGEON, 20, 20, 60, 60, 30, 600)
Monster.CreateEx
Creates a temporary monster with custom stats. Each stat is only applied when its value is greater than 0; otherwise the monster data is kept.
Monster.CreateEx(class, map, x, y, dir, moveRange, life, damageMin, damageMax, defense, attackRate, defenseRate) -> integer
| Parameter | Type | Description |
|---|---|---|
class, map, x, y | integer | Same as Monster.Create |
dir | integer | Direction 0 to 7; -1 = random |
moveRange | integer | Movement range; -1 = according to the monster data |
life | integer | Maximum HP (and current HP) |
damageMin, damageMax | integer | Minimum / maximum physical damage |
defense | integer | Defense |
attackRate | integer | Attack success rate |
defenseRate | integer | Defense success rate |
Returns: the index of the monster just created; -1 on failure. A monster created with this function does not disappear by itself. Short name: MonsterCreateEx(class, map, x, y, dir, moveRange, life, damage, defense, attackRate, defenseRate) (a single damage value is used for both the minimum and the maximum).
local boss = Monster.CreateEx(78, MAP_ICARUS, 100, 100, -1, -1, 5000000, 8000, 12000, 3000, 2000, 1500)
Monster.Delete
Deletes a temporary monster (created by a script or a GM command). A fixed monster of the map cannot be deleted.
Monster.Delete(aIndex) -> boolean
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Monster index |
Returns: true if it was deleted; false if it is not a temporary monster, is invalid or the script is in restricted mode. Short name: MonsterDelete.
Monster.Delete(npc)
Monster.GetTopDamageDealer
Returns the player with the highest hatred (aggro) toward the monster, according to the monster's threat table (the result of GetMaxAggro in GameServer). This is the player the monster is targeting the most, usually the one dealing the most damage, but it is not an accumulated damage statistics table.
Monster.GetTopDamageDealer(aIndex) -> integer
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Monster index |
Returns: the index of the player with the highest aggro; -1 if aIndex is not a valid monster, nobody is in the monster's threat table yet, or that player is no longer in game.
local top = Monster.GetTopDamageDealer(bossIndex)
if top ~= -1 then Message.SendAll(0, Player.GetName(top) .. " dealt the most damage to the Boss") end
Monster.GetAttr
Reads the base data of a monster type (from the server's monster data file).
Monster.GetAttr(class) -> table | nil
| Parameter | Type | Description |
|---|---|---|
class | integer | Monster code |
Returns: a table, or nil if the monster code does not exist. The fields:
| Field | Type | Meaning |
|---|---|---|
Class | integer | Monster code |
Name | string | Name |
Level | integer | Level |
Life, Mana | integer | HP, MP |
DamageMin, DamageMax | integer | Minimum / maximum damage |
Defense | integer | Defense |
AttackRate, DefenseRate | integer | Attack / defense success rate |
MoveRange, AttackRange, ViewRange | integer | Movement / attack / view range |
AttackSpeed | integer | Attack speed |
RespawnTimeMin, RespawnTimeMax | integer | Minimum / maximum respawn time |
ItemRate, ZenRate | integer | Item / zen drop rate |
ElementalAttribute | integer | Elemental attribute |
ScriptName | string | Name of the monster's AI script |
local a = Monster.GetAttr(44)
if a then Log.Add(a.Name .. " HP=" .. a.Life) end
Monster.WatchRespawn
Turns on / off GameServer calling the onMonsterRespawn callback for a monster type. By default GameServer does not report this event, to save resources.
Monster.WatchRespawn(class [, watch])
| Parameter | Type | Description |
|---|---|---|
class | integer | Monster code (0 to 65535) |
watch | boolean | true = on (default), false = off |
Monster.WatchRespawn(44, true)
Skill
Skill.Watch
Turns on / off GameServer calling the onUseSkill callback when a player uses a skill.
Skill.Watch(skill [, watch])
| Parameter | Type | Description |
|---|---|---|
skill | integer | Skill number (0 to 65535) |
watch | boolean | true = on (default), false = off |
Skill.Watch(17, true) -- watch skill 17
Party
Party.GetCount
Returns the number of members in the party.
Party.GetCount(partyNumber) -> integer
| Parameter | Type | Description |
|---|---|---|
partyNumber | integer | Party number, obtained from Player.GetPartyNumber |
Returns: the number of members; 0 if the party does not exist. Short name: PartyGetMemberCount.
local n = Party.GetCount(Player.GetPartyNumber(aIndex))
Party.GetMember
Returns the index of the n-th member of the party.
Party.GetMember(partyNumber, n) -> integer
| Parameter | Type | Description |
|---|---|---|
partyNumber | integer | Party number |
n | integer | Position in the party, from 1 (party leader) to 5 |
Returns: the character index; -1 if there is no member at that position or that member is not online on this GameServer. Short name: PartyGetMemberIndex(party, slot) with slot counted from 0.
local leader = Party.GetMember(Player.GetPartyNumber(aIndex), 1)
Map
The Map functions take a map number map (a MAP_* constant). If the map does not exist on this GameServer, the function returns the default value (an empty string, 0, false).
Map.GetName
Returns the map name.
Map.GetName(map) -> string
| Parameter | Type | Description |
|---|---|---|
map | integer | Map number |
Returns: the map name; an empty string if it does not exist. Short name: GetMapName.
Message.SendAll(1, "Event at " .. Map.GetName(MAP_ARENA))
Map.Exists
Checks whether the map is running on this GameServer.
Map.Exists(map) -> boolean
| Parameter | Type | Description |
|---|---|---|
map | integer | Map number |
if Map.Exists(MAP_CRYWOLF) then ... end
Map.GetAttr
Reads the attributes of a map cell.
Map.GetAttr(map, x, y) -> integer
| Parameter | Type | Description |
|---|---|---|
map | integer | Map number |
x, y | integer | Cell coordinates (clamped from 0 to 255) |
Returns: the cell attribute bit mask: bit 1 safe zone (SAFE), bit 2 standing cell (STAND), bits 4, 8, 16 are lock cells 1, 2, 3 (LOCK_1, LOCK_2, LOCK_3). Lock cells are used by event maps to block / open areas (for example Chaos Castle uses lock cell 2, Imperial Guardian uses lock cell 3 for areas that are not yet open); the exact meaning depends on the map. Returns 0 if the map does not exist or the parameters are wrong.
local attr = Map.GetAttr(MAP_LORENCIA, 130, 130)
Map.CheckAttr
Checks whether a cell carries the specified attribute bit(s).
Map.CheckAttr(map, x, y, attr) -> boolean
| Parameter | Type | Description |
|---|---|---|
map | integer | Map number |
x, y | integer | Cell coordinates (clamped from 0 to 255) |
attr | integer | Bit mask to check (see Map.GetAttr) |
Returns: true if the cell has at least one bit of attr; false if not or the parameters are wrong. Short name: MapCheckAttr (returns 1 / 0).
if Map.CheckAttr(Object.GetMap(aIndex), Object.GetX(aIndex), Object.GetY(aIndex), 1) then
Message.Send(aIndex, 1, "You are in a safe zone")
end
Map.Fireworks
Launches fireworks at a cell for the players nearby.
Map.Fireworks(map, x, y [, instance])
| Parameter | Type | Description |
|---|---|---|
map | integer | Map number (must exist on this GameServer) |
x, y | integer | Coordinates (clamped from 0 to 255) |
instance | integer | 4th parameter: the map's instance number; default -1 (a normal map, not a copy). Only players belonging to exactly this instance and no more than 20 cells away from cell (x, y) see the fireworks |
Short name: FireworksSend(aIndex, x, y) launches on the map of aIndex; if x, y are omitted, the position of aIndex is used.
Map.Fireworks(MAP_LORENCIA, 130, 130)