Page 2 of 2

Posted: Sun Aug 22, 2004 9:51 pm
by Splaetos
I have no idea where that is in your script, or how you are launching the threads. Have you looked at the scripting reference or appendixes on this site? Bjarne posted a link to the wiki version above.

how are you starting these threads? with setthread or from within the main portion of your script? If your using a setthread, you dont need waitTill trigger but you need to make All triggers that move the gate untriggerable including the one that is being used at the moment. If not, and someone hits the same trigger again, it will start the process all over.

off the top of my head, if I were going to do it it would look something like this. This does not use setthreads, it is started within the script, and waits for the triggers to be pressed in game.



main:

waitTill prespawn

waitTIll spawn

thread gate_initialize

end


gate_initialization:
level.gate_open = 0
thread gate_control1
thread gate_control2
end

gate_control1:
{
$gate_trigger1 waitTill trigger
$gate_trigger1 untriggerable
$gate_trigger2 untriggerable
if (level.gate_open == 0)
{
open gate, playsounds etc.
level.gate_open = 1
}
else
{
close gate, playsounds etc
level.gate_open = 0
}
$gate_trigger1 triggerable
$gate_trigger2 triggerable
}
end

gate_control2:
while(1)
{
$gate_trigger2 waitTill trigger
$gate_trigger1 untriggerable
$gate_trigger2 untriggerable
if (level.gate_open == 0)
{
open gate, playsounds etc.
level.gate_open = 1
}
else
{
close gate, playsounds etc
level.gate_open = 0
}
$gate_trigger1 triggerable
$gate_trigger2 triggerable
}
end


Those two threads could probably be condensed to one of the same size, but Im not sure how to format a || statement into a waitTill trigger statement. IT could be one thread as well if using setthreads from the triggers, because then your not waiting for the trigger inside the script, but I dont use setthreads very often. And of course, there are many other ways to do it.

Posted: Mon Aug 23, 2004 11:53 am
by Dani
OK i will try your code. I have use_trigers so i do not have to setthread in the code. My levers are like this:
DOOR - leveropen/close

GATE - leveropen + lever close

GATE2 - leveropen + lever close

Posted: Mon Aug 23, 2004 2:01 pm
by Dani
i changed some of the variables, and it doesn't work! AHHH, OK, i am gona make it simpler. I am going to have 2 Levers, 1 that opens and closes a door, and another one that opens and closes BOTH gates.

P.S both gates have the same targetname so they will just be referd to as $gate, also, what code do i need so that when the lever is pulled it shows a message???

Posted: Mon Aug 23, 2004 3:54 pm
by Dani
OH GOD.
OK.
Two triggers which are BOTH use_triggers. One has :
setthread gate_switch
The other has:
setthread cell_switch

My code for them is:

Code: Select all

main: 

level waittill prespawn 
$gate time 5
$cell time 2

//INSTALL
gate_initialization: 
level.gate_open = 0 
level.cell_open = 0
thread gate_switch
thread cell_switch
end 


//GATE SWITCH
gate_switch: 
{ 
 $gate_switch waitTill trigger 
 $gate_switch untriggerable 
 if (level.gate_open == 0) 
  { 
  $gate moveup 432 
  level.gate_open = 1 
  } 
  else 
  { 
  gate movedown 432
  level.gate_open = 0 
  } 
 $gate_switch triggerable 
} 
end 
//CELL SWITCH
cell_switch: 
 { 
 $cell_switch waitTill trigger 
 $cell_switch untriggerable 
 if (level.cell_open == 0) 
  { 
  $cell moveright 20
  level.cell_open = 1 
  } 
  else 
  { 
  gate moveleft 20
  level.cell_open = 0 
  } 
 $cell_switch triggerable 
} 
end
Is this alright???

Posted: Mon Aug 23, 2004 8:24 pm
by Splaetos
I dunno what happens when you use setthread and a 'waitTIll trigger' line. I suppose it might be ok cause the thread would simultaneously continue and start a new version of itself?

you should look at a full script someone else has with triggers in it maybe.
there are many maps out there with working triggers.

