O Ilusionista
Captain 100K
I'm writing some code to prevent the NPC from getting stuck off-screen in levels that have walls.
Since they are set to be "subject to screen," that's the only scenario where they could end up off-screen.
So, I created code to grab P1's position (since P1 is always on-screen—it's a single-player mode) and direction, then teleport the NPC to P1's location and switch to the respawn animation, which acts like a teleport.
I'm calling this function during both the NPC's walk and run states, but unfortunately, nothing happens.
even if I use killentity or try to log a message, nothing happens, which means that something is wrong on the logic but I can't pinpoint what.
The code is identifying cases where the NPC is off-screen—both beyond the screen boundaries and before the screen starts—because I am reusing another function that already works.
Since they are set to be "subject to screen," that's the only scenario where they could end up off-screen.
So, I created code to grab P1's position (since P1 is always on-screen—it's a single-player mode) and direction, then teleport the NPC to P1's location and switch to the respawn animation, which acts like a teleport.
I'm calling this function during both the NPC's walk and run states, but unfortunately, nothing happens.
even if I use killentity or try to log a message, nothing happens, which means that something is wrong on the logic but I can't pinpoint what.
The code is identifying cases where the NPC is off-screen—both beyond the screen boundaries and before the screen starts—because I am reusing another function that already works.
C-like:
void isOffScreenNPC(){
// Check if the NPC is stuck offscreen and teleport it to P1 position
// Douglas Baldan / O Ilusionista - 16.08.2026
void self = getlocalvar("self");
int XPos = openborvariant("xpos");
int selfx = getentityproperty(self, "x");
int Screenwidth = openborvariant("hResolution"); // Get screen width
int P1 = getplayerproperty(0, "entity");
int P1X = getentityproperty(P1, "x"); //Get X location and add adjustment.
int P1Y = getentityproperty(P1, "y"); //Get X location and add adjustment.
int P1Z = getentityproperty(P1, "z"); //Get X location and add adjustment.
int P1D = getentityproperty(P1, "direction"); //Get X location and add adjustment.
if (selfx > XPos + Screenwidth){
return 1;
if (P1){
changeentityproperty(self, "position", P1X, P1Z,P1Y);
changeentityproperty(self, "direction", P1D);
changeentityproperty(self, "animation",openborconstant("ANI_RESPAWN"));
} // beyond camera pos
if (selfx < XPos){
return 2;
if (P1){
changeentityproperty(self, "position", P1X, P1Z,P1Y);
changeentityproperty(self, "direction", P1D);
changeentityproperty(self, "animation",openborconstant("ANI_RESPAWN"));
} // before camera pos
}
}
}