From 2106a081b91eefddb6e4b3fc1ea659f012634e1b Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Sat, 8 Sep 2018 18:21:33 +0100 Subject: [PATCH] lifetimer check every 0.25 seconds --- api.lua | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/api.lua b/api.lua index 83c4d5e..e920ed1 100644 --- a/api.lua +++ b/api.lua @@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi") mobs = { mod = "redo", - version = "20180907", + version = "20180908", intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {}, } @@ -2746,15 +2746,8 @@ local mob_activate = function(self, staticdata, def, dtime) end --- main mob function -local mob_step = function(self, dtime) - - if use_cmi then - cmi.notify_step(self.object, dtime) - end - - local pos = self.object:get_pos() - local yaw = 0 +-- handle mob lifetimer and expiration +local mob_expire = function(self, pos, dtime) -- when lifetimer expires remove mob (except npc and tamed) if self.type ~= "npc" @@ -2790,6 +2783,18 @@ local mob_step = function(self, dtime) return end end +end + + +-- main mob function +local mob_step = function(self, dtime) + + if use_cmi then + cmi.notify_step(self.object, dtime) + end + + local pos = self.object:get_pos() + local yaw = 0 -- get node at foot level every quarter second self.node_timer = (self.node_timer or 0) + dtime @@ -2808,6 +2813,9 @@ local mob_step = function(self, dtime) self.standing_in = node_ok({ x = pos.x, y = pos.y + y_level + 0.25, z = pos.z}, "air").name -- print ("standing in " .. self.standing_in) + + -- check for mob expiration (0.25 instead of dtime since were in a timer) + mob_expire(self, pos, 0.25) end -- check if falling, flying, floating