Player spawn location problem

Die_In_Fire

Well-known member
In some stages. when player loses a life, it respawns inside walls or over the walls...
how can I prevent this?
 
but this is for normal levels, not 2d levels, with direction right, left or both.

before the player was spawned over the wall, but now is being spawned inside the walls, I don't know why. I dont know if changing build did alter this behaviour.

edit:
This script only works for players who have joined the game however. It doesn't work for players who join later.
 
I've solved this problem by recording coords on safe moments!!
Then on spawn/respawn I take these coords and I set those coords for the player.
A bit of code:
Code:
int set_coords(void player) {
    if ( getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN") ) {
        float x,z,a;
        int p = getentityproperty(player, "playerindex"); // non puoi ricavarti il player con getentityproperty(getplayerproperty(p, "entity")) poichè non esiste ancora
        int t;

        x = getglobalvar("p"+(p+1)+"respawn_x");
        z = getglobalvar("p"+(p+1)+"respawn_z");
        a = getglobalvar("p"+(p+1)+"respawn_a");

        if ( x != NULL() && z != NULL() && a != NULL() ) { // se sono nulle allora non è mai stato nel livello il personaggio. Verrà eseguita l'animazione RESPAWN
            changeentityproperty(player, "position", x, z, a);
        }
    }

}

int set_coords_predeath(void player) {
    int frames = 2, mem_frames = 150; // 150
    int refresh_time = openborvariant("elapsed_time")%frames;
    int anim_id = getentityproperty(player, "animationid");

    if ( refresh_time == 0 && anim_id != openborconstant("ANI_SPAWN") && anim_id != openborconstant("ANI_RESPAWN") ) {
        float x = getentityproperty(player, "x");
        float z = getentityproperty(player, "z");
        float a = getentityproperty(player, "a");
        float base = getentityproperty(player, "base");
        int p = getentityproperty(player, "playerindex");

        if ( ( anim_id == openborconstant("ANI_IDLE") || anim_id == openborconstant("ANI_RUN") || anim_id == openborconstant("ANI_WALK") || anim_id == openborconstant("ANI_LAND")
            || anim_id == openborconstant("ANI_GET") || anim_id == openborconstant("ANI_BLOCK") || anim_id == openborconstant("ANI_UP") || anim_id == openborconstant("ANI_DOWN")
            || anim_id == openborconstant("ANI_JUMPLAND") )
            && checkhole(x,z) == 0 && (a == base) ) { 

            setglobalvar("p"+(p+1)+"respawn_x", x);
            setglobalvar("p"+(p+1)+"respawn_z", z);
            setglobalvar("p"+(p+1)+"respawn_a", a);
        }
    }

}

Now in your script call:
    set_coords_predeath(self);
    set_coords(self);

Your chara will respawn exactly on prev position!! ;)

Then I wrote also a func to respawn in the right position if your chara spawn for the first time while some chara is in game/level yet.
But this func is a bit complex.
If you join later:
Code:
#define MAX_ALTITUDE 5000

