Elevator System Help

maxman

Well-known member
I am always having so much trouble with the elevator system I made. I got the elevator set with globalvars. I noticed using globalvars is for getting the game saved after exiting the game mode. (For instance, when you flick the elevator from the first floor to the second, and the second to the third, and you exit game after going to the third floor, you continue where you left off the last time having the elevator appear in the third instead of the first. You'll have it there stuck unless you close or shut down the engine.) I looked up to Damon Caskey's script tutorial mentioning on using localvars instead of globalvars, but I don't know how to set localvars for the system.

I also have a problem with x distance where you are on the elevator floor and some enemy knocks you out, the elevator door closes. It's the door entity I talk about.

Here's the following entities that are in for the elevator system accordingly.

elevator.txt:

Code:
name Elevator
type none
nolife 1
subject_to_gravity 1
antigravity 100
facing 1
load door
load elevceil
load elevleft
#load switchen
defense all 0
animationscript data/scripts/handy.c
subject_to_platform 0
subject_to_minz 1
subject_to_maxz 1

anim spawn # 0 Begin
#@script
void self = getlocalvar("self");
int y = getentityproperty(self, "y");
if(y >= 0){
	changeentityproperty(self, "velocity", NULL(), NULL(), -1);
}
@end_script
offset 32 128
delay 2
@cmd	spawnBind2 "door" 0 15 0
#@cmd	spawnBind2 "elevceil" 0 101 0
#@cmd	spawnBind2 "elevleft" -32 15 0
platform 32 128 -32 -32 32 32 1 21 #Bottom base
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

anim idle # First floor
@script
    void self = getlocalvar("self"); //Get calling entity
    void Stats = getglobalvar("Stats");

    if(Stats == 4){
      performattack(self, openborconstant("ANI_FOLLOW1"));
    }
@end_script
offset 32 128
delay 4
loop 1
platform 32 128 -32 -32 32 32 1 21 #Bottom base
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

anim follow1 # From first floor to second
@script
    void self = getlocalvar("self"); //Get calling entity
    void Go1 = getglobalvar("Go1");
    void P = findtarget(self);
    float y = getentityproperty(P, "y");

    if(Go1 == 1){
      performattack(self, openborconstant("ANI_FOLLOW2"));
    }
@end_script
delay 2
loop 1 3
offset 32 128
platform 32 128 -32 -32 32 32 1 21
frame data/chars/misc/elevator/2.png
offset 32 128
delay 164 # 164 + 21 = 185; y movement + platform height = y base
platform 32 128 -32 -32 32 32 1 21 #Bottom base
@cmd	velo001 0 0 1
frame data/chars/misc/elevator/2.png
delay 2
@cmd	stop
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

anim follow2 #From second floor to third
@script
    void self = getlocalvar("self"); //Get calling entity
    void Run = getglobalvar("Run");

    if(Run == 1){
      performattack(self, openborconstant("ANI_FOLLOW3"));
    }
@end_script
offset 32 128
delay 185 # 185 + 185 = 370; floor 2 + movement = floor 3
loop 1 2
platform 32 128 -32 -32 32 32 1 21 #Bottom base
@cmd	velo001 0 0 1
frame data/chars/misc/elevator/2.png
delay 2
@cmd	stop
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

anim follow3 #From third floor to fifth
@script
    void self = getlocalvar("self"); //Get calling entity
    void Run = getglobalvar("Run");

    if(Run == 2){
	performattack(self, openborconstant("ANI_FOLLOW4"));
    }
@end_script
offset 32 128
delay 370 # 185 + 185 = 370; 185 + 370 = 555
loop 1 2
platform 32 128 -32 -32 32 32 1 21 #Bottom base
@cmd	velo001 0 0 1 # 1 smooth movement per pixel
frame data/chars/misc/elevator/2.png
delay 2
@cmd	stop
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

anim follow4 # From fifth to fourth
@script
    void self = getlocalvar("self"); //Get calling entity
    void Run = getglobalvar("Run");

    if(Run == 3){
	performattack(self, openborconstant("ANI_FOLLOW5"));
    }
@end_script
offset 32 128
delay 140
loop 1 2
platform 32 128 -32 -32 32 32 1 21 #Bottom base
@cmd	velo001 0 0 -1
frame data/chars/misc/elevator/2.png
delay 2
@cmd	stop
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

anim follow5 # From fourth to sixth
@script
    void self = getlocalvar("self"); //Get calling entity
    void Run = getglobalvar("Run");

    if(Run == 4){
	performattack(self, openborconstant("ANI_FOLLOW6"));
    }
@end_script
offset 32 128
loop 1 4
delay 480
platform 32 128 -32 -32 32 32 1 21 #Bottom base
@cmd	velo001 0 0 1
frame data/chars/misc/elevator/2.png
delay 2
@cmd	stop
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

anim follow6 # From sixth to eighth
@script
    void self = getlocalvar("self"); //Get calling entity
    void Run = getglobalvar("Run");

    if(Run == 5){
	performattack(self, openborconstant("ANI_FOLLOW7"));
    }
@end_script
offset 32 128
loop 1 4
delay 530
platform 32 128 -32 -32 32 32 1 21 #Bottom base
@cmd	velo001 0 0 1
frame data/chars/misc/elevator/2.png
delay 2
@cmd	stop
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

anim follow7
@script
    void self = getlocalvar("self"); //Get calling entity
    void Run = getglobalvar("Run");

    if(Run == 6){
      performattack(self, openborconstant("ANI_FOLLOW8"));
    }
@end_script
offset 32 128
loop 1 4
delay 275
platform 32 128 -32 -32 32 32 1 21 #Bottom base
@cmd	velo001 0 0 -1
frame data/chars/misc/elevator/2.png
delay 2
@cmd	stop
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

anim follow8
#@script
	void self = getlocalvar("self");
	//void P = findtarget(self);
	//void Ty = getentityproperty(P, "a");
	//void Run = getglobalvar("Run");
	//void Run = getentityvar("Run");

	/*if(Run == 7){
		performattack(self, openborconstant("ANI_FOLLOW9"));
	}
	*/
@end_script
offset 32 128
loop 1 4
delay 458
platform 32 128 -32 -32 32 32 1 21 #Bottom base
@cmd	velo001 0 0 1
frame data/chars/misc/elevator/2.png
delay 2
@cmd	stop
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png
frame data/chars/misc/elevator/2.png

door.txt:

https://pastebin.com/rDTNicFZ

switch.txt:

Code:
name Switch
type obstacle
health 1000
nolife 1
facing 1
shadow 0
speed 10
hostile player
antigravity 100
setlayer 1
load switchlight
#load on-off
#death		1
defense		all 0
#nodieblink	3
animationscript data/scripts/script.c
takedamagescript data/scripts/switch1.c

anim idle #Switch no. 1
@script
    void self = getlocalvar("self"); //Get calling entity.
    void State = getentityvar(self,1);

    if(State == 3){
      setglobalvar(0, 1);
      performattack(self, openborconstant("ANI_FOLLOW1"));
    }
	@end_script	
offset	16 16
delay 2
loop 1
bbox 8 0 16 16
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png

anim follow1 #Turning power on
offset	16 16
delay 10
sound data/sounds/klunk.wav
@cmd spawnBind2 "switchlight" 0 9 0
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/4.png
#@cmd increasehealth 200
frame data/chars/misc/elevator/5.png
@cmd	changeentityproperty getlocalvar("self") "animation" openborconstant("ANI_FOLLOW2")
frame data/chars/misc/elevator/6.png

anim follow2 #On

offset	16 16
delay 2
loop 1
frame data/chars/misc/elevator/6.png

anim follow3 #Turn power off

offset	16 16
delay 2
#loop 1
frame data/chars/misc/elevator/6.png
frame data/chars/misc/elevator/5.png
frame data/chars/misc/elevator/4.png
frame data/chars/misc/elevator/3.png


anim freespecial # Switch no. 2
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Switch = getentityvar(self, "switch");

    if(Switch == 1){
      setglobalvar("Go1", 1);
      performattack(self, openborconstant("ANI_FOLLOW1"));
    }
	@end_script	
offset	16 16
delay 2
loop 1
bbox 8 0 16 16
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png

anim follow4 #Turning power on
offset	16 16
delay 10
sound data/sounds/klunk.wav
@cmd spawnBind2 "switchlight" 0 9 0
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/4.png
#@cmd increasehealth 200
frame data/chars/misc/elevator/5.png
@cmd	changeentityproperty getlocalvar("self") "animation" openborconstant("ANI_FOLLOW5")
frame data/chars/misc/elevator/6.png

anim follow5 #On

offset	16 16
delay 2
loop 1
frame data/chars/misc/elevator/6.png

anim freespecial2 # Switch no. 3
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Switch2 = getentityvar(self, "switch2");

    if(Switch2 == 2){
      setglobalvar("Go2", 2);
      performattack(self, openborconstant("ANI_FOLLOW6"));
    }
	@end_script	
offset	16 16
delay 2
loop 1
bbox 8 0 16 16
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png

anim freespecial3 # Switch no. 4
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Switch3 = getentityvar(self, "switch3");

    if(Switch3 == 3){
      setglobalvar("Go3", 3);
      performattack(self, openborconstant("ANI_FOLLOW6"));
    }
	@end_script	
offset	16 16
delay 2
loop 1
bbox 8 0 16 16
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png

anim freespecial4 # Switch no. 5
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Switch4 = getentityvar(self, "switch4");

    if(Switch4 == 4){
      setglobalvar("Go4", 4);
      performattack(self, openborconstant("ANI_FOLLOW6"));
    }
	@end_script	
offset	16 16
delay 2
loop 1
bbox 8 0 16 16
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png

anim freespecial5 # Switch no. 6
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Switch5 = getentityvar(self, "switch5");

    if(Switch5 == 5){
      setglobalvar("Go5", 5);
      performattack(self, openborconstant("ANI_FOLLOW6"));
    }
	@end_script	
offset	16 16
delay 2
loop 1
bbox 8 0 16 16
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png

anim freespecial6 # Switch no. 7
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Switch6 = getentityvar(self, "switch6");

    if(Switch6 == 6){
      setglobalvar("Go6", 6);
      performattack(self, openborconstant("ANI_FOLLOW6"));
    }
	@end_script	
offset	16 16
delay 2
loop 1
bbox 8 0 16 16
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png

anim freespecial7 # Switch no. 7
#@script
    void self = getlocalvar("self"); //Get calling entity.
    void Switch7 = getentityvar(self, "switch7");
//    void Switch8 = getentityvar(self, "switch8");

    if(Switch7 == 7){
      setglobalvar("Go7", 7);
      performattack(self, openborconstant("ANI_FOLLOW6"));
    }
/*
    if(Switch8 == 8){
      setglobalvar("Go8", 8);
      performattack(self, openborconstant("ANI_FOLLOW6"));
    }
*/
	@end_script	
offset	16 16
delay 2
loop 1
bbox 8 0 16 16
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/3.png

anim follow6 #Turning power on
offset	16 16
delay 10
sound data/sounds/klunk.wav
@cmd spawnBind2 "switchlight" 0 9 0
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/4.png
#@cmd increasehealth 200
frame data/chars/misc/elevator/5.png
@cmd	changeentityproperty getlocalvar("self") "animation" openborconstant("ANI_FOLLOW7")
frame data/chars/misc/elevator/6.png

anim follow7 #On

offset	16 16
delay 2
loop 1
frame data/chars/misc/elevator/6.png


anim follow8
offset	16 16
delay 10
sound data/sounds/klunk.wav
#@cmd spawnBind2 "switchlight" 0 9 0
frame data/chars/misc/elevator/3.png
frame data/chars/misc/elevator/4.png
frame data/chars/misc/elevator/5.png
frame data/chars/misc/elevator/6.png
delay 2050
frame data/chars/misc/elevator/6.png
delay 10
frame data/chars/misc/elevator/6.png
frame data/chars/misc/elevator/5.png
frame data/chars/misc/elevator/4.png
frame data/chars/misc/elevator/3.png
#@cmd anichange "ani_freespecial9"
frame data/chars/misc/elevator/3.png

switchen.txt:

Code:
name Switchen
type obstacle
health 1
nolife 1
antigravity 100
subject_to_platform 0
defense all 0
death 1
noatflash 1
#takedamagescript data/chars/misc/elevator/equal.c
takedamagescript data/chars/misc/elevator/elevator.c

anim idle #Stay idle
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Go = getentityvar(self,"Go");

    if(Go == 5){
      setglobalvar("Stats", 4);
      performattack(self, openborconstant("ANI_follow1"));
    }
	@end_script
@end_script
offset 1 1
delay 3
loop 1
bbox 0 0 10 10
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif
frame data/chars/misc/empty.gif
frame data/chars/misc/empty.gif

anim follow1 #Switch for first platform/floor (Moving up)

offset 1 1
delay 3
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif
@cmd killentity getlocalvar("self")
frame data/chars/misc/empty.gif

anim follow2 # Between ground and 2nd floor

offset 1 1
delay 3
#loop 1
#bbox 0 0 10 10
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif
@cmd killentity getlocalvar("self")
frame data/chars/misc/empty.gif

anim follow3 #Between 1st and 3rd floors

offset 1 1
delay 3
loop 1
#bbox 0 0 10 10
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim follow4 #Between 2nd and 4th floors

offset 1 1
delay 3
loop 1
#bbox 0 0 10 10
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim freespecial #In 4th floor; Switch for 3rd floor?
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Go1 = getentityvar(self,"Go1");

    if(Go1 == 1){
      setglobalvar("Run", 1);
      performattack(self, openborconstant("ANI_follow2"));
    }
	@end_script
offset 1 1
delay 3
loop 1
bbox 0 0 20 20
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim freespecial2 #
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Go2 = getentityvar(self,"Go2");

    if(Go2 == 2){
      setglobalvar("Run", 2);
      performattack(self, openborconstant("ANI_follow2"));
    }
	@end_script
offset 1 1
delay 3
loop 1
bbox 0 0 10 20
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim freespecial3 #
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Go3 = getentityvar(self,"Go3");

    if(Go3 == 3){
      setglobalvar("Run", 3);
      performattack(self, openborconstant("ANI_follow2"));
    }
	@end_script
offset 1 1
delay 3
loop 1
bbox 0 0 10 20
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim freespecial4 #
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Go4 = getentityvar(self,"Go4");

    if(Go4 == 4){
      setglobalvar("Run", 4);
      performattack(self, openborconstant("ANI_follow2"));
    }
	@end_script
offset 1 1
delay 3
loop 1
bbox 0 0 10 20
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim freespecial5 #
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Go5 = getentityvar(self,"Go5");

    if(Go5 == 5){
      setglobalvar("Run", 5);
      performattack(self, openborconstant("ANI_follow2"));
    }
	@end_script
offset 1 1
delay 3
loop 1
bbox 0 0 10 20
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim freespecial6 #
@script
    void self = getlocalvar("self"); //Get calling entity.
    void Go6 = getentityvar(self,"Go6");

    if(Go6 == 6){
      setglobalvar("Run", 6);
      performattack(self, openborconstant("ANI_follow2"));
    }
	@end_script
offset 1 1
delay 3
loop 1
bbox 0 0 10 20
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim freespecial7 #
#@script
    void self = getlocalvar("self"); //Get calling entity.
    void Go7 = getentityvar(self,"Go7");

    if(Go7 == 7){
      setglobalvar("Run", 7);
      performattack(self, openborconstant("ANI_follow2"));
    }
	@end_script
offset 1 1
delay 3
loop 1
bbox 0 0 10 20
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim fall
offset 1 1
delay 3
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

anim death
offset 1 1
delay 3
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/empty.gif

switch1.c:

https://pastebin.com/F7aUMMrc

elevator.c:

https://pastebin.com/aRfXixAF
 
Hello maxman!
I agree to msmalik681, a button in each floor is a good idea.
About the globalvars, I used some in my SOR2X and the best solution that I found was apply the command  "clearglobalvar" at the title screen in the updated.c. No matter how you end the game (exiting, dying, etc...) the title screen is always shown.

Code:
void main()
{//MISC OPERATIONS
	if(openborvariant("in_titlescreen")){
		clearglobalvar();
	}
}
About the elevator, can you make a video to show the problem? I had a lot of trouble making SOR3 elevators  ;D and maybe I can help if have more information
 
msmalik681 said:
Why dont you add a button on each floor to call the elevator like in real life. That way you can never be stuck.

Well, there is for each floor outside of the elevator which you can call but most of them are far away (the only closest one is in the first floor). You press or strike the elevator button so the elevator door opens. You get in, and the door closes. After the door closes, you can press or strike an invisible button inside the elevator (which I made a script of my own for it; it's called "spawnen" for spawning anim script and "switchen" for activating the elevator) to make it move up and I have no problem with that. But the REAL problem is that, after the elevator gets to the second floor and the door opens, you encounter an enemy or an enemy projectile which knocks you out of the elevator floor and the door closes. And this is because I use this targetx - x here.

Code:
anim follow1 # Followup 1-1 / Open elevator door at first floor
@script
    void self = getlocalvar("self");
    void P = findtarget(self);

    float x = getentityproperty(self, "x");
    float Ty = getentityproperty(P, "a");

    float Disx = getentityproperty(P, "x") - x;

    if(Disx < 0){
      Disx = -Disx;
    }

    if(frame >= 4){
      if(Disx <= 45 && Ty == 21){
        performattack(self, openborconstant("ANI_FOLLOW2"));
      }
    }
@end_script
offset 32 96
delay 10
loop 1 3
platform 32 96 30 30 32 32 5 111
frame data/chars/misc/elevator/7.png
delay 10
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/8.png
frame data/chars/misc/elevator/9.png
platform 1 1 1 1 1 1 1 1
frame data/chars/misc/elevator/10.png
frame data/chars/misc/elevator/10.png
frame data/chars/misc/elevator/10.png
frame data/chars/misc/elevator/10.png

anim follow2 # Followup 1-2 / Landed on elevator and closed elevator door
@script
if(frame == 4){
    void self = getlocalvar("self"); //Get calling entity
    void Stats = getglobalvar("Stats");

    if(Stats == 4){
      performattack(self, openborconstant("ANI_FOLLOW3"));
    }
}
@end_script
offset 32 96
delay 10
loop 1 4
frame data/chars/misc/elevator/10.png
frame data/chars/misc/elevator/9.png
frame data/chars/misc/elevator/8.png
platform 32 96 30 30 32 32 5 106
@cmd	spawnen "switchen" "ani_idle" 26 65
frame data/chars/misc/elevator/7.png #3
frame data/chars/misc/elevator/7.png #4
frame data/chars/misc/elevator/7.png
frame data/chars/misc/elevator/7.png
frame data/chars/misc/elevator/7.png

Here's what my spawnen is like and I added it in spawn.h:

Code:
void spawnen(void Name, void Ani, float dx, float dy){
//Modified by Max Man
//Spawning a spawned entity with its own animation
	void self = getlocalvar("self");
	void vSpawn;

	vSpawn = spawn01(Name, dx, dy, 0);
	performattack(vSpawn, openborconstant(Ani));
	
}

Kratus: I'm really sorry. I'm using an old version which is from 2015 of April 22. So I cannot get it working in updated.c. I think I'm gonna send that to you if you don't have it. I'll show a video if I have time.
 
Nice game, I liked especially the HUD. Now I understand the problem better and based in what I can see, will give some suggestions:

1- Make a bbox for elevator door and give to it a large amount of health to not be killed. Give a sufficient size to the bbox that grants a safe exit. All projectiles will be erased before hits the player and the elevator will not close with the hero inside. It will work like as enemies having difficulties to aim the player inside the elevator and missing the shots. And don't forget to spawn enemies far from the door to not get hit by normal attacks and fall inside the elevator again, or you can define to the enemies a high height and make a higher platform that will block movement with defined safe distance, but allow players to go out

2 - Another suggestion is to use update/ondraw scripts to detect player position in real time and check current door animation. You can use it as a elevator sensor and check if the player is inside/outside and change to the correct animation when needed.

For example, suppose that you killed all enemies in the first floor. Then, hit the button and the elevator door will open. You will enter, the door will be closed and it will be moved to second floor.

In the second floor, the door will open and constantly check if the player is inside or outside the elevator using target script. If the player is inside the elevator, the door will remain opened even if get hit by enemies. When the player get outside, it will check if has a safe X distance and then close the door again.

The door will not open until you beat the enemies in this floor and hit the button to open elevator door again, and so on... You can make this using animation scripts but update/ondraw has more precision to check all status, no matter what animation you are using.

3 - I've seen that enemies don't check players range in Y axis (rangea) and they will shoot no matter you are in the same height or not. They continue attacking even if you are in a lower floor. You can adjust "rangea" or use think script in enemies header to change aimove or aggression according to players height. This will prevent enemies to attack when you are in a lower floor or moving inside the elevator. Also, you can define a range in think script to change enemies aimove or aggression against elevator door entity and make them not attack if the closest hostile type is any other different than players.

4 - I don't know too much about how your game is coded but I think that an alternative to clear the globalvars is using "clearglobalvar" command in the endlevel.c, instead of updated.c

You can combine some of these suggestions and make another different solution. I'm trying to help according to all problems that I had in SOR2X elevators, and the best way that I founded was using ondraw/update scripts combined with animation scripts.

I have a similar script in one of my SOR3 elevators. They will not work if any enemy is alive in the screen. I have a blockade acting like doors in each floor and no matter how many hits in the switchs, if at least 1 enemy is alive, the elevator don't works.

I hope it helps, but if not, I can make some tests if you send a demo
 
Quick FYI about AI range on Y axis. Both Y and base range are -1000 to 1000 by default, so effectively they have virtually limitless vertical vision. It's a good idea to adjust it even when you aren't doing elevator work.

In the coming release the default is 0 to model's jump height * 3.

DC
 
Back
Top Bottom