From b51bafcf0edc6aaf4825bd2e6f0a0f3b351dc951 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Thu, 28 Apr 2016 20:18:00 +0100 Subject: Added custom_attack function (thanks to NPXcoot) --- api.lua | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'api.lua') diff --git a/api.lua b/api.lua index 3c8bcf4..eed21bf 100644 --- a/api.lua +++ b/api.lua @@ -1,5 +1,5 @@ --- Mobs Api (25th April 2016) +-- Mobs Api (28th April 2016) mobs = {} mobs.mod = "redo" @@ -1529,33 +1529,44 @@ local do_states = function(self, dtime) set_velocity(self, 0) set_animation(self, "punch") - if self.timer > 1 then + if not self.custom_attack then - self.timer = 0 + if self.timer > 1 then - local p2 = p - local s2 = s + self.timer = 0 - p2.y = p2.y + 1.5 - s2.y = s2.y + 1.5 + local p2 = p + local s2 = s - --if minetest.line_of_sight(p2, s2) == true then - if line_of_sight_water(self, p2, s2) == true then + p2.y = p2.y + 1.5 + s2.y = s2.y + 1.5 - -- play attack sound - if self.sounds.attack then + --if minetest.line_of_sight(p2, s2) == true then + if line_of_sight_water(self, p2, s2) == true then - minetest.sound_play(self.sounds.attack, { - object = self.object, - max_hear_distance = self.sounds.distance - }) + -- play attack sound + if self.sounds.attack then + + minetest.sound_play(self.sounds.attack, { + object = self.object, + max_hear_distance = self.sounds.distance + }) + end + + -- punch player + self.attack:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = self.damage} + }, nil) end + end + else -- call custom attack every second + if self.custom_attack + and self.timer > 1 then + + self.timer = 0 - -- punch player - self.attack:punch(self.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {fleshy = self.damage} - }, nil) + self.custom_attack(self, p) end end end @@ -2165,6 +2176,7 @@ minetest.register_entity(name, { pathfinding = def.pathfinding, immune_to = def.immune_to or {}, explosion_radius = def.explosion_radius, + custom_attack = def.custom_attack, on_step = mob_step, -- cgit v1.2.3