modding around death screen (second chance mod)

olivattaque
New member
 
Posts: 2
Joined: Tue Oct 04, 2016 14:39

modding around death screen (second chance mod)

by olivattaque » Tue Oct 04, 2016 16:19

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
 

User avatar
taikedz
Member
 
Posts: 587
Joined: Sun May 15, 2016 11:11
GitHub: taikedz
IRC: DuCake
In-game: DuCake

Re: modding around death screen (second chance mod)

by taikedz » Tue Oct 04, 2016 23:15

To work around the countdown I would say, put that in chat_send_player for the dead player

A player leaves bones where they die so the inventory is there.... if you can reliably get the position of the bones block, you can get its inventory...

There is an on_respawnplayer function http://dev.minetest.net/minetest.regist ... pawnplayer which gets called before the player is moved to a new position

On respawn, using a minetest.after(0.5 , ...) or so, teleport the player back to that location; if they are resurrected, you can take the bones inventory and put it back in the player's inventory, and remove the bones block... If not saved by anyone, present a new formspec asking whether to do the special resurrect. if not, return player to their respawn point (you need to have saved it before, at the start of the minetest.after handler)...

Would that work for your purposes?
 

olivattaque
New member
 
Posts: 2
Joined: Tue Oct 04, 2016 14:39

Re: modding around death screen (second chance mod)

by olivattaque » Thu Oct 06, 2016 22:14

Thanks for your reply !

Your input gave me some ideas and since i can't prevent death screen, i rework the mod around it.
So i use chat_send_player to send information to the player for example the countdown, when someone saves the player i put something like "player helped you, click on resurrect". It's not ideal but it's the best I can do for now I think.
Thanks to on_respawnplayer that is called before the player is moved i return false if the player has been saved so it doesn't teleport him. I can get the inventory of the player in the bones.

The trouble I have now is the after method for the countdown doesn't seem to work properly. The value aren't always the expected (for example 2.49 instead of 2 or 3 and it often skip the 3) maybe because of the after method, i should manage the countdown in global step.
The other problem is that the bones mod put the bones when the player die and not when he respawn (maybe to prevent player quitting the game without putting his bones) but for my purpose it's a bit ugly as when someone will try to save the player he will have the bones block on him. I could bypass the bones modes by saving the inventory, removing the block and putting it only when the player as not been saved but it may be a bit tricky and it the issue mentionned before (prevent player quitting the game without putting his bones) i could do it on register.leaveplayer.

PS : minetest.node_dig(bones_pos, node, player) doesn't seems to work on the bones block so I do it manually like in the bones mod code.
minetest.remove_node(bones_pos) doesn't work either so I use minetest.set_node(bones_pos, {name="air"})
I'll continue investigating around this

here is the version updated : http://pastebin.com/QJGHyLNV
 

User avatar
taikedz
Member
 
Posts: 587
Joined: Sun May 15, 2016 11:11
GitHub: taikedz
IRC: DuCake
In-game: DuCake

Re: modding around death screen (second chance mod)

by taikedz » Fri Oct 07, 2016 23:48

Line 9 -- add "if not minetest.is_singleplayer() then" ; add an "end" at the end of the file, if you want to

Line 11 -- should you not decrement your counter?

Line 22 -- does it write an error to your debug.txt?

Line 66 -- minetest.chat_send_player(obj:get_player_name(), player_name .. " is dying and needs help") -- be gender neutral

olivattaque wrote:The value aren't always the expected (for example 2.49 instead of 2 or 3 and it often skip the 3) maybe because of the after method, i should manage the countdown in global step.


The value of what is 2.49? As noted above, you sould be decrementing your counter; but doing a globalsetp version would probably indeed be better...

olivattaque wrote: I could bypass the bones modes by saving the inventory, removing the block and putting it only when the player as not been saved but it may be a bit tricky and it the issue mentionned before (prevent player quitting the game without putting his bones) i could do it on register.leaveplayer


Again, if you managed things with global step, if th eplayer leaves when in limbo, you can use th global step handler to put bones back for known inventiroies whose players are no longer connected.

You can also leave the global step to manage saved and dead players, rather than relying on join and leave handlers (do these play well with player timeouts?)
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 38 guests