GM:S 1.4 Respawn exactly inside the room without restarting it.

Discussion in 'Programming' started by Sugor, Jun 2, 2019.

  1. Sugor

    Sugor Member

    Joined:
    May 28, 2019
    Posts:
    17
    Can anyone help on making a respawn at the exact room without restarting the room and with death animation...
    I used the if (hp <= 0) {
    Instance_destroy();
    }

    Instead of making it destroy anyone has an idea?
     
  2. trentallain

    trentallain Member

    Joined:
    Aug 6, 2016
    Posts:
    521
    Create a controller object that checks a global variable for hp and keeps track of the object's x and y that you want to respawn. If the hp is <= 0 then destroy the object and then recreate it at the x and y you stored. To have a death animation, just have a variable that is false until the object is dead, then play the animation and then destroy it.
     
  3. Sugor

    Sugor Member

    Joined:
    May 28, 2019
    Posts:
    17
    Thank you I already think of that just to make sure...I haven't tested yet I'm fixing my laptop
     
  4. JasonTomLee

    JasonTomLee Member

    Joined:
    Jul 20, 2016
    Posts:
    115
    Here's some example code you could try out~
    Lmk if you got any questions- happy to help

    Code:
    [ Spawn Player right away ]
    
    //Destroy event of Player Object
    instance_create( x,y, oPlayer );
    
    [ or create the Player after a set respawn time ]
    
    // Destroy Event of Player Object
    with( oController ){
    spawnx = other.x;
    spawny = other.y;
    alarm[ 0 ] = room_speed;//spawn timer
    }
    
    //oController Object//
    //Create
    spawnx = 0;
    spawny = 0;
    
    //Alarm[0]
    instance_create( spawnx, spawny, oPlayer );
    
    
     
  5. Sugor

    Sugor Member

    Joined:
    May 28, 2019
    Posts:
    17
    am i suppose to put it on step event Then put inside of the if (Hp <= 0) { } or
    Or i will put Destroy event then put the script?
    Code:
    [ Spawn Player right away ]
    
    //Destroy event of Player Object
    instance_create( x,y, oPlayer );
    
    [ or create the Player after a set respawn time ]
    
    // Destroy Event of Player Object
    with( oController ){
    spawnx = other.x;
    spawny = other.y;
    alarm[ 0 ] = room_speed;//spawn timer
    }
     
  6. JasonTomLee

    JasonTomLee Member

    Joined:
    Jul 20, 2016
    Posts:
    115
    @Sugor
    You could do either!
    But I prefer putting death code inside the Destroy Event because it keeps things organized & it triggers the code only once.

    So you'd keep your current code of:
    if ( Hp <= 0 ) { instance_destroy }

    Then the instance_destroy would trigger the Destroy event because the object no longer exists. Make sure to create the Controller object as well! Lmk if you still need help w/that mate
     
  7. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,453
    The easiest way to do this is to make the player object create a new player object at its xstart/ystart position when it's destroyed. When you touch a checkpoint, create a new player object at it and destroy the old one. (Or change xstart / ystart - you CAN change them)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice