]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/timers.lua
Make zombies and slimes light on fire during the day
[Crafter.git] / mods / mob / api / timers.lua
1 local
2 minetest,math
3 =
4 minetest,math
5 local pos
6 local light
7 mobs.create_timer_functions = function(def,mob_register)
8         --this controls how fast the mob punches
9         mob_register.manage_punch_timer = function(self,dtime)
10                 if self.punch_timer > 0 then
11                         self.punch_timer = self.punch_timer - dtime
12                 end
13                 --this controls how fast you can punch the mob (punched timer reset)
14                 if self.punched_timer > 0 then
15                         --print(self.punched_timer)
16                         self.punched_timer = self.punched_timer - dtime
17                 end
18         end
19
20         --this controls the hostile state
21         if def.hostile == true or def.attacked_hostile == true then
22                 if def.hostile_cooldown == true then
23                         mob_register.manage_hostile_timer = function(self,dtime)
24                                 if self.hostile_timer > 0 then
25                                         self.hostile_timer = self.hostile_timer - dtime
26                                 end
27                                 if self.hostile_timer <= 0 then
28                                         self.hostile = false
29                                 end
30                         end
31                 end
32         else
33                 mob_register.manage_scared_timer = function(self,dtime)
34                         if self.scared_timer > 0 then
35                                 self.scared_timer = self.scared_timer - dtime
36                         end
37                         if self.scared_timer <= 0 then
38                                 self.scared = false
39                         end
40                 end
41         end
42
43         mob_register.manage_hurt_color_timer = function(self,dtime)
44                 if self.hurt_color_timer > 0 then
45                         self.hurt_color_timer = self.hurt_color_timer - dtime
46                         if self.hurt_color_timer  <= 0 then
47                                 self.hurt_color_timer = 0
48                                 self.object:set_texture_mod("")
49                         end
50                 end
51         end
52
53         mob_register.manage_explode_timer = function(self,dtime)
54                 self.tnt_timer = self.tnt_timer - dtime
55                 self.tnt_tick_timer = self.tnt_tick_timer  - dtime
56                 if self.tnt_tick_timer <= 0 and not self.dead then
57                         self.tnt_tick_timer = self.explosion_blink_timer
58                         self.tnt_mod_state = math.abs(self.tnt_mod_state-1)
59                         if self.tnt_mod_state == 0 then
60                                 self.object:set_texture_mod("")
61                         else
62                                 self.object:set_texture_mod("^[colorize:"..self.explosion_blink_color..":130")
63                         end
64                         --print(self.object:get_texture_mod())
65                         --self.object:set_texture_mod("^[colorize:red:130")
66                 end
67                 if self.tnt_timer <= 0 and not self.dead then
68                         
69                         self.object:set_texture_mod("^[colorize:red:130")
70                         
71                         pos = self.object:get_pos()
72                         self.object:remove()
73                         tnt(pos,self.explosion_power,self.explosion_type)
74                 end
75         end
76
77         if def.custom_timer then
78                 mob_register.do_custom_timer = function(self,dtime)
79                         self.c_timer = self.c_timer + dtime
80                         if self.c_timer >= self.custom_timer then
81                                 self.c_timer = 0 
82                                 self.custom_timer_function(self,dtime)
83                         end
84                 end
85         end
86
87         mob_register.manage_projectile_timer = function(self,dtime)
88                 self.projectile_timer = self.projectile_timer - dtime
89         end
90
91         if def.friendly_in_daylight then
92                 mob_register.handle_friendly_in_daylight_timer = function(self,dtime)
93                         self.friendly_in_daylight_timer = self.friendly_in_daylight_timer + dtime
94                         if self.friendly_in_daylight_timer >= 2 then
95                                 self.friendly_in_daylight_timer = 0
96                                 pos = self.object:get_pos()
97                                 light = minetest.get_node_light(pos)
98                                 if pos and light and light >= 13 then --1 greater than torch light
99                                         if self.following == false then
100                                                 self.hostile = false
101                                         end
102                                 else
103                                         self.hostile = true
104                                 end
105                         end
106                 end
107         end
108
109         --this stops the pig from flying into the air
110         mob_register.manage_jump_timer = function(self,dtime)
111                 if self.jump_timer > 0 then
112                         self.jump_timer = self.jump_timer - dtime
113                 end
114         end
115         return(mob_register)
116 end