Page 1 of 2

Lightswitch

Posted: Tue Aug 10, 2004 12:46 am
by PsychoE
I tried Mansteins lightswitch tut. After compiling, the light just kept turning on and off without having to use the trigger (I wasn't even near it when it was going on/off. I don't know if there is a typo here somewhere, but here is the script:

Code: Select all

level waittill spawn

thread lightswitch1

end

Code: Select all

lightswitch1:
	$light light 1 1 1 206
	$lightswitch_trigger triggerable
	$lightswitch_trigger waittill trigger
	$lightswitch_trigger nottriggerable
	$lightswitch anim turn
	$lightswitch playsound alarm_switch
	wait .5
	thread lightoff
end

lightoff:
	$light light 0 0 0 64
	$corona hide
	wait .5
	thread lightswitch2
end


lightswitch2:
	$lightswitch_trigger triggerable
	$lightswitch_trigger waittill trigger
	$lightswitch_trigger nottriggerable
	$lightswitch anim off
	$lightswitch playsound alarm_switch
	wait .5
	thread lighton
end

lighton:
	$light light 1 1 1 206
	$corona show
	wait .5
	thread lightswitch1
end

targetname

Posted: Tue Aug 10, 2004 1:00 am
by tltrude
Make sure your trigger's targetname "lightswitch_trigger" is exactly the same in the map.

Posted: Tue Aug 10, 2004 1:17 am
by lizardkid
perhaps you should just exempt the waittill triggers and rely on the trigger itself to do the triggering and have setthread value to the script...

Re: targetname

Posted: Tue Aug 10, 2004 11:20 am
by PsychoE
tltrude wrote:Make sure your trigger's targetname "lightswitch_trigger" is exactly the same in the map.
I think that is it. (At work now and will check when at home).

If I recall correctly, I had named it lightswitchtrigger instead of lightswitch_trigger.

Thanks

EDIT: P.S. - is there any more animated lightswitches that I could use? More specifically, I want a modern day style switch.

Posted: Wed Aug 11, 2004 12:09 am
by PsychoE
Curious if i can script 10 lightswitches with one script or do i have to script each one individually?

and is there any more animated lightswitches that I could use? More specifically, I want a modern day style switch

Posted: Wed Aug 11, 2004 12:57 am
by bdbodger
Try doing this make all your lighttrigger's with the same targetname lighttrigger and
have the trigger's target the lightswitch and have the lightswitch target the light and
have the light target the corona .


lightswitches:

for(local.i= 1;local.i <= $lighttrigger.size;local.i++)
{
$lighttrigger[local.i] thread lighttriggersetup
}

end

lighttriggersetup:



local.switch = $(self.target) // trigger targets the switch
local.light = $(local.switch.target) // the switch targets the light
local.corona = $(local.light.target) // the light targets the corona

local.light light 1 1 1 206
local.light.lite = 1

while(1)
{
self waittill trigger
local.switch anim turn
local.switch playsound alarm_switch
wait .5
if(local.light.lite == 1)
{
local.light.lite = 0
local.light lightoff
local.corona hide
}
else
{
local.light.lite = 1
local.light lighton
local.corona show
}
}

end

Posted: Wed Aug 11, 2004 7:10 am
by PsychoE
hmmmm. Keeping in mind that I understood nothing u had typed there, I tried but didn't work. The switches turned and made sound - turned back right away without me triggering the "off". No lights worked. I know the targetnames were all the same, cause the lines in radient went from one to the other.

Is it crazy of me to just script each one? Cut and paste the script, but just modify each targetname slightly.

switch

Posted: Wed Aug 11, 2004 7:31 am
by tltrude
There is no modern light switch, but you can make one easy enough. Make a switch plate and add an arm that is a script_object. Then in place of the animation for the model switch, make the arm rotate up and down in the script.

$myswitch rotateZup 60
$myswitch move

$myswitch rotateZdown 60
$myswitch move

The script_object arm should also have an origin brush for the hindge point (like a door) as part of the object. If axis Z does not work, try X or Y.

Posted: Wed Aug 11, 2004 8:32 am
by bdbodger
Try adding a wait at the end of the thread like this it maybe that you are triggering it again that wait will give you time to let go of the use key . I assume it is a trigger_use . If the wait is not long enough make it longer . From what you have posted it seem that the script is working ok it is just the trigger triggering again too fast I think . This way is the best no sence makeing a long script for no reason .

}
wait 2
}

end