int check_respawn(void player, float threshold) {

    if ( getentityproperty(getglobalvar("last_player_spawned"), "exists") && getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN")
        && getlocalvar("respawn") == NULL() ) { // && getentityproperty(player, "animpos") > 0
        void last_player = getglobalvar("last_player_spawned");
        int p = getentityproperty(last_player, "playerindex");
        float x = getglobalvar("p"+(p+1)+"respawn_x");
        float z = getglobalvar("p"+(p+1)+"respawn_z");
        float a = getglobalvar("p"+(p+1)+"respawn_a");
        int i;
        float t_alt = MAX_ALTITUDE;
        float x2, z2;

            //drawstring( 20,160,0,"Siamo qui!" );
            if ( getglobalvar("last_player_spawned") == player ) return; // Questa funzione ha senso rispetto ad altri giocatori e non a se stessi!! Altrimenti usare le p#respawn_X
            // Respawniamo un valore threshold di px in avanti/dietro/giù/su rispetto al giocatore già in gara
            for ( i = 0; i <= threshold; ++i ) { // <= così può assumere valore 0!

                    x2 = x-(threshold-i); z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break; // vedi se stai sopra un muro o una piattaforma

                    x2 = x-(threshold-i); z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x-(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x-(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

            } // fine for

        changeentityproperty(player, "position", x2, z2, a);
        //setglobalvar("last_player_spawned", player); // Impostiamo l'ultimo giocatore spawnato!
        // Lo impostiamo tra le animazioni con @cmd...

        setlocalvar("respawn", 1);
    }
}

int checkplatform(float distx, float distz, float altitude) {
    if ( checkplatformbelow(distx,distz,altitude) == checkplatformbelow(0,0,0) ) return NULL();
    else return checkplatformbelow(distx,distz,altitude);
}

Call this func in your script with: check_respawn(self,15);
By this way your chara will join in right position.
The func will perform a spiral around last player spawned as long as there is a right position.
Only thing you HAVE TO SET  a globalvar:
@cmd setglobalvar "last_player_spawned" getlocalvar("self")
You HAVE to set this globalvar at the second frame on your spawn/respawn animation.
It's all!!

Ps. param threshold (15) is the distance from last player spawned
 
Make your wall as tall as 1000 will prevent most such situations. The engine will check if the wall is too tall to spawn on, just in case som levels have low walls that allows you to walk on.
 
utunnels said:
Make your wall as tall as 1000 will prevent most such situations. The engine will check if the wall is too tall to spawn on, just in case som levels have low walls that allows you to walk on.
I can't. I have some levels that have small walls that interact with player and enemies.

I can't understand your solution white dragon, where to copy the code. I need to create a spawn script with your code?
 
Maybe you can place your character from the start with this I think:

Code:
spawn1	120 20

If it doesn't work for you, you can copy the two .txt files I have for spawning and respawning. You may need to make new .txt files and rename them in the following.

1spawn.txt:
name  1spawn
type  none
shadow  0

anim idle
@script
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x"); //Get character's x coordinate
    int z = getentityproperty(self,"z"); //Get character's z coordinate
    int a = getentityproperty(self,"a"); //Get character's a coordinate
    int P1 = getplayerproperty(0, "entity");

    changeentityproperty(P1, "position", x, z, a);
    killentity(self); //Suicide!
@end_script
  loop  1
  delay  5
  offset  1 1
  frame  data/chars/misc/empty.gif

Respawn.txt:
name Respawn
type none
offscreenkill 3000
antigravity 100


anim idle
@script
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x");
    int a = getentityproperty(self,"a");

    setindexedvar(0, x);
    setindexedvar(1, a);
    killentity(self);
@end_script
loop 1
delay 5
offset 1 1
frame data/chars/misc/empty.gif

Here's an example of a stage I have for respawn and 1spawn in a level. Spawning them is tricky. You need to know/understand about the number of scrollpos (at) for location in order where the entities are going to be spawned, but with total distance.

spawn  1spawn #Begin with 1spawn and its coords and at from the very beginning like this one here
coords  20 920 455 #1st par for spawn a char, 2nd par for z max, 3rd par for altitude for moving up when increasing number on entity (to move up) from the very ground (maybe zmax I think)
at      0 #0+20= 20

spawn Empty
coords 4500 920 200
at 0 #4500+0=4500

spawn  Ice_Floor
coords  0 920 440
at      0

spawn  Ice_Block
coords  424 920 440
at      0 #0+424= 424

spawn Star
health 20
coords 700 920 600
at 0

spawn Star
health 20
coords 900 920 700
at 17

spawn  Ice_Floor2
coords  780 920 632 #481+300
at      18 #781+17= 798

spawn  Respawn
coords  0 920 460 #Have it respawned with 0 in x coord
at      220 #0+220= 220 #Where you're going to be respawned after getting killed/dying/falling

spawn  Respawn
coords  0 920 600
at      500

spawn  Ice_Panel
coords  528 920 714 #480+48=528
at      682 # 528+682= 1210 / 682-528=156

spawn  Ice_Panel
coords  528 920 714
at      767 #528+767= 1295

spawn  Respawn
coords  0 920 700
at      850

spawn    Ice_Panel
coords  528 920 714
at      850 #850+528= 1378

Here's a character spawn and respawn anims as example:

anim respawn
@script
    void self = getlocalvar("self");
    int x = getindexedvar(0); //Get respawn x coordinate
    int z = getentityproperty(self,"z"); //Get character's z coordinate
    int a = getindexedvar(1); //Get respawn a coordinate

    if(x==NULL()){
      x = getentityproperty(self, "x");
    }

    if(a!=NULL()){
      if(frame == 1){
        changeentityproperty(self, "position", x, z, a);
      }
    }
@end_script
delay 1
offset 23 66
frame data/chars/jj/stand1.png
frame data/chars/jj/stand1.png

anim spawn
delay 1
offset 23 66
frame data/chars/jj/stand1.png
frame data/chars/jj/stand1.png

Bloodbane helped me on the set for the spawns.

Please excuse the 1spawn.txt 'cause I think it's 1 player. I think if you remove the P1 under that when you want all players to spawn where you are, you can modify or change it. You can change the name from '1spawn' to 'spawn' 'cause I have it for 1 player. I don't know about yours. You can try to figure it out I think.
 
Die_In_Fire said:
I can't understand your solution white dragon, where to copy the code. I need to create a spawn script with your code?

To use my code use script event to call these func:
1) create spawn.c and write my funcs.
2) Then write in chara.txt -> script data/scripts/spawn.c to call the script on script event
3) Then in spawn.c write in the main:
set_coords_predeath(self);
set_coords(self);
check_respawn(self,15);
4) Write @cmd setglobalvar "last_player_spawned" getlocalvar("self") ABOVE the SECOND frame of your spawn/respawn anim.
 
:-[
White Dragon said:
1) create spawn.c and write my funcs.
3) Then in spawn.c write in the main:
set_coords_predeath(self);
set_coords(self);
check_respawn(self,15);
please can you check if my spawn.c is ok??
Code:
int set_coords(void player) {
    if ( getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN") ) {
        float x,z,a;
        int p = getentityproperty(player, "playerindex"); // non puoi ricavarti il player con getentityproperty(getplayerproperty(p, "entity")) poichè non esiste ancora
        int t;

        x = getglobalvar("p"+(p+1)+"respawn_x");
        z = getglobalvar("p"+(p+1)+"respawn_z");
        a = getglobalvar("p"+(p+1)+"respawn_a");

        if ( x != NULL() && z != NULL() && a != NULL() ) { // se sono nulle allora non è mai stato nel livello il personaggio. Verrà eseguita l'animazione RESPAWN
            changeentityproperty(player, "position", x, z, a);
        }
    }

}

int set_coords_predeath(void player) {
    int frames = 2, mem_frames = 150; // 150
    int refresh_time = openborvariant("elapsed_time")%frames;
    int anim_id = getentityproperty(player, "animationid");

    if ( refresh_time == 0 && anim_id != openborconstant("ANI_SPAWN") && anim_id != openborconstant("ANI_RESPAWN") ) {
        float x = getentityproperty(player, "x");
        float z = getentityproperty(player, "z");
        float a = getentityproperty(player, "a");
        float base = getentityproperty(player, "base");
        int p = getentityproperty(player, "playerindex");

        if ( ( anim_id == openborconstant("ANI_IDLE") || anim_id == openborconstant("ANI_RUN") || anim_id == openborconstant("ANI_WALK") || anim_id == openborconstant("ANI_LAND")
            || anim_id == openborconstant("ANI_GET") || anim_id == openborconstant("ANI_BLOCK") || anim_id == openborconstant("ANI_UP") || anim_id == openborconstant("ANI_DOWN")
            || anim_id == openborconstant("ANI_JUMPLAND") )
            && checkhole(x,z) == 0 && (a == base) ) { 

            setglobalvar("p"+(p+1)+"respawn_x", x);
            setglobalvar("p"+(p+1)+"respawn_z", z);
            setglobalvar("p"+(p+1)+"respawn_a", a);
        }
    }

}

