Closed bas080 closed 6 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.
I could really use such feature for an upcoming arena mod
@ShadowNinja seems a good idea !
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:
set_hp(0)
damage_per_second
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.
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.
Maybe breaking compatibility for this would be an option since we are going to version 0.5+?
No, we're not breaking API compatibility in 0.5.0, this should be done without an API breakage.
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.
Wouldn't it be nice to have a reason given each time a player is damaged, e.g.
... 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:
This might require for the set_hp(hp) function to also ask for extra information on the reason for the hp reduction.