Questions on animated player model and animated entities

Post Reply
FireAlphaT
New member
Posts: 8
Joined: Tue Sep 10, 2019 22:23

Questions on animated player model and animated entities

by FireAlphaT » Post

Hi, I'm working on a game and wanted to use a custom player model and wanted to use animated entities. I've already managed to make and animate the models in Blender and exported them as .b3d, using the default player .blend file as an example.
However, for what concerns the entities I cannot figure out their declaration, despite having looked through the API documentation, the wiki, and some mods, but couldn't check the forum because of the various errors and connection timeouts, while for the player model I tried to modify the player_api mod, but when I start the game I get this error:

Code: Select all

2020-04-21 10:38:54: ACTION[Main]: World at [F:\Download\minetest-5.2.0-win64\bin\..\worlds\assa]
2020-04-21 10:38:54: ACTION[Main]: Server for gameid="test" listening on 0.0.0.0:55198.
2020-04-21 10:38:55: ACTION[Server]: singleplayer [127.0.0.1] joins game. List of players: singleplayer
2020-04-21 10:38:55: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'player_api' in callback on_joinplayer(): Invalid position (expected table got number).
2020-04-21 10:38:55: ERROR[Main]: stack traceback:
2020-04-21 10:38:55: ERROR[Main]: 	[C]: in function 'set_local_animation'
2020-04-21 10:38:55: ERROR[Main]: 	...t-5.2.0-win64\bin\..\games\test\mods\player_api\init.lua:21: in function <...t-5.2.0-win64\bin\..\games\test\mods\player_api\init.lua:18>
2020-04-21 10:38:55: ERROR[Main]: 	...ad\minetest-5.2.0-win64\bin\..\builtin\game\register.lua:429: in function <...ad\minetest-5.2.0-win64\bin\..\builtin\game\register.lua:413>
2020-04-21 10:38:55: ERROR[Main]: stack traceback:
2020-04-21 10:38:55: ERROR[Main]: 	[C]: in function 'set_local_animation'
2020-04-21 10:38:55: ERROR[Main]: 	...t-5.2.0-win64\bin\..\games\test\mods\player_api\init.lua:21: in function <...t-5.2.0-win64\bin\..\games\test\mods\player_api\init.lua:18>
2020-04-21 10:38:55: ERROR[Main]: 	...ad\minetest-5.2.0-win64\bin\..\builtin\game\register.lua:429: in function <...ad\minetest-5.2.0-win64\bin\..\builtin\game\register.lua:413>
2020-04-21 10:38:55: ACTION[Server]: singleplayer leaves game. List of players: 
2020-04-21 10:38:55: ACTION[Main]: Server: Shutting down
2020-04-21 10:39:10: ERROR[Main]: Per favore scegli un nome!
I'm using Minipeli as a base and I have added only a mod to add a few meshnodes and particle spawners.
Thanks in advance for any help

EDIT: updated the error code, the error is the same as before
Last edited by FireAlphaT on Tue Apr 21, 2020 08:42, edited 1 time in total.

Eran
Member
Posts: 120
Joined: Fri May 03, 2019 16:46

Re: Questions on animated player model and animated entities

by Eran » Post

Can you post your modified player_api mod's code? That would make it a lot easier to make sense of the error message.

FireAlphaT
New member
Posts: 8
Joined: Tue Sep 10, 2019 22:23

Re: Questions on animated player model and animated entities

by FireAlphaT » Post

init.lua

Code: Select all

dofile(minetest.get_modpath("player_api") .. "/api.lua")

-- Default player appearance
player_api.register_model("character.b3d", {
	animation_speed = 30,
	textures = {"character.png"},
	animations = {
		-- Standard animations.
		stand	= {x = 0,   y = 59},
		jump	= {x = 61, y = 90}
	},
	collisionbox = {-0.3, 0.0, -0.3, 0.3, 0.3, 0.3},
	stepheight = 1,
	eye_height = 1,
})

-- Update appearance when the player joins
minetest.register_on_joinplayer(function(player)
	player_api.player_attached[player:get_player_name()] = false
	player_api.set_model(player, "character.b3d")
	player:set_local_animation(
		{x = 0,   y = 59},
		{x = 61, y = 90},
		30
	)
end)
api.lua

Code: Select all

-- Global table for use by other mods
player_api = {}

-- Player animation blending
-- Note: This is currently broken due to a bug in Irrlicht, leave at 0
local animation_blend = 0


-- Tables
---------

-- Registered models
player_api.registered_models = {}
-- Localize for better performance
local models = player_api.registered_models

-- Player stats and animations
local player_model = {}
local player_textures = {}
local player_anim = {}
local player_sneak = {}
player_api.player_attached = {}


-- Functions
------------

function player_api.register_model(model_name, def)
	models[model_name] = def
end


function player_api.get_animation(player)
	local name = player:get_player_name()
	return {
		model = player_model[name],
		textures = player_textures[name],
		animation = player_anim[name],
	}
end


-- Called when a player's appearance needs to be updated
function player_api.set_model(player, model_name)
	local name = player:get_player_name()
	local model = models[model_name]
	if player_model[name] == model_name then
		return
	end
	player:set_properties({
		mesh = model_name,
		textures = player_textures[name] or model.textures,
		visual = "mesh",
		visual_size = model.visual_size or {x = 1, y = 1},
		collisionbox = model.collisionbox or {-0.3, 0.0, -0.3, 0.3, 0.3, 0.3},
		stepheight = model.stepheight or 1,
		eye_height = model.eye_height or 1,
	})
	player_api.set_animation(player, "stand")
	player_model[name] = model_name
end


function player_api.set_textures(player, textures)
	local name = player:get_player_name()
	local model = models[player_model[name]]
	local model_textures = model and model.textures or nil
	player_textures[name] = textures or model_textures
	player:set_properties({textures = textures or model_textures,})
end


function player_api.set_animation(player, anim_name, speed)
	local name = player:get_player_name()
	if player_anim[name] == anim_name then
		return
	end
	local model = player_model[name] and models[player_model[name]]
	if not (model and model.animations[anim_name]) then
		return
	end
	local anim = model.animations[anim_name]
	player_anim[name] = anim_name
	player:set_animation(anim, speed or model.animation_speed, animation_blend)
end


minetest.register_on_leaveplayer(function(player)
	local name = player:get_player_name()
	player_model[name] = nil
	player_anim[name] = nil
	player_textures[name] = nil
end)


-- Localize for better performance in globalstep function
local player_set_animation = player_api.set_animation
local player_attached = player_api.player_attached

-- 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, "stand")
			elseif walking then
				if player_sneak[name] ~= controls.sneak then
					player_anim[name] = nil
					player_sneak[name] = controls.sneak
				end
				player_set_animation(player, "jump", animation_speed_mod)
			else
				player_set_animation(player, "stand", animation_speed_mod)
			end
		end
	end
end)

User avatar
AspireMint
Member
Posts: 362
Joined: Mon Jul 09, 2012 12:59
GitHub: AspireMint
IRC: AspireMint
In-game: AspireMint
Location: Stuck at spawn

Re: Questions on animated player model and animated entities

by AspireMint » Post

player:set_local_animation expects 5 params - 4 tables and 5th is number (frame speed)
Your 3rd param is number, not table.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest