Character position after death

Daniele Spadoni

New member
In my level the character has position
spawn1  610 0 0

After the character dies he reappears every time to the right until he gets over my wall by making a bug.

How can I place a new position on the character after he dies?
 
in my double dragon game I used a script on one of the stages to always ensure the player would respawn in a safe place it would changed based on how far along the stage is.

Code:
anim respawn
	loop	0
	offset	19 75
	delay	3
	frame	none
	@cmd	teleport
	frame	none

void teleport()
{// used to respawn in safe locations
    
	char branch = OBV("current_branch");
	float x = GEP(self, "x");
	
	if(branch=="stage_6")
	{
		//CEP(self, "position", 0, 200, 0);
		CEP(self, "position", x, x<1059?309:278, 0);
	}
	
	if(branch=="stage_4")
	{
      CEP(self, "position", 1500, 188, 0);
	} else if(branch=="stage_1")
	{
      CEP(self, "position", x, 215, 0);
	} else if(branch=="stage_2")
	{
      CEP(self, "position", x, 280, 0);
	} else if(branch=="stage_5")
	{
      CEP(self, "position", 999, x<1400?310:300, 0);
	}
}
 
msmalik681 said:
in my double dragon game I used a script on one of the stages to always ensure the player would respawn in a safe place it would changed based on how far along the stage is.

Code:
anim respawn
	loop	0
	offset	19 75
	delay	3
	frame	none
	@cmd	teleport
	frame	none

void teleport()
{// used to respawn in safe locations
    
	char branch = OBV("current_branch");
	float x = GEP(self, "x");
	
	if(branch=="stage_6")
	{
		//CEP(self, "position", 0, 200, 0);
		CEP(self, "position", x, x<1059?309:278, 0);
	}
	
	if(branch=="stage_4")
	{
      CEP(self, "position", 1500, 188, 0);
	} else if(branch=="stage_1")
	{
      CEP(self, "position", x, 215, 0);
	} else if(branch=="stage_2")
	{
      CEP(self, "position", x, 280, 0);
	} else if(branch=="stage_5")
	{
      CEP(self, "position", 999, x<1400?310:300, 0);
	}
}

I can't understand how it works. :(
 
Daniele Spadoni said:
msmalik681 said:
in my double dragon game I used a script on one of the stages to always ensure the player would respawn in a safe place it would changed based on how far along the stage is.

Code:
anim respawn
	loop	0
	offset	19 75
	delay	3
	frame	none
	@cmd	teleport
	frame	none

void teleport()
{// used to respawn in safe locations
    
	char branch = OBV("current_branch");
	float x = GEP(self, "x");
	
	if(branch=="stage_6")
	{
		//CEP(self, "position", 0, 200, 0);
		CEP(self, "position", x, x<1059?309:278, 0);
	}
	
	if(branch=="stage_4")
	{
      CEP(self, "position", 1500, 188, 0);
	} else if(branch=="stage_1")
	{
      CEP(self, "position", x, 215, 0);
	} else if(branch=="stage_2")
	{
      CEP(self, "position", x, 280, 0);
	} else if(branch=="stage_5")
	{
      CEP(self, "position", 999, x<1400?310:300, 0);
	}
}

I can't understand how it works. :(

Sorry- - in the meantime while we wait for someone else to help you - see if my parameters work

spawn1 130 404 300


Basically this is from the manual:

Code:
spawn1 {x} {z} {a}

    Optional.
    {x} is relative to the starting edge of the screen. {z} is relative to the stage's minimum z value. {a} is relative to the ground.
    {x} is measured from left for levels with direction right and both and it's measured from right for levels with direction left.
    Although {x} could be any value, its maximum value is 320. Value more than 320 will be deducted by 320. For instance, setting x = 540 will put player in x = 220 instead (220 = 540 - 320).
    However, it's possible to give {x} negative value in direction both and right or big value in direction left and leftright to put player1 offscreen when level start. Why would you want this though?
    {z} could be any value but it can't put player 1 beyond maximum z value.
    Setting {a} > 0 makes player falls down on respawn. Default value for a is 300. NOTE: {a} only effect respawn not when level starts.
    If there's a hole on player's spawn spot, the spawn spot will be shifted up or down to safe place temporary.
 
PS VITA said:
Daniele Spadoni said:
msmalik681 said:
in my double dragon game I used a script on one of the stages to always ensure the player would respawn in a safe place it would changed based on how far along the stage is.

Code:
anim respawn
	loop	0
	offset	19 75
	delay	3
	frame	none
	@cmd	teleport
	frame	none

void teleport()
{// used to respawn in safe locations
    
	char branch = OBV("current_branch");
	float x = GEP(self, "x");
	
	if(branch=="stage_6")
	{
		//CEP(self, "position", 0, 200, 0);
		CEP(self, "position", x, x<1059?309:278, 0);
	}
	
	if(branch=="stage_4")
	{
      CEP(self, "position", 1500, 188, 0);
	} else if(branch=="stage_1")
	{
      CEP(self, "position", x, 215, 0);
	} else if(branch=="stage_2")
	{
      CEP(self, "position", x, 280, 0);
	} else if(branch=="stage_5")
	{
      CEP(self, "position", 999, x<1400?310:300, 0);
	}
}

I can't understand how it works. :(

Sorry- - in the meantime while we wait for someone else to help you - see if my parameters work

spawn1 130 404 300


Basically this is from the manual:

