2024-08-31 16:41:17 +02:00
# 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 engine
* `def` : 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:
2024-09-02 03:41:21 +02:00
* `ignore_gravity` : if true, the projectile will not be affected by gravity
* `liquid_drag` : if true, apply drag from liquid nodes to the projectile
2024-08-31 16:41:17 +02:00
* `survive_collision` : if this field is `false` or `nil` , the projectile will be removed after a collision.
* `sticks_in_players` : if true, the projectile will stick into players after colliding with them.
2024-09-08 14:06:00 +02:00
* `damages_players` : if true, the projectile will deal damage to players.
2024-08-31 16:41:17 +02:00
* `damage_groups` : damage group information to use for `punch()` . May be a function of type `function(projectile, entity_def, projectile_def, obj)`
that returns dynamic damange group information.
2024-09-24 14:00:03 +02:00
* `allow_punching` : will the projectile punch entities it collides with. May be either a boolean or a function of type `function(projectile, entity_def, projectile_def, obj)` .
* `survive_collision` : will the projectile surive collisions. May be either a boolean or a fnction of type `function(projectile, entity_def, projectile_def, type, ...)` .
* If `type` is "node" then the additional parameters `node, node_def` will be provided.
* If `type` is "entity" then the additional parameter `objet` will be provided.
2024-09-02 03:41:21 +02:00
* `behaviors` : a list of behavior callbacks that define the projectile's behavior. This mod provides the following
2024-09-02 03:53:46 +02:00
behaviors: `vl_projectiles.collides_with_solids` , `vl_projectiles.collides_with_entities` and `vl_projectiles.raycast_collides_with_entities`
2024-08-31 16:41:17 +02:00
* `sounds` : sounds for this projectile. All fields take a table with three parameters corresponding to the
three parameters for `minetest.play_sound()` . Supported sounds are:
* `on_collision` : played when no other more specific sound is defined. May be a function of type `function(projectile, entity_def, projectile_def, type, ...)`
* `on_solid_collision` : played when the projectile collides with a solid node. May be a function of type
`funciton(projectile, entity_def, projectile_def, type, pos, node, node_def)` with `type = "node"`
2024-09-02 03:41:21 +02:00
* `on_entity_collision` : played when the projectile collides with another entity. May be a function of type
2024-08-31 16:41:17 +02:00
`function(projectile, entity_def, projectile_def, type, entity)` with `type = "entity"`
* `on_collide_with_solid` : callback of type `function(projectile, pos, node, node_def)` used when the projectile collides with a solid node. Requires
`vl_projectile.collides_with_solids` in `behaviors` list.
* `on_collide_with_entity` : callback of type `function(projectile, pos, obj)` used when the projectile collides with an entity. Requires
`vl_projectile.collides_with_entities` in `behaviors` 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 update
* `dtime` : The amount of time that has passed since the last update. Nomally the `dtime`
parameter of the entity's `on_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 to `vl_projectile.register()`
* `options` : A table with optional parameters. Supported fields are:
* `dir` : direction the projectile is moving in
* `velocity` : scalar velocity amount
2024-09-02 03:51:08 +02:00
* `drag` : scalar resistance to velocity
2024-08-31 16:41:17 +02:00
* `owner` : passed thru unmodified
* `extra` : passed thru unmodified
## Custom Projectile Behaviors
2024-08-31 16:47:09 +02:00
The projectile API supports specifying the behaviors that a projectile will exhibit. There are several
standard behaviors provided with the API:
2024-10-20 20:31:29 +02:00
* `vl_projectile.burns` : projectile can be set on fire
2024-08-31 16:47:09 +02:00
* `vl_projectile.collides_with_solids` : handles collisions between projectiles and solid nodes
* `vl_projectile.collides_with_entities` : handles collisions between projectiles and entities by checking nearby entities
2024-10-20 20:31:29 +02:00
* `vl_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.
2024-10-20 22:42:00 +02:00
* `vl_projectile.sticks` : projectile will stick into nodes. Forces `_vl_projectile.sticks_in_nodes = true`
and `_vl_projectile.survive_collision = true` .
2024-08-31 16:47:09 +02:00
* `vl_projectile.raycast_collides_with_entities` : handles collisions between projectils and entities by performing a raycast
check along the path of movement.
2024-08-31 16:41:17 +02:00
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 projectile
* `dtime` : The amount of time that has passed since the last update. Nomally the `dtime`
parameter of the entity's `on_step(self, dtime)` callback.
* `entity_def` : The definition from `minetest.registered_entities` for the projectile.
* `projectile_def` : Same as `entity_def._vl_projectile`