Script problem with a lift...


(MadJack) #1

Got this nifty little lift.
Two buttons. One one top floor, the other one at the bottom floor. They each target a different target_script_trigger that calls the same “function” (lift) but with different subfunction (up/down) You’ll understand with the code below.

What I want to do is pretty simple:

Player hits the top floor button, if lift is up, bring it down. If it’s down, bring the lift up (and when it gets to top floor, he’ll push the button to go down again). Same thing with the bottom button.

Now, what happens is that if I push the top floor button, I hear everything, ie: the sound of the lift but it stays there. :disgust: Exactly the same happens if I push the bottom (floor) button and I’m at the bottom level. BUT! If I noclip myself down and use the button while the lift is up it WILL come down. Same if the lift is down and I push the button from up top! :eek3: Now… I’ve g_debugscript enabled and I see that those up/down functions are hit THREE times when they fire properly. And that’s even if I put resetscript (but I’ve just inserted that so I might gotten it wrong).

Here’s the monster :moo:


lift
{
	spawn
	{
		accum 0 set 1 // Lift position (0 = down, 1 = up)
		accum 1 set 0 // Is lift moving?

	                      wait 200 // let things spawn
	}

	trigger call_lift_bup // bup = button up top
	{
		accum 0 trigger_if_equal 0 lift bring_lift_up // If lift DOWN move it UP
		accum 1 abort_if_not_equal 0 // Dont try to move if already moving
		resetscript

		accum 1 set 1 // we're moving! :D

		playsound sound\movers\elevators\elev1_start.wav

		wait 400

		playsound sound\movers\elevators\elev1_loop.wav LOOPING

		gotomarker path_lift_bottom 50 wait

		stopsound
		playsound sound\movers\elevators\elev1_end.wav

		accum 1 set 0 // we've stopped :(
		accum 0 set 0 // down bottom
	}

	trigger call_lift_bdown // bdown = button down level
	{
		accum 0 trigger_if_equal 1 lift bring_lift_down // if lift UP move it DOWN
		accum 1 abort_if_not_equal 0 // Dont try to move if already moving
		resetscript
		
		accum 1 set 1 // we're moving! :D

		playsound sound\movers\elevators\elev1_start.wav

		wait 400

		playsound sound\movers\elevators\elev1_loop.wav LOOPING

		gotomarker path_lift_top 50 wait

		stopsound
		playsound sound\movers\elevators\elev1_end.wav

		accum 1 set 0 // we've stopped :(
		accum 0 set 1 // up top
	}
	
	trigger bring_lift_up
	{
		accum 1 set 1
		
		playsound sound\movers\elevators\elev1_start.wav
		
		wait 400
	
		playsound sound\movers\elevators\elev1_loop.wav LOOPING
		
		gotomarker path_lift_top 50 wait
		
		stopsound
		playsound sound\movers\elevators\elev1_end.wav
		
		accum 1 set 0
		accum 0 set 1
		resetscript
	}
	
	trigger bring_lift_down
	{
		accum 1 set 1
		
		playsound sound\movers\elevators\elev1_start.wav
		
		wait 400
	
		playsound sound\movers\elevators\elev1_loop.wav LOOPING
		
		gotomarker path_lift_bottom 50 wait
		
		stopsound
		playsound sound\movers\elevators\elev1_end.wav
		
		accum 1 set 0
		accum 0 set 0
		resetscript
	}	
}

Top button (bup) is linked to target_script_trigger with:

target: call_lift_bup
scriptname: lift
targetname: call_lift_bup_st

Top button’s attributes:

cursorhint: HINT_ACTIVATE
target: call_lift_bup_st
targetname: lift_button_up

Bottom button (bdown) linked to target_script_trigger with:

target: call_lift_bdown
scriptname: lift
targetname: call_lift_bdown_st

Bottom button’s attributes:

target: call_lift_bdown_st
targetname: lift_button_down
cursorhint: HINT_ACTIVATE

Any ideas? :???:

edit: made it clearer… I think :smiley:


(TFate) #2

First… does the lift start out at the top? Yes I know, simple question, but might have been overlooked.

Also, I think four buttons instead of two would be sooo much easier, all you would have to do is label the buttons up and down. Quickly glancing at your script here, I think that the resetscripts don’t work at all…

