Jump to content

Use Light Once script


Thief3Wannabe

Recommended Posts

Currently I'm using the light switch script to allow the player to turn on a vaults power supply:

 

ScriptName LightSwitchScript

 

ref light

 

Begin OnActivate

if light == 0

set light to GetLinkedRef

endif

 

if light.GetDisabled

light.Enable

else

light.Disable

endif

Activate

End

 

However, I would like to make it so the player can only turn on the power once and not be able to turn it off. I've got everything else set up thanks to enable parenting but I'm obviously missing something really simple here. I tried looking at scripts that use "counts" but anytime I try to incorporate what I think I've learned into the lightswitch script it just doesn't work. Any help would be greatly appreciated.

Link to comment
Share on other sites

As you've no doubt realised, the script that you're using allows the player to turn the lights on and off any number of times by repeatedly activating the switch. If you only want the first activation to have an effect, then you'll want to use a variable to store whether or not it has been activated already, and only run code the first time it is activated:

ScriptName LightSwitchScript

int bDoOnce
ref rLinkedRef

Begin OnActivate player

if bDoOnce == 0
	set bDoOnce to 1

	set rLinkedRef to GetLinkedRef
	rLinkedRef.Enable

	Activate
endif

End

P.S. Please use code or codebox tags when posting scripts. This forces them to be displayed in a fixed width font and maintains indentation, making them easier to read. If you don't know how to indent your scripts, here is a web-based tool that can do it for you - Script Validator

 

Cipscis

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...