]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/mob/api/timers.lua
Make mob spawning work better
[Crafter.git] / mods / mob / api / timers.lua
index 053e2a345958239f4b3fd963e442145e626c343e..1e8135bf7fd0cd5a461dfa751a6e78f7ba45471f 100644 (file)
@@ -1,3 +1,9 @@
+local
+minetest,math
+=
+minetest,math
+local pos
+local light
 mobs.create_timer_functions = function(def,mob_register)
        --this controls how fast the mob punches
        mob_register.manage_punch_timer = function(self,dtime)
@@ -23,6 +29,15 @@ mobs.create_timer_functions = function(def,mob_register)
                                end
                        end
                end
+       else
+               mob_register.manage_scared_timer = function(self,dtime)
+                       if self.scared_timer > 0 then
+                               self.scared_timer = self.scared_timer - dtime
+                       end
+                       if self.scared_timer <= 0 then
+                               self.scared = false
+                       end
+               end
        end
 
        mob_register.manage_hurt_color_timer = function(self,dtime)
@@ -53,9 +68,19 @@ mobs.create_timer_functions = function(def,mob_register)
                        
                        self.object:set_texture_mod("^[colorize:red:130")
                        
-                       local pos = self.object:get_pos()
+                       pos = self.object:get_pos()
                        self.object:remove()
-                       tnt(pos,self.explosion_power)
+                       tnt(pos,self.explosion_power,self.explosion_type)
+               end
+       end
+
+       if def.custom_timer then
+               mob_register.do_custom_timer = function(self,dtime)
+                       self.c_timer = self.c_timer + dtime
+                       if self.c_timer >= self.custom_timer then
+                               self.c_timer = 0 
+                               self.custom_timer_function(self,dtime)
+                       end
                end
        end
 
@@ -68,8 +93,9 @@ mobs.create_timer_functions = function(def,mob_register)
                        self.friendly_in_daylight_timer = self.friendly_in_daylight_timer + dtime
                        if self.friendly_in_daylight_timer >= 2 then
                                self.friendly_in_daylight_timer = 0
-                               local pos = self.object:get_pos()
-                               if minetest.get_node_light(pos) >= 13 then --1 greater than torch light
+                               pos = self.object:get_pos()
+                               light = minetest.get_node_light(pos)
+                               if pos and light and light >= 13 then --1 greater than torch light
                                        if self.following == false then
                                                self.hostile = false
                                        end