From 050dd1dbb0a4b23812cdbba860e023e5893ffce4 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Sun, 8 May 2016 18:08:25 +0100 Subject: [PATCH] Added 'punch2' 'shoot' animations, 'double_melee_attack' flag and tweaks to api --- api.lua | 54 +++++++++++++++++++++++++++++++++++++++++++----------- api.txt | 29 ++++++++++++++++++----------- 2 files changed, 61 insertions(+), 22 deletions(-) diff --git a/api.lua b/api.lua index 56ccc18..39a1633 100644 --- a/api.lua +++ b/api.lua @@ -85,13 +85,12 @@ set_animation = function(self, type) and self.animation.current ~= "stand" then if self.animation.stand_start - and self.animation.stand_end - and self.animation.speed_normal then + and self.animation.stand_end then self.object:set_animation({ x = self.animation.stand_start, y = self.animation.stand_end}, - self.animation.speed_normal, 0) + (self.animation.speed_stand or self.animation.speed_normal), 0) self.animation.current = "stand" end @@ -100,13 +99,12 @@ set_animation = function(self, type) and self.animation.current ~= "walk" then if self.animation.walk_start - and self.animation.walk_end - and self.animation.speed_normal then + and self.animation.walk_end then self.object:set_animation({ x = self.animation.walk_start, y = self.animation.walk_end}, - self.animation.speed_normal, 0) + (self.animation.speed_walk or self.animation.speed_normal), 0) self.animation.current = "walk" end @@ -115,8 +113,7 @@ set_animation = function(self, type) and self.animation.current ~= "run" then if self.animation.run_start - and self.animation.run_end - and self.animation.speed_run then + and self.animation.run_end then self.object:set_animation({ x = self.animation.run_start, @@ -130,8 +127,7 @@ set_animation = function(self, type) and self.animation.current ~= "punch" then if self.animation.punch_start - and self.animation.punch_end - and self.animation.speed_normal then + and self.animation.punch_end then self.object:set_animation({ x = self.animation.punch_start, @@ -140,6 +136,32 @@ set_animation = function(self, type) self.animation.current = "punch" end + elseif type == "punch2" + and self.animation.current ~= "punch2" then + + if self.animation.punch2_start + and self.animation.punch2_end then + + self.object:set_animation({ + x = self.animation.punch2_start, + y = self.animation.punch2_end}, + (self.animation.speed_punch2 or self.animation.speed_normal), 0) + + self.animation.current = "punch2" + end + elseif type == "shoot" + and self.animation.current ~= "shoot" then + + if self.animation.shoot_start + and self.animation.shoot_end then + + self.object:set_animation({ + x = self.animation.shoot_start, + y = self.animation.shoot_end}, + (self.animation.speed_shoot or self.animation.speed_normal), 0) + + self.animation.current = "shoot" + end end end @@ -1333,6 +1355,8 @@ local do_states = function(self, dtime) set_animation(self, "run") else set_velocity(self, 0) + set_animation(self, "punch") + self.timer = self.timer + dtime self.blinktimer = (self.blinktimer or 0) + dtime @@ -1535,6 +1559,13 @@ local do_states = function(self, dtime) self.timer = 0 + if self.double_melee_attack + and math.random(1, 2) == 1 then + set_animation(self, "punch") + else + set_animation(self, "punch2") + end + local p2 = p local s2 = s @@ -1603,7 +1634,7 @@ local do_states = function(self, dtime) and math.random(1, 100) <= 60 then self.timer = 0 - set_animation(self, "punch") + set_animation(self, "shoot") -- play shoot attack sound if self.sounds.shoot_attack then @@ -2189,6 +2220,7 @@ minetest.register_entity(name, { immune_to = def.immune_to or {}, explosion_radius = def.explosion_radius, custom_attack = def.custom_attack, + double_melee_attack = def.double_melee_attack, on_blast = def.on_blast or do_tnt, diff --git a/api.txt b/api.txt index 93c4500..475b9a0 100644 --- a/api.txt +++ b/api.txt @@ -80,6 +80,7 @@ This functions registers a new mob as a Minetest entity. 'explode' follows player in range and will flash and explode when in reach 'dogshoot' shoots arrows when in range and one on one attack when in reach 'custom_attack' is a function that is called when mob is in range to attack player, parameters are (self, to_attack) + 'double_melee_attack' if false then api will choose randomly between 'punch' and 'punch2' attack animations 'on_blast' is called when TNT explodes near mob, function uses (object, damage) and returns (do_damage, do_knockback, drops) 'explosion_radius' radius of explosion attack (defaults to 1) 'arrow' if the attack_type is "shoot" or "dogshoot" then the entity name of the arrow is required @@ -97,17 +98,23 @@ This functions registers a new mob as a Minetest entity. 'explode' sound when exploding 'distance' maximum distance sounds are heard from (default is 10) 'animation' a table with the animation ranges and speed of the model - 'stand_start' - 'stand_end' - 'walk_start' - 'walk_end' - 'run_start' - 'run_end' - 'punch_start' - 'punch_end' - 'speed_normal' - 'speed_run' used when mob runs behind player to make animation faster - 'speed_punch' used when mob punches player to make animation faster + 'stand_start' start frame of stand animation + 'stand_end' end frame of stand animation + 'walk_start' start frame of walk animation + 'walk_end' end frame of walk animation + 'run_start' start frame of run animation + 'run_end' end frame of run animation + 'punch_start' start frame of punch animation + 'punch_end' end frame of punch animation + 'punch2_start' start frame of alt.punch animation + 'punch2_end' end frame of alt.punch animation + 'shoot_start' start frame of shoot animation + 'shoot_end' end frame of shoot animation + 'speed_normal' normal animation speed + 'speed_run' running animation speed + 'speed_punch' punching animation speed + 'speed_punch2' alternative punching animation speed + 'speed_shoot' shooting animation speed 'replace_what' group if items to replace e.g. {"farming:wheat_8", "farming:carrot_8"} 'replace_with' replace with what e.g. "air" or in chickens case "mobs:egg" 'replace_rate' how random should the replace rate be (typically 10)