Jump to content

Simple script help


lynxcali

Recommended Posts

Okay so I have this light switch script that I got from another thread, and I used it and it works, but every time I use it, a stupid messagebox comes up. I removed the messagebox but it wont function without it. I want to be able to turn the light on and off without the messagebox. Here is my script:

 

scn aaLightSwitch

 

short button

short go

 

Begin OnActivate player

MessageBox "aaLightSwitchref1"

set go to 1

End

 

Begin GameMode

if go

set button to GetButtonPressed

if button == -1

Return

elseif button == 0

if aaLightSwitchref1.GetDisabled

aaLightSwitchref1.Enable 0

else

aaLightSwitchref1.Disable

endif

elseif button == 1

if aaLightSwitchref1.GetDisabled

aalightswitchref1.Enable 0

else

aalightswitchref1.Disable

endif

endif

Set Go to 0

Activate

endif

End

 

Thanks guys :)

Link to comment
Share on other sites

The message box is actually a menu, where two of the results either switch it on or off, hence why it wont work without the menu.

 

To set it up such that it will alternate, try:

 

scn aaLightSwitch 

begin OnActivate player   
if aaLightSwitchref1.GetDisabled  
 aaLightSwitchref1.Enable 0   
else   
 aaLightSwitchref1.Disable	
endif  
activate ;This may not be needed   
end

 

If you have multiple light/switches, you may want to look into linked references and/or parents, while a bit more complicated, it can save a whole lot of time in that one script can be applied directly to multiple light switches without any modification, unlike the one above which will need the reference changed for every light.

Edited by Skevitj
Link to comment
Share on other sites

For more info you can use this tutorial which does what Skevij describes, but with more in depth information.

 

You can daisy chain lights and have them turn on and off at specific times and more. Some of the vanilla game light scripts can help you there as well, especially the street light scripts that turn the lights on and off at set times.

 

I don't really know why you'd want message boxes for light switches anyway.

 

EDIT:

Great, now I've double posted because of a browser glitch. I'll report it myself.

Edited by Maigrets
Link to comment
Share on other sites

Ahh thank you Skevij, I will try it and Maigrets I dont see a tutorial any where in that post unfortunately. Try to post the link. Also Skevij if you could teach me how to use one script for multiple lights? I have 4 lights but I can only use 1 light switch unfortunately.
Link to comment
Share on other sites

Ahh thank you Skevij, I will try it and Maigrets I dont see a tutorial any where in that post unfortunately. Try to post the link. Also Skevij if you could teach me how to use one script for multiple lights? I have 4 lights but I can only use 1 light switch unfortunately.

 

The link is there. I don't need to "try" and post it since my browser had an issue and double posted before I could add it, thanks all the same.

 

That tutorial will do what you're asking by the way. You need to use scripts to parent one switch to an other and so on for as many as you need. All will be explained if you read it thoroughly. Also, you will need the invisible mesh it mentions and there is a link in the tutorial.

 

EDIT: FYI...I'm a female not a Bro... :yes:

Edited by Maigrets
Link to comment
Share on other sites

The tutorial actually uses two invisible switches on top of each other, with only one enabled at a time, giving the effect of a single switch with two different states.

 

If you only have the one switch and a small number of lights, the easiest way to do it is just to expand on the code I posted before (unless you really want to practice and understand the contents of the tutorial, which isn't a bad thing, but can be time consuming).

 

scn aaLightSwitch

begin onactivate player
if aaLightSwitchref1.GetDisabled
 aaLightSwitchref1.Enable
 aaLightSwitchref2.Enable
 aaLightSwitchref3.Enable
 aaLightSwitchref4.Enable
 ;... etc, for as many lights as there are
else
 aaLightSwitchref1.Disable
 aaLightSwitchref2.Disable
 aaLightSwitchref3.Disable
 aaLightSwitchref4.Disable
 ;... etc, for as many lights as there are
endif
end

That will determine the state of light 1 and switch all of them (including 1) to the opposite. It will work with multiple switches, but it's not a neat solution and will need to be changed if the lights are ever changed.

Edited by Skevitj
Link to comment
Share on other sites

You probably should take that last post out.

 

Modding consoles is illegal and even talking about it will result in your account being banned. Not my rules, but they exist for a reason

 

Ahh okay, it has been removed. I was not aware of that rules. Thank you for catching me.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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