minetest / minetest

Luanti (formerly Minetest) is an open source voxel game-creation platform with easy modding and game creation
https://www.minetest.net/
Other
10.82k stars 2.03k forks source link

on_dieplayer and on_hpchange reasons #1342

Closed bas080 closed 6 years ago

bas080 commented 10 years ago

Wouldn't it be nice to have a reason given each time a player is damaged, e.g.

player:set_hp(damage, reason)

player:punch(puncher, time_from_last_punch, tool_capabilities, direction, reason)

minetest.register_on_player_hpchange(function(player, hp_change, reason)

... where 'reason' is a simple text string containing something like "lava", "fire", "mob_sandmonster", "ethereal:crystal_spike" etc.

This would come in very handy for award or death messages or even stats on a players game :)


Instead of just a player the on_dieplayer should also pass the node or entitiy that killed it as a parameter.

A suggestion:

minetest.register_on_dieplayer(params                                                                              
  print(params.player) --the player that got killed
  print(params.killer) --returns the player that killed him/her
  print(params.node) --retruns the node that inflicted the final blow
end)

This might require for the set_hp(hp) function to also ask for extra information on the reason for the hp reduction.

ShadowNinja commented 10 years ago

The player argument can't be removed because of compatibility, but a reason argument could be added. This would hold data for deaths by fire and the like too, so there would have to be an API to damage a player with a reason.

indriApollo commented 9 years ago

I could really use such feature for an upcoming arena mod

nerzhul commented 9 years ago

@ShadowNinja seems a good idea !

Wuzzy2 commented 7 years ago

This should include all possible ways to damage a player. It makes sense to include these parameters in the damage callback as well, because it's similar. And there should be no way for a player to die which doesn't “send” the relevant data to the callback.

Possible damage/death sources:

raymoo commented 7 years ago

If set_hp always gives a reason then it should have a required reason argument for the caller, because it's not that useful to just know that the HP was set.

Wuzzy2 commented 7 years ago

Well, for starters, the fact that a Lua function was used is a start to distinguish from hardcoded sources such as fall damage. We can't just make adding a reason into set_hp mandatory because this would break pretty much everything. As I already stated in #5971, if we add a reason argument, we should immediately standardize the most common death causes, otherwise it will quickly degrade into an unholy mess.

raymoo commented 7 years ago

Maybe breaking compatibility for this would be an option since we are going to version 0.5+?

paramat commented 7 years ago

No, we're not breaking API compatibility in 0.5.0, this should be done without an API breakage.

raymoo commented 6 years ago

Stated this in the other issue, but damage reasons should be structured and not just a simple string. A table with a reason type and extra data specific to each type would be useful.