1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-12-24 17:50:21 +01:00

Added ability for multiple animations per action

This commit is contained in:
TenPlus1 2018-08-03 09:43:50 +01:00
parent 4badcec318
commit 0482581f18
2 changed files with 28 additions and 7 deletions

30
api.lua
View File

@ -3,7 +3,7 @@
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
mobs.version = "20180719" mobs.version = "20180803"
-- Intllib -- Intllib
@ -182,6 +182,23 @@ local set_animation = function(self, anim)
self.animation.current = self.animation.current or "" self.animation.current = self.animation.current or ""
-- check for more than one animation
local num = 0
for n = 1, 4 do
if self.animation[anim .. n .. "_start"]
and self.animation[anim .. n .. "_end"] then
num = n
end
end
-- choose random animation from set
if num > 0 then
num = random(0, num)
anim = anim .. (num ~= 0 and num or "")
end
if anim == self.animation.current if anim == self.animation.current
or not self.animation[anim .. "_start"] or not self.animation[anim .. "_start"]
or not self.animation[anim .. "_end"] then or not self.animation[anim .. "_end"] then
@ -1190,6 +1207,7 @@ local smart_mobs = function(self, s, p, dist, dtime)
if self.fear_height ~= 0 then dropheight = self.fear_height end if self.fear_height ~= 0 then dropheight = self.fear_height end
self.path.way = minetest.find_path(s, p1, 16, self.stepheight, dropheight, "Dijkstra") self.path.way = minetest.find_path(s, p1, 16, self.stepheight, dropheight, "Dijkstra")
--[[ --[[
-- show path using particles -- show path using particles
if self.path.way and #self.path.way > 0 then if self.path.way and #self.path.way > 0 then
@ -2121,12 +2139,12 @@ local do_states = function(self, dtime)
self.timer = 0 self.timer = 0
if self.double_melee_attack -- if self.double_melee_attack
and random(1, 2) == 1 then -- and random(1, 2) == 1 then
set_animation(self, "punch2") -- set_animation(self, "punch2")
else -- else
set_animation(self, "punch") set_animation(self, "punch")
end -- end
local p2 = p local p2 = p
local s2 = s local s2 = s

View File

@ -172,7 +172,7 @@ functions needed for the mob to work properly which contains the following:
'rotate' custom model rotation, 0 = front, 90 = side, 180 = back, 'rotate' custom model rotation, 0 = front, 90 = side, 180 = back,
270 = other side. 270 = other side.
'double_melee_attack' when true has the api choose between 'punch' and 'double_melee_attack' when true has the api choose between 'punch' and
'punch2' animations. 'punch2' animations. [DEPRECATED]
'animation' holds a table containing animation names and settings for use with mesh models: 'animation' holds a table containing animation names and settings for use with mesh models:
'stand_start' start frame for when mob stands still. 'stand_start' start frame for when mob stands still.
@ -207,6 +207,9 @@ functions needed for the mob to work properly which contains the following:
'speed_normal' is used for animation speed for compatibility with some 'speed_normal' is used for animation speed for compatibility with some
older mobs. older mobs.
Note: Up to 5 different animations can be used per action e.g.
stand_start, stand_end, stand1_start, stand1_end .. up to stand4_start
Node Replacement Node Replacement
---------------- ----------------