Solved Restart current Level on Death

Question that is answered or resolved.

dantedevil

Well-known member
I check this link first:

ChronoCrash


My idea is restart the same level when the bulldozer crush the player.
So when player dies, he resstart the same level losing a life.

But after restart level, the player loss a life but the bar of health is empty.

I do not understand why that happens.

If try to use an item with health, the bar never charges.


When the enemy kill the player he spawn this:
Code:
name     GO6-3
type    none


onspawnscript data/bgs/branches/end6-3.c
animationscript data/scripts/obstacle.c


anim idle
    delay    10
    offset    1 1
    frame    data/chars/misc/empty.png
        @cmd    anichange "ANI_FREESPECIAL1" 0
    frame    data/chars/misc/empty.png



anim freespecial1
    delay    2
    offset    1 1
        @cmd    restart
    frame    data/chars/misc/empty.png
    @script
        void iStage = openborvariant("current_branch");
         if(frame == 1){
        jumptobranch(iStage, 1);
        }
    @end_script
    frame    data/chars/misc/empty.png
    frame    data/chars/misc/empty.png
    frame    data/chars/misc/empty.png



And one more thing, how works this scrip for three players?
 
Last edited:
Solution
Not sure if this one will work for adding other players for restart, but I think it could be for one of the players to die first. I might be wrong though. You could possibly add player functions.

Code:
void restart()
{ 
void p1 = getplayerproperty(0, "entity");
int p1lives = getplayerproperty(p1, "lives");
void p2 = getplayerproperty(1, "entity");
int p2lives = getplayerproperty(p2, "lives");
void p3 = getplayerproperty(2, "entity");
int p3lives = getplayerproperty(p3, "lives");
 if(getentityproperty(p1, "exists"))
{
 changeplayerproperty(0, "lives", p1lives -1);
 }
 if(getentityproperty(p2, "exists"))
{
 changeplayerproperty(1, "lives", p2lives -1);
 }
 if(getentityproperty(p3, "exists"))
{
 changeplayerproperty(2, "lives", p3lives -1)...
TBH I think you want something slightly different. The script Beastie created is run on player's death meaning you will get level reset on death in ANY level not just bulldozer level

That means you need to run the script in other entity, either a blank entity or just the bulldozer itself. Since bulldozer or blank entity (if you use this) only appear in certain level, level reset on death won't occur in other levels

But after restart level, the player loss a life but the bar of health is empty.

That's easy, you can just fill player's HP and MP to max when level restarts. That's what I did in jousting in D&D mod :)

how works this scrip for three players?

It simply restarts the level on any player death, no matter how many active players there
 
That's easy, you can just fill player's HP and MP to max when level restarts. That's what I did in jousting in D&D mod :)

It would be better to modify the script to fill the health bar and work for 3 players?

That's easy, you can just fill player's HP and MP to max when level restarts. That's what I did in jousting in D&D mod :)

No idea about that,  how works?
 
Try this:
spawn empty
@script
void main()
{
    int P1 = getplayerproperty(0, "entity");
    int P2 = getplayerproperty(1, "entity");
    int P3 = getplayerproperty(2, "entity");

    if(P1){
      int MaxHP1 = getentityproperty(P1, "maxhealth");
      int MaxMP1 = getentityproperty(P1, "maxmp");

      changeentityproperty(P1,"health", MaxHP1);
      changeentityproperty(P1,"mp", MaxMP1);
    }
    if(P2){
      int MaxHP2 = getentityproperty(P2, "maxhealth");
      int MaxMP2 = getentityproperty(P2, "maxmp");

      changeentityproperty(P2,"health", MaxHP2);
      changeentityproperty(P2,"mp", MaxMP2);
    }
    if(P3){
      int MaxHP3 = getentityproperty(P3, "maxhealth");
      int MaxMP3 = getentityproperty(P3, "maxmp");

      changeentityproperty(P3,"health", MaxHP3);
      changeentityproperty(P3,"mp", MaxMP3);
    }
}
@end_script
coords 160 220 1
at 0

Actually you can just paste this script on any entity you spawn at beginning of the level. But if you're not sure, you can just use empty entity like in this example
 
Now works perfect my friend!
Thanks!

Only one more thing:

My players have three lifes, when loss all lifes crush by the bulldozer, the games goes to GAME OVER and never show the credits to continue.
That's not the idea.
 
I see the credits works ok without use this:
Code:
spawn   empty
@script
void main()
{
    int P1 = getplayerproperty(0, "entity");
    int P2 = getplayerproperty(1, "entity");
    int P3 = getplayerproperty(2, "entity");

    if(P1){
      int MaxHP1 = getentityproperty(P1, "maxhealth");
      int MaxMP1 = getentityproperty(P1, "maxmp");

      changeentityproperty(P1,"health", MaxHP1);
      changeentityproperty(P1,"mp", MaxMP1);
    }
    if(P2){
      int MaxHP2 = getentityproperty(P2, "maxhealth");
      int MaxMP2 = getentityproperty(P2, "maxmp");

      changeentityproperty(P2,"health", MaxHP2);
      changeentityproperty(P2,"mp", MaxMP2);
    }
    if(P3){
      int MaxHP3 = getentityproperty(P3, "maxhealth");
      int MaxMP3 = getentityproperty(P3, "maxmp");

      changeentityproperty(P3,"health", MaxHP3);
      changeentityproperty(P3,"mp", MaxMP3);
    }
}
@end_script
coords   160 220 1
at   0

So I think the best is update this script adding the refill health and the function for three players.

Code:
void restart()
{  
void p1 = getplayerproperty(0, "entity"); 
int p1lives = getplayerproperty(p1, "lives");
 if(getentityproperty(p1, "exists")) 
{ 
 changeplayerproperty(0, "lives", p1lives -1);
 } 
}
 
Not sure if this one will work for adding other players for restart, but I think it could be for one of the players to die first. I might be wrong though. You could possibly add player functions.

Code:
void restart()
{ 
void p1 = getplayerproperty(0, "entity");
int p1lives = getplayerproperty(p1, "lives");
void p2 = getplayerproperty(1, "entity");
int p2lives = getplayerproperty(p2, "lives");
void p3 = getplayerproperty(2, "entity");
int p3lives = getplayerproperty(p3, "lives");
 if(getentityproperty(p1, "exists"))
{
 changeplayerproperty(0, "lives", p1lives -1);
 }
 if(getentityproperty(p2, "exists"))
{
 changeplayerproperty(1, "lives", p2lives -1);
 }
 if(getentityproperty(p3, "exists"))
{
 changeplayerproperty(2, "lives", p3lives -1);
 }
}
 
Solution
You made my friend!

Your script works perfect!

Now I can devote myself completely to the last stage of the demo.
This problem was bothering me long ago.

Thank you very much friend!
 
Back
Top Bottom