disable player swing or punch?

Post Reply
User avatar
ErrorNull
Member
Posts: 222
Joined: Thu Mar 03, 2016 00:43

disable player swing or punch?

by ErrorNull » Post

I'm trying to disable the player's ability to swing or punch during certain conditions, like when food or health is too low. i can easily 'disable' this for player movement and jumping by modifying the player's physics parameters.

But disabling the player swing/punch seems impossible? In a hacky way, i'm able to prevent nodes from getting damaged by modifying callback functions for punching and digging, but the actual swing/punch animation is still there. The "frame_speed" parameter within set_local_animation() doesn't seem be what i'm looking for either.

... or is there some way i can force minetest to ignore the left mouse button (LMB) player control?
My Villagers Mod: [villagers]

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: disable player swing or punch?

by AspireMint » Post

If you can not swing or punch, and place node (?), you can say his right arm is down, like left arm.
Then you just hide wielditem (hand with item) and set player animation of digging to standing, and digging while running to running :-)

Here is code to hide right arm:

Code: Select all

local hud_flags = player:hud_get_flags()
hud_flags.wielditem = false
player:hud_set_flags(hud_flags)

User avatar
ErrorNull
Member
Posts: 222
Joined: Thu Mar 03, 2016 00:43

Re: disable player swing or punch?

by ErrorNull » Post

ah wonderful. i'll look into that method. how would you go about setting the player animation from digging to standing? i looked into set_local_animation() doesn't seem be the correct way.
My Villagers Mod: [villagers]

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: disable player swing or punch?

by AspireMint » Post

you have 2 options:

1) modify player_api:
Not just use - there are globalsteps - first will change player anim if player is not attached (useful for beds mod), yes you can just add player_name to table of attached objs to ignore this globalstep, but another globalsteps will change anim on player control press...

Look at https://github.com/minetest/minetest_ga ... nit.lua#L6
and this https://github.com/minetest/minetest_ga ... pi.lua#L36
and this https://github.com/minetest/minetest_ga ... pi.lua#L74

I would change player_api.set_model to accept third param (optional in this case), lets say "version"
player_api.set_model(player, model_name, version) and modify this function + player_api.set_animation ... just to reuse character.b3d model.

for example (first param is model_name.."."..version):

Code: Select all

player_api.register_model("character.b3d.my_version", {
	animation_speed = 30,
	textures = {"character.png", },
	animations = {
		-- Standard animations.
		stand     = {x = 0,   y = 0}, -- use some other values x) this is just example
		lay       = {x = 0, y = 0},
		walk      = {x = 0, y = 0},
		mine      = {x = 0, y = 0},
		walk_mine = {x = 0, y = 0},
		sit       = {x = 0,  y = 0},
	},
	collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
	stepheight = 0.6,
	eye_height = 1.47,
})
then:
player_api.set_model(player, "character.b3d", "no_arm_anim")

2) or make copies of character.b3d and register it X times, then you dont have to modify anything x) but this will increase loading time...

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests