mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-25 03:51:05 +01:00
5.8 KiB
5.8 KiB
Projectiles API
vl_projectile.register(entity_name, def)
Registers a projectile entity.
Arguments:
entity_name
: The name the entity will be refered to by the minetest enginedef
: Projectile defintion. Supports all fields that standard minetest entities support. Must include the field_vl_projectile
for projectile-specific behaviors. These are the supported fields:ignore_gravity
: if true, the projectile will not be affected by gravityliquid_drag
: if true, apply drag from liquid nodes to the projectilesurvive_collision
: if this field isfalse
ornil
, the projectile will be removed after a collision.sticks_in_players
: if true, the projectile will stick into players after colliding with them.damages_players
: if true, the projectile will deal damage to players.damage_groups
: damage group information to use forpunch()
. May be a function of typefunction(projectile, entity_def, projectile_def, obj)
that returns dynamic damange group information.allow_punching
: will the projectile punch entities it collides with. May be either a boolean or a function of typefunction(projectile, entity_def, projectile_def, obj)
.survive_collision
: will the projectile surive collisions. May be either a boolean or a fnction of typefunction(projectile, entity_def, projectile_def, type, ...)
.- If
type
is "node" then the additional parametersnode, node_def
will be provided. - If
type
is "entity" then the additional parameterobjet
will be provided.
- If
behaviors
: a list of behavior callbacks that define the projectile's behavior. This mod provides the following behaviors:vl_projectiles.collides_with_solids
,vl_projectiles.collides_with_entities
andvl_projectiles.raycast_collides_with_entities
maximum_time
: number of seconds until projectiles are removed.sounds
: sounds for this projectile. All fields take a table with three parameters corresponding to the three parameters forminetest.play_sound()
. Supported sounds are:on_collision
: played when no other more specific sound is defined. May be a function of typefunction(projectile, entity_def, projectile_def, type, ...)
on_solid_collision
: played when the projectile collides with a solid node. May be a function of typefunciton(projectile, entity_def, projectile_def, type, pos, node, node_def)
withtype = "node"
on_entity_collision
: played when the projectile collides with another entity. May be a function of typefunction(projectile, entity_def, projectile_def, type, entity)
withtype = "entity"
on_collide_with_solid
: callback of typefunction(projectile, pos, node, node_def)
used when the projectile collides with a solid node. Requiresvl_projectile.collides_with_solids
inbehaviors
list.on_collide_with_entity
: callback of typefunction(projectile, pos, obj)
used when the projectile collides with an entity. Requiresvl_projectile.collides_with_entities
inbehaviors
list.
vl_projectile.update_projectile(self, dtime)
Performs standard projectile update logic and runs projectile behaviors.
Arguments:
self
: The lua entity of the projectile to updatedtime
: The amount of time that has passed since the last update. Nomally thedtime
parameter of the entity'son_step(self, dtime)
callback.
vl_projectile.create(entity_id, options)
Creates a projectile and performs convenience initialization.
Arguments:
entity_id
: The name the entity as passed tovl_projectile.register()
options
: A table with optional parameters. Supported fields are:dir
: direction the projectile is moving invelocity
: scalar velocity amountdrag
: scalar resistance to velocityowner
: passed thru unmodifiedextra
: passed thru unmodified
vl_projectile.replace_with_item_drop(projectile_lua_entity, pos, projectile_def)
Removes the projectile and replaces it with an item entity based on either the entity's _arrow_item
field or
the value self._vl_projectile.item
.
Arguments:
projectile_lua_entity
: the lua entity of the projectile to be replaced.pos
: the position to create the item entityprojectile_def
: The projectile's_vl_projectile
field. If not provided, it will be extracted from the projectile's lua entity.
Custom Projectile Behaviors
The projectile API supports specifying the behaviors that a projectile will exhibit. There are several standard behaviors provided with the API:
vl_projectile.burns
: projectile can be set on firevl_projectile.collides_with_solids
: handles collisions between projectiles and solid nodesvl_projectile.collides_with_entities
: handles collisions between projectiles and entities by checking nearby entitiesvl_projectile.has_tracer
: projectile will have a tracer trail when thrown/shot. Projectile can define_vl_projectile.hide_tracer = function(self)
to conditionally hide the tracer.vl_projectile.sticks
: projectile will stick into nodes. Forces_vl_projectile.sticks_in_nodes = true
and_vl_projectile.survive_collision = true
.vl_projectile.raycast_collides_with_entities
: handles collisions between projectils and entities by performing a raycast check along the path of movement.
Custom behaviors can be provided by adding a function with the signature function(self, dtime, entity_def, projectile_def)
to the list of behaviors a projectile supports.
Arguments:
self
: The lua entity of the projectiledtime
: The amount of time that has passed since the last update. Nomally thedtime
parameter of the entity'son_step(self, dtime)
callback.entity_def
: The definition fromminetest.registered_entities
for the projectile.projectile_def
: Same asentity_def._vl_projectile