I’m not sure how exactly lift scripting goes, but what is with the “50 wait” after the gotomarker “path_lift_bottom” sequences? Shouldn’t you just put a “wait 50” after it instead?


(sock) #3

Me and djbob did a collection of lift tutorials a couple of years ago.

Basic lift : http://www.planetquake.com/simland/pages/articles/rtcw_baslift.htm
Advanced Lift : http://www.planetquake.com/simland/pages/articles/rtcw_advlift.htm

They are RTCW examples but the map files/scripts should work with ET as well.

Sock
:moo:


(MadJack) #4

TFate, yeah it starts at the top :slight_smile:
I see your point about “50 wait” and indeed it looks odd… I’ll check that up. As I say below, the script is mainly a copy/paste of sock & djbob’s tut. But I should’ve seen that… maybe mapping for +12 hours is not so good :smiley: lol :wink:

sock, it’s almost a complete copy/paste of that tut which I modified some but not that much. The main difference is that I don’t use buttons with green/red light, I connect directly to the lift. Those buttons simply called the lift-up/lift-down routine depending which button was pressed.


(MadJack) #5

TFate, 50 is the speed at which the lift will go… hehe


(TFate) #6

ok I didn’t know :wink:

I’m going to add a lift in my upcoming map so yeh, I’ll tell you how that goes :beer:


(MadJack) #7

There’s no progress, it still behaves the same way but I’ve condump what happens…

Here, I'm an Axis calling pushing the button so it can go down. The lift is already up and it's waiting to go down.

100450 : (n/a) GScript event: activate axis
100450 : (lift) GScript event: trigger call_lift_bup
100450 : (lift) GScript command: accum 0 trigger_if_equal 0 lift bring_lift_up
100450 : (lift) GScript command: accum 1 abort_if_not_equal 0
100450 : (lift) GScript command: resetscript
100500 : (lift) GScript command: accum 1 set 1
100500 : (lift) GScript command: playsound sound\movers\elevators\elev1_start.wav
100500 : (lift) GScript command: wait 400
100950 : (lift) GScript command: playsound sound\movers\elevators\elev1_loop.wav LOOPING
100950 : (lift) GScript command: gotomarker path_lift_bottom 50 wait
113600 : (lift) GScript command: stopsound
113600 : (lift) GScript command: playsound sound\movers\elevators\elev1_end.wav
113600 : (lift) GScript command: accum 1 set 0
113600 : (lift) GScript command: accum 0 set 0

The above should work but the lift stays there.


Now, since it "thinks" it's down, let's call it up. Click the button...

167750 : (n/a) GScript event: activate axis
167750 : (lift) GScript event: trigger call_lift_bup
167750 : (lift) GScript command: accum 0 trigger_if_equal 0 lift bring_lift_up
167750 : (lift) GScript event: trigger bring_lift_up <<< Function 
167750 : (lift) GScript command: accum 1 set 1 
167750 : (lift) GScript command: playsound sound\movers\elevators\elev1_start.wav
167750 : (lift) GScript command: wait 400
167750 : (lift) GScript event: trigger bring_lift_up <<< Function 2nd TIME!
167750 : (lift) GScript command: accum 1 set 1
167750 : (lift) GScript command: playsound sound\movers\elevators\elev1_start.wav
167750 : (lift) GScript command: wait 400
167750 : (lift) GScript event: trigger bring_lift_up <<< Function 3rd TIME!
167750 : (lift) GScript command: accum 1 set 1
167750 : (lift) GScript command: playsound sound\movers\elevators\elev1_start.wav
167750 : (lift) GScript command: wait 400
168200 : (lift) GScript command: playsound sound\movers\elevators\elev1_loop.wav LOOPING
168200 : (lift) GScript command: gotomarker path_lift_top 50 wait
168200 : (lift) GScript command: playsound sound\movers\elevators\elev1_loop.wav LOOPING
168200 : (lift) GScript command: gotomarker path_lift_top 50 wait
168200 : (lift) GScript command: playsound sound\movers\elevators\elev1_loop.wav LOOPING
168200 : (lift) GScript command: gotomarker path_lift_top 50 wait
168350 : (lift) GScript command: stopsound
168350 : (lift) GScript command: playsound sound\movers\elevators\elev1_end.wav
168350 : (lift) GScript command: accum 1 set 0
168350 : (lift) GScript command: accum 0 set 1
168350 : (lift) GScript command: resetscript
178300 : (lift) GScript command: stopsound
178300 : (lift) GScript command: playsound sound\movers\elevators\elev1_end.wav
178300 : (lift) GScript command: accum 1 set 0
178300 : (lift) GScript command: accum 0 set 1
178300 : (lift) GScript command: resetscript
178800 : (lift) GScript command: stopsound
178800 : (lift) GScript command: playsound sound\movers\elevators\elev1_end.wav
178800 : (lift) GScript command: accum 1 set 0
178800 : (lift) GScript command: accum 0 set 1
178800 : (lift) GScript command: resetscript