Also only the triggers need to have the same targetname in fact if you take away all the targetnames of the lights , switches and coronas and then redo the targeting by first selecting the trigger then the switch press control k on the key board to get the line from the trigger to the switch then do the same for the switch to the light and then light to corona the game will actually give then a targetname when you do the control k .

Posted: Wed Aug 11, 2004 8:52 pm
by PsychoE
Maybe I am naming something wrong. I tried using ctrl-k, but still the switches wont work properly and will turn back. They won't stay on/off. Also they are not triggering the coronas - the light is present but corona doesn't get activated.

I have 2 lights - both targetname lighttrigger. My switches are targetname switch1 and switch2. i used ctrl-k to link up the trigger to its corresponding switch. I have 2 lights targetname light1 and light2. I used ctrl-k to link switch to light. I have 2 coronas targetname corona1 and corona2. I used ctrl-k here as well.

I used word for word the script above including the "wait 2" line.

Posted: Wed Aug 11, 2004 11:39 pm
by bdbodger
You are only running the lightswitches thread once right? and you are not useing setthread for the triggers right ? Try this then it should work better .

lightswitches:

for(local.i= 1;local.i <= $lighttrigger.size;local.i++)
{
$lighttrigger[local.i] thread lighttriggersetup
}

end

lighttriggersetup:

local.switch = $(self.target) // trigger targets the switch
local.light = $(local.switch.target) // the switch targets the light
local.corona = $(local.light.target) // the light targets the corona

local.light light 1 1 1 206
local.light.lite = 1

while(1)
{
self waittill trigger

local.player = parm.other

local.switch anim turn
local.switch playsound alarm_switch
wait .5
if(local.light.lite == 1)
{
local.light.lite = 0
local.light lightoff
local.corona hide
}
else
{
local.light.lite = 1
local.light lighton
local.corona show
}
while(local.player.useheld == 1)
waitframe
}

end

Posted: Mon Aug 16, 2004 2:59 am
by PsychoE
ARRRRRRGGGGGGHHHHH!!!!!!!!!!!!! Finally got multiple (2) switches to work. This is using the animate/equipment/electric switch no pulse and the second script that bdbodger added. Now, HOW and WHERE can I add tltrudes:
$myswitch rotateZup 60
$myswitch move

$myswitch rotateZdown 60
$myswitch move
to my script. I have 3 brushes in my switches: 1 back plate, 1 origin brush, and the knob that is supposed to move. If at all possible, how would I make 2 lights activated by 1 switch. Questions questions.....

Image

Posted: Mon Aug 16, 2004 3:49 am
by bdbodger
local.switch = $(self.target) // trigger targets the switch

the trigger should target your new switch or should I say the knob

This part of the thread turns off the light so it makes sence to put the rotatezdown line inside this part of the thread does it not ? I think if you think about it you will be to see where to put the lines and use local.switch rotatezdown 60 for this .
if(local.light.lite == 1)
{
local.light.lite = 0
local.light lightoff
local.corona hide
}

Posted: Mon Aug 16, 2004 4:55 am
by PsychoE
K - got that working, but.... When i push the use button for the first time, I hear the alarm_switch sound, but nothing moves. After the initial use, everything works perfect. This happens for each switch I have.

Code: Select all

lighttriggersetup: 

local.switch = $(self.target) // trigger targets the switch 
local.light = $(local.switch.target) // the switch targets the light 
local.corona = $(local.light.target) // the light targets the corona 

local.light light 1 1 1 206 
local.light.lite = 1 

while(1) 
{ 
self waittill trigger 

local.player = parm.other 

//local.switch anim turn 
local.switch playsound alarm_switch
local.switch move 
wait .5 
if(local.light.lite == 1) 
{
local.light.lite = 0 
local.light lighton
local.corona show 
local.switch rotatexup 60  
} 
else 
{ 
local.light.lite = 1 
local.light lightoff 
local.corona hide 
local.switch rotatexdown 60
} 
while(local.player.useheld == 1) 
waitframe 
} 

end

Posted: Mon Aug 16, 2004 7:32 am
by bdbodger
local.switch move should go after every rotate statement in other words you do the rotate command but the switch does not move untill the move statement is used .

if(local.light.lite == 1)
{
local.light.lite = 0
local.light lighton
local.corona show
local.switch rotatexup 60
local.switch waitmove
}

also positive x rotation is forward and down it looks ok to you because the move statement does not happen untill the trigger is triggered again the way you have it . You will probably switch the rotatestatements when you make the changes to the two parts of the thread to add the move or waitmove statements to them . Move and waitmove are the same but with waitmove the script pauses untill the move is done before continueing .