Respawning player after instance_destroy[SOLVED]

K

Karrlem

Guest
Hello, so I am trying to figure out how to respawn my player with a timer after it is destroyed, any ideas?
 

TheouAegis

Member
Suggestion 1: don't destroy it

Suggestion 2: you need the timer in a controller object that respawns the player
 

Fabseven

Member
set alarm[0] to some value when player is dead
in alarm[0] event : alarm[0] --
in draw gui or draw : draw countdown
in step event when countdown = 0 revive player and set countdown at -1

use instance_desactivate and instance_activate instead of destroy/create
(you still have to create the player in the beginning)
 
K

Karrlem

Guest
Suggestion 1: don't destroy it

Suggestion 2: you need the timer in a controller object that respawns the player
So what should I do to get rid of the player temporarily? I was thinking about using a timer the same way @Fabseven used it but I wasn't sure how to set it up properly.
 
K

Karrlem

Guest
set alarm[0] to some value when player is dead
in alarm[0] event : alarm[0] --
in draw gui or draw : draw countdown
in step event when countdown = 0 revive player and set countdown at -1

use instance_desactivate and instance_activate instead of destroy/create
(you still have to create the player in the beginning)
I will try is this out and see what happens.
 

Fabseven

Member
set alarm[0] to some value when player is dead
in alarm[0] event : alarm[0] --
in draw gui or draw : draw countdown
in step event when countdown = 0 revive player and set countdown at -1

use instance_desactivate and instance_activate instead of destroy/create
(you still have to create the player in the beginning)
I can explain it better i made some mistake in my explanation,
create an object "obj_system" or something
In this object , in create event : create a variable countdown_max_value = 100 (or other value)
in this object, in alarm 0 event : if(alarm[0] > 0) { alarm[0] --}
in this object, in draw or in draw gui : if(alarm[0] >0) { draw_text( xmiddle,ymiddle, "countdown before ressurection : " + string (alarm[0]) }
where xmiddle and y middle is the center of the screen or view (i do not want to explain there how you get theses values)
in this object : in step event : if (alarm[0] == 0) { //code to revive player , maybe with instance_activate or with instance_create, set alarm[0] to -1 }
in step event of obj_player : if( hp <= 0) { obj_system.alarm[0] = obj_system.countdown_max_value; instance_destroy or instance_desactivate }

SO , when the player is dead it will be destroyed or desactivated and alarm[0] of your obj_system will start to countdown from 100 to 0
While it's > 0 : we are drawing the countdown on the screen, nothing else
When it's a 0 : setting alarm[0] to -1 (so i cannot retrigger again) and then pop the obj_player again with create_instance or instance_activate
Is it better ?
 
K

Karrlem

Guest
I can explain it better i made some mistake in my explanation,
create an object "obj_system" or something
In this object , in create event : create a variable countdown_max_value = 100 (or other value)
in this object, in alarm 0 event : if(alarm[0] > 0) { alarm[0] --}
in this object, in draw or in draw gui : if(alarm[0] >0) { draw_text( xmiddle,ymiddle, "countdown before ressurection : " + string (alarm[0]) }
where xmiddle and y middle is the center of the screen or view (i do not want to explain there how you get theses values)
in this object : in step event : if (alarm[0] == 0) { //code to revive player , maybe with instance_activate or with instance_create, set alarm[0] to -1 }
in step event of obj_player : if( hp <= 0) { obj_system.alarm[0] = obj_system.countdown_max_value; instance_destroy or instance_desactivate }

SO , when the player is dead it will be destroyed or desactivated and alarm[0] of your obj_system will start to countdown from 100 to 0
While it's > 0 : we are drawing the countdown on the screen, nothing else
When it's a 0 : setting alarm[0] to -1 (so i cannot retrigger again) and then pop the obj_player again with create_instance or instance_activate
Is it better ?
Thanks a lot, It is better.
 
Top