CrAsHnBuRnPs3 Posted June 26, 2010 Share Posted June 26, 2010 i have a question i want to make some lights turn on when someone or thing comes withing range of a certain point (like 10ft from a fence) what trigger do i need to make the lights come on and how do i link it with the link ref, active parent and enable parent. and once triggered how do i then turn the lights off Link to comment Share on other sites More sharing options...
Cipscis Posted June 26, 2010 Share Posted June 26, 2010 I'd recommend using a scripted triggerbox with an OnTriggerLeave block that disables the lights. Something like this: ref rLinkedRef int iCount Begin OnTriggerLeave if rLinkedRef == 0 set rLinkedRef to GetLinkedRef endif set iCount to iCount - 1 if iCount < 0 set iCount to 0 endif if iCount == 0 rLinkedRef.Disable 1 endif End Begin OnTriggerEnter if rLinkedRef == 0 set rLinkedRef to GetLinkedRef endif set iCount to iCount + 1 if iCount > 0 rLinkedRef.Enable 1 endif End You'll want to set one "master" reference, which could be one of your lights or an invisible XMarker, as both the triggerbox's linked reference and the enable parent of every other light that you want to switch on and off. If you want the lights to be controlled via a switch as well, then you'll also need to check the position of the switch so you don't turn the lights off when all of the actors have left. The most general way to do this would be to make the light the linked reference of your "master" reference, which is the triggerbox's linked reference, and use a script like this: ref rLinkedRef ref rSwitch int iCount Begin OnTriggerLeave if rLinkedRef == 0 set rLinkedRef to GetLinkedRef set rSwitch to rLinkedRef.GetLinkedRef endif set iCount to iCount - 1 if iCount < 0 set iCount to 0 endif if iCount == 0 if rSwitch.GetOpenState == 3 ; Closed. You might want to use a different value or function to check if the switch is on rLinkedRef.Disable 1 endif endif End Begin OnTriggerEnter if rLinkedRef == 0 set rLinkedRef to GetLinkedRef endif set iCount to iCount + 1 if iCount > 0 rLinkedRef.Enable 1 endif End Cipscis Link to comment Share on other sites More sharing options...
Quetzlsacatanango Posted June 26, 2010 Share Posted June 26, 2010 Cipscis, why do you choose a trigger box instead of getdistance? So it doesn't run in gamemode? Good to see you back, btw. Link to comment Share on other sites More sharing options...
kartman314 Posted June 26, 2010 Share Posted June 26, 2010 Cipscis, how did you do that thing with the spoiler button and expanding text? Link to comment Share on other sites More sharing options...
Cipscis Posted June 27, 2010 Share Posted June 27, 2010 @Quetzlsacatanango:Not entirely. If I were to use GetDistance in a GameMode block, then I'd either only be able to check the position of a set number of predefined references, or I'd have to loop through all actors in the cell and determine their distance. By using a triggerbox with OnTriggerEnter and OnTriggerLeave blocks, I can the location of all actors without needing some method of finding them first. That said, the fact that the code only runs when required, instead of in a GameMode block, is definitely an advantage. Even if I wanted to set up something like this so that only the player could activate the lights by proximity, I would still use a triggerbox instead of GetDistance. Good to see you back, btw.Thanks! @kartman314:I used the spoiler tag: [spoiler]Some code[/spoiler] Cipscis Link to comment Share on other sites More sharing options...
Recommended Posts