Notice how it loops 3 times above? I hear the sound and everything but since the lift is already up… it doesn’t move.


Now, I /noclip myself down and call the bastard. At that point, the lift is up there and I'm in the basement...

285000 : (n/a) GScript event: activate axis
285000 : (lift) GScript event: trigger call_lift_bdown
285000 : (lift) GScript command: accum 0 trigger_if_equal 1 lift bring_lift_down
285000 : (lift) GScript event: trigger bring_lift_down <<< Once
285000 : (lift) GScript command: accum 1 set 1
285000 : (lift) GScript command: playsound sound\movers\elevators\elev1_start.wav
285000 : (lift) GScript command: wait 400
285000 : (lift) GScript event: trigger bring_lift_down <<< Twice
285000 : (lift) GScript command: accum 1 set 1
285000 : (lift) GScript command: playsound sound\movers\elevators\elev1_start.wav
285000 : (lift) GScript command: wait 400
285000 : (lift) GScript event: trigger bring_lift_down <<< SOLD!
285000 : (lift) GScript command: accum 1 set 1
285000 : (lift) GScript command: playsound sound\movers\elevators\elev1_start.wav
285000 : (lift) GScript command: wait 400
285450 : (lift) GScript command: playsound sound\movers\elevators\elev1_loop.wav LOOPING
285450 : (lift) GScript command: gotomarker path_lift_bottom 50 wait
285450 : (lift) GScript command: playsound sound\movers\elevators\elev1_loop.wav LOOPING
285450 : (lift) GScript command: gotomarker path_lift_bottom 50 wait
285450 : (lift) GScript command: playsound sound\movers\elevators\elev1_loop.wav LOOPING
285450 : (lift) GScript command: gotomarker path_lift_bottom 50 wait
296050 : (lift) GScript command: stopsound
296050 : (lift) GScript command: playsound sound\movers\elevators\elev1_end.wav
296050 : (lift) GScript command: accum 1 set 0
296050 : (lift) GScript command: accum 0 set 0
296050 : (lift) GScript command: resetscript
296050 : (lift) GScript command: stopsound
296050 : (lift) GScript command: playsound sound\movers\elevators\elev1_end.wav
296050 : (lift) GScript command: accum 1 set 0
296050 : (lift) GScript command: accum 0 set 0
296050 : (lift) GScript command: resetscript
296050 : (lift) GScript command: stopsound
296050 : (lift) GScript command: playsound sound\movers\elevators\elev1_end.wav
296050 : (lift) GScript command: accum 1 set 0
296050 : (lift) GScript command: accum 0 set 0
296050 : (lift) GScript command: resetscript

It works… it comes down! But again, it loops 3 times.

:???:


(MadJack) #8

Success!

I decided to play with something else for a time and to come back at it later. So I made a REAL skybox with terragen and came back to that lift…

Jahaa!

It seems the scripting engine didn’t like me to call the lift function directly from the the Target_Script_trigger… So I made two buffer functions called: lift_down_trigger and lift_up_trigger that are called by the bottom button and the top button respectively.

Lift_down_trigger calls trigger lift lift_button_up which check if it’s up or down, if it’s not at its proper position, it brings the lift to where the button was pushed. Or it simply moves the lift as it should.

There are no loops, it does its thing as it should. Now… on to other things :smiley:

Oh and thx anyway TFate :wink: