Jump to content

help on a simple enable/disable checker script


kane4355

Recommended Posts

I am trying to create a simple script that will enable/disable a certain object and disable/enable another on activate. pretty much alternating between object A and object B being displayed when the player activates a certain switch and also play a sound. I have looked over other scripts but unfortunately all i have found is how to do a check on objects within the players inventory and not whether a certain object reference in game is disabled or enabled allowing to alternate between the objects. maybe i am looking too far into and confusing myself. can anyone help?

 

here is a simple jist of what i want to do:

 

object1 disabled

object2 enabled

on activate play sound

if object1 is disabled, enable object1

disable object2

if object1 is enabled, disable object1

enable object2

 

 

sorry for not using papyrus language, i was just running it through my head of what i wanted to do and haven't really put anything together. Also, object1 would actually cover over 4 objects so it would be object 1a-d that needed to be enabled/disabled. would a checker like this work on statics in game?

Link to comment
Share on other sites

Scriptname SwitchScript extends ObjectReference

ObjectReference Property object1 Auto
ObjectReference Property object2 Auto 

;Thanks Cipscis - http://www.cipscis.com/skyrim/tutorials/states.aspx
Auto State On
Function Toggle()
	object2.Enable()
	object1.Disable()
	GoToState("Off")
EndFunction
EndState

State Off
Function Toggle()
	object1.Enable()
	object2.Disable()
	GoToState("On")
EndFunction
EndState

Function Toggle()
; Empty function definition to allow Toggle to be defined inside states. More on this soon...
EndFunction

Event OnActivate()
Toggle()
EndEvent

Thanks Cipscis - States tutorial

Link to comment
Share on other sites

Scriptname SwitchScript extends ObjectReference

ObjectReference Property object1 Auto
ObjectReference Property object2 Auto 

;Thanks Cipscis - http://www.cipscis.com/skyrim/tutorials/states.aspx
Auto State On
Function Toggle()
	object2.Enable()
	object1.Disable()
	GoToState("Off")
EndFunction
EndState

State Off
Function Toggle()
	object1.Enable()
	object2.Disable()
	GoToState("On")
EndFunction
EndState

Function Toggle()
; Empty function definition to allow Toggle to be defined inside states. More on this soon...
EndFunction

Event OnActivate()
Toggle()
EndEvent

Thanks Cipscis - States tutorial

 

ok wow thanks. lot better than what i had in mind. i will try using this and see how it fits into what i want to do, looks to be it though. However, on the play sound line, should i add that under "onactivate" or under each state? it will be the same sound for each toggle.

 

what i was going to use was this:

 

Event OnActivate(ObjectReference akActionRef)

if ("sound")

"sound".Play(Self)

endif

Link to comment
Share on other sites

Scriptname SwitchScript extends ObjectReference

ObjectReference Property object1 Auto
ObjectReference Property object2 Auto
Sound Property mySound Auto 

;Thanks Cipscis - http://www.cipscis.com/skyrim/tutorials/states.aspx
Auto State On
Function Toggle()
	object2.Enable()
	object1.Disable()
	GoToState("Off")
EndFunction
EndState

State Off
Function Toggle()
	object1.Enable()
	object2.Disable()
	GoToState("On")
EndFunction
EndState

Function Toggle()
; Empty function definition to allow Toggle to be defined inside states. More on this soon...
EndFunction

Event OnActivate()
mySound.Play(Self) ;<-- edit
Toggle()
EndEvent

Link to comment
Share on other sites

Just want to note that in this case, getting rid of the function and sticking OnActivate into the states make for a better and shorter script. If you do change it, you don't need to put a dummy OnActivate in the null state, like you need to do with functions.
Link to comment
Share on other sites

Ok this is what i used:

 

Scriptname DKDrawbridgescript extends ObjectReference

 

ObjectReference Property bridge1a Auto

ObjectReference Property bridge1b Auto

ObjectReference Property bridge1c Auto

ObjectReference Property bridge1d Auto

ObjectReference Property bridge1e Auto

ObjectReference Property bridge2 Auto

Sound Property bridgesound Auto

 

;Thanks Cipscis - http://www.cipscis.com/skyrim/tutorials/states.aspx

Auto State On

Function Toggle()

object2.Enable()

bridge1a.Disable()

bridge1b.Disable()

bridge1c.Disable()

bridge1d.Disable()

bridge1e.Disable()

GoToState("Off")

EndFunction

EndState

 

State Off

Function Toggle()

object1a.Enable()

object1b.Enable()

object1c.Enable()

object1d.Enable()

object1e.Enable()

object2.Disable()

GoToState("On")

EndFunction

EndState

 

Function Toggle()

; Empty function definition to allow Toggle to be defined inside states. More on this soon...

EndFunction

 

Event OnActivate()

bridgesound.Play(Self)

Toggle()

EndEvent

 

the bridge i want to toggle is actually comprised of 6 parts, 5 active on one side and 1 on the other. when i went to compile it this is the error i recieved:

 

Starting 1 compile threads for 1 files...

Compiling "DKDrawbridgescript"...

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(14,16): variable object2 is undefined

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(14,24): none is not a known user-defined type

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(26,16): variable object1a is undefined

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(26,25): none is not a known user-defined type

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(27,16): variable object1b is undefined

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(27,25): none is not a known user-defined type

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(28,16): variable object1c is undefined

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(28,25): none is not a known user-defined type

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(29,16): variable object1d is undefined

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(29,25): none is not a known user-defined type

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(30,16): variable object1e is undefined

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(30,25): none is not a known user-defined type

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(31,16): variable object2 is undefined

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(31,24): none is not a known user-defined type

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\DKDrawbridgescript.psc(40,0): the parameter types of function onactivate in the empty state on script dkdrawbridgescript do not match the parent script objectreference

No output generated for DKDrawbridgescript.psc, compilation failed.

 

Batch compile of 1 files finished. 0 succeeded, 1 failed.

Failed on DKDrawbridgescript.psc

Link to comment
Share on other sites

Scriptname DKDrawbridgescript extends ObjectReference

ObjectReference Property bridge1a Auto
ObjectReference Property bridge1b Auto
ObjectReference Property bridge1c Auto
ObjectReference Property bridge1d Auto
ObjectReference Property bridge1e Auto
ObjectReference Property bridge2 Auto
Sound Property bridgesound Auto

;Thanks Cipscis - http://www.cipscis.c...als/states.aspx
Auto State On
Event OnActivate(ObjectReference akActionRef)
	GoToState("Off")
	bridgesound.Play(Self)
	bridge1a.Disable()
	bridge1b.Disable()
	bridge1c.Disable()
	bridge1d.Disable()
	bridge1e.Disable()
	bridge2.Enable()
EndEvent
EndState

State Off
Event OnActivate(ObjectReference akActionRef)
	GoToState("On")
	bridgesound.Play(Self)
	bridge1a.Enable()
	bridge1b.Enable()
	bridge1c.Enable()
	bridge1d.Enable()
	bridge1e.Enable()
	bridge2.Disable()
EndEvent
EndState

Link to comment
Share on other sites

I haven't tried compiling this, but I thought it would be a good idea to check whether the objects are enabled/disabled, not just assume it is so.

Using states is overkill in a script like this.

 

 

Scriptname SwitchScript extends ObjectReference

ObjectReference Property bridge1a Auto
ObjectReference Property bridge1b Auto
ObjectReference Property bridge1c Auto
ObjectReference Property bridge1d Auto
ObjectReference Property bridge1e Auto
ObjectReference Property bridge2 Auto
Sound Property bridgesound Auto

Event OnActivate()
; added some checks for safety
If bridge1a.IsEnabled() && bridge1b.IsEnabled() && bridge1c.IsEnabled() && bridge1d.IsEnabled() && bridge1e.IsEnabled() && bridge2.IsDisabled()
               bridgesound.Play(Self)
               bridge1a.Disable()
               bridge1b.Disable()
               bridge1c.Disable()
               bridge1d.Disable()
               bridge1e.Disable()
               bridge2.Enable()
ElseIf bridge1a.IsDisabled() && bridge1b.IsDisabled() && bridge1c.IsDisabled() && bridge1d.IsDisabled() && bridge1e.IsDisabled() && bridge2.IsEnabled()
               bridgesound.Play(Self)
               bridge1a.Enable()
               bridge1b.Enable()
               bridge1c.Enable()
               bridge1d.Enable()
               bridge1e.Enable()
               bridge2.Disable()
Else
	Debug.Trace("[switchScript]Error: the bridges are out of sync.")
EndIf
EndEvent

Edited by steve40
Link to comment
Share on other sites

Scriptname DKDrawbridgescript extends ObjectReference

ObjectReference Property bridge1a Auto
ObjectReference Property bridge1b Auto
ObjectReference Property bridge1c Auto
ObjectReference Property bridge1d Auto
ObjectReference Property bridge1e Auto
ObjectReference Property bridge2 Auto
Sound Property bridgesound Auto

;Thanks Cipscis - http://www.cipscis.c...als/states.aspx
Auto State On
Event OnActivate(ObjectReference akActionRef)
	GoToState("Off")
	bridgesound.Play(Self)
	bridge1a.Disable()
	bridge1b.Disable()
	bridge1c.Disable()
	bridge1d.Disable()
	bridge1e.Disable()
	bridge2.Enable()
EndEvent
EndState

State Off
Event OnActivate(ObjectReference akActionRef)
	GoToState("On")
	bridgesound.Play(Self)
	bridge1a.Enable()
	bridge1b.Enable()
	bridge1c.Enable()
	bridge1d.Enable()
	bridge1e.Enable()
	bridge2.Disable()
EndEvent
EndState

 

 

so this script was able to compile. I will let you know if it works in game thank you :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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