• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.

Solved Restart Level on Death

Question that is answered or resolved.

aL BeasTie

Well-known member
LINK TO SOLUTION
http://www.chronocrash.com/forum/index.php?topic=1085.msg30486;topicseen#new

-----------------
I was trying to make a basic way to restart the current stage on death, I set up branches and named them 1 and 2 - then I have this script in player's death.

Code:
	@script
    	int iStage = openborvariant("current_stage");
    	if(frame == 4){
    	jumptobranch("iStage", 1);
    	}
	@end_script

I have stagenumber # set in the levels.

It kinda works except it just seems to jump to whatever the next level in the set is,  not the branch I want.

The level.txt is something like
Code:
set  TEST
file  data/levels/test.txt

branch 1
file  data/levels/1.txt

branch 2
file  data/levels/2.txt

It will just go test, 1, 2 and then end

 
update - I tried several ways to do the script, all of them work the same, it works perfectly how I wanted it too except it still just skipping to whatever comes after the current level in the set.
 
Ok I realized the problem, should of been jumptobranch(""+iStage, 1);

Code:
	@script
    	int iStage = openborvariant("current_stage");
    	if(frame == 4){
    	jumptobranch(""+iStage, 1);
    	}
	@end_script


But it still has a problem, it will jump to the correct branch now when you die, but if you die a second time the game just ends.  I don't understand why it would do this.
 
I thought it just means 'empty value'+stage number, or am adding a leading zero doing this? 

But it works the first time so the value must be okay right?  Before I changed it like this it just skipped to next level, now it skips to correct branch, but only once.

Also seems to be timing issue with changing stage before the game removes a life, if death anim takes too long the engine respawns the char before it gets to run the jumptobranch script.
But if I can't make the death anim any shorter, so I was using script to remove a life. 


But I'm still don't know how to subtract a value rather than just changing it.

Code:
void restart()
{
  void p1 = getplayerproperty(0, "entity");

  if(getentityproperty(p1, "exists")) {
  changeplayerproperty(0, "lives", -1);
}
 }
[/script]
 
Hey Beastie, try something like that:
Code:
  void restart()
{  
void p1 = getplayerproperty(0, "entity"); 
int p1lives = getplayerproperty(p1, "lives");
 if(getentityproperty(p1, "exists")) 
{ 
 changeplayerproperty(0, "lives", p1lives -1);
} 
}[/script] 
 
Thanks heaps it worked great. :)

I tried something like this after I posted, but I must of done it wrong.
 
UPDATE:

Well I got it working, but not sure why this would work.  ???

I changed the set in level.txt like this.

Code:
set  TEST
file  data/levels/test.txt
next
file  data/levels/test2.txt

branch 1
file  data/levels/1.txt
branch 1
file  data/levels/1.txt


branch 2
file  data/levels/2.txt
branch 2
file  data/levels/2.txt

Now it works and will restart the current stage every time you die, until it's game over.  If you end the stage it goes to 'next' in the main set as it should.
 
UPDATE/SOLVED!  ;D

So I was looking at this MOD again and fixed the problem, it was just a minor typo.  ::)
Also openborvariant("current_branch")  is the correct variant, thou current_level seemed to work anyway.



This is the script for restarting to current BRANCH.  In this example on FRAME 1
Code:
	@script
    	void iStage = openborvariant("current_branch");
     	if(frame == 1){
    	jumptobranch(iStage, 1);
    	}
	@end_script


This is the script command to restart to make sure player looses a life.  You need to put this somewhere.

Code:
void restart()
{  
void p1 = getplayerproperty(0, "entity"); 
int p1lives = getplayerproperty(p1, "lives");
 if(getentityproperty(p1, "exists")) 
{ 
 changeplayerproperty(0, "lives", p1lives -1);
 } 
}

I spawn this one frame after the jumptobranch command. 


I'm also using pause script by DC at the start on the animation to freeze gameplay the instant you die.

Code:
void paus0001(int iToggle, int iTime){

    /*
    paus0001
    Damon Vaughn Caskey
    11022009
    Pause or unpause action for all entities except self.
    */

    void vSelf      = getlocalvar("self");                  //Caller    
    int  iETime     = openborvariant("elapsed_time");       //Current time.
    int  iMax       = openborvariant("ent_max");            //Entity count.
    int  iEntity;                                           //Loop counter.
    void vEntity;                                           //Target entity.

    for(iEntity=0; iEntity<iMax; iEntity++)
    {    
        vEntity = getentity(iEntity);                                       //Get target entity from current loop.        
        
        if (vEntity != vSelf)                                               //Not Self?
        {
            changeentityproperty(vEntity, "frozen", iToggle);               //Toggle frozen.
            changeentityproperty(vEntity, "freezetime", iETime + iTime);    //Toggle frozen time.
        }
    }    
}
 
