Hi all,
This is my first attempt to make a mod so I may not be aware of some functionalities of minetest api.
What I want to do is basically a second chance like in Call of Duty or similiar games : When you die you can either directly resurrect or stay on the ground (you can't move) for 20 seconds and wait for someone to help you. If another player saves you, you resurrect where you died with all your items and a little health.
Optionally you could save yourself if you kill an enemy but that could be done another time. Enemy can't attack you which seems possible depending on the mob mod. Thanks to tenplus1 help on irc (https://github.com/tenplus1/mobs_redo/commit/47abff26aed78b606aad72c79ec027269a7fc15f) it would work with mobs redo.
I didn't really focus for now on how player could save another one, I was thinking of using a tool like syringe, but I run into some limitations or problems trying to implement the first part of the mod.
The best way to manage it in my opinion (and performance wise) would be to use minetest.register_on_dieplayer so I can override the death screen and mecanism. However I run into two main limitations :
- 1.1: It seems impossible to add anything to the death screen (like a text saying "Dying in 20 seconds")
- 1.2: it seems impossible to bypass the death screen, for example if a player actually save you there is no way of making the death screen disappear. I tried by setting a positive health which work but doesn't do anything to the death screen.
Another way i though about was to use minetest.register_on_player_hpchange(function(player, hp_change) with the entry condition if player:get_hp() + hp_change <= 1.
I started experimenting with this one but same thing, here is what I encountered :
- 2.1: Since I'm not using the death screen I made a formspec so the player can resurrect directly. I can't update the text I put ("Dying in x seconds" where x change overtime) and if someone save the player I can't close programmaticaly the formspec.
- 2.2: This work if the player happen to have exactly 1 health, if less the death screen is launched and there is no way to prevent it. I tried to set the health of the player to 1 to see if hpchange is processed before death but that doesn't work (and make sense if it's an event).
- 2.3: If player want to resurrect directly and hit the button of my formspec, i kill him to launch the death process (so his items are put into a bones, get teleported to hisspawn point etc.) because i can't do it with the api right ? But that means he has to click on two buttons (mine and the one from the death screen)
Any help would be appreciated ^^ If someone can point where I'm wrong or think of another way to do it etc.
here is my init.lua if someone wants to check the code or try something http://pastebin.com/JRD2v6rw
Thanks for all ! Oli