Last month, I mentioned about that I want to create a mod that will allow for easier changing of player models (tentatively to be named
chchar, giving homage to Unix command names). I found out that the files
https://github.com/minetest/minetest_game/blob/master/mods/player_api/api.lua and
https://github.com/minetest/minetest_game/blob/master/mods/player_api/init.lua are the best helpers to help me realize my mod. However, I'm getting stuck at the two functions:
- How to register new models - what parameters am I supposed to pass (from init.lua) (it has to search in a directory for models and register all of them)
- Code: Select all
-- Default player appearance
player_api.register_model("character.b3d", {
animation_speed = 30,
textures = {"character.png", },
animations = {
-- Standard animations.
stand = {x = 0, y = 79},
lay = {x = 162, y = 166},
walk = {x = 168, y = 187},
mine = {x = 189, y = 198},
walk_mine = {x = 200, y = 219},
sit = {x = 81, y = 160},
},
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
stepheight = 0.6,
eye_height = 1.47,
})
- Where to apply actions based on events - I can override the existing function if needed (from api.lua) (I want characters to be more dynamic if they have animations, otherwise fallback on other code if they don't exist)
- Code: Select all
-- Check each player and apply animations
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local model_name = player_model[name]
local model = model_name and models[model_name]
if model and not player_attached[name] then
local controls = player:get_player_control()
local walking = false
local animation_speed_mod = model.animation_speed or 30
-- Determine if the player is walking
if controls.up or controls.down or controls.left or controls.right then
walking = true
end
-- Determine if the player is sneaking, and reduce animation speed if so
if controls.sneak then
animation_speed_mod = animation_speed_mod / 2
end
-- Apply animations based on what the player is doing
if player:get_hp() == 0 then
player_set_animation(player, "lay")
elseif walking then
if player_sneak[name] ~= controls.sneak then
player_anim[name] = nil
player_sneak[name] = controls.sneak
end
if controls.LMB then
player_set_animation(player, "walk_mine", animation_speed_mod)
else
player_set_animation(player, "walk", animation_speed_mod)
end
elseif controls.LMB then
player_set_animation(player, "mine")
else
player_set_animation(player, "stand", animation_speed_mod)
end
Other things, I think I can figure it out on my own, given enough time. If I run into any further trouble, I'll ask again later.