1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-11-13 05:50:17 +01:00

add particle effect global function, arrow lifetime, api.txt update

This commit is contained in:
tenplus1 2020-06-20 10:07:32 +01:00
parent 245128f9e6
commit ec122aa6de
2 changed files with 41 additions and 6 deletions

22
api.lua
View File

@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20200619",
version = "20200620",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}
}
@ -645,7 +645,14 @@ local effect = function(pos, amount, texture, min_size, max_size,
max_size = max_size or 1
gravity = gravity or -10
glow = glow or 0
fall = fall and 0 or -radius
if fall == true then
fall = 0
elseif fall == false then
fall = radius
else
fall = -radius
end
minetest.add_particlespawner({
amount = amount,
@ -665,6 +672,12 @@ local effect = function(pos, amount, texture, min_size, max_size,
})
end
function mobs:effect(pos, amount, texture, min_size, max_size,
radius, gravity, glow, fall)
effect(pos, amount, texture, min_size, max_size, radius, gravity, glow, fall)
end
-- update nametag colour
function mob_class:update_tag()
@ -3862,6 +3875,7 @@ function mobs:register_arrow(name, def)
drop = def.drop or false, -- drops arrow as registered item when true
collisionbox = def.collisionbox or {-.1, -.1, -.1, .1, .1, .1},
timer = 0,
lifetime = def.lifetime or 4.5,
switch = 0,
owner_id = def.owner_id,
rotate = def.rotate,
@ -3876,11 +3890,11 @@ function mobs:register_arrow(name, def)
on_step = def.on_step or function(self, dtime)
self.timer = self.timer + 1
self.timer = self.timer + dtime
local pos = self.object:get_pos()
if self.switch == 0 or self.timer > 150 then
if self.switch == 0 or self.timer > self.lifetime then
self.object:remove() ; -- print("removed arrow")

25
api.txt
View File

@ -293,7 +293,8 @@ enhance mob functionality and have them do many interesting things:
'custom_attack' when set this function is called instead of the normal mob
melee attack, parameters are (self, to_attack) and if true
is returned normal attack function continued.
'on_die' a function that is called when mob is killed (self, pos)
'on_die' a function that is called when mob is killed (self, pos), also
has access to self.cause_of_death table.
'do_custom' a custom function that is called every tick while mob is
active and which has access to all of the self.* variables
e.g. (self.health for health or self.standing_in for node
@ -387,6 +388,24 @@ true the mob will not spawn.
'name' is the name of the animal/monster
Particle Effects
----------------
mobs:effect(pos, amount, texture, min_size, max_size, radius, gravity, glow, fall)
This function provides a quick way to spawn particles as an effect.
'pos' center position of particle effect.
'amount' how many particles.
'texture' texture filename to use for effect.
'min_size' smallest particle size.
'max_size' largest particle size.
'radius' how far particles spread outward from center.
'gravity' gravity applied to particles once they spawn.
'glow' number between 1 and 15 for glowing particles.
'fall' when true particles fall, false has them rising, nil has them scatter.
Making Arrows
-------------
@ -422,7 +441,9 @@ This function registers a arrow for mobs with the attack type shoot.
'on_step' is a custom function when arrow is active, nil for
default.
'on_punch' is a custom function when arrow is punched, nil by default
'collisionbox' is hitbox table for arrow, {0,0,0,0,0,0} by default.
'collisionbox' is hitbox table for arrow, {-.1,-.1,-.1,.1,.1,.1} by default.
'lifetime' contains float value for how many seconds arrow exists in
world before being removed (default is 4.5 seconds).
Spawn Eggs