Jump to content

[Scripting help] Enable a reference on activation


Haagaar

Recommended Posts

[EDIT] : Sorry if that topic already exists, I didn't found one when I searched.

 

Hello everyone,

 

I am very new to scripting, not only for papyrus. I went through a number of pages in the CK official wiki, various forums, checked built-in scripts, and so on. I think I pretty much understand the very basics of it. However I'm struggling with something :

 

I'm on a player house mod of my own. I want to add a script to a "DweButton01" form (meaning not the base reference obviously) that will enable a form that's initially disabled. I came out with several tries but can't understand why the compiler rejects them.

 

This is what I have written :

 

 

Scriptname AHVA_PortalButtonScript extends ObjectReference
{Enable or disable a linked reference when the player presses the button}


Bool Property isEnabled = false auto hidden


Event OnActivate(ObjectReference akActivator)
If(isEnabled == false) ; Is the door enabled ?

If akActivator == Game.GetPlayer()
isEnabled = true
self.getLinkedRef().Enable(true) ; Enables the door.

EndIf

Else
isEnabled = false
self.getLinkedRef().Disable(true) ; Disables the door.
EndIf
EndEvent

 

Could someone kindly provide me with an example script please ? That would be greatly appreciated, and I could figure out what's wrong with whatever I'm doing.

 

Thank you !!

Edited by Haagaar
Link to comment
Share on other sites

IsEnabled is already a function defined on the ObjectReference script. As a result the compiler does not understand what you are trying to do when using a property variable of the same name. Below is an example that should perform what you want. Please note that it has not been tested for compilation or function.

 

 

Scriptname AHVA_PortalButtonScript extends ObjectReference
{Enable or disable a linked reference when the player presses the button}

Event OnActivate(ObjectReference akActivator)
  If akActivator == Game.GetPlayer()
    If Self.GetLinkedRerf.IsDisabled()  ; Is the door disabled ?
      self.getLinkedRef().Enable(true) ; Enables the door.
    Else
      self.getLinkedRef().Disable(true) ; Disables the door.
    EndIf
  EndIf
EndEvent

 

 

Edited by IsharaMeradin
Link to comment
Share on other sites

Thank you for the very quick answer !

As usual with "beginners", the solution is easy and right in front of my nose haha ! Sorry for that.

I just renamed the bool property to isEnabled_01, because your script does not compile (compiler says that the "isEnabled" variable is undefined).

 

Again, thanks for the help !

Edited by Haagaar
Link to comment
Share on other sites

Anyway, I tweaked the script a little to add sound fx, here it is, if anyone needs it :

 

 

 

Scriptname AHVA_PortalButtonScript extends ObjectReference
{Enable or disable a linked reference when the player presses the button, with FX}


ObjectReference Property DoortoEnable auto

Sound Property DoorAppearFX auto
Sound Property DoorDisappearFX auto
Sound Property DoorLoopFX auto

Event OnActivate(ObjectReference akActivator)
     If akActivator == Game.GetPlayer()
          If DoortoEnable.isDisabled() ; Is the door enabled ?
               DoorAppearFX.Play(Self)
               DoortoEnable.Enable(true) ; Enables the door.
          Else
               DoortoEnable.Disable(true) ; Disables the door.
               DoorDisappearFX.Play(Self)
          EndIf
     EndIf
     
     While DoortoEnable.isEnabled()
          DoorLoopFX.PlayAndWait(DoortoEnable)
     EndWhile
EndEvent

Link to comment
Share on other sites

  • Recently Browsing   0 members

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