Returns the unique number identifier for this Entity. No two
Entities have the same ID, and the ID is unchanged for its lifetime.
IDs are set as the Entity is constructed. An Entity created sooner
than another Entity will have a smaller ID, but note that this does
not necessarily denote spawn order because Entities can be created
and then spawned out of order.
Returns the String this Entity has for a name.
Sets a new name for the Entity. Enemy Character names appear in
battle, during the first card select. For other Entities, this
goes unused, but is still readable by
get_name,
and so can be acted on by scripted mods.
Returns the Entity's current
Element.
Sets a new
Element for the
Entity. Entities have a default of
Element.None
⚠️ In v2.1,
Player mods often call this in the
player_init to set the initial
Element,
but in v2.5, this should be done with
PlayerPackage.set_element
so that it appears in the Player select screen.
get_tile
(self [, dir [, count]])
Returns a
Tile relative to the
Entity,
count away in
dir Direction.
If no Tile exists at that distance in that direction, returns
nil
instead, for example if moving
count to the
dir would reach beyond the bounds of the
Field.
dir and
count are optional. If called
without either, returns the current Tile, as in
get_current_tile.
Otherwise, both args must be present.
count will be forced positive, as in cast to an
unsigned number. If a negative number is passed in, it will likely
become a very large positive number. If wanting to get a
Tile
"behind" the Entity, instead of using its
facing Direction
as the
dir with a negative
count, use the
opposite
Direction with a positive
count.
Returns the Entity's
Tile. Returns
nil if the Entity has not been
spawned.
Sets whether or not the Entity is allowed to share Tiles with other
Entities, based on share. Often checked as part of
movement processing to determine if an occupied destination
Tile can be moved to.
Returns the Entity's
Field.
This
Field is invalid if the Entity has not been
spawned. An invalid
Field
will have any function on it fail, giving a
data deleted
message.
Sets a new
Direction for the
Entity to "face". This affects whether or not their
Sprite
will be drawn flipped to face one direction or the other.
Only
Direction.Left
and
Direction.Right
are acceptable values.
If unset, an Entity will adopt their spawn
Tile's facing,
which is
Direction.Right for
Tiles that are
on the left side of the
Field (with X <= 3), and
Direction.Left for
Tiles that are on the
right side of the
Field (with X >= 4). This is usually
undesired, so call this function accordingly when creating an Entity.
Because perspective flips for players based on
Team,
keep in mind that "player 2" will visually be looking to the right
on their screen, but their facing is
Direction.Left.
Because of this, it's most common and recommended to call
set_facing
with a
Direction relative to the related Entity. For
example, when creating a
Spell
during an attack performed by an
Entity, almost all use
cases would call
set_facing for that
Spell
while passing in the return value of
get_facing, as in
function create_attack(user)
local spell = Battle.Spell.new(user:get_team())
spell:set_texture(tex)
spell:set_facing(user:get_facing())
end
Returns the
Direction that
the Entity is "facing". Often used by scripted mods to determine
a direction to move in, or to
set_facing
on another related Entity.
Utility function that returns the
Direction
set by
set_move_direction.
Direction.None by default.
Unused internally, so its usage is entirely determined by scripted
content. May be used to learn that this Entity is currently moving
in a particular direction.
Utility function that sets a
Direction
to be read by
get_move_direction.
Unused internally, so its usage is entirely determined by scripted
content. May be used to tell other mods that this Entity is
currently moving in a particular direction.
Sets a height in
pixels to draw the Entity. Differs from offsets in several
ways:
- Positive
elevation goes up, and negative goes down
- The Entity's sprite moves, but its
shadow
stays on the ground
Useful when scripting the appearance of moving upwards, like during
a jump, because the shadow is left on the ground.
Returns the value set by
Entity.set_elevation.
0.0 by default. A positive number indicates that the
Entity is drawn above the ground by that many pixels.
Offsets the Entity by
x half pixels horizontally and
y half pixels vertically, relative to the screen position
of its
Tile.
Because every
1 unit is a
half pixel, multiply your
desired offset by
2. The reason for
half pixels is
because the game's screen is actually upscaled by
x2.
Positive
x
moves to the right, and positive
y moves down. The
offset is stored and replaced by a subsequent call, so
Entity:set_offset(0, 0) will reset the offset.
Perspective flipping causes a
Team.Blue player to see
positive
x visually move left instead of right, as
everything is flipped. Because of this, it's common in most use
cases to make
x positive or negative based on a related
Direction.
For example, consider an
Artifact that should be
spawned on an Entity's
Tile, offset to appear visually
behind them. The offset can be flipped to always point behind them.
function create_attack(user)
local spell = Battle.Spell.new(user:get_team())
spell:set_texture(tex)
local facing = user:get_facing()
spell:set_facing(facing)
-- 10 pixels backwards
local x_off = -10
-- Flip if facing Left, so that x_off is still "backwards" relative to facing
if facing == Direction.Left then
x_off = x_off * -1
end
spell:set_offset(x_off, 0)
end
If trying to visually move vertically, consider if
set_elevation
would be better.
Returns the Entity's current offset as a
vec2, as set by
Entity.set_offset.
Often used when tracking the Entity's previous offset to restore
after a temporary offset change, or to add to the the offset of a
graphical effect that is meant to be near the Entity's visual
position.
Not to be confused with
get_tile_offset,
which returns the visual offset away from the current
Tile, and is a separate value.
Returns the Entity's current offset from its
Tile as a
vec2.
The tile offset is not set by any Lua function. Instead, it
represents movement, and is set as a
MoveEvent progresses.
Often used alongside
get_offset
to add to the the offset of a graphical effect that is meant to be
near the Entity's visual position. Not to be confused with
get_offset,
which returns the sprite offset away from the parent origin, and is
a separate value.
Returns the Entity's Sprite
Node.
Note that while `Node` has some functions with similar names and utility
to the Entity, they sometimes act differently.
Tells the Entity to stop drawing. It will become invisible. Calliing
this again while already hidden will do nothing.
Tells the Entity to draw. It will become visible if it was hidden
(see
hide. Calling this
again while already visible will do nothing.
Note that this is a different name from
Node.show,
despite having similar functionality.
Toggles whether or not to allow the Entity's sprite to be drawn
flipped. If toggle is false, disallows flipping based
on facing and perspective flip.
set_shadow
(self , shadow_type)
Sets the Shadow for the Entity. Hidden unless
show_shadow reveals
it.
shadow_type can be a
Shadow
or a
Texture. Because there is no associated animation
file for a
Texture input, the center of the image is
used as the origin.
Shadows draw beneath other Entities, and appear on the "floor". If
the Entity is
offset,
the Shadow mimics the offset. If the Entity is
elevated,
the Shadow stays on the ground.
Sets a
Texture to use to color the pixels in the
Entity's sprites. If calling this for the first time because a
"default" palette is being set for a Player, it's recommended to
also call
store_base_palette.
A palette is a 256x1 image where each pixel is a color that will
be used to color in corresponding pixels in the Entity's
Texture.
To use the palette properly, the image used for the Entity's
Texture should be greyscaled. RGB 0,0,0 in the Entity's
Texture will be colored using the color of the pixel at
(0,0) (transparency is recommended here).
RGB 1,1,1 will use the color of the pixel at
(1,0), and so on.
Returns the
Texture set by
set_palette.
This will be
nil if no palette has been set.
Sets a value for the Entity's height. This does not necessarily
need to match the height of its visible sprite, and often should
be taller than that.
Used by the engine for sizing and positioning various effects,
including the visual effects for the Freeze status. It's also used
in calculating the fallback position of the visual effects for the
Confusion and Blind statuses, if there is no "HEAD"
animation point to use in calculation instead.
For Players, this is used to position selected cards.
Registers a
Component for the
Entity. If the Entity is currently in the middle of updating, the
Component is instead queued to be added when its update is finished.
Creates a new
Node, adds it to
the Entity, and returns it. This
Node is anchored at
the origin in the Entity's animation state.
Sets the Texture to be used when drawing this Entity.
Returns the Texture currently used by the Entity to
draw.
q ⚠️ v2.5 only
Returns the Entity's Sprite
Node.
Note that while `Node` has some functions with similar names and utility
to the Entity, they sometimes act differently.
Sets the path for the animation file used for the Player's battle
sprites. Associated with the
Texture set by
set_texture
⚠️ Removed in v2.5. Instead, use
Animation.load,
as in
player:get_animation():load(path)
Returns the
Animation object
used by this Entity.
Sets
Animation keyframes that
will toggle on and off counterability.
Does nothing if
keyframe_start is greater than
keyframe_end, or if either value is less than 1. If
both are the same value, 1 is added to
keyframe_end.
This is essentially a shortcut function for
local anim = char:get_animation()
-- Assume keyframe_start and keyframe_end are defined as numbers
anim:on_frame(keyframe_start, function()
char:toggle_counter(true)
end)
anim:on_frame(keyframe_end, function()
char:toggle_counter(false)
end)
Because this is tied to the current
Animation state, anything that
invalidates frame callbacks, such as a call to
Animation.set_state, will
also prevent these toggles from running if they have yet to run.
Causes the Entity's
Tile to highlight with the
Highlight mode.
This highlight is checked during
Spell updates, so it's
common that the
Tile will not react on the frame an
an Entity calls this, or the frame an Entity is spawned
Unlike
Tile.highlight,
which is for a single, targeted
Tile and lasts for
a single frame, this always highlights the Entity's current
Tile until called with
Highlight.None (or the
Entity is removed from the
Field).
Returns the Entity's
Context object, which includes
information such as its ID. Its fields are unreadable from Lua,
and is mostly used as part of constructing
HitProps, which will set the
Hitprops.aggressor
to the ID in the
Context.
If the Entity has not yet executed a
CardAction, the
Context will not have an aggressor set. This is unusual
to worry about, however, as hitboxes are almost always created
during a
CardAction.
Returns the Entity's
HitProps
object, as set by
set_hit_props.
Often used when inspecting an attacker's
HitProps inside
a
DefenseRule.can_block_func
in order to react to the damage, flags, element, or aggressor for
the attack.
Because this is a copy, modifications to the return value will not
affect the
HitProps on the Entity. Use
set_hit_props afterwards with the modified copy to do
this.
Sets the Entity's
HitProps.
Often used when creating
Spells or
Obstacles
that will attempt attacks as part of their scripted logic.
Less commonly, this is also used during a
DefenseRule.can_block_func
in order to modify the
HitProps of an incoming attack.
If doing this, keep in mind that
HitProps are treated
somewhat differently during defense checks. Their
HitProps
are temporarily modified to include the
Hit.Cancel flag, and the
attacker's original
HitProps will be restored
afterwards.
Sets the
Color to draw the Entity
wit this frame. Influenced by the set
ColorMode.
Unlike other nodes, an Entity's coloring will only last a single
frame, resetting at the start of its update.
Returns the
Color that the
Entity will be drawn with this frame.
Sets the Entity's health. Cannot be set to a negative number, and
cannot exceed the Entity's max health. If max health is 0, max
health will be set to
health.
If an Entity has a nonzero max health, and their health is 0 at
the start of their update, they call
delete
automatically.
For
Obstacles only, passing a
health value
of 0 causes
delete to be called immediately.
Returns the Entity's current health as a number.
Returns the Entity's current max health as a number.
Note that there is no
set_max_health. Max health is
instead set through the Entity's first call to
set_health.
Enables or disables the float shoe ability. When enabled, the Entity
avoids certain negative
TileState effects:
- Does not cause
Cracked Tiles to become Broken when stepping off them
- Will not be forced to move by
Ice Tiles
- Does not trigger damage from
Lava Tiles
- Does not take damage from
Poison Tiles
- Will not be forced to move by any of the
Direction* Tiles
- Will not be afflicted by Root when stepping on
Sea Tiles
- Will not be afflicted by Root when stepping on
Sand Tiles
Enables or disables the air shoe ability. When enabled, the Entity
is allowed to move onto
Broken Tiles.
For non-Players, the Entity's
can_move_to_func
takes priority.
Adds a
DefenseRule to the
Entity. If the
rule's priority matches an existing
added
DefenseRule, the previous one is removed before
the new one is added.
⚠️ In v2.5, replacing another
DefenseRule will trigger
its
DefenseRule.on_replace_func.
Removes the
DefenseRule
rule from the Entity. If
rule has already
been removed or otherwise is not on the Entity, does nothing.
Toggles whether or not the Entity should ignore attacks whose
HitProps.aggressor
matches the Entity's own
HitProps.aggressor.
This could be useful, for example, in the scenario that one Entity
creates two Obstacles that are able to attack each other, such as if
they are opposing
Teams or
Team.Other, but they should
avoid attacking each other regardless. If they both ignore Entities
with the same aggressor, they will not attack each other.
Tells the Entity to call
callback whenever the
Hit flag
flag is
processed. These flags are processed at the start of the Entity's
update, so hits that occur during time freeze will not activate
any callbacks until after time resumes.
flag must be a single
Hit flag, not a
combination of them. If it is a combination of flags, it will never
be run.
Hit.None will similarly
never be processed.
Attempting to add a second callback for a flag will result in the
previous callback being replaced by the new one. Because of this,
it's recommended to only use this function on Entities created by
your own mods, so that calling this doesn't compromise any
functionality.
set_hurt_sfx
(self , audio [, priority])
Sets the SFX to play when the Entity is damaged
1 by an attack with
the
Hit.Impact flag. The SFX
set by a call to this function will not be used unless enabled in
a call to
use_default_hurt_sfx.
audio can be a
loaded audio file,
an
AudioType, or
nil. If
nil is passed in, no sound will play when taking damage.
priority is the
AudioPriority
for the SFX to play at. If not provided, defaults to the
AudioPriority
last set by this function, or, if this has not been called before,
defaults to
AudioPriority.Low.
Typically called by the Player mod itself in its
player_init,
rather than other scripted mods. Attacks or other things that want
to alter the SFX temporarily should consider using
DefenseFrameStateJudge.set_hit_sfx
instead.
1. "Taking damage" means an attack passed all DefenseRules
without being blocked, and dealt more than 0 damage
Returns the SFX that the Entity is currently using to play when it
takes damage. This takes
use_default_hurt_sfx
into account, and returns the default SFX instead of any custom
SFX set by
set_hurt_sfx if the
default is being used.
Can return
nil if that is the current set SFX. This is
normal, and all functions which use an SFX object can safely accept
nil.
Whether or not the default hurt SFX or the custom hurt SFX set by
set_hurt_sfx
should play when this Entity takes damage.
teleport
(self , dest [, order [, on_begin]])
Creates and queues a preconfigured
MoveEvent
for a "teleport" movement. The event will have the following
properties:
In short, the movement will complete instantly when starting, unless
the Entity moving is a Player.
If provided,
order is the
ActionOrder
the event will be queued with
(
Voluntary by
default), and
on_begin is a function to be called if the
movement starts, when it starts. Because queuing the movement is no
guarantee that it will happen, the
on_begin can be a
good way to react to it happening.
Returns
true if the Entity is able to reach
dest
at the time this is called. This is not a guarantee that it will still
be reachable when movement tries to begin, nor a guarantee that the
movement will succeed, or even start. Internally, the return value
is based on a call to
can_move_to_func.
If
false is returned, the movement is not added to the
queue.
slide
(self , dest , slide_time [, endlag [, order [, on_begin]]])
Creates and queues a preconfigured
MoveEvent
for a "slide" movement. The event will have the following
properties:
In short, the movement will visually slide to the destination,
without any starting delay.
If provided,
order is the
ActionOrder
the event will be queued with
(
Voluntary by
default), and
on_begin is a function to be called if the
movement starts, when it starts. Because queuing the movement is no
guarantee that it will happen, the
on_begin can be a
good way to react to it happening.
Returns
true if the Entity is able to reach
dest
at the time this is called. This is not a guarantee that it will still
be reachable when movement tries to begin, nor a guarantee that the
movement will succeed, or even start. Internally, the return value
is based on a call to
can_move_to_func.
If
false is returned, the movement is not added to the
queue.
jump
(self , dest , dest_height , jump_time [, endlag [, order [, on_begin]]])
Creates and queues a preconfigured
MoveEvent
for a "jump" movement. The event will have the following
properties:
In short, the movement will visually jump to the destination,
without any starting delay. The Entity will be elevated to a height
of
float_height by the time the movement is half over,
at which point it begins descending in a smooth parabola.
If provided,
order is the
ActionOrder
the event will be queued with
(
Voluntary by
default), and
on_begin is a function to be called if the
movement starts, when it starts. Because queuing the movement is no
guarantee that it will happen, the
on_begin can be a
good way to react to it happening.
Returns
true if the Entity is able to reach
dest
at the time this is called. This is not a guarantee that it will still
be reachable when movement tries to begin, nor a guarantee that the
movement will succeed, or even start. Internally, the return value
is based on a call to
can_move_to_func.
If
false is returned, the movement is not added to the
queue.
Attempts to queue a movement using a fully configured
MoveEvent..
Unlike the functions that create configured events, this function
requires
order, which is the
ActionOrder the event will
be queued with.
Returns
true if the Entity is able to reach the evebt's
destination at the time this is called. This is not a guarantee that
it will still be reachable when movement tries to begin, nor a
guarantee that the movement will succeed, or even start. Internally,
the return value is based on a call to
can_move_to_func.
If
false is returned, the movement is not added to the
queue.
Returns
true when all of the following are true:
- The Entity is currently processing a
MoveAction
- The current
MoveAction has a nonzero height
- The current
MoveAction has a nonzero deltaframes
Returns
true when all of the following are true:
- The Entity is currently processing a
MoveAction
- The current
MoveAction has height of 0
- The current
MoveAction has a nonzero deltaframes
Returns
true when all of the following are true:
- The Entity is currently processing a
MoveAction
- The current
MoveAction has height of 0
- The current
MoveAction has deltaframes of 0
In other words, a MoveEvent that finishes its movement instantly
is a teleport. Because the deltaframes is 0, is_teleporting often
returns false, as the move finishes almost instantly. Most likely
to return
true if the movement also has delayframes or
endlag.
Returns
true if the Entity is currently intangible,
otherwise
false. Currently unused in v2.1, so the
return value will never be useful. In some cases where you would
want to check intangibility, consider checking
is_flashing.
Checks whether or not the Entity is maked deleted, and returns
the answer.
A deleted Entity can be one of two things:
- An Entity that has been marked for removal by a call to
delete
- An Entity that has had its memory freed, likely because it was
cleaned up after having been marked for removal
In both cases, the Entity should be considered unfit to act on. In
the second case, attempting to call functions on the deleted Entity
will result in an error saying
data deleted.
Check this or
will_erase_eof
when working with an Entity across multiple frames. For
example, if you collect an Entity through
Field.find_characters
and keep a reference to it, and your code still makes use of its
reference next frame, the Entity may have been deleted by then. Check
this to make sure no errors happen.
Checks whether or not the Entity is marked as erased, and returns
the answer. An erased Entity can be one of two things:
- An Entity that has been marked for erasure by a call to
erase
- An Entity that has had its memory freed, likely because it was
cleaned up after having been marked for removal
In both cases, the Entity should be considered unfit to act on. In
the second case, attempting to call functions on the erased Entity
will result in an error saying
data deleted.
Check this or
is_deleted
when working with an Entity across multiple frames. For
example, if you collect an Entity through
Field.find_characters
and keep a reference to it, and your code still makes use of its
reference next frame, the Entity may have been erased by then. Check
this to make sure no errors happen.
Checks if the Entity is considered a teammate to
team.
Returns
true if one of the following is true:
- The Entity is
Team.Other
team is Team.Other
- The Entity is the same
Team as team
In summary,
true if
Team.Other is involved
or the Entity is the same
Team as the input, else
returns
false.
It's common that
Team checks want to target exactly
a single
Team to denote real allies, or they target
exactly not the Entity's
Team. If this is the case,
use
get_team and compare
to one
Team instead.
Sets the Entity's
Team to
team. There is often no need to call this, as
most Entity types must be provided a
Team during
construction.
Most use cases would pass in either
Team.other
or the returned value from of a call to
get_team.
This ensures the
Team is set relative to some other
Entity, which is important when considering that the user of an
effect could be on any
Team.
Players default to the same
Team as the
Tile they spawn on. This is
the same for
Characters spawned
by a
Mob.
If the local
Player changes
Team, the
perspective may flip to accommodate.
Returns the Entity's current
Team.
The return value is often used to check for enemies or allies, to
use as input to
set_team,
or to construct Entity types that require a
Team during
construction.
Marks the Entity as erased, which prepares it to be removed. It will
be removed after its
Tile updates. See
will_erase_eof.
If an Entity is removed in this way, its
delete_func will not
run. Because of this, it's common to only call this for Entities which
do not have any
delete_func set. Often when affecting
Entities not created by the mod which calls this, you don't know if
they have a
delete_func set. It's recommended to instead
call
delete in this scenario,
so that the other mod may handle anything it needs to.
Marks the Entity as deleted, which prepares it to be removed. It will
be removed after its
Tile updates. See
is_deleted.
If it has not already run, the Entity's
delete_func will be
called immediately. Because this could let Entities clean up more
smoothly, it's recommended to call this when working with Entities
that you don't know have a
delete_func set or not.
Unlike
erase, the
Entity will still be drawn on the frame this is called. If you need
the benefits of
delete but want the visibility of
erase, simply call
hide
afterwards, which will prevent the Entity from drawing this frame.
Enables or disables the Entity's ability to be hit.
Toggling
false will cause the Entity to skip all
attack checks. Attacks made against the Entity will not check any
DefenseRules, will not
make collision, and will not deal damage. Toggling
false
multiple times will do nothing.
Toggling
true while the hitbox is disabled will re-enable
all of the above behavior, or do nothing if it was not already
disabled.
Recommended to be used alongside
hide,
to mimic the Entity being "off the field" and unable to be targeted
or attacked.
Tile.remove_entity_by_id
can also accomplish this, but with the caveat that the Entity's
update_func will not
run, which can be more difficult to work with. There are cases where
you want an Entity to be targetable but take no damage and/or have no
collision. These cases can instead be solved using
DefenseRules.
⚠️ In v2.5, toggling
false will also prevent the Entity
from being returned by any search for Entities, for example by
Field.find_nearest_characters
or
Tile.find_obstacles.
Whether or not the Entity is currently able to be countered. If the
Entity is counterable, they will be countered if hit by an attack
with all of the following properties:
An attack that meets the above criteria and causes a counter will
add the
Hit.Counter flag to
be processed, which will add a 150f
Hit.Stun
and remove
Hit.Flash from the
flags to be applied.
If the
HitProps.aggressor of an attack that counters
was a Player, that Player will enter the
FullSynchro
Emotion. A local Player in the
FullSynchro Emotion will see a
counterable Entity flash blue.
Toggle Whether or not the Entity is currently able to be countered. If the
Entity is counterable, they will be countered if hit by an attack
with all of the following properties:
An attack that meets the above criteria and causes a counter will
add the
Hit.Counter flag to
be processed, which will add a 150f
Hit.Stun
and remove
Hit.Flash from the
flags to be applied.
If the
HitProps.aggressor of an attack that counters
was a Player, that Player will enter the
FullSynchro
Emotion. A local Player in the
FullSynchro Emotion will see a
counterable Entity flash blue.
Whether or not the Entity is currently afflicted by the
Bubble status. See
Hit.Bubble.
Whether or not the Entity is currently afflicted by the
Drag status. See
Hit.Drag.
Whether or not the Entity is currently afflicted by the
Blind status. See
Hit.Blind.
Whether or not the Entity is currently afflicted by the
Confuse status. See
Hit.Confuse.
Whether or not the Entity is currently afflicted by the
Stun status. See
Hit.Stun.
Whether or not the Entity is currently afflicted by the
Freeze status. See
Hit.Freeze.
Whether or not the Entity is currently afflicted by the
Root status. See
Hit.Root.
shake_camera
(self , power , duration)
Requests that the camera shake with the given power and duration.
The shake starts with power and gradually weakens over
the duration.
Does nothing if the camera is in the middle of another shake.
Function to run when the Entity updates, which is generally one time
per frame. Used as a place for logic which must do something every
frame. Note that this also runs once when the Entity first spawns,
because it didn't get to run earlier in the frame, as it was not
spawned yet.
Does not run if the Entity is stunned, frozen, or bubbled. If it's
necessary that your logic run even in these circumstances, consider
registering a
Component with
Lifetimes.Local instead.
This also does not run if the Entity is time frozen, because the
Entity does not update at all if time frozen.
When the set function is called, it will receive two parameters,
which are the Entity that is updating, and an extra value known as
"delta time", or
dt. The Entity parameter will match
the type of the Entity; for example, it will be a
ScriptedPlayer if the Entity is a
ScriptedPlayer.
dt will always be equal to
a float representation of 1/60. There is no use in including or
reading this value, as tracking time through an incremented integer
will always be more precise and easier to handle.
⚠️ In v2.5, the
dt parameter will be removed, which is
another reason to not use it.
Function to run when checking if the Entity is allowed to move to a
given
Tile. The engine will call this during movement
to check that a destination can be moved to, and will pass in the
Tile to be tested as a parameter. Most notably used in
teleport,
teleport, and
teleport to determine the
return value, and if the movement should proceed.
If the function returns false, that means the given
Tile
should not be moved to. If this is unset, the default value for all
move checks will be
false. It's common to want certain
Entities, such as Spells, to ignore all movement restrictions, which
can be done by setting this to a function that always returns
true.
Function to run when the Entity is spawned for the first time. Often
used as initial setup for certain variables that require a
Tile or Field on the Entity, which are
unset before spawning.
When the set function is called, it will receive two parameters,
which are the Entity that spawned, and the Tile Tile it
spawned on. This Entity parameter will match the type of the Entity;
for example, it will be a ScriptedPlayer if the Entity
is a ScriptedPlayer.
Function to run when the Entity is deleted. Specifically, it will be
called immediately when
delete is called. This
is often used for effects that go with deletion, such as spawning
explosions. It's also used to do cleanup, such as removing related
Entities or signaling progress in an attack, but it's safer to use
other functions for important logic that should never be skipped.
erase will remove the Entity
without causing this function to be called. Use other callbacks,
like
Field.callback_on_delete
or
Field.notify_on_delete
for logic that absolutely must happen.
When the set function is called, it will receive one parameter,
which is the Entity that is deleting. This parameter will match the
type of the Entity; for example, it will be a
ScriptedSpell if the Entity is a
ScriptedSpell.
Note: This is not present on scripted player objects!
Function to run when the battle sends the signal that it has ended.
Typically used to clean up things that should no longer be around
while the battle results appear or the screen fade out, or to
block scripted logic that would create new attacks during that time.
When the set function is called, it will receive one parameter,
which is the Entity that received the signal. This parameter will
match the type of the Entity; for example, it will be a
ScriptedPlayer if the Entity is a ScriptedPlayer.
Function to run when the battle sends the signal that battle has
begun. The signal is sent when the Card Select battle state
finishes. The set function will also run immediately when the
Entity spawns if it was spawned after battle started.
Typically used to set up data that will be used by the Entity
during battle.
When the set function is called, it will receive one parameter,
which is the Entity that received the signal. This parameter will
match the type of the Entity; for example, it will be a
ScriptedPlayer if the Entity is a ScriptedPlayer.
Function to run when an attack made by the Entity makes collision
with another Entity. This is a step signifying that something was
hit, but it's still unsure if damage will be done. See
attack_func for that.
Often used to spawn graphic effects that signify
the hit, and to delete the Entity so that it stops attacking now that
it has hit. It's common to read the given
DefenseFrameStateJudge
to see if graphics are suggested to spawn or not. See
DefenseFrameStateJudge.hint_spawn_gfx
When the set function is called, it will receive three parameters,
which are the Entity this callback belongs to, the
Entity
that was collided with, and the
DefenseFrameStateJudge
overseeing the attack. The first parameter will match the type of
this Entity; for example, it will be a
ScriptedSpell if
the Entity is a
ScriptedSpell.
Function to run when an attack made by the Entity deals damage to
another Entity. This is a step signifying that the attack passed
all defense checks on the target without being
blocked, which
means that the actual damage taken may have been 0, but it did hit.
Commonly used to apply effects that shouldn't happen when an attack
only makes collision and is blocked (e.g. blocked by a barrier or
shield), such as applying an HP bug.
It's uncommon to do things like deleting the attacker here or creating
graphic effects for the hit. These are usually done in the
collision_func instead.
When the set function is called, it will receive three parameters,
which are the Entity this callback belongs to, the
Entity
that was collided with, and the
DefenseFrameStateJudge
overseeing the attack. The first parameter will match the type of
this Entity; for example, it will be a
ScriptedSpell if
the Entity is a
ScriptedSpell.
new
(team , rank)
Returns a newly-created ScriptedCharacter, with
team
and
rank as its Team
and Rank, respectively.
It's not common to create a Character in this way, as they are usually
instead created and spawned by a Mob.
Sometimes a Character might be spawned in the middle of combat, which
is where this comes in.
from
(self , entity)
Attempts to convert the given entity to a Player.
If successful, returns a reference to the entity as
a Player. Otherwise, returns nil. Use this when
a callback or engine function gives back an Entity or Character, but
you need a function that only exists on Player.
Expect nil when the underlying type of
entity is Artifact, Spell, or Obstacle.
If entity is already explicitly Player, returns a
ScriptedPlayer.
from_package
(self , uuid , team , rank)
Finds a Character defined with
uuid as its UUID,
and calls its associated script. If the script is found and properly
executed, returns a Character created from that script, with
team and
rank as its
Team and
Rank,
respectively. If not found, an error is raised.
The uuid should not be the UUID of a Mob package,
which creates Characters but is not the Character itself. Instead,
it is the UUID passed into
Engine.define_character
that declared a UUID and script for a Character.
It's not common to create a Character in this way, as they are usually
instead created and spawned by a Mob.
Sometimes a Character might be spawned in the middle of combat, which
is where this comes in.
This function is a relic of v1.0. Does nothing as of v2.0.
Queues the given
CardAction
action with the
ActionOrder
order. The queued CardAction will remain queued until
either it is performed, or the queue is cleared, such as a result of
Hit.Cancel and related
statuses.
Does not guarantee that
action will be executed. Another
action may queue ahead of it, or it may be removed before executing.
Returns
true if the Character is currently able to
perform actions, otherwise
false. If returning false,
expect any CardActions added by
card_action_event
to be performed later than expected.
It's sometimes recommended to check this alongside
Entity.is_moving to
determine whether or not
card_action_event should be
called, to comply with other expectations around action queuing.
For example:
player.update_func = function(self)
-- If moving or can't attack, the player won't do the action immediately
if self:is_moving() or not self:can_attack() then
return
end
if self:input_has(Input.Pressed.Left_Shoulder) then
self:card_action_event(make_shoulder_action(self), ActionOrder.Voluntary)
end
end
Expect
false under these cases for Characters:
- The Character is already processing a
CardAction
- The Character is stunned, frozen, bubbled, or dragged
- The Character is a Player and is flinching
Notice that movement is not part of this list, despite movement
delaying other actions queued behind it. This is to allow for
queuing during movement. If this is not desired, then follow the
above code snippet and check for movement at the same time.
Returns the
Rank used to create this
Character.
Specifies the number and speed of explosions to spawn while the
Character is deleting. If as_boss is true,
some extra graphic effects are added in to look more spectacular, as
if this is a boss exploding. speed will be used as the
playback speed, so consider 1.0 to be the default, and
2.0 to be twice as fast.
Function to run when the Character is
countered. Note that this will
run before statuses for attacks have been finalized, so calls to
can_attack,
Entity.is_bubbled, and
so on may give different results than if they were called later,
such as in the
Entity.update_func.
When the set function is called, it will receive one parameters,
which is the Character that was countered.
Creates a new
SyncNode and
returns it. The SyncNode will be "attached" to the point
point.
SyncNodes automatically change animation state to match the parent's.
If the current keyframe of its animation state has no point with the
label
point, the SyncNode will appear in the top-left
of the keyframe's bounding box. Make sure points are set up
appropriately.
(0,0) coordinate is the paren't top-left
corner of their frame.
Removes the
SyncNode
node from the Entity.
returns it. The SyncNode will be "attached" to the point
point.
If
node is not currently attached to the Entity,
throws an error.
Returns
true if the Player is currently cgaring their
charged_attack_func,
else
false. Continues to return
true while
fully charged.
A value of
true indicates that the charging graphic
is currently visible. In other words, the Player has held the Shoot
input for at least 10 frames in a row while being allowed to charge.
Modifies the Player's current max health by mod, a
positive or negative number. If the Player has full health, the
Player's health will also change to reflect the new max. If
changing max health by mod causes the Player's max
health to drop below their current health, their current health will
change to the new max.
Returns the cumulative health mod through all calls to
Player.mod_max_health.
For example, if
mod_max_health had been called with
a value of
50 and then
-20, returns
30.
Enables or disables slide movement. Disabled by default. When
enabled, the Player's movement inputs will do a slide instead of a
teleport, which will last for
frames
frametime duration.
Unusual to use, as all playables move normally in source material.
Returns the number of times the Player has been flinched. This number
is incremented for each time the Player is afflicted by
Flinch,
Stun,
Freeze,
Bubble,
or
Drag.
Sometimes read by attacks that increase in damage the more times the
Player has been flinched.
Creates a new
PlayerForm,
registers it, and returns it. Only 5 forms can be created this way.
If 5 forms have already been registered, throws an error instead.
Forms can only be registerd in the
player_init, before
the Player has finished being created.
Function to run when the Player uses their normal attack. This is
triggered when the Player releases the Shoot button while not fully
charged. Expects a valid
CardAction
to be returned, which will then be queued and executed a few game
frames later.
It's common to read the Player's
attack level to use in a formula
for the attack's damage.
When the set function is called, it will receive one parameter,
which is the ScriptedPlayer that is performing the attack.
Function to run when the Player uses their charged attack. This is
triggered when the Player releases the Shoot button while fully
charged. Expects a valid
CardAction
to be returned, which will then be queued and executed a few game
frames later.
It's common to read the Player's
attack level to use in a formula
for the attack's damage.
When the set function is called, it will receive one parameter,
which is the ScriptedPlayer that is performing the attack.
Function to run when the Player uses their Special attack. This is
triggered when the Player releases the Special button.
Expects a valid
CardAction
to be returned, which will then be queued and executed a few game
frames later.
It's not unusual to leave this unset in a Player mod. It's somewhat
common for Block mods to set this. When it is set, the special attack
is typically used as a sort of utility action, like creating a shield
or temporary invulnerability, with extra scripting to enforce a
cooldown.
When the set function is called, it will receive one parameter,
which is the ScriptedPlayer that is performing the attack.
Function to run when the Player decides the time it will take to
charge its
charged attack.
Called by the engine when set, and when the Player's
charge level is set.
When the set function is called, it will receive two parameters,
which are the Player that is having its charge times updated, and
the current charge level to calculate a charge time for. Expects
a return value of type
frametime,
which is the charge time to use. The returned time does not factor
in the 10f that it takes to begin charging, so a return value of
frames(1) will require 11 consecutive frames of holding
the Shoot button to be fully charged.
Remember that the
level parameter will only ever be in
the range of 1 to 5, inclusive, so cover all cases.
Example:
player.charge_time_func = function(self, level)
if level == 1 then
return frames(50)
end
if level == 2 then
return frames(40)
end
-- For every other case (level 3, 4, 5), return frames(20)
return frames(20)
end
If unset, the charge times are 90, 80, 70, 60, and 50, for levels
1 through 5. This is equivalent to the Lua function
player.charge_time_func = function(self, level)
return frames(100 - 10 * level)
end