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