for the moment, all I can say tho, is to look at this below. It has no setthreads in the maps. the two 'logic' threads are called from the main script... each prison system has two triggers - either one of which will start the opening/closing sequence. Then it goes into seperate waitthreads for opening/waiting/closing the cells(if i included that it would be very long indeed.

why is your script failing? Do you get console errors? Are you in debug and logging it so you can see? or do the doors just move wrong? Its alot easier to know what the script is trying to do, and know how to read the errors that cause it to fail, then just to try and patch in bits of code...


the full script that this coems from you could find by searching for 'gefangnis' or 'gefangenschaft' on these boards, or looking through the new map releases from a while back, its from the old version of my map.

its not the same as what your doing but its an example of two triggers triggering the same event that moves something. like i said, no set threads in the map for this.

Code: Select all

//*************************************************
//***             AXIS PRISON LOGIC             ***
//***  Thread Loop for regulating Axis Triggers ***
//*************************************************

axis_prison:
	thread axis_prison_trigger1
	thread axis_prison_trigger2
end


//*************************************************
//***             ALLIED PRISON LOGIC           ***
//***  Thread Loop for regulating Ally Triggers ***
//*************************************************

allied_prison:
	thread allied_prison_trigger1
	thread allied_prison_trigger2
end


//*************************************************
//***             AXIS TRIGGER I                ***
//***Used by ALLIED players to release teamates.***
//*************************************************

axis_prison_trigger1:
	$axis_trigger1 waitTill trigger
	if (parm.other.dmteam == allies)
	{
		$axis_trigger1 playsound snd_triggers
		parm.other iprint "Your team has been released!" 0
		$axis_trigger1 nottriggerable
		$axis_trigger2 nottriggerable
		waitthread axis_prison_open
		$axis_trigger2 triggerable
		$axis_trigger1 triggerable
		thread axis_prison
	}
	else
	{
		if(parm.other.dmteam == axis)
		{
			parm.other iprint "Idiot!" 0
			thread axis_prison_trigger1
		}
	}
end


//*************************************************
//***             AXIS TRIGGER II               ***
//***Used by ALLIED players to release teamates.***
//*************************************************
axis_prison_trigger2:
	$axis_trigger2 waitTill trigger
	if (parm.other.dmteam == allies)
	{
		$axis_trigger2 playsound snd_triggers
		parm.other iprint "Your team has been released!" 0
		$axis_trigger1 nottriggerable
		$axis_trigger2 nottriggerable
		waitthread axis_prison_open
		$axis_trigger2 triggerable
		$axis_trigger1 triggerable
		thread axis_prison
	}
	else
	{
		if(parm.other.dmteam == axis)
		{
			parm.other iprint "Idiot!" 0
			thread axis_prison_trigger2
		}
	}
end



//**********************************************
//***            ALLIED TRIGGER I            ***
//***Used by AXIS players to release teamates***
//**********************************************

allied_prison_trigger1:
	$allied_trigger1 waitTill trigger
	if (parm.other.dmteam == axis)
	{
		$allied_trigger1 playsound snd_triggers
		parm.other iprint "Your team has been released!" 0
		$allied_trigger1 nottriggerable
		$allied_trigger2 nottriggerable
		waitthread allied_prison_open
		$allied_trigger1 triggerable
		$allied_trigger2 triggerable
		thread allied_prison
	}
	else
	{
		if(parm.other.dmteam == allies)
		{
			parm.other iprint "Idiot!" 0
			thread allied_prison_trigger1
		}
	}
end



//**********************************************
//***            ALLIED TRIGGER II           ***
//***Used by AXIS players to release teamates***
//**********************************************

allied_prison_trigger2:
	$allied_trigger2 waitTill trigger
	if (parm.other.dmteam == axis)
	{
		$allied_trigger2 playsound snd_triggers
		parm.other iprint "Your team has been released!" 0
		$allied_trigger1 nottriggerable
		$allied_trigger2 nottriggerable
		waitthread allied_prison_open
		$allied_trigger1 triggerable
		$allied_trigger2 triggerable
		thread allied_prison
	}
	else
	{
		if(parm.other.dmteam == allies)
		{
			parm.other iprint "Idiot!" 0
			thread allied_prison_trigger2
		}
	}
end

Posted: Mon Aug 23, 2004 9:20 pm
by Dani
This is quite useful, but wat i don't understand is how to make it so that when u click USE inside the use_trigger box, how do you get it to trigger the bit in the script, do u have to call it something??? I am not getting any errors. I do not think the error is in my actually script, i think it is the way i am linking the use_trigger to the thread in the script, please tell me how to do this. Thx

Posted: Mon Aug 23, 2004 10:43 pm
by Splaetos
1) - in your map you make a trigger_use with the right click drop down menu.