#define MAX_ALTITUDE 5000

int check_respawn(void player, float threshold) {

    if ( getentityproperty(getglobalvar("last_player_spawned"), "exists") && getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN")
        && getlocalvar("respawn") == NULL() ) { // && getentityproperty(player, "animpos") > 0
        void last_player = getglobalvar("last_player_spawned");
        int p = getentityproperty(last_player, "playerindex");
        float x = getglobalvar("p"+(p+1)+"respawn_x");
        float z = getglobalvar("p"+(p+1)+"respawn_z");
        float a = getglobalvar("p"+(p+1)+"respawn_a");
        int i;
        float t_alt = MAX_ALTITUDE;
        float x2, z2;

            //drawstring( 20,160,0,"Siamo qui!" );
            if ( getglobalvar("last_player_spawned") == player ) return; // Questa funzione ha senso rispetto ad altri giocatori e non a se stessi!! Altrimenti usare le p#respawn_X
            // Respawniamo un valore threshold di px in avanti/dietro/giù/su rispetto al giocatore già in gara
            for ( i = 0; i <= threshold; ++i ) { // <= così può assumere valore 0!

                    x2 = x-(threshold-i); z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break; // vedi se stai sopra un muro o una piattaforma

                    x2 = x-(threshold-i); z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x-(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x-(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

            } // fine for

        changeentityproperty(player, "position", x2, z2, a);
        //setglobalvar("last_player_spawned", player); // Impostiamo l'ultimo giocatore spawnato!
        // Lo impostiamo tra le animazioni con @cmd...

        setlocalvar("respawn", 1);
    }
}

int checkplatform(float distx, float distz, float altitude) {
    if ( checkplatformbelow(distx,distz,altitude) == checkplatformbelow(0,0,0) ) return NULL();
    else return checkplatformbelow(distx,distz,altitude);
}

set_coords_predeath(self);
set_coords(self);
check_respawn(self,15);

2) Then write in chara.txt -> script data/scripts/spawn.c to call the script on script event
but I should declare like this? animationscript script data/scripts/spawn.c <--is correct?

4) Write @cmd setglobalvar "last_player_spawned" getlocalvar("self") ABOVE the SECOND frame of your spawn/respawn anim.

like this right?
Code:
anim respawn
	loop    0
	delay   5
	offset  30 81
	frame      data/chars/billy/02.png
	@cmd setglobalvar "last_player_spawned" getlocalvar("self")
	frame      data/chars/billy/02.png
	frame      data/chars/billy/02.png

PS: I tried to upload a .c file, size 6kb and failed, then tried a .rar file size 2kb and also failed, giving me this message:
The upload folder is full. Please try a smaller file and/or contact an administrator.
Does anybody else have this problem?
 
This is the Whole "spawn.c" file:

Code:
#define MAX_ALTITUDE 5000
void main() {
    void self = getlocalvar("self");

    set_coords_predeath(self);
    set_coords(self);
    check_respawn(self,15);
}

int set_coords(void player) {
    if ( getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN") ) {
        float x,z,a;
        int p = getentityproperty(player, "playerindex"); // non puoi ricavarti il player con getentityproperty(getplayerproperty(p, "entity")) poichè non esiste ancora
        int t;

        x = getglobalvar("p"+(p+1)+"respawn_x");
        z = getglobalvar("p"+(p+1)+"respawn_z");
        a = getglobalvar("p"+(p+1)+"respawn_a");

        if ( x != NULL() && z != NULL() && a != NULL() ) { // se sono nulle allora non è mai stato nel livello il personaggio. Verrà eseguita l'animazione RESPAWN
            changeentityproperty(player, "position", x, z, a);
        }
    }
}

int set_coords_predeath(void player) {
    int frames = 2, mem_frames = 150; // 150
    int refresh_time = openborvariant("elapsed_time")%frames;
    int anim_id = getentityproperty(player, "animationid");

    if ( refresh_time == 0 && anim_id != openborconstant("ANI_SPAWN") && anim_id != openborconstant("ANI_RESPAWN") ) {
        float x = getentityproperty(player, "x");
        float z = getentityproperty(player, "z");
        float a = getentityproperty(player, "a");
        float base = getentityproperty(player, "base");
        int p = getentityproperty(player, "playerindex");

        if ( ( anim_id == openborconstant("ANI_IDLE") || anim_id == openborconstant("ANI_RUN") || anim_id == openborconstant("ANI_WALK") || anim_id == openborconstant("ANI_LAND")
            || anim_id == openborconstant("ANI_GET") || anim_id == openborconstant("ANI_BLOCK") || anim_id == openborconstant("ANI_UP") || anim_id == openborconstant("ANI_DOWN")
            || anim_id == openborconstant("ANI_JUMPLAND") )
            && checkhole(x,z) == 0 && (a == base) ) { 

            setglobalvar("p"+(p+1)+"respawn_x", x);
            setglobalvar("p"+(p+1)+"respawn_z", z);
            setglobalvar("p"+(p+1)+"respawn_a", a);
        }
    }
}

