Lua API

LuaCharacter classmod

Represents a character.

Fields

LuaCharacter.index [R] The index of this character in the global characters array.
LuaCharacter.integer_id [R] The integer ID of this character.
LuaCharacter.hp [R] The character's proper name without any qualifiers.
LuaCharacter.max_hp [R] The character's maximum HP.
LuaCharacter.sp [R] The character's current stamina.
LuaCharacter.max_sp [R] The character's maximum stamina.
LuaCharacter.mp [R] The character's current MP.
LuaCharacter.max_mp [R] The character's maximum MP.
LuaCharacter.god [RW] The character's worshipped god.
LuaCharacter.position [RW] The character's position.
LuaCharacter.initial_position [RW] The character's initial position.
LuaCharacter.shop_rank [RW] The shop rank of this character.
LuaCharacter.role [RW] The role this character takes on.
LuaCharacter.gold [RW] The character's current gold.
LuaCharacter.experience [RW] The character's current experience points.
LuaCharacter.fame [RW] The character's current fame.
LuaCharacter.level [RW] The character's current level.
LuaCharacter.talk_type [RW] The character's current talk type.
LuaCharacter.pv [RW] The character's current PV.
LuaCharacter.dv [RW] The character's current DV.
LuaCharacter.hit_bonus [RW] The character's current hit bonus.
LuaCharacter.growth_buffs [RW] The character's current growth buffs.
LuaCharacter.hate [RW] The character's current hate.
LuaCharacter.emotion_icon [RW] The character's current emotion icon.
LuaCharacter.karma [RW] The character's current karma.
LuaCharacter.enemy_id [RW] The index of a character this character is targeting..
LuaCharacter.image [RW] The character's current image.
LuaCharacter.portrait [RW] The character's current portrait.
LuaCharacter.impression [RW] The character's current impression.
LuaCharacter.interest [RW] The character's current interest.
LuaCharacter.ai_calm [RW] The character's AI calmness.
LuaCharacter.id [R] The new-style version prototype ID of the character.
LuaCharacter.name [R] The name of the character with article and title.
LuaCharacter.basename [R] The name of the character without article and title.
LuaCharacter.alias [R] The alias of the character.
LuaCharacter.sex [RW] The sex of the character.
LuaCharacter.relationship [RW] The relationship of the character to the player.
LuaCharacter.original_relationship [RW] The original relationship of the character to the player.
LuaCharacter.quality [RW] The quality of the character.
LuaCharacter.prototype [R] The prototype data of the character.

Methods

LuaCharacter:damage_hp (amount[, source]) Damages this character.
LuaCharacter:damage_hp (amount, source) Damages this character, with the source being set as another character.
LuaCharacter:apply_ailment (ailment, power) Applies a status ailment to this character.
LuaCharacter:heal_ailment (ailment, power) Heals a status ailment on a character.
LuaCharacter:add_buff (buff_id, power, turns[, doer]) Adds a buff to a character.
LuaCharacter:set_growth_buff (index, power) Sets a growth buff of this character.
LuaCharacter:recruit_as_ally () Attempts to recruit this character as an ally of the player.
LuaCharacter:get_flag (flag) Gets the value of a flag on this character.
LuaCharacter:set_flag (flag, value) Sets the value of a flag on this character.
LuaCharacter:get_skill (skill_id) Obtains the skill of the given ID.
LuaCharacter:gain_skill (skill_id, initial_level[, initial_stock]) Makes this character gain a new skill or spell.
LuaCharacter:gain_skill_exp (skill_id, amount) Makes this character gain experience in a skill or spell.
LuaCharacter:modify_resistance (element, delta) Modifies this character's resistance.
LuaCharacter:modify_sanity (delta) Modifies this character's sanity.
LuaCharacter:modify_karma (delta) Modifies this character's karma.
LuaCharacter:modify_corruption (delta) Modifies this character's ether corruption.
LuaCharacter:make_pregnant () Makes this character pregnant.
LuaCharacter:eat_rotten_food () Applies the effects of eating rotten food to this character.
LuaCharacter:vanquish () Deletes this character and removes it from the map.
LuaCharacter:act_hostile_against (target) Applies the effects of acting hostile towards a target character.
LuaCharacter:refresh () Refreshes this character, reapplying bonuses given by equipment.
LuaCharacter:refresh_burden_state () Refreshes the burden state of this character.
LuaCharacter:move_to (x, y) Moves this character to a new position.
LuaCharacter:move_to (pos) Moves this character to a new position.
LuaCharacter:switch_religion (god_id) Changes the worshipped god of this character without invoking the god switching penalty.
LuaCharacter:get_ailment (ailment) Returns the duration of an ailment on this character.

Fields

# LuaCharacter.index

