Page 1 of 1

death and hurt sounds

PostPosted: Sat Oct 13, 2012 19:25
by Microsuperman
I have been looking at trying to make a mod to add sound to when you get hurt and when you die.
But I can't seem to figure out how the api's minetest.sound_play minetest.register_on_dieplayer structure works. Let alone how to use them together. Also I don't see an api for when you get hurt. Could someone explain what the different parts of the register on dieplayer are and do that would be nice. And she same for the sound play.

Thanks Microsuperman

PostPosted: Sat Oct 13, 2012 19:42
by Casimir
Look at the drowning or hunger mod. Everything you need is done there.

PostPosted: Sat Oct 13, 2012 19:59
by Mito551
deathsound from my dwarves game ;)

PostPosted: Sun Oct 14, 2012 03:27
by Microsuperman
Well with the hunger and drowning they way they play a sound is by having it created damage with a sound added too it.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
if player:get_hp() > 0 then
    player:set_hp(player:get_hp() - DROWNING_DAMAGE)
    pos = player:getpos()
    pos.y=pos.y+1
    minetest.sound_play({name="drowning_gurp"}, {pos = pos, gain = 1.0, max_hear_distance = 16})

This is a good work around for something that is missing from the API, but I do wonder how you would add it to something like falling. I could see this work around working for getting hit by a mod that you have created.

The deathsound mod was exactly what I was looking to do.
I think I made an improvement for its code changing it from
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
 minetest.register_on_dieplayer(function(player)

local pname = player:getpos()

minetest.sound_play({name="ds_hurt"}, {pos = pname, gain = 0.5, max_hear_distance = 8})

end)


to

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_dieplayer(function(player)

minetest.sound_play({name="ds_hurt"}, {to_player, gain = 0.5, max_hear_distance = 8})

end)

but I am not sure if max_hear_distance still applies when using to_player.

Microsuperman

PostPosted: Sun Oct 14, 2012 07:20
by Mito551
actually, if i'm understanding this correctly, the original code is made so everyone hears when you die. your, however, makes that only player who died hears it. am i correct?

PostPosted: Sun Oct 14, 2012 08:19
by PilzAdam
Microsuperman wrote:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.sound_play({name="ds_hurt"}, {to_player, gain = 0.5, max_hear_distance = 8})

to_player needs a value:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.sound_play({name="ds_hurt"}, {to_player=player:get_player_name(), gain = 0.5, max_hear_distance = 8})

PostPosted: Mon Oct 15, 2012 20:21
by Microsuperman
Well I was playing around with death sound. I have found that using the code
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.sound_play({name="ds_hurt"}, {pos = pname, gain = 0.5, max_hear_distance = 8})

or
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.sound_play({name="ds_hurt"}, {pos, gain = .25})

no matter how far you are from each other when you die. It plays the sound as if you are right next to each other.
The code
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.sound_play({name="ds_hurt"}, {to_player=player:get_player_name(), gain = 0.5, max_hear_distance = 8})

only plays to the dead person. So I think max_hear_distance is not needed.
So here is a rewrite that only plays the sound to the player that died. But broadcast to all the location of their death.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local precision = 10^2 --rounds to the hundredths place.

minetest.register_on_dieplayer(function(player)
    pos = player:getpos()
    pos.x = math.floor(pos.x * precision + .5) / precision
 --rounds to hundredths place.
    pos.y = math.floor(pos.y * precision + .5) / precision
    pos.z = math.floor(pos.z * precision + .5) / precision
    minetest.chat_send_all("player ".. player:get_player_name() .." has died at location: ".. minetest.pos_to_string(pos))
    minetest.sound_play({name="ds_hurt"}, {to_player=player:get_player_name(), gain = 1})
end)

Hope you like it.

PostPosted: Mon Oct 15, 2012 21:45
by Mito551
you sure about broadcasting? if it's used with bones mod or any other drop-inventory mod, it's just a bit unfair. don't you think?

PostPosted: Mon Oct 15, 2012 23:53
by Microsuperman
I did it that way, because the sound is all or only you. but it can it easily be changed or commented out. You also could use minetest.get_modnames to see if the mod bones is install. If it is then just if over it. But if you were doing a coop or something like that. it could be of use. It would also be nice if there was a way to tell what killed you. like lava, fire, mob, player, etc...
side note: I did find that if you -3 for pos.y you can use minetest.env:get_node(pos).name to find out what you were standing on when you died.