Skip to content

Creature

Creature Class

The Creature class is the base class for all living entities in the game (Players, Monsters, NPCs). It provides common functionality shared by all creature types.

Constructor

Creature(identifier)
ParameterTypeDescription
identifiernumber/stringCreature ID or name

Type Checking

MethodReturnsDescription
isCreature()booleanIs a creature
isPlayer()booleanIs a player
isMonster()booleanIs a monster
isNpc()booleanIs an NPC
isRemoved()booleanHas been removed from game
if creature:isPlayer() then
local player = creature:getPlayer()
elseif creature:isMonster() then
local monster = creature:getMonster()
end

Identity

MethodReturnsDescription
getId()numberUnique creature ID
getName()stringCreature name
getDescription(distance)stringLook description

Position & Movement

MethodReturnsDescription
getPosition()PositionCurrent position
getTile()TileCurrent tile
getDirection()numberFacing direction
setDirection(direction)-Set direction
teleportTo(position, pushMovement)booleanTeleport creature
move(direction)booleanMove one step
getPathTo(position)tableGet path to position

Directions: DIRECTION_NORTH, DIRECTION_EAST, DIRECTION_SOUTH, DIRECTION_WEST

-- Teleport to position
creature:teleportTo(Position(1000, 1000, 7))
-- Move north
creature:move(DIRECTION_NORTH)
-- Get path
local path = creature:getPathTo(targetPosition)

Health

MethodReturnsDescription
getHealth()numberCurrent health
getMaxHealth()numberMaximum health
setHealth(health)-Set current health
setMaxHealth(health)-Set maximum health
addHealth(amount)-Add/subtract health
setHiddenHealth(hidden)-Hide health bar
isHealthHidden()booleanIs health hidden
-- Heal to full
creature:setHealth(creature:getMaxHealth())
-- Damage creature
creature:addHealth(-100)

Speed

MethodReturnsDescription
getSpeed()numberCurrent speed
getBaseSpeed()numberBase speed
changeSpeed(delta)-Modify speed

Target & Follow

MethodReturnsDescription
getTarget()CreatureAttack target
setTarget(creature)-Set attack target
getFollowCreature()CreatureFollow target
setFollowCreature(creature)-Set follow target

Master & Summons

MethodReturnsDescription
getMaster()CreatureMaster (if summon)
setMaster(creature)-Set master
getSummons()tableList of summons

Light

MethodReturnsDescription
getLight()level, colorLight info
setLight(level, color)-Set light
-- Set bright light
creature:setLight(10, 215)

Outfit

MethodReturnsDescription
getOutfit()OutfitCurrent outfit
setOutfit(outfit)-Set outfit
local outfit = creature:getOutfit()
outfit.lookType = 130
creature:setOutfit(outfit)

Skull

MethodReturnsDescription
getSkull()numberSkull type
setSkull(skull)-Set skull

Skulls: SKULL_NONE, SKULL_YELLOW, SKULL_GREEN, SKULL_WHITE, SKULL_RED, SKULL_BLACK, SKULL_ORANGE


Conditions

MethodReturnsDescription
getCondition(conditionType, conditionId, subId)ConditionGet condition
addCondition(condition)-Add condition
removeCondition(conditionType, conditionId, subId, force)-Remove condition
hasCondition(conditionType, subId)booleanHas condition
-- Add poison
local condition = Condition(CONDITION_POISON)
condition:setParameter(CONDITION_PARAM_TICKS, 10000)
condition:setParameter(CONDITION_PARAM_MINVALUE, 10)
condition:setParameter(CONDITION_PARAM_MAXVALUE, 20)
creature:addCondition(condition)
-- Check for haste
if creature:hasCondition(CONDITION_HASTE) then
print("Has haste!")
end

Vision

MethodReturnsDescription
canSee(position)booleanCan see position
canSeeCreature(creature)booleanCan see creature
canSeeGhostMode(creature)booleanCan see ghost
canSeeInvisibility()booleanCan see invisible
isInGhostMode()booleanIs in ghost mode

Immunity & Movement

MethodReturnsDescription
isImmune(conditionType)booleanIs immune
isMovementBlocked()booleanMovement blocked
setMovementBlocked(blocked)-Block movement

Combat

MethodReturnsDescription
getDamageMap()tableDamage dealt/received
setDropLoot(drop)-Enable/disable loot
setSkillLoss(loss)-Enable/disable skill loss

Parent

MethodReturnsDescription
getParent()CylinderParent container/tile
getZone()numberCurrent zone type

Zones: ZONE_PROTECTION, ZONE_NOPVP, ZONE_PVP, ZONE_NOLOGOUT, ZONE_NORMAL


Speech

MethodDescription
say(text, type, ghost, target, position)Say text
creature:say("Hello!", TALKTYPE_MONSTER_SAY)
creature:say("*roars*", TALKTYPE_MONSTER_YELL)

Events

MethodReturnsDescription
getEvents(type)tableRegistered events
registerEvent(eventName)booleanRegister creature event
unregisterEvent(eventName)booleanUnregister event
creature:registerEvent("OnDeath")

Removal

MethodDescription
remove()Remove from game

Custom Skills & Stats

MethodReturnsDescription
giveSkill(skillName, params)-Give custom skill
addSkill(skillName, levels)-Add skill levels
subtractSkill(skillName, levels)-Remove skill levels
removeSkill(skillName)-Remove custom skill
hasSkill(skillName)booleanHas custom skill
getSkillLevel(skillName)numberCustom skill level
giveStat(statName, params)-Give custom stat
removeStat(statName)-Remove custom stat
hasStat(statName)booleanHas custom stat
getStat(statName)StatGet stat object
getStats()tableAll custom stats

Examples

Distance Check

local function isNear(creature, target, range)
local pos1 = creature:getPosition()
local pos2 = target:getPosition()
return pos1:getDistance(pos2) <= range
end

Safe Teleport

local function safeTeleport(creature, destination)
local tile = Tile(destination)
if tile and not tile:hasProperty(CONST_PROP_BLOCKSOLID) then
creature:teleportTo(destination)
destination:sendMagicEffect(CONST_ME_TELEPORT)
return true
end
return false
end