[R] The index of this character in the global characters array.

  • index : (num)
# LuaCharacter.integer_id

[R] The integer ID of this character.

  • integer_id : (num)
# LuaCharacter.hp

[R] The character's proper name without any qualifiers.

  • hp : (string)
# LuaCharacter.max_hp

[R] The character's maximum HP.

  • max_hp : (num)
# LuaCharacter.sp

[R] The character's current stamina.

  • sp : (num)
# LuaCharacter.max_sp

[R] The character's maximum stamina.

  • max_sp : (num)
# LuaCharacter.mp

[R] The character's current MP.

  • mp : (num)
# LuaCharacter.max_mp

[R] The character's maximum MP.

  • max_mp : (num)
# LuaCharacter.god

[RW] The character's worshipped god.

  • god : (string)
# LuaCharacter.position

[RW] The character's position.

# LuaCharacter.initial_position

[RW] The character's initial position.

# LuaCharacter.shop_rank

[RW] The shop rank of this character.

Used only if they are a shopkeeper.

  • shop_rank : (num)
# LuaCharacter.role

[RW] The role this character takes on.

  • role : (num)
# LuaCharacter.gold

[RW] The character's current gold.

  • gold : (num)
# LuaCharacter.experience

[RW] The character's current experience points.

  • experience : (num)
# LuaCharacter.fame

[RW] The character's current fame.

  • fame : (num)
# LuaCharacter.level

[RW] The character's current level.

  • level : (num)
# LuaCharacter.talk_type

[RW] The character's current talk type.

  • talk_type : (num)
# LuaCharacter.pv

[RW] The character's current PV.

Reset on refresh.

  • pv : (num)
# LuaCharacter.dv

[RW] The character's current DV.

Reset on refresh.

  • dv : (num)
# LuaCharacter.hit_bonus

[RW] The character's current hit bonus.

Reset on refresh.

  • hit_bonus : (num)
# LuaCharacter.growth_buffs

[RW] The character's current growth buffs.

  • growth_buffs : (num)
# LuaCharacter.hate

[RW] The character's current hate.

  • hate : (num)
# LuaCharacter.emotion_icon

[RW] The character's current emotion icon.

Valid values are 0-99.

  • emotion_icon : (num)
# LuaCharacter.karma

[RW] The character's current karma.

Only valid if the character is the player.

  • karma : (num)
# LuaCharacter.enemy_id

[RW] The index of a character this character is targeting..

  • enemy_id : (num)
# LuaCharacter.image

[RW] The character's current image.

  • image : (num)
# LuaCharacter.portrait

[RW] The character's current portrait.

  • portrait : (string)
# LuaCharacter.impression

[RW] The character's current impression.

  • impression : (num)
# LuaCharacter.interest

[RW] The character's current interest.

  • interest : (num)
# LuaCharacter.ai_calm

[RW] The character's AI calmness.

  • ai_calm : (num)
# LuaCharacter.id

[R] The new-style version prototype ID of the character.

  • id : (string)
# LuaCharacter.name

[R] The name of the character with article and title.

  • name : (string)
# LuaCharacter.basename

[R] The name of the character without article and title.

  • basename : (string)
# LuaCharacter.alias

[R] The alias of the character.

  • alias : (string)
# LuaCharacter.sex

[RW] The sex of the character.

  • sex : (Gender)
# LuaCharacter.relationship

[RW] The relationship of the character to the player.

  • relationship : (Relationship)
# LuaCharacter.original_relationship

[RW] The original relationship of the character to the player.

  • original_relationship : (Relationship)
# LuaCharacter.quality

[RW] The quality of the character.

  • quality : (Quality)
# LuaCharacter.prototype

[R] The prototype data of the character.

Methods

# LuaCharacter:damage_hp (amount[, source])

Damages this character.

Parameters:
  • amount : (num) the amount to damage
  • source : (Enums.DamageSource) the source of the damage (defaults to the unseen hand) (optional)
Usage:
local chara = Chara.player()
  chara:damage_hp(100)
# LuaCharacter:damage_hp (amount, source)

Damages this character, with the source being set as another character.

Parameters:
  • amount : (num) the amount to damage
  • source : (LuaCharacter) the character acting as the source of the damage
Usage:
local chara = Chara.player()
 local other = Chara.create(0, 0, "core.putit")
 chara:damage_hp(100, other)
# LuaCharacter:apply_ailment (ailment, power)

Applies a status ailment to this character.

Parameters:
  • ailment : (Enums.StatusAilment) the kind of status ailment
  • power : (num) the power of the status ailment
Usage:
local chara = Chara.player()
  chara:apply_ailment("Blinded", 100)
# LuaCharacter:heal_ailment (ailment, power)

Heals a status ailment on a character.