It's possible modify this script to the player respawn with 100 of health (full bar) always?

Code:
void restart()
{  
void p1 = getplayerproperty(0, "entity"); 
int p1lives = getplayerproperty(p1, "lives");
 if(getentityproperty(p1, "exists")) 
{ 
 changeplayerproperty(0, "lives", p1lives -1);
 } 
}

Because I'm using this script when player dies, when respawn the player loss a life, but the bar health is empty.

And one more thing, how works this scrip for three players?
Need a modification too?
 
Here an updated version of the restart script, for three players.
Courtesy of Maxman.

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);
 }
}


And if you restart the level after an enemiy kill you, just paste this script on any entity you spawn at beginning of the level, for restart the level with full health. Courtesy of Bloodbane.

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
 
I still working in the restart level on death and I can not find a solution for the restart work when players fall into the hole in Bulldozer level.
 
I may need to try couple things but I can tell for sure that ondeathscript is run when entity falls to hole.
 
These are very good news my friend.
But I don't want the player always run the ondeathscript when falls to hole.
I need only happend when falls in a specific hole.
In this case I mean the hole of stage6-3.
 
Hmm... that might need extra check to see which stage/level player in before running the restart level function
If you are using stage number, we might use that. But that might not be stable if you have other level with holes with same stage number
Okay forget about that, do you have any indexed variable or global variable which is resetted after a level end? we might use that

For other readers, here's a rough ondeathscript which checks hole when entity dies:

Code:
void main()
{// Death script
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x");
    int z = getentityproperty(self,"z");
    int y = getentityproperty(self,"a");

    int H = checkhole(x,z,y);

    if(H == 1){
// Lines in this bracket is run only if entity falls into hole
    }
}
 
Okay forget about that, do you have any indexed variable or global variable which is resetted after a level end? we might use that

Mmmm I think I have none.
The only script in the level stage6-3.txt

Is 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
 
Bloodbane said:
Can you show me your endlevel.c? that script might contain variable which can be used for that
Here my endlevel.c
Code:
#include "data/scripts/story/story_clear.c"

void main()
{
   clearStory();
   setdrawmethod(NULL(),0,256,256,0,0,0,0,0,0,0,0,0,NULL());
}
 
Hmmm... If you're using bosser item, there should be certain variables there
Anyways, never mind that, this is the updated ondeathscript with certain variable check:
Code:
void main()
{
    void self = getlocalvar("self");
    int Check = getindexedvar(1);
    int x = getentityproperty(self,"x");
    int z = getentityproperty(self,"z");
    int y = getentityproperty(self,"a");

    int H = checkhole(x,z,y);

    if(H == 1 && Check=="Chase"){
//  Insert restart function here
    }
}

Don't forget to insert restart function there :)
In order for this script to work, you need to set indexed variable 1 with "Chase" like this:
spawn Empty
@script
void main()
{
    setindexedvar(1, "Chase");
}
@end_script
coords 100 460
at 0

and to avoid the script be run on other holed levels, add this line in endlevel.c:
Code:
  setindexedvar(1, NULL());

HTH
 
Thanks my friend!

Let's go step by step to see if I'm ok:

here ondeathscript with restart function:
Code:
void main()
{
    void self = getlocalvar("self");
    int Check = getindexedvar(1);
    int x = getentityproperty(self,"x");
    int z = getentityproperty(self,"z");
    int y = getentityproperty(self,"a");

    int H = checkhole(x,z,y);

    if(H == 1 && Check=="Chase"){
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);
 }
}

Here my updated endlevel.c:
Code:
#include "data/scripts/story/story_clear.c"

void main()
{
   clearStory();
   setdrawmethod(NULL(),0,256,256,0,0,0,0,0,0,0,0,0,NULL());
{
  setindexedvar(1, NULL()); 
}


If this updated fles is ok, now can you tell me if this is the righ way to use this:

1) First set the ondeathscipt in all players.
2) Set this in the levels with the restart holes.
Code:
spawn   Empty
@script
void main()
{
    setindexedvar(1, "Chase");
}
@end_script
coords   100 460
at   0
3) How can spawn a dialogue story when player dies in the restart holes?
I think the wat is add in the ondeathscipt, but dont know how.
 
Back
Top Bottom