X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=mods%2Fmob%2Fapi%2Finteraction.lua;h=18f84c4d8de86c3b7e419501513d8d35fff82df5;hb=420641d8718e843aecadb304e2ac4db0067584f3;hp=8ad690209d8b3d8f1fadedae0d2338464e332ea8;hpb=d086df2302682e64389ac7a856af67853d700e44;p=Crafter.git diff --git a/mods/mob/api/interaction.lua b/mods/mob/api/interaction.lua index 8ad6902..18f84c4 100644 --- a/mods/mob/api/interaction.lua +++ b/mods/mob/api/interaction.lua @@ -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,13 +106,25 @@ 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 + 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.hostile_timer = 20 - self.punched_timer = 0.8 --critical effect if critical == true then @@ -135,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 @@ -144,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({ @@ -191,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 @@ -226,24 +247,19 @@ 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(pos,pos2) - local distance = vector.distance(pos,pos2)-2 - if distance < 0 then - distance = 0 - end + local distance = vector.distance(pos,pos2) --punch the player if self.attack_type == "punch" then - if distance < 1 and self.punch_timer <= 0 and object:get_hp() > 0 then + if distance < 2.5 and self.punch_timer <= 0 and object:get_hp() > 0 then local line_of_sight = minetest.line_of_sight(pos, pos2) if line_of_sight == true then self.punch_timer = 1 @@ -260,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 @@ -278,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.speed = self.max_speed - end + self.direction = vector.direction(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z)) + self.speed = self.max_speed self.following = true end --only look at one player