int check_respawn(void player, float threshold) {

    if ( getentityproperty(getglobalvar("last_player_spawned"), "exists") && getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN")
        && getlocalvar("respawn") == NULL() ) { // && getentityproperty(player, "animpos") > 0
        void last_player = getglobalvar("last_player_spawned");
        int p = getentityproperty(last_player, "playerindex");
        float x = getglobalvar("p"+(p+1)+"respawn_x");
        float z = getglobalvar("p"+(p+1)+"respawn_z");
        float a = getglobalvar("p"+(p+1)+"respawn_a");
        int i;
        float t_alt = MAX_ALTITUDE;
        float x2, z2;

            //drawstring( 20,160,0,"Siamo qui!" );
            if ( getglobalvar("last_player_spawned") == player ) return; // Questa funzione ha senso rispetto ad altri giocatori e non a se stessi!! Altrimenti usare le p#respawn_X
            // Respawniamo un valore threshold di px in avanti/dietro/giù/su rispetto al giocatore già in gara
            for ( i = 0; i <= threshold; ++i ) { // <= così può assumere valore 0!

                    x2 = x-(threshold-i); z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break; // vedi se stai sopra un muro o una piattaforma

                    x2 = x-(threshold-i); z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z+(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x; z2 = z-(threshold-i);
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x-(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x-(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

                    x2 = x+(threshold-i); z2 = z;
                    if ( checkwall(x2,z2) <= 0  && checkplatform(x2,z2,t_alt) == NULL() && checkhole(x2,z2) == 0 ) break;

            } // fine for

        changeentityproperty(player, "position", x2, z2, a);
        //setglobalvar("last_player_spawned", player); // Impostiamo l'ultimo giocatore spawnato!
        // Lo impostiamo tra le animazioni con @cmd...

        setlocalvar("respawn", 1);
    }
}

int checkplatform(float distx, float distz, float altitude) {
    if ( checkplatformbelow(distx,distz,altitude) == checkplatformbelow(0,0,0) ) return NULL();
    else return checkplatformbelow(distx,distz,altitude);
}

1) Copy all prev script and write it in spawn.c file.
2) Then in your chara.txt
    animationscript script data/scripts/spawn.c //----------> IS WRONG
    script data/scripts/spawn.c //----------> IS RIGHT!! ;)
3) OK for: @cmd setglobalvar "last_player_spawned" getlocalvar("self") # ----------> YOU ARE RIGHT!! ;)

Ps. I advice you to clearglobalvar(); at the beginning of a level!! ;)
 
for example write this code in your level1.txt (not levels.txt):

Code:
levelscript @script
void main() {
    clearglobalvar();
}
@end_script

This script runs once at the beginning of the level. ;)
 
White Dragon, here's my question. How can I get to respawn characters without killing himself or dying of respawning after going back near the beginning of the stage from an ending part for ending a level? It's because when I walk from ending a level to near the beginning of level and I fall down to a pit, the character keeps killing himself every time I press start to continue and I keep losing credits after falling. I already set the offscreenkill value to 17000 or 30000, but my character keeps doing it (I guess). I think I have a respawning problem.
 
White Dragon said:
Mmm.. tell me, have you used my script?
because I check for a hole...
If u use my script you'll respawn at last SAFE position ^__^
Nope. Haven't used. I will try out your script to see how it works.
 
Update:

Intstead of @cmd setglobalvar "last_player_spawned" getlocalvar("self")
Use this code into a spawn/respawn anim:

Code:
	@script
		void self = getlocalvar("self");
		int p = getentityproperty(self, "playerindex");
		int animpos = getentityproperty(self, "animpos");

		if ( animpos == 1 ) {
        		float x = getentityproperty(self, "x");
        		float z = getentityproperty(self, "z");
        		float a = getentityproperty(self, "a");

            		setglobalvar("p"+(p+1)+"respawn_x", x);
            		setglobalvar("p"+(p+1)+"respawn_z", z);
            		setglobalvar("p"+(p+1)+"respawn_a", a);
			setglobalvar("last_player_spawned", self);
		}
	@end_script

Example:

Code:
anim	SPAWN
	@script
		void self = getlocalvar("self");
		int p = getentityproperty(self, "playerindex");
		int animpos = getentityproperty(self, "animpos");

		if ( animpos == 1 ) {
        		float x = getentityproperty(self, "x");
        		float z = getentityproperty(self, "z");
        		float a = getentityproperty(self, "a");

            		setglobalvar("p"+(p+1)+"respawn_x", x);
            		setglobalvar("p"+(p+1)+"respawn_z", z);
            		setglobalvar("p"+(p+1)+"respawn_a", a);
			setglobalvar("last_player_spawned", self);
		}
	@end_script

	loop 0

	bbox	0 0 0 0
	jumpframe 0 2.8 0.6
	landframe 3

	delay 1
	offset	28 59
	frame	data/chars/misc/empty.gif

	delay	80
	offset  26  84
	frame	data/chars/don/044.gif
	frame	data/chars/don/044.gif
 
Die_In_Fire said:
White Dragon, what is the difference using this new updated method?

latest script a bit buggy.
Now the script works on walls and on platforms and no longer need to set @cmd setglobalvar etc...
New Update:

spawn.c
Code:
#define MAX_ALTITUDE 5000
#define MAX_PLAYERS openborvariant("maxplayers")

void main() {
    void self = getlocalvar("self");

    set_inspawning(self,15); // must be first func!!
    set_coords_predeath(self);
    set_coords(self);
}