Parameters:
  • ailment : (Enums.StatusAilment) the kind of status ailment
  • power : (num) the power of the healing. If 0, heal the ailment completely.
Usage:
local chara = Chara.player()
  chara:heal_ailment("Blinded", 100)
# LuaCharacter:add_buff (buff_id, power, turns[, doer])

Adds a buff to a character.

Parameters:
  • buff_id : (string) the buff to add
  • power : (num) the buff's power
  • turns : (num) the number of turns the buff will last
  • doer : (LuaCharacter) the character who applied this buff (optional)
# LuaCharacter:set_growth_buff (index, power)

Sets a growth buff of this character.

Parameters:
  • index : (num)
  • power : (num)
# LuaCharacter:recruit_as_ally ()

Attempts to recruit this character as an ally of the player.

This will only work if the character isn't already an ally, isn't the player, is alive and the player has a free party slot.

Returns:
  • (bool) true if the character was recruited successfully
# LuaCharacter:get_flag (flag)

Gets the value of a flag on this character.

Parameters: Returns:
  • (bool)
# LuaCharacter:set_flag (flag, value)

Sets the value of a flag on this character.

Note: Currently, all flags up to isquicktempered are "intrinsic" and are always reset when this character is refreshed each turn. To change these flags, you must call this function inside a handler for core.character_refreshed, or the flag will be reset later.

Parameters:
  • flag : (Enums.CharaFlag) the flag to set
  • value : (bool) the flag's new value
See also: Usage:
local Event = ELONA.require("core.Event")

 local function make_invisible(e)
 e.chara:set_flag("is_invisible", true) -- intrinsic, reset on refresh
 end

 -- force this flag to be overridden after this character is refreshed.
 Event.register("core.character_refreshed", make_invisible)
 Event.register("core.character_created", make_invisible)
# LuaCharacter:get_skill (skill_id)

Obtains the skill of the given ID.

Parameters:
  • skill_id : (string) ID of type core.ability
Returns:
# LuaCharacter:gain_skill (skill_id, initial_level[, initial_stock])

Makes this character gain a new skill or spell.

This only has an effect if the character does not already know the skill/spell.

Parameters:
  • skill_id : (string) the skill/spell ID of type core.ability
  • initial_level : (num) the intial skill/spell level
  • initial_stock : (num) the initial spell stock for spells (optional)
# LuaCharacter:gain_skill_exp (skill_id, amount)

Makes this character gain experience in a skill or spell.

This only has an effect if the character already knows the skill/spell.

Parameters:
  • skill_id : (string) the skill/spell ID of type core.ability
  • amount : (num) the amount of experience
# LuaCharacter:modify_resistance (element, delta)

Modifies this character's resistance.

Since the effect is permanent, once your resistance is modified, it will not be reset on refreshing.

Parameters:
  • element : (num) the corresponding element
  • delta : (num) the amount of increase/decrease (can be negative)
# LuaCharacter:modify_sanity (delta)

Modifies this character's sanity.

Parameters:
  • delta : (num) the amount of increase/decrease (can be negative)
# LuaCharacter:modify_karma (delta)

Modifies this character's karma.

Currently only has an effect if the character is the player.

Parameters:
  • delta : (num) the amount of increase/decrease (can be negative)
# LuaCharacter:modify_corruption (delta)

Modifies this character's ether corruption.

Currently only has an effect if the character is the player.

Parameters:
  • delta : (num) the amount of increase/decrease (can be negative)
# LuaCharacter:make_pregnant ()

Makes this character pregnant.

Only has an effect if the character is not already pregnant.

# LuaCharacter:eat_rotten_food ()

Applies the effects of eating rotten food to this character.

# LuaCharacter:vanquish ()

Deletes this character and removes it from the map.

The character will no longer be valid for use.

# LuaCharacter:act_hostile_against (target)

Applies the effects of acting hostile towards a target character.

Parameters:
# LuaCharacter:refresh ()

Refreshes this character, reapplying bonuses given by equipment.

# LuaCharacter:refresh_burden_state ()

Refreshes the burden state of this character.

Only valid if called on the player. Call this method if the character's inventory changes so the weight can be reapplied.

# LuaCharacter:move_to (x, y)

Moves this character to a new position.

Parameters:
  • x : (num)
  • y : (num)
# LuaCharacter:move_to (pos)

Moves this character to a new position.

Parameters:
# LuaCharacter:switch_religion (god_id)

Changes the worshipped god of this character without invoking the god switching penalty.

Parameters:
  • god_id : (string) ID of type core.god.
# LuaCharacter:get_ailment (ailment)

Returns the duration of an ailment on this character.

Parameters:
  • ailment : (StatusAilment)
Returns:
  • (num)