2) - you place it wherever, make it however big.

3) - give it the key/value

targetname/gate_trigger1

thats about it for mapping unless you use setthreads.

I dont use setthreads usualy, I just give it a targetname.

5) - now in the script you start a thread for executing whatever the trigger does.

thread gate_controls

6) - in that thread, you wait for the trigger to be pressed by a valid target.

$gate_trigger1 waitTill trigger

as soon as someone hits use on the trigger, it will pass that line in the script and commence doing whatever.




thats all there is to actualy setting up the simplest of triggers, but of course, there is more scripting to check the trigger for correct team or stop other triggers from conflicting etc. but as far as the script waiting for someone to use a trigger_use it jsut needs a targetname, and a line instructing the script to wait until someone tries to use it.

make sure that the trigger has the correct targetname, or the script wont have aclue what trigger its waiting for someone to press.

Posted: Mon Aug 23, 2004 11:07 pm
by lizardkid
setthreads are better for noobs but dont affect it any differently, they wait until triggerered anyway so it's a waste of code imo.

setthread/mythreadname

key/value... mythreadname should be the thread you want to call when it's triggered.

Posted: Tue Aug 24, 2004 12:16 pm
by Dani
Well i am already using your way lizardkid, so i think i will try Splaetos's way. Thx

Posted: Tue Aug 24, 2004 12:18 pm
by Dani
I just realised that i am half already using this. I just have to set the targetname gate_switch and cell_switch this is my code already:

Code: Select all

main: 

level waittill prespawn 
$gate time 5 
$cell time 2 

//INSTALL 
gate_initialization: 
level.gate_open = 0 
level.cell_open = 0 
thread gate_switch 
thread cell_switch 
end 


//GATE SWITCH 
gate_switch:
{ 
 $gate_switch waitTill trigger 
 $gate_switch untriggerable 
 if (level.gate_open == 0) 
  { 
  $gate moveup 368 
  $gate waitmove
  level.gate_open = 1 
  } 
  else 
  { 
  $gate movedown 368 
  $gate waitmove
  level.gate_open = 0 
  } 
 $gate_switch triggerable 
} 
end 

//CELL SWITCH 
cell_switch: 
 { 
 $cell_switch waitTill trigger 
 $cell_switch untriggerable 
 if (level.cell_open == 0) 
  { 
  $cell moveright 20
  $cell waitmove 
  level.cell_open = 1 
  } 
  else 
  { 
  $cell moveleft 20
  $cell waitmove 
  level.cell_open = 0 
  } 
 $cell_switch triggerable 
} 
end
[/code]

Posted: Tue Aug 24, 2004 7:55 pm
by lizardkid

Code: Select all

$cell_switch untriggerable 
correction.

Code: Select all

$cell_switch nottriggerable
:wink:

Posted: Tue Aug 24, 2004 8:39 pm
by Dani
THANKS YOU GOD!

Posted: Tue Aug 24, 2004 9:01 pm
by Dani
OK! i got the gate working and everything, the only glitch i get is that it can be triggered more than once, WHY? i have the nottriggerable and triggerable here is my code, tell me why it is not working?:

Code: Select all

main:
$gate time 10 
$cell time 3

//INSTALL 
gate_initialization: 
level.gateopen = 0
level.cellopen = 0
end 

gateswitch:
if(level.gateopen == 0){
 $gateswitch nottriggerable
 $gate moveup 368
 $gate waitmove
 level.gateopen = 1 
 $gateswitch triggerable
}else{
 $gateswitch nottriggerable
 $gate movedown 368
 $gate waitmove
 level.gateopen = 0
 $gateswitch triggerable 
}
end

Posted: Thu Aug 26, 2004 3:35 am
by Splaetos
haha yea, not triggerable is correct not untriggerable, no clue why i typed that =) its correct in my posted code sample =)