Jump to content

Enable/disable objects when using a workbench. Help.


antstubell

Recommended Posts

Made myself a chemical crafting station/workbench... whatever. Looks nice with beakers, mortar and pestle and works as a crafting bench. I thought would be nice if the bunsen burner lit up when player uses the bench. Editted a flame in Nifskope and place it over the burner. I am using a simple OnActivate toggle script to enable/disable the flame. Issue is as you can guess is that the flame turns on/off when the player starts crafting but when player exits the crafting menu the flame stays to its enable/disable state. So what I need is that when player starts crafting > flame turns on + sfx and other stuff and when player exits the crafting menu > flame turns off.

Here's my simple script - nothing special, just to show what I am using.

 

ObjectReference myLinkedRef
bool property fade = False Auto

Event OnActivate(ObjectReference triggerRef)
myLinkedRef = GetLinkedRef() as ObjectReference
if (myLinkedRef.IsEnabled())
myLinkedRef.Disable(fade)
Else
myLinkedRef.Enable(fade)
EndIf

EndEvent

 

Edited by antstubell
Link to comment
Share on other sites

Hmm.. you are asking for so many things here.. maybe next script is helpful.. tested not yet.

 

antFlameCraftingScript

 

Scriptname antFlameCraftingScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/8192258-enabledisable-objects-when-using-a-workbench-help/

  Bool PROPERTY bFade auto        ; [default=False]


; -- EVENT --
; https://www.creationkit.com/index.php?title=WaitMenuMode_-_Utility
; https://www.creationkit.com/index.php?title=IsFurnitureInUse_-_ObjectReference

EVENT OnActivate(ObjectReference akActionRef)
IF (akActionRef == Game.GetPlayer() as ObjectReference)
ELSE
    RETURN    ; - STOP -    crafting table not player activated
ENDIF
;=====================
    objectReference oRef = self.GetLinkedRef()         ; the flame
IF ( oRef )
ELSE
    RETURN    ; - STOP -    missing the linked Ref
ENDIF
;---------------------
    gotoState("Done")                ; ### STATE ###

    oRef.Enable(bFade)
    Utility.WaitMenuMode(0.1)           ; wait while player is in crafing (menu action)

;;;    WHILE Utility.IsInMenuMode()
;;;        Utility.Wait(0.5)            ; player is still in a menu
;;;    ENDWHILE

    WHILE self.IsFurnitureInUse()
          Utility.Wait(0.1)
    ENDWHILE

    Utility.Wait(0.25)                  ; just wait a bit more while leaving crafting menu
    oRef.Disable(bFade)

    gotoState("")                    ; ### STATE ###
ENDEVENT


;================================
state Done        ; do not activate more than once
;=========
EVENT OnActivate(ObjectReference akActionRef)
ENDEVENT
;=======
endState

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

I see where you're going with the script. Couple of new things I didn't know about and will experiment with such as IsInMenuMode and IsFurnitureInuse.

As for your script as it is - when player starts crafting - flame turns on for a split second then turns off.

Link to comment
Share on other sites

If your workbench is just an activator rather than a furniture activator or it is an activator linking to a furniture, then the above script as-is would yield the results that you are seeing. Without knowing the specific setup, cannot speculate on a solution. However, if you remove the comment markers from the IsInMenuMode, it should wait for the crafting session to complete.

 

If you are already using SKSE, you can enable the flame as you have, register for the crafting menu, then use the OnMenuClose event to catch when crafting is complete. Then turn off the flame and unregister for the menu.

Edited by IsharaMeradin
Link to comment
Share on other sites

I did delete the comments that you mentioned and it still is the same.

https://onedrive.live.com/?cid=B60C11D037429D8E&id=B60C11D037429D8E%2151748&parId=B60C11D037429D8E%21191&o=OneUp

 

I run the game from SKSE.exe but don't use it in CK.

 

OMG why can't I upload a tiny file to this site!?

https://onedrive.live.com/?cid=B60C11D037429D8E&id=B60C11D037429D8E%2151749&parId=B60C11D037429D8E%21191&o=OneUp

Edited by antstubell
Link to comment
Share on other sites

IsharaMeradin already post a way how to do this.

Attach it to the crafting station, this requires SKSE, this is just an example:



Event OnInit()
RegisterForMenu("NAME OF THE MENU")
EndEvent


Event OnMenuOpen(String MenuName)
If ( MenuName == "NAME OF THE MENU" )
; Do Stuff
EndIf
EndEvent

Event OnMenuClose(String MenuName)
If ( MenuName == "NAME OF THE MENU" )
; Do Stuff
EndIf
EndEvent




Link to comment
Share on other sites

I've done that several times. Still won't compile.

 

ObjectReference Property Flame Auto

Event OnInit()
RegisterForMenu("Crafting Menu ")
EndEvent


Event OnMenuOpen(String MenuName)
If ( MenuName == "Crafting Menu" )
debug.notification("Menu Opened")
Flame.enable()
; Do Stuff
EndIf
EndEvent

Event OnMenuClose(String MenuName)
If ( MenuName == " Crafting Menu " )
debug.notification("Menu Closed")
Flame.disable()
; Do Stuff
EndIf
EndEvent

 

(6,14): RegisterForMenu is not a function or does not exist

Link to comment
Share on other sites

You are on SSE. If you have not changed the source folder location in the Creation Kit ini file, then your source folder is different from original Skyrim.

Default SSE PEX files -- Data > Scripts

Default SSE PSC files -- Data > Source > Scripts

 

Some mod authors elect to change the INI entry and keep the same layout as original Skyrim. Others adapted to work the way the SSE shipped. This discrepancy can be problematic when wanting to work with scripts from other sources. Always check where the source scripts you want to work with or need to access are located and move them if necessary.

 

An alternative would be to setup a 3rd party text editor (Sublime Text, Notepad++, etc) that is capable of using multiple source file locations and doing as much script compiling as possible in that utility rather than in the Creation Kit.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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