Code:
spawn1 {x} {z} {a}

    Optional.
    {x} is relative to the starting edge of the screen. {z} is relative to the stage's minimum z value. {a} is relative to the ground.
    {x} is measured from left for levels with direction right and both and it's measured from right for levels with direction left.
    Although {x} could be any value, its maximum value is 320. Value more than 320 will be deducted by 320. For instance, setting x = 540 will put player in x = 220 instead (220 = 540 - 320).
    However, it's possible to give {x} negative value in direction both and right or big value in direction left and leftright to put player1 offscreen when level start. Why would you want this though?
    {z} could be any value but it can't put player 1 beyond maximum z value.
    Setting {a} > 0 makes player falls down on respawn. Default value for a is 300. NOTE: {a} only effect respawn not when level starts.
    If there's a hole on player's spawn spot, the spawn spot will be shifted up or down to safe place temporary.

No it doesn't work
 
msmalik681 I saw that you use shortcuts for changeentityproperty, openborvariant, etc.
Without the code explaining that part, most of users won't understand how it work - neither it will work, to be honest.
I think its better to post the part where you define those constants.

Daniele Spadoni Its not a bug per se. You are trying to respawn the player inside a wall.
If I am not mistaken, Bloodbane has a script for that.

The code Malik had posted above works too, but its more complex for you now - because it depends on other things, like current branch, etc.
 
O Ilusionista said:
msmalik681 I saw that you use shortcuts for changeentityproperty, openborvariant, etc.
Without the code explaining that part, most of users won't understand how it work - neither it will work, to be honest.
I think its better to post the part where you define those constants.

Daniele Spadoni Its not a bug per se. You are trying to respawn the player inside a wall.
If I am not mistaken, Bloodbane has a script for that.

The code Malik had posted above works too, but its more complex for you now - because it depends on other things, like current branch, etc.

No it is. the player after his death reappears more and more to the right until you reach and overcome the wall.
Maybe I expressed myself badly. The player simply crosses the wall that he shouldn't.
I would like the player to reappear at a specific point.
 
Hmmm....
spawn1 610 0 0

For 640x480 resolution, that would place player 1 near right edge of screen on respawn. Even on regular levels, that's pretty risky location to respawn IMO.

Anyways, while waiting for malik's code, let me ask this:
where is this specific point? is it specific coords? ex: player1 will always respawn at x = 500 and z = 300 even if player dies at scrollpos 100 or 1000.
OR is it relative coords? ex: player1 will spawn 200 pixels relative to left edge of screen and 100 pixels from minimum z limit.
 
Hi, I'm looking at Daniele's level.txt. the problem could be a wall problem with the spawn1 coord (the screen resolution is 320X240 here).
Here's the level.txt:
Code:
music		data/music/livel1.bor


panel		data/bgs/stage1/stage1.1.png


direction both


order	a



# group1 #


nofadeout 1



#-------------------------------------
spawn1 610 64 0


wall -49 139 34 29 81 81 97 44
wall 468 138 49 49 424 410 97 40

#------------------------------------

spawn	police
alias   POLICEMAN
coords	50 0
at	10

I tried x=290 to align the character with the door but if he dies near a wall, the player will respawn at x= 290 (or previously x=610) above the wall, according to the current game screen.
The question is: how to fix the spawn/respawn point in one specific point of the level?

 
Here's script I've coded for fixed respawn coords:
Code:
anim	respawn
@script
    void self = getlocalvar("self");
    int iPIndex = getentityproperty(self,"playerindex");
    int x = getindexedvar(0); //Get respawn x coordinate
    int z = getindexedvar(1); //Get respawn z coordinate
    int a = getindexedvar(2); //Get respawn a coordinate
    int Flag = getindexedvar(3); //Get respawn flag
    int XPos = openborvariant("xpos");
    int Sx;

    if(a && x && z && frame == 0){
      if(Flag){
        Sx = x;
      } else {
        Sx = XPos+x;
      }

      if(iPIndex == 0){
        changeentityproperty(self, "position", Sx-10, z, a);
      } else if(iPIndex == 1){
        changeentityproperty(self, "position", Sx+10, z, a);
      }
    }
@end_script	
	delay	5
	offset	68 131
	frame	data/chars/misc/empty.gif
	frame	data/chars/billy/idle1.png

The script is using indexed variables but they can be changed into global variables easily if needed
Anyways, the script simply takes respawn coords defined in those variables and apply it when player respawns. Respawn coords are defined in level text like this:
Code:
spawn	Empty
@script
void main()
{
    setindexedvar(0, 100);
    setindexedvar(1, 584);
    setindexedvar(2, 380);
    setindexedvar(3, 1);
}
@end_script
coords	300 584
at	0

It means when player respawns, he/she will be respawned at x = 100, z = 584 and y = 380.

The script has features to position player 1 and player 2 apart when both respawns at the same time and flag to use relative respawning system.

This fixed respawn system is essential in 2D levels for many reasons. One reason is to ensure player is respawned at safe spot after respawning. The other reason is to prevent advancing forward after falling to hole by respawning.
 
You declared that respawn script in player's RESPAWN animation as shown in example.

The other script to set respawn coords is declared on any entity spawn. I choose empty cause it's not enemy type and won't disrupt enemy grouping.
 
Bloodbane said:
You declared that respawn script in player's RESPAWN animation as shown in example.

The other script to set respawn coords is declared on any entity spawn. I choose empty cause it's not enemy type and won't disrupt enemy grouping.

It doesn't work ... nothing happens .. same errors ... but it doesn't matter I start the character on the left of the screen and solve the problem.
 
Back
Top Bottom