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

added new animation function

This commit is contained in:
TenPlus1 2017-03-06 14:19:51 +00:00
parent 36cf0693fe
commit c1c17a6849
2 changed files with 32 additions and 98 deletions

90
api.lua
View File

@ -1,5 +1,5 @@
-- Mobs Api (5th March 2017) -- Mobs Api (6th March 2017)
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
@ -133,85 +133,29 @@ get_velocity = function(self)
end end
set_anim = function(self, anim_start, anim_end, anim_speed, anim_name) -- set defined animation
set_animation = function(self, anim)
if not anim_start or not anim_end then if not self.animation then return end
return
end
self.object:set_animation(
{x = anim_start, y = anim_end}, anim_speed or 15, 0)
self.animation.current = anim_name
end
set_animation = function(self, type)
if not self.animation then
return
end
self.animation.current = self.animation.current or "" self.animation.current = self.animation.current or ""
if type == "stand" and self.animation.current ~= "stand" then if anim == self.animation.current
or not self.animation[anim .. "_start"]
set_anim(self, or not self.animation[anim .. "_end"] then
self.animation.stand_start, return
self.animation.stand_end,
self.animation.speed_stand, "stand")
elseif type == "walk" and self.animation.current ~= "walk" then
set_anim(self,
self.animation.walk_start,
self.animation.walk_end,
self.animation.speed_walk, "walk")
elseif type == "run" and self.animation.current ~= "run" then
set_anim(self,
self.animation.run_start,
self.animation.run_end,
self.animation.speed_run, "run")
elseif type == "punch" and self.animation.current ~= "punch" then
set_anim(self,
self.animation.punch_start,
self.animation.punch_end,
self.animation.speed_punch, "punch")
elseif type == "punch2" and self.animation.current ~= "punch2" then
set_anim(self,
self.animation.punch2_start,
self.animation.punch2_end,
self.animation.speed_punch2, "punch2")
elseif type == "shoot" and self.animation.current ~= "shoot" then
set_anim(self,
self.animation.shoot_start,
self.animation.shoot_end,
self.animation.speed_shoot, "shoot")
elseif type == "die" and self.animation.current ~= "die" then
set_anim(self,
self.animation.die_start,
self.animation.die_end,
self.animation.speed_die, "die")
elseif type == "fly" and self.animation.current ~= "fly" then
set_anim(self,
self.animation.fly_start,
self.animation.fly_end,
self.animation.speed_fly, "fly")
end end
self.animation.current = anim
self.object:set_animation({
x = self.animation[anim .. "_start"],
y = self.animation[anim .. "_end"]
}, self.animation[anim .. "_speed"] or self.animation.speed_normal or 15)
end end
-- get distance -- get distance
local get_distance = function(a, b) local get_distance = function(a, b)

40
api.txt
View File

@ -1,5 +1,5 @@
MOB API (21st February 2017) MOB API (6th March 2017)
The mob api is a function that can be called on by other mods to add new animals or monsters into minetest. The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
@ -102,35 +102,24 @@ This functions registers a new mob as a Minetest entity.
'jump' sound when jumping 'jump' sound when jumping
'explode' sound when exploding 'explode' sound when exploding
'distance' maximum distance sounds are heard from (default is 10) 'distance' maximum distance sounds are heard from (default is 10)
'animation' a table with the animation ranges and speed of the model
'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
'die_start' start frame of die animation
'die_end' end frame of die animation
'speed_normal' normal animation speed
'fly_start' start frame of fly animation
'fly_end' end frame of fly animation
'speed_run' running animation speed
'speed_punch' punching animation speed
'speed_punch2' alternative punching animation speed
'speed_shoot' shooting animation speed
'speed_die' die animation speed
'speed_fly' fly animation speed
'replace_what' group if items to replace e.g. {"farming:wheat_8", "farming:carrot_8"} '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_with' replace with what e.g. "air" or in chickens case "mobs:egg"
'replace_rate' how random should the replace rate be (typically 10) 'replace_rate' how random should the replace rate be (typically 10)
'replace_offset' +/- value to check specific node to replace 'replace_offset' +/- value to check specific node to replace
Mob animation comes in three parts, start_frame, end_frame and frame_speed which
can be added to the mob definition under pre-defined mob animation names like:
'animation' a table with the animation ranges and speed of the model
'stand_start', 'stand_end', 'stand_speed' when mob stands still
'walk_start', 'walk_end', 'walk_speed' when mob walks
'run_start', 'run_end', 'run_speed' when mob runs
'fly_start', 'fly_end', 'fly_speed' when mob flies
'punch_start', 'punch_end', 'punch_speed' when mob attacks
'punch2_start', 'punch2_end', 'punch2_speed' when mob attacks (alternative)
'die_start', 'die_end', 'die_speed' when mob dies
also 'speed_normal' for compatibility with older mobs for animation speed (deprecated)
The mob api also has some preset variables and functions that it will remember for each mob The mob api also has some preset variables and functions that it will remember for each mob
@ -139,6 +128,7 @@ The mob api also has some preset variables and functions that it will remember f
'self.child' used for when breeding animals have child, will use child_texture and be half size 'self.child' used for when breeding animals have child, will use child_texture and be half size
'self.owner' string used to set owner of npc mobs, typically used for dogs 'self.owner' string used to set owner of npc mobs, typically used for dogs
'self.order' set to "follow" or "stand" so that npc will follow owner or stand it's ground 'self.order' set to "follow" or "stand" so that npc will follow owner or stand it's ground
'self.nametag' contains the name of the mob which it can show above
'on_die' a function that is called when mob is killed 'on_die' a function that is called when mob is killed
'do_custom' a custom function that is called every tick while mob is active and which has access to all of the self.* variables e.g. (self.health for health or self.standing_in for node status), return with 'false' to skip remainder of mob API. 'do_custom' a custom function that is called every tick while mob is active and which has access to all of the self.* variables e.g. (self.health for health or self.standing_in for node status), return with 'false' to skip remainder of mob API.