From e3cc11d07f335da2eadcf431293fc8bfc8980578 Mon Sep 17 00:00:00 2001 From: npx Date: Fri, 29 Apr 2016 21:22:06 +0200 Subject: [PATCH] Using os.time() instead of minetest globalstep to count time where possible --- nssm_weapons.lua | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/nssm_weapons.lua b/nssm_weapons.lua index 6d14e56..91e03cf 100644 --- a/nssm_weapons.lua +++ b/nssm_weapons.lua @@ -42,8 +42,10 @@ local function search_on_step2( local pos = self.object:getpos() --Disappear after a certain time - self.timer = self.timer + dtime - if self.timer > max_time then + if self.life_time == 0 then + self.life_time = os.time() + end + if os.time() - self.life_time > max_time then self.object:remove() return end @@ -121,12 +123,15 @@ local function search_on_step( local pos = self.object:getpos() --Disappear after a certain time - self.timer = self.timer + dtime - if self.timer > max_time then + if self.life_time == 0 then + self.life_time = os.time() + end + if os.time() - self.life_time > max_time then self.object:remove() return end + --Look for an entity to follow local objects = minetest.env:get_objects_inside_radius(pos, radius) local min_dist = 100 @@ -201,17 +206,21 @@ local function default_on_step( local pos = self.object:getpos() - local t = os.time() - minetest.chat_send_all("Tempo: "..t) - self.timer = self.timer + dtime - if self.timer > max_time then + if self.life_time == 0 then + self.life_time = os.time() + end + + + if os.time() - self.life_time > max_time then local node = nssm:node_ok(pos).name self.hit_node(self, pos, node) self.object:remove() return end + self.timer = self.timer + dtime + --while going around it damages entities local objects = minetest.env:get_objects_inside_radius(pos, 2) if self.timer > 0.3 then @@ -308,6 +317,7 @@ local function nssm_register_weapon(name, def) def.hit_node(self, pos, node) end, move = def.move, + life_time = 0, timer = 0 })