added custom after_activate function check

This commit is contained in:
TenPlus1 2017-10-18 19:56:04 +01:00
parent f6f3b58ac6
commit ec4ba73bab
3 changed files with 37 additions and 29 deletions

11
api.lua
View File

@ -2099,9 +2099,9 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
end end
-- mob health check -- mob health check
if self.health <= 0 then -- if self.health <= 0 then
return -- return
end -- end
-- error checking when mod profiling is enabled -- error checking when mod profiling is enabled
if not tool_capabilities then if not tool_capabilities then
@ -2507,6 +2507,11 @@ local mob_activate = function(self, staticdata, def, dtime)
end end
end end
-- run after_activate
if def.after_activate then
def.after_activate(self, staticdata, def, dtime)
end
if use_cmi then if use_cmi then
self._cmi_components = cmi.activate_components(self.serialized_cmi_components) self._cmi_components = cmi.activate_components(self.serialized_cmi_components)
cmi.notify_activate(self.object, dtime) cmi.notify_activate(self.object, dtime)

View File

@ -1,5 +1,5 @@
MOB API (13th October 2017) MOB API (18th October 2017)
The mob api is a function that can be called on by other mods to add new animals or monsters into minetest. The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
@ -110,6 +110,7 @@ Custom mob functions inside mob registry:
'on_rightclick' its same as in minetest.register_entity() 'on_rightclick' its same as in minetest.register_entity()
'on_blast' is called when an explosion happens near mob when using TNT functions, parameters are (object, damage) and returns (do_damage, do_knockback, drops) 'on_blast' is called when an explosion happens near mob when using TNT functions, parameters are (object, damage) and returns (do_damage, do_knockback, drops)
'on_spawn' is a custom function that runs on mob spawn with 'self' as variable, return true at end of function to run only once. 'on_spawn' is a custom function that runs on mob spawn with 'self' as variable, return true at end of function to run only once.
'after_activate' is a custom function that runs once mob has been activated with the paramaters (self, staticdata, def, dtime)
'on_breed' called when two similar mobs breed, paramaters are (parent1, parent2) objects, return false to stop child from being resized and owner/tamed flags and child textures being applied. 'on_breed' called when two similar mobs breed, paramaters are (parent1, parent2) objects, return false to stop child from being resized and owner/tamed flags and child textures being applied.
'on_grown' is called when a child mob has grown up, only paramater is (self). 'on_grown' is called when a child mob has grown up, only paramater is (self).
'do_punch' called when mob is punched with paramaters (self, hitter, time_from_last_punch, tool_capabilities, direction), return false to stop punch damage and knockback from taking place. 'do_punch' called when mob is punched with paramaters (self, hitter, time_from_last_punch, tool_capabilities, direction), return false to stop punch damage and knockback from taking place.

View File

@ -1,5 +1,5 @@
Mobs Redo API (last updated 13th Oct 2017) Mobs Redo API (last updated 18th Oct 2017)
========================================== ==========================================
Welcome to the world of mobs in minetest and hopefully an easy guide to defining Welcome to the world of mobs in minetest and hopefully an easy guide to defining
@ -228,30 +228,32 @@ Custom Definition Functions
Along with the above mob registry settings we can also use custom functions to Along with the above mob registry settings we can also use custom functions to
enhance mob functionality and have them do many interesting things: enhance mob functionality and have them do many interesting things:
'on_die' a function that is called when the mob is killed the 'on_die' a function that is called when the mob is killed the
parameters are (self, pos) parameters are (self, pos)
'on_rightclick' its same as in minetest.register_entity() 'on_rightclick' its same as in minetest.register_entity()
'on_blast' is called when an explosion happens near mob when using TNT 'on_blast' is called when an explosion happens near mob when using TNT
functions, parameters are (object, damage) and returns functions, parameters are (object, damage) and returns
(do_damage, do_knockback, drops) (do_damage, do_knockback, drops)
'on_spawn' is a custom function that runs on mob spawn with 'self' as 'on_spawn' is a custom function that runs on mob spawn with 'self' as
variable, return true at end of function to run only once. variable, return true at end of function to run only once.
'on_breed' called when two similar mobs breed, paramaters are 'after_activate' is a custom function that runs once mob has been activated
(parent1, parent2) objects, return false to stop child from with these paramaters (self, staticdata, def, dtime)
being resized and owner/tamed flags and child textures being 'on_breed' called when two similar mobs breed, paramaters are
applied. Function itself must spawn new child mob. (parent1, parent2) objects, return false to stop child from
'on_grown' is called when a child mob has grown up, only paramater is being resized and owner/tamed flags and child textures being
(self). applied. Function itself must spawn new child mob.
'do_punch' called when mob is punched with paramaters (self, hitter, 'on_grown' is called when a child mob has grown up, only paramater is
time_from_last_punch, tool_capabilities, direction), return (self).
false to stop punch damage and knockback from taking place. 'do_punch' called when mob is punched with paramaters (self, hitter,
'custom_attack' when set this function is called instead of the normal mob time_from_last_punch, tool_capabilities, direction), return
melee attack, parameters are (self, to_attack). false to stop punch damage and knockback from taking place.
'on_die' a function that is called when mob is killed 'custom_attack' when set this function is called instead of the normal mob
'do_custom' a custom function that is called every tick while mob is melee attack, parameters are (self, to_attack).
active and which has access to all of the self.* variables 'on_die' a function that is called when mob is killed
e.g. (self.health for health or self.standing_in for node 'do_custom' a custom function that is called every tick while mob is
status), return with 'false' to skip remainder of mob API. active and which has access to all of the self.* variables
e.g. (self.health for health or self.standing_in for node
status), return with 'false' to skip remainder of mob API.
Internal Variables Internal Variables