Skip to content

Metatable:Creature

Stefan A. Brannfjell edited this page Dec 3, 2020 · 14 revisions

The Creature metatable contains all of the methods that handle/require creatures.
This metatable is also inherited by the Player, Monster and Npc metatables, therefore they can use these Creature methods.

Creating an instance of the Creature metatable (2 options):

local creature = Creature(uid)
local creature = Creature(name)

Available methods:

addCondition(condition, force = false)
addHealth(healthChange)
addMana(manaChange, animationOnLoss = false)
canSee(position)
canSeeCreature(creature)
changeSpeed(delta)
getBaseSpeed()
getCondition(conditionType, conditionId = CONDITIONID_COMBAT, subId = 0)
getDamageMap()
getDescription(distance)
getDirection()
getEvents()
getFollowCreature()
getHealth()
getId()
getLight()
getMana()
getMaster()
getMaxHealth()
getMaxMana()
getName()
getOutfit()
getParent()
getPathTo(pos, minTargetDist = 0, maxTargetDist = 1, fullPathSearch = true, clearSight = true, maxSearchDist = 0)
getPosition()
getSkull()
getSpeed()
getSummons()
getTarget()
getTile()
getZone()
isCreature()
isHealthHidden()
isInGhostMode()
isItem()
isMonster()
isMovementBlocked()
isNpc()
isPlayer()
isRemoved()
isTile()
registerEvent(name)
remove()
removeCondition(conditionType, conditionId = CONDITIONID_COMBAT, subId = 0, force = false)
say(text, type, ghost = false, target = nil, position)
setDirection(direction)
setDropLoot(doDrop)
setFollowCreature(followedCreature)
setHealth(health)
setHiddenHealth(hide)
setLight(color, level)
setMaster(master)
setMaxHealth(maxHealth)
setMovementBlocked(bool)
setOutfit(outfit)
setSkull(skull) setTarget(target)
teleportTo(position, pushMovement = false)
unregisterEvent(name)


addCondition(condition[, force = false])

Description: N/A
Parameters:

  • condition - No description
  • force - (optional, default: false)
Returns: N/A
Example:
local creature = Creature(...)
creature:addCondition(some_userdata, false)

[To the top] Added in version: 1.0


addHealth(healthChange)

Description: N/A
Parameters:

  • healthChange - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:addHealth(1)

[To the top] Added in version: 1.0


addMana(manaChange[, animationOnLoss = false])

Description: N/A
Parameters:

  • manaChange - No description
  • animationOnLoss - (optional, default: false)
Returns: N/A
Example:
local creature = Creature(...)
creature:addMana(1, false)

[To the top] Added in version: 1.0


canSee(position)

Description: N/A
Parameters:

  • position - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:canSee(Position())

[To the top] Added in version: 1.0


canSeeCreature(creature)

Description: N/A
Parameters:

  • creature - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:canSeeCreature(some_userdata)

[To the top] Added in version: 1.0


changeSpeed(delta)

Description: N/A
Parameters:

  • delta - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:changeSpeed(unknown)

[To the top] Added in version: 1.0


getBaseSpeed()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getBaseSpeed()

[To the top] Added in version: 1.0


getCondition(conditionType[, conditionId = CONDITIONID_COMBAT[, subId = 0]])

Description: N/A
Parameters:

  • conditionType - No description
  • conditionId - (optional, default: CONDITIONID_COMBAT)
  • subId - (optional, default: 0)
Returns: N/A
Example:
local creature = Creature(...)
creature:getCondition(CONDITION_POISON, CONDITIONID_COMBAT, 0)

[To the top] Added in version: 1.0


getDamageMap()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getDamageMap()

[To the top] Added in version: 1.0


getDescription(distance)

Description: N/A
Parameters:

  • distance - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:getDescription(1)

[To the top] Added in version: 1.0


getDirection()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getDirection()

[To the top] Added in version: 1.0


getEvents()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getEvents()

[To the top] Added in version: 1.2


getFollowCreature()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getFollowCreature()

[To the top] Added in version: 1.0


getHealth()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getHealth()

[To the top] Added in version: 1.0


getId()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getId()

[To the top] Added in version: 1.0


getLight()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getLight()

[To the top] Added in version: 1.0


getMana()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getMana()

[To the top] Added in version: 1.0


getMaster()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getMaster()

[To the top] Added in version: 1.0


getMaxHealth()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getMaxHealth()

[To the top] Added in version: 1.0


getMaxMana()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getMaxMana()

[To the top] Added in version: 1.0


getName()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getName()

[To the top] Added in version: 1.0


getOutfit()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getOutfit()

[To the top] Added in version: 1.0


getParent()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getParent()

[To the top] Added in version: 1.0


getPathTo(pos[, minTargetDist = 0[, maxTargetDist = 1[, fullPathSearch = true[, clearSight = true[, maxSearchDist = 0]]]]])

Description: N/A
Parameters:

  • pos - No description
  • minTargetDist - (optional, default: 0)
  • maxTargetDist - (optional, default: 1)
  • fullPathSearch - (optional, default: true)
  • clearSight - (optional, default: true)
  • maxSearchDist - (optional, default: 0)
Returns: N/A
Example:
local creature = Creature(...)
creature:getPathTo(Position(), 0, 1, true, true, 0)

[To the top] Added in version: 1.0


getPosition()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getPosition()

[To the top] Added in version: 1.0


getSkull()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getSkull()