int set_coords(void player, float max_alt) {
    if ( getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN") ) {
        float x,z,a,base;
        int p = getentityproperty(player, "playerindex"); // non puoi ricavarti il player con getentityproperty(getplayerproperty(p, "entity")) poichè non esiste ancora
        int t;

        x = getglobalvar("p"+(p+1)+"respawn_x");
        z = getglobalvar("p"+(p+1)+"respawn_z");
        a = getglobalvar("p"+(p+1)+"respawn_a");
        base = getglobalvar("p"+(p+1)+"respawn_base");

        if ( check_incam_pos(x,z) == 1 ) { // siamo nel riquadro giusto?
            if ( x != NULL() && z != NULL() && a != NULL() && a < max_alt ) { // se sono nulle allora non è mai stato nel livello il personaggio. Verrà eseguita l'animazione RESPAWN
                //changeentityproperty(player, "subject_to_wall", 0);
                //changeentityproperty(player, "subject_to_platform", 0);
                changeentityproperty(player, "position", x, z, a);
            } else {
                void last_player = getglobalvar("last_player_spawned");
                int p = getentityproperty(last_player, "playerindex");
                int distance = getlocalvar("distance");
                int result;

                //if ( !getentityproperty(last_player,"exists") || getentityproperty(last_player,"type") != openborconstant("type_player") ) {
                    last_player = generate_last_player_spawned(player,1);
                //}

                if (distance == NULL()) distance = 15;
                result = check_respawn(player,distance);
                if ( result < 1 ) set_latest_safe_coords(player);
                setlocalvar("respawn", 1);
            }
        } else {
            void last_player = getglobalvar("last_player_spawned");
            int p = getentityproperty(last_player, "playerindex");
            int distance = getlocalvar("distance");
            int result;

            //if ( !getentityproperty(last_player,"exists") || getentityproperty(last_player,"type") != openborconstant("type_player") ) {
                last_player = generate_last_player_spawned(player,1);
            //}

            if (distance == NULL()) distance = 15;
            result = check_respawn(player,distance);
            if ( result < 1 ) set_latest_safe_coords(player);
            setlocalvar("respawn", 1);
        } // fine if incam

        // ##### IMPORTANTE: Facciamo eseguire questo script per tutta la durata del respawn!! Perchè al primo frame potrebbero accadere errori!!
    }
}

void set_latest_safe_coords(void player) {
    float xmax = NULL();
    int p;
    float xp,zp,ap,basep,x,z,a;
    int pindex = getentityproperty(player, "playerindex");

    for (p = 0; p < MAX_PLAYERS; ++p) {
        int max_player = getplayerproperty(p, "entity");

        //if ( !getentityproperty(max_player, "exists") ) continue;

        xp = getglobalvar("p"+(p+1)+"respawn_x");
        zp = getglobalvar("p"+(p+1)+"respawn_z");
        ap = getglobalvar("p"+(p+1)+"respawn_a");
        basep = getglobalvar("p"+(p+1)+"respawn_base");

        if ( xmax == NULL() || xp > xmax ) {
            if ( xp != NULL() && zp != NULL() && ap != NULL() && check_incam_pos(xp,zp) == 1 ) {
                xmax = xp;
                setglobalvar("p"+(pindex+1)+"respawn_x",xp);
                setglobalvar("p"+(pindex+1)+"respawn_z",zp);
                setglobalvar("p"+(pindex+1)+"respawn_a",ap);
                setglobalvar("p"+(pindex+1)+"respawn_base",basep);
            }
        } // fine if xmax
    } // fine for

    if ( x != NULL() && z != NULL() && a != NULL() ) {
        changeentityproperty(player, "position", x, z, a);
    }
}

// if flag on, search last player spawned but not == self
void generate_last_player_spawned(void self, int self_flag) {
    int p;
    float last_player = NULL();

    for (p = 0; p < MAX_PLAYERS; ++p) {
        int player = getplayerproperty(p, "entity");
        int time = NULL(), last_time = NULL();

        if ( !getentityproperty(player, "exists") ) continue;
        if ( getglobalvar("p"+(p+1)+"spawning") == 1 ) continue; // sta spawnando ora
        if ( self_flag > 1 && self == player ) continue;

        time = getglobalvar("p"+(p+1)+"spawn_time");
        if ( last_time == NULL() || time > last_time ) {
            last_player = player;
            last_time = time;
        }
    } // fine for

    setglobalvar("last_player_spawned", last_player);

    return last_player;
}

void set_inspawning(void player, int respawn_distance) {
    int anim_id = getentityproperty(player, "animationid");

    if ( anim_id == openborconstant("ANI_RESPAWN") || anim_id == openborconstant("ANI_SPAWN") ) {
        int p = getentityproperty(player, "playerindex");

        if ( respawn_distance != getlocalvar("distance") ) setlocalvar("distance", respawn_distance);
        if ( getglobalvar("p"+(p+1)+"spawning") != 1 ) setglobalvar("p"+(p+1)+"spawning", 1);
    } else {
        int p = getentityproperty(player, "playerindex");

        if ( getglobalvar("p"+(p+1)+"spawning") == 1 ) {
                setglobalvar("last_player_spawned", player);
                setglobalvar("p"+(p+1)+"spawn_time", openborvariant("elapsed_time"));
                if ( getlocalvar("respawn") != NULL() ) setlocalvar("respawn", NULL());
                setglobalvar("p"+(p+1)+"spawning", 0);
        }
    }

}

int check_incam_pos(float x, float z) {
    float scr_posx = openborvariant("xpos");
    int hres = openborvariant("hresolution");
    float zmin_distance = get_zmin_distance();
    float zmax_distance = get_zmax_distance();
    float threshold = 5;

    if ( x == NULL() || z == NULL() ) return 0;
    if ( x < scr_posx+threshold || x > scr_posx+hres-threshold ) return 0;
    if ( z < zmin_distance+threshold || z > zmax_distance-threshold ) return 0;

    return 1;
}

int set_coords_predeath(void player, float max_alt) {
    int frames = 2, mem_frames = (openborvariant("game_speed")/4)*3; // 150
    int refresh_time = openborvariant("elapsed_time")%frames;
    int anim_id = getentityproperty(player, "animationid");

    if ( refresh_time == 0 && anim_id != openborconstant("ANI_SPAWN") && anim_id != openborconstant("ANI_RESPAWN") ) {
        float x = getentityproperty(player, "x");
        float z = getentityproperty(player, "z");
        float a = getentityproperty(player, "a");
        float base = getentityproperty(player, "base");
        int p = getentityproperty(player, "playerindex");

        if ( ( anim_id == openborconstant("ANI_IDLE") || anim_id == openborconstant("ANI_RUN") || anim_id == openborconstant("ANI_WALK") || anim_id == openborconstant("ANI_LAND")
            || anim_id == openborconstant("ANI_GET") || anim_id == openborconstant("ANI_BLOCK") || anim_id == openborconstant("ANI_UP") || anim_id == openborconstant("ANI_DOWN")
            || anim_id == openborconstant("ANI_JUMPLAND") ) && checkhole(x,z) == 0 && (a == base) ) {

            //drawstring( 10,200,0,"Storing Coords...");
            setglobalvar("p"+(p+1)+"respawn_x", x);
            setglobalvar("p"+(p+1)+"respawn_z", z);
            setglobalvar("p"+(p+1)+"respawn_a", a);
            setglobalvar("p"+(p+1)+"respawn_base", base);

            // Memorizziamo l'altitudine così da confrontarla con la prossima al prossimo frame. In caso si deve memorizzare la posizione sopra una piattaforma.
            // Infatti se stesse saltando o cadendo l'altitudine non sarebbe mai uguale da un frame all'altro...
            //setlocalvar("a_coord", a);
        }
    }
}

