]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/mob/api/interaction.lua
Hack in jumping fix for mobs that walk - makes mobs randomly jump though
[Crafter.git] / mods / mob / api / interaction.lua
index dade0f937959bf8e7cd34100371700aa6999372c..18f84c4d8de86c3b7e419501513d8d35fff82df5 100644 (file)
@@ -54,8 +54,8 @@ mobs.create_interaction_functions = function(def,mob_register)
                                
                                local velocity = vector.multiply(dir,1.1)
                                
-                               vel1 = vector.multiply(velocity, -1)
-                               vel2 = velocity
+                               local vel1 = vector.multiply(velocity, -1)
+                               local vel2 = velocity
                                self.object:add_velocity(vel1)
                                
                                if object:is_player() then
@@ -106,20 +106,24 @@ mobs.create_interaction_functions = function(def,mob_register)
                end
                
                local hp = hp-hurt
-               
-               if (self.punched_timer <= 0 and hp > 1) then
+
+               if (self.punched_timer <= 0 and hp > 1) and not self.dead then
+                       self.object:set_texture_mod("^[colorize:red:130")
+                       self.hurt_color_timer = 0.25
                        if puncher ~= self.object then
-                               self.hostile = true
-                               if self.group_attack == true then
-                                       for _,object in ipairs(minetest.get_objects_inside_radius(pos, self.view_distance)) do
-                                               if not object:is_player() and object:get_luaentity() and object:get_luaentity().mobname == self.mobname then
-                                                       object:get_luaentity().hostile = true
-                                                       object:get_luaentity().hostile_timer = 20
+                               self.punched_timer = 0.8
+                               if self.attacked_hostile then
+                                       self.hostile = true
+                                       self.hostile_timer = 20
+                                       if self.group_attack == true then
+                                               for _,object in ipairs(minetest.get_objects_inside_radius(pos, self.view_distance)) do
+                                                       if not object:is_player() and object:get_luaentity() and object:get_luaentity().mobname == self.mobname then
+                                                               object:get_luaentity().hostile = true
+                                                               object:get_luaentity().hostile_timer = 20
+                                                       end
                                                end
                                        end
                                end
-                               self.hostile_timer = 20
-                               self.punched_timer = 0.8
                        end
                        
                        --critical effect
@@ -143,6 +147,23 @@ mobs.create_interaction_functions = function(def,mob_register)
                        self.object:add_velocity(dir)
                        self.add_sword_wear(self, puncher, time_from_last_punch, tool_capabilities, dir)
                elseif (self.punched_timer <= 0 and self.death_animation_timer == 0) then
+                       self.object:set_texture_mod("^[colorize:red:130")
+                       self.hurt_color_timer = 0.25
+                       if puncher ~= self.object then
+                               self.punched_timer = 0.8
+                               if self.attacked_hostile then
+                                       self.hostile = true
+                                       self.hostile_timer = 20
+                                       if self.group_attack == true then
+                                               for _,object in ipairs(minetest.get_objects_inside_radius(pos, self.view_distance)) do
+                                                       if not object:is_player() and object:get_luaentity() and object:get_luaentity().mobname == self.mobname then
+                                                               object:get_luaentity().hostile = true
+                                                               object:get_luaentity().hostile_timer = 20
+                                                       end
+                                               end
+                                       end
+                               end
+                       end
                        self.death_animation_timer = 1
                        self.dead = true
                        
@@ -152,18 +173,13 @@ mobs.create_interaction_functions = function(def,mob_register)
                                minetest.sound_play("critical", {object=self.object, gain = 0.1, max_hear_distance = 10,pitch = math.random(80,100)/100})
                        end
                        minetest.sound_play(self.die_sound, {object=self.object, gain = 1.0, max_hear_distance = 10,pitch = math.random(80,100)/100})
-                       
-                       self.object:set_texture_mod("^[colorize:red:130")
-                       if self.child then
-                       self.child:set_texture_mod("^[colorize:red:130") 
-                       end
                        self.add_sword_wear(self, puncher, time_from_last_punch, tool_capabilities, dir)
                end
        end
 
        --this is what happens when a mob dies
        mob_register.on_death = function(self, killer)
-               local pos = self.object:getpos()
+               local pos = self.object:get_pos()
                --pos.y = pos.y + 0.4
                minetest.sound_play("mob_die", {pos = pos, gain = 1.0})
                minetest.add_particlespawner({
@@ -199,9 +215,6 @@ mobs.create_interaction_functions = function(def,mob_register)
                        
                global_mob_amount = global_mob_amount - 1
                print("Mobs Died. Current Mobs: "..global_mob_amount)
-               if self.child and self.child:get_luaentity() then
-                       self.child:get_luaentity().parent = nil
-               end
                
                self.object:remove()
        end
@@ -234,19 +247,16 @@ mobs.create_interaction_functions = function(def,mob_register)
                                local pos2 = object:get_pos()
                                pos2.y = pos2.y + 1.625
                                
-                               player_found = true
+                               player_found = false
                                
                                if self.head_bone then
-                                       self.move_head(self,pos2,dtime)
+                                       player_found = self.move_head(self,pos2,dtime)
                                end
                                
                                
                                if self.hostile == true then
-                                       
-                                       self.direction = vector.direction(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z))
                                        local distance = vector.distance(pos,pos2)
                                        
-                                       
                                        --punch the player
                                        if self.attack_type == "punch" then
                                                if distance < 2.5 and self.punch_timer <= 0 and object:get_hp() > 0 then
@@ -266,6 +276,8 @@ mobs.create_interaction_functions = function(def,mob_register)
                                                        if not self.tnt_timer then
                                                                minetest.sound_play("tnt_ignite", {object = self.object, gain = 1.0,})
                                                                self.tnt_timer = self.explosion_time
+                                                               self.tnt_tick_timer  = 0.2
+                                                               self.tnt_mod_state = 1
                                                                self.object:set_texture_mod("^[colorize:white:130")
                                                        end
                                                end
@@ -284,10 +296,8 @@ mobs.create_interaction_functions = function(def,mob_register)
                                                        end
                                                end
                                        end
-                                       --self.speed = distance * 4
-                                       --if self.speed > self.max_speed then
+                                       self.direction = vector.direction(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z))
                                        self.speed = self.max_speed
-                                       --end
                                        self.following = true
                                end
                                --only look at one player