[To the top] Added in version: 1.0 for players, since 1.1 for any creature


getSpeed()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getSpeed()

[To the top] Added in version: 1.0


getSummons()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getSummons()

[To the top] Added in version: 1.0


getTarget()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getTarget()

[To the top] Added in version: 1.0


getTile()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:getTile()

[To the top] Added in version: 1.0


getZone()

Description: Returns the zone (ZoneType_t) of a tile
Parameters: None
Returns: (enum) ZoneType_t
Example:

local creature = Creature(...)
creature:getZone()

[To the top] Added in version: 1.3


isCreature()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:isCreature()

[To the top] Added in version: 1.0


isHealthHidden()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:isHealthHidden()

[To the top] Added in version: 1.0


isInGhostMode()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:isInGhostMode()

[To the top] Added in version: 1.0


isItem()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:isItem()

[To the top] Added in version: 1.0


isMonster()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:isMonster()

[To the top] Added in version: 1.0


isMovementBlocked()

Description: Check if this creature can move or if it is blocked.
Parameters: None
Returns: bool (true/false)
Example:

local creature = Creature(...)
if not creature:isMovementBlocked() then
    creature::setMovementBlocked(true)
    print("Blocking " .. creature:getName() .. " from being able to move.")
end

[To the top] Added in version: 1.3 #2553


isNpc()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:isNpc()

[To the top] Added in version: 1.0


isPlayer()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:isPlayer()

[To the top] Added in version: 1.0


isRemoved()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:isRemoved()

[To the top] Added in version: 1.0


isTile()

Description: N/A
Parameters: None
Returns: false
Example:

local creature = Creature(...)
creature:isTile()

[To the top] Added in version: 1.1


registerEvent(name)

Description: N/A
Parameters:

  • name - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:registerEvent(some_name)

[To the top] Added in version: 1.0


remove()

Description: N/A
Parameters: None
Returns: N/A
Example:

local creature = Creature(...)
creature:remove()

[To the top] Added in version: 1.0


removeCondition(conditionType[, conditionId = CONDITIONID_COMBAT[, subId = 0[, force = false]]])

Description: N/A
Parameters:

  • conditionType - No description
  • conditionId - (optional, default: CONDITIONID_COMBAT)
  • subId - (optional, default: 0)
  • force - (optional, default: false)
Returns: N/A
Example:
local creature = Creature(...)
creature:removeCondition(CONDITION_POISON, CONDITIONID_COMBAT, 0, false)

[To the top] Added in version: 1.0


say(text, type[, ghost = false[, target = nil[, position]]])

Description: Test description
Parameters:

  • text - Text shown to others.
  • type - Type of text that is shown.
  • ghost - (optional, default: false)
  • target - (optional, default: nullptr)
  • position - (optional)
Returns: N/A
Example:
local creature = Creature(...)
creature:say(any_string, TALKTYPE_SAY, false, nil, nil)

[To the top] Added in version: 1.0


setDirection(direction)

Description: N/A
Parameters:

  • direction - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setDirection(NORTH)

[To the top] Added in version: 1.0


setDropLoot(doDrop)

Description: N/A
Parameters:

  • doDrop - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setDropLoot(unknown)

[To the top] Added in version: 1.0


setFollowCreature(followedCreature)

Description: N/A
Parameters:

  • followedCreature - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setFollowCreature(some_userdata)

[To the top] Added in version: 1.0


setHealth(health)

Description: N/A
Parameters:

  • health - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setHealth(185)

[To the top] Added in version: 1.3


setHiddenHealth(hide)

Description: N/A
Parameters:

  • hide - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setHiddenHealth(unknown)

[To the top] Added in version: 1.0


setLight(color, level)

Description: N/A
Parameters:

  • color - No description
  • level - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setLight(0xD7, LIGHT_LEVEL_DAY)

[To the top] Added in version: 1.0


setMaster(master)

Description: N/A
Parameters:

  • master - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setMaster(some_userdata)

[To the top] Added in version: 1.0


setMaxHealth(maxHealth)

Description: N/A
Parameters:

  • maxHealth - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setMaxHealth(185)

[To the top] Added in version: 1.0


setMovementBlocked(bool)

Description: Block or unblock a creature from being able to move
Parameters:

  • bool - true/false - Block or unblock player
Returns: N/A
Example:
local creature = Creature(...)
if creature:isMovementBlocked() then
    creature::setMovementBlocked(false)
    print("Allowing " .. creature:getName() .. " to move again.")
end

[To the top] Added in version: 1.3 #2553


setOutfit(outfit)

Description: N/A
Parameters:

  • outfit - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setOutfit(unknown)

[To the top] Added in version: 1.0


setSkull(skull)

Description: N/A
Parameters:

  • skull - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setSkull(SKULL_RED)

[To the top] Added in version: 1.0 for players, since 1.1 for any creature


setTarget(target)

Description: N/A
Parameters:

  • target - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:setTarget(some_userdata)

[To the top] Added in version: 1.0


teleportTo(position[, pushMovement = false])

Description: N/A
Parameters:

  • position - No description
  • pushMovement - (optional, default: false)
Returns: N/A
Example:
local creature = Creature(...)
creature:teleportTo(Position(), false)

[To the top] Added in version: 1.0


unregisterEvent(name)

Description: N/A
Parameters:

  • name - No description
Returns: N/A
Example:
local creature = Creature(...)
creature:unregisterEvent(some_name)

[To the top] Added in version: 1.0

Clone this wiki locally