// Sistemiamo il personaggio dopo il respawn ne caso è dentro una platform (lo script può essere eseguito solo ora e non onspawn event)
// 1 ha esito positivo, 0 non esiste l'ultimo player spawned o non è nel quadro, -1 ultimo giocatore spawnato è se stesso, 2 non viene eseguito
int check_respawn(void player, float threshold) {
    if ( getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN") && getlocalvar("respawn") == NULL() ) { // && getentityproperty(player, "animpos") > 0
        void last_player = getglobalvar("last_player_spawned");

            //drawstring( 20,160,0,"Siamo qui!" );
            if ( getglobalvar("last_player_spawned") == player ) {
                    return -1; // Questa funzione ha senso rispetto ad altri giocatori e non a se stessi!! Altrimenti usare le p#respawn_X
            }

            if ( !getentityproperty(last_player,"exists") || getentityproperty(last_player,"type") != openborconstant("type_player") || last_player == NULL() ) {
                return 0;
            } else {
                int p = getentityproperty(last_player, "playerindex");
                float x = getglobalvar("p"+(p+1)+"respawn_x");
                float z = getglobalvar("p"+(p+1)+"respawn_z");
                float a = getglobalvar("p"+(p+1)+"respawn_a");
                float base = getglobalvar("p"+(p+1)+"respawn_base");
                int i;
                float t_alt = MAX_ALTITUDE;
                float x2, z2;
                float wall, platform_a;
                void platform;

                    if ( check_incam_pos(x,z) == 0 ) {
                        return 0;
                    }

                    // Respawniamo un valore threshold di px in avanti/dietro/giù/su rispetto al giocatore già in gara
                    for ( i = 0; i <= threshold; ++i ) { // <= così può assumere valore 0!
                            x2 = x-(threshold-i); z2 = z+(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break; // vedi se stai sopra un muro o una piattaforma

                            x2 = x-(threshold-i); z2 = z-(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x+(threshold-i); z2 = z+(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x+(threshold-i); z2 = z-(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x; z2 = z+(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x; z2 = z-(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x; z2 = z+(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x; z2 = z-(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x-(threshold-i); z2 = z;
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x-(threshold-i); z2 = z;
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x+(threshold-i); z2 = z;
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x+(threshold-i); z2 = z;
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;
                    } // fine for

                changeentityproperty(player, "position", x2, z2, a);

                //setglobalvar("last_player_spawned", player); // Impostiamo l'ultimo giocatore spawnato!
                // Lo impostiamo tra le animazioni con @cmd...
                setlocalvar("respawn", 1);
                return 1;
            } // fine if last_player exists
    } else {
        return 2;
    }
}

int checkplatform(float distx, float distz, float altitude) {
    if ( checkplatformbelow(distx,distz,altitude) == checkplatformbelow(0,0,0) ) return NULL();
    else return checkplatformbelow(distx,distz,altitude);
}

float get_zmin_distance() {
    float scr_posy = openborvariant("ypos");
    int zmin_threshold = 20;
    float zmin_bound = scr_posy+zmin_threshold;

    return zmin_bound;
}

float get_zmax_distance() {
    float scr_posy = openborvariant("ypos");
    int vres = openborvariant("vresolution");
    int zmax_threshold = 20;
    float zmax_bound = scr_posy+vres+zmax_threshold;

    return zmax_bound;
}

To use this new code:
1) Copy all prev script and write it in spawn.c file.
2) Then in your chara.txt write
    script data/scripts/spawn.c

Ps. I advice you to clearglobalvar(); at the beginning of a level with:
Code:
levelscript @script
void main() {
    clearglobalvar();
}
@end_script
 
it doesn't work for me...

I did this:
1. I replaced the previous spawn.c with your update
White Dragon said:
spawn.c
Code:
#define MAX_ALTITUDE 5000
#define MAX_PLAYERS openborvariant("maxplayers")

void main() {
    void self = getlocalvar("self");

    set_inspawning(self,15); // must be first func!!
    set_coords_predeath(self);
    set_coords(self);
}

int set_coords(void player, float max_alt) {
    if ( getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN") ) {
        float x,z,a,base;
        int p = getentityproperty(player, "playerindex"); // non puoi ricavarti il player con getentityproperty(getplayerproperty(p, "entity")) poichè non esiste ancora
        int t;

        x = getglobalvar("p"+(p+1)+"respawn_x");
        z = getglobalvar("p"+(p+1)+"respawn_z");
        a = getglobalvar("p"+(p+1)+"respawn_a");
        base = getglobalvar("p"+(p+1)+"respawn_base");

        if ( check_incam_pos(x,z) == 1 ) { // siamo nel riquadro giusto?
            if ( x != NULL() && z != NULL() && a != NULL() && a < max_alt ) { // se sono nulle allora non è mai stato nel livello il personaggio. Verrà eseguita l'animazione RESPAWN
                //changeentityproperty(player, "subject_to_wall", 0);
                //changeentityproperty(player, "subject_to_platform", 0);
                changeentityproperty(player, "position", x, z, a);
            } else {
                void last_player = getglobalvar("last_player_spawned");
                int p = getentityproperty(last_player, "playerindex");
                int distance = getlocalvar("distance");
                int result;

                //if ( !getentityproperty(last_player,"exists") || getentityproperty(last_player,"type") != openborconstant("type_player") ) {
                    last_player = generate_last_player_spawned(player,1);
                //}

                if (distance == NULL()) distance = 15;
                result = check_respawn(player,distance);
                if ( result < 1 ) set_latest_safe_coords(player);
                setlocalvar("respawn", 1);
            }
        } else {
            void last_player = getglobalvar("last_player_spawned");
            int p = getentityproperty(last_player, "playerindex");
            int distance = getlocalvar("distance");
            int result;

            //if ( !getentityproperty(last_player,"exists") || getentityproperty(last_player,"type") != openborconstant("type_player") ) {
                last_player = generate_last_player_spawned(player,1);
            //}

            if (distance == NULL()) distance = 15;
            result = check_respawn(player,distance);
            if ( result < 1 ) set_latest_safe_coords(player);
            setlocalvar("respawn", 1);
        } // fine if incam

        // ##### IMPORTANTE: Facciamo eseguire questo script per tutta la durata del respawn!! Perchè al primo frame potrebbero accadere errori!!
    }
}

void set_latest_safe_coords(void player) {
    float xmax = NULL();
    int p;
    float xp,zp,ap,basep,x,z,a;
    int pindex = getentityproperty(player, "playerindex");

    for (p = 0; p < MAX_PLAYERS; ++p) {
        int max_player = getplayerproperty(p, "entity");

        //if ( !getentityproperty(max_player, "exists") ) continue;

        xp = getglobalvar("p"+(p+1)+"respawn_x");
        zp = getglobalvar("p"+(p+1)+"respawn_z");
        ap = getglobalvar("p"+(p+1)+"respawn_a");
        basep = getglobalvar("p"+(p+1)+"respawn_base");

        if ( xmax == NULL() || xp > xmax ) {
            if ( xp != NULL() && zp != NULL() && ap != NULL() && check_incam_pos(xp,zp) == 1 ) {
                xmax = xp;
                setglobalvar("p"+(pindex+1)+"respawn_x",xp);
                setglobalvar("p"+(pindex+1)+"respawn_z",zp);
                setglobalvar("p"+(pindex+1)+"respawn_a",ap);
                setglobalvar("p"+(pindex+1)+"respawn_base",basep);
            }
        } // fine if xmax
    } // fine for

    if ( x != NULL() && z != NULL() && a != NULL() ) {
        changeentityproperty(player, "position", x, z, a);
    }
}

// if flag on, search last player spawned but not == self
void generate_last_player_spawned(void self, int self_flag) {
    int p;
    float last_player = NULL();

    for (p = 0; p < MAX_PLAYERS; ++p) {
        int player = getplayerproperty(p, "entity");
        int time = NULL(), last_time = NULL();

        if ( !getentityproperty(player, "exists") ) continue;
        if ( getglobalvar("p"+(p+1)+"spawning") == 1 ) continue; // sta spawnando ora
        if ( self_flag > 1 && self == player ) continue;

        time = getglobalvar("p"+(p+1)+"spawn_time");
        if ( last_time == NULL() || time > last_time ) {
            last_player = player;
            last_time = time;
        }
    } // fine for

    setglobalvar("last_player_spawned", last_player);

    return last_player;
}

void set_inspawning(void player, int respawn_distance) {
    int anim_id = getentityproperty(player, "animationid");

    if ( anim_id == openborconstant("ANI_RESPAWN") || anim_id == openborconstant("ANI_SPAWN") ) {
        int p = getentityproperty(player, "playerindex");

        if ( respawn_distance != getlocalvar("distance") ) setlocalvar("distance", respawn_distance);
        if ( getglobalvar("p"+(p+1)+"spawning") != 1 ) setglobalvar("p"+(p+1)+"spawning", 1);
    } else {
        int p = getentityproperty(player, "playerindex");

        if ( getglobalvar("p"+(p+1)+"spawning") == 1 ) {
                setglobalvar("last_player_spawned", player);
                setglobalvar("p"+(p+1)+"spawn_time", openborvariant("elapsed_time"));
                if ( getlocalvar("respawn") != NULL() ) setlocalvar("respawn", NULL());
                setglobalvar("p"+(p+1)+"spawning", 0);
        }
    }

}

int check_incam_pos(float x, float z) {
    float scr_posx = openborvariant("xpos");
    int hres = openborvariant("hresolution");
    float zmin_distance = get_zmin_distance();
    float zmax_distance = get_zmax_distance();
    float threshold = 5;

    if ( x == NULL() || z == NULL() ) return 0;
    if ( x < scr_posx+threshold || x > scr_posx+hres-threshold ) return 0;
    if ( z < zmin_distance+threshold || z > zmax_distance-threshold ) return 0;

    return 1;
}

int set_coords_predeath(void player, float max_alt) {
    int frames = 2, mem_frames = (openborvariant("game_speed")/4)*3; // 150
    int refresh_time = openborvariant("elapsed_time")%frames;
    int anim_id = getentityproperty(player, "animationid");

    if ( refresh_time == 0 && anim_id != openborconstant("ANI_SPAWN") && anim_id != openborconstant("ANI_RESPAWN") ) {
        float x = getentityproperty(player, "x");
        float z = getentityproperty(player, "z");
        float a = getentityproperty(player, "a");
        float base = getentityproperty(player, "base");
        int p = getentityproperty(player, "playerindex");

        if ( ( anim_id == openborconstant("ANI_IDLE") || anim_id == openborconstant("ANI_RUN") || anim_id == openborconstant("ANI_WALK") || anim_id == openborconstant("ANI_LAND")
            || anim_id == openborconstant("ANI_GET") || anim_id == openborconstant("ANI_BLOCK") || anim_id == openborconstant("ANI_UP") || anim_id == openborconstant("ANI_DOWN")
            || anim_id == openborconstant("ANI_JUMPLAND") ) && checkhole(x,z) == 0 && (a == base) ) {

            //drawstring( 10,200,0,"Storing Coords...");
            setglobalvar("p"+(p+1)+"respawn_x", x);
            setglobalvar("p"+(p+1)+"respawn_z", z);
            setglobalvar("p"+(p+1)+"respawn_a", a);
            setglobalvar("p"+(p+1)+"respawn_base", base);

            // Memorizziamo l'altitudine così da confrontarla con la prossima al prossimo frame. In caso si deve memorizzare la posizione sopra una piattaforma.
            // Infatti se stesse saltando o cadendo l'altitudine non sarebbe mai uguale da un frame all'altro...
            //setlocalvar("a_coord", a);
        }
    }
}

// Sistemiamo il personaggio dopo il respawn ne caso è dentro una platform (lo script può essere eseguito solo ora e non onspawn event)
// 1 ha esito positivo, 0 non esiste l'ultimo player spawned o non è nel quadro, -1 ultimo giocatore spawnato è se stesso, 2 non viene eseguito
int check_respawn(void player, float threshold) {
    if ( getentityproperty(player, "animationid") == openborconstant("ANI_RESPAWN") && getlocalvar("respawn") == NULL() ) { // && getentityproperty(player, "animpos") > 0
        void last_player = getglobalvar("last_player_spawned");

            //drawstring( 20,160,0,"Siamo qui!" );
            if ( getglobalvar("last_player_spawned") == player ) {
                    return -1; // Questa funzione ha senso rispetto ad altri giocatori e non a se stessi!! Altrimenti usare le p#respawn_X
            }

            if ( !getentityproperty(last_player,"exists") || getentityproperty(last_player,"type") != openborconstant("type_player") || last_player == NULL() ) {
                return 0;
            } else {
                int p = getentityproperty(last_player, "playerindex");
                float x = getglobalvar("p"+(p+1)+"respawn_x");
                float z = getglobalvar("p"+(p+1)+"respawn_z");
                float a = getglobalvar("p"+(p+1)+"respawn_a");
                float base = getglobalvar("p"+(p+1)+"respawn_base");
                int i;
                float t_alt = MAX_ALTITUDE;
                float x2, z2;
                float wall, platform_a;
                void platform;

                    if ( check_incam_pos(x,z) == 0 ) {
                        return 0;
                    }

                    // Respawniamo un valore threshold di px in avanti/dietro/giù/su rispetto al giocatore già in gara
                    for ( i = 0; i <= threshold; ++i ) { // <= così può assumere valore 0!
                            x2 = x-(threshold-i); z2 = z+(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break; // vedi se stai sopra un muro o una piattaforma

                            x2 = x-(threshold-i); z2 = z-(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x+(threshold-i); z2 = z+(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x+(threshold-i); z2 = z-(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x; z2 = z+(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x; z2 = z-(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x; z2 = z+(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x; z2 = z-(threshold-i);
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x-(threshold-i); z2 = z;
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x-(threshold-i); z2 = z;
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x+(threshold-i); z2 = z;
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;

                            x2 = x+(threshold-i); z2 = z;
                            wall = checkwall(x2,z2); platform = checkplatform(x2,z2,t_alt);
                            if ( platform != NULL() ) platform_a = getentityproperty(platform, "a");
                            if ( (wall <= 0 || (wall > 0 && wall == a)) && (platform == NULL() || (platform != NULL() && platform_a == a)) && checkhole(x2,z2) == 0 ) break;
                    } // fine for

                changeentityproperty(player, "position", x2, z2, a);

                //setglobalvar("last_player_spawned", player); // Impostiamo l'ultimo giocatore spawnato!
                // Lo impostiamo tra le animazioni con @cmd...
                setlocalvar("respawn", 1);
                return 1;
            } // fine if last_player exists
    } else {
        return 2;
    }
}

int checkplatform(float distx, float distz, float altitude) {
    if ( checkplatformbelow(distx,distz,altitude) == checkplatformbelow(0,0,0) ) return NULL();
    else return checkplatformbelow(distx,distz,altitude);
}

float get_zmin_distance() {
    float scr_posy = openborvariant("ypos");
    int zmin_threshold = 20;
    float zmin_bound = scr_posy+zmin_threshold;

    return zmin_bound;
}

float get_zmax_distance() {
    float scr_posy = openborvariant("ypos");
    int vres = openborvariant("vresolution");
    int zmax_threshold = 20;
    float zmax_bound = scr_posy+vres+zmax_threshold;

    return zmax_bound;
}

2. on my character txt, as previously, got this:
Code:
script data/scripts/spawn.c

3. on my spawn and respawn animation put like this:
Code:
anim spawn
	@script
		void self = getlocalvar("self");
		int p = getentityproperty(self, "playerindex");
		int animpos = getentityproperty(self, "animpos");

		if ( animpos == 1 ) {
        		float x = getentityproperty(self, "x");
        		float z = getentityproperty(self, "z");
        		float a = getentityproperty(self, "a");

            		setglobalvar("p"+(p+1)+"respawn_x", x);
            		setglobalvar("p"+(p+1)+"respawn_z", z);
            		setglobalvar("p"+(p+1)+"respawn_a", a);
			setglobalvar("last_player_spawned", self);
		}
	@end_script
	loop    0
	delay   5
	offset  30 81
	frame      data/chars/billy/empty.png
#	@cmd setglobalvar "last_player_spawned" getlocalvar("self")
	frame      data/chars/billy/02.png
	frame      data/chars/billy/02.png

but got this error:
cript function 'openborvariant' returned an exception, check the manual for details.
parameters: 18, 

********** An Error Occurred **********
*            Shutting Down            *

There's an exception while executing script 'updateentityscript' data/chars/billy/bimmy.txt

:(
 
Back
Top Bottom