Jump to content

How do you "enable" a "disabled" chest via spell?


Recommended Posts

So I've been messing around with a simple idea -- I know nothing, I'm a noob with scripting as always -- but I wanted to see how to make a chest/container simply enable.

So in Riverwood, I placed a chest somewhere and created a reference for it in the CK. I set it as "Initially disabled" and wanted to see how to "enable" it by using a simple spell.

 

The spell/magic effect is just a simple FFS (Fire forget self) with the archetype set to Script.

 

Below is the script I mustered up but it doesn't seem to be working, I think there's something missing somewhere -- can anyone fill in the blanks and educate me?

 

The property is pointing at the reference chest in the render window. At first it didn't let me pick it but once I created a reference ID, instead of the chest just being a case base object, I was able to point to it.

Scriptname ChestEnable extends activemagiceffect  
{This script will enable an initially disabled chest and vice versa}

ObjectReference Property JWCHEST Auto

event OnInit()
        If (JWCHEST.IsDisabled())    ;if the chest is currently disabled...
		Debug.Notification("The chest is disabled")   ;display a message that it is being enabled just because
		JWCHEST.Enable(true)  ;and enable it with a fadein
		Debug.Notification("The chest is now enabled")   ;display a message that it is being enabled just because
		;JWCHEST.SetOpen()
	ElseIf (JWCHEST.IsEnabled())
		Debug.Notification("The chest is enabled")   ;display a message that it is being disabled just because
		JWCHEST.Disable(true)  ;and disable it with a fadeout
		Debug.Notification("The chest is now disabled")   ;display a message that it is being enabled just because
	EndIf
endEvent

Also, can someone explain to me what this does below, assuming of course there's a layman's term for it. Does this mean that akSpeaker (which is an actor), is being looked at "as" an objectreference? I'm confused what "as" does. I see this alot and always wondered that.

 

https://www.creationkit.com/index.php?title=Cast_Reference

 

Function Fragment_0(ObjectReference akSpeakerRef)
Actor akSpeaker = akSpeakerRef as Actor
Thanks for any help!
Edited by justinglen75
Link to comment
Share on other sites

For starters, I would replace the OnInit event with OnEffectStart. But do keep in mind that I've never set a spell up to enable / disable objects.

 

 

 

As far as casting that is typically used when you want to check an object currently stored as a broad type to see if it might be of a more narrow type.

Using your example:

Function Fragment_0(ObjectReference akSpeakerRef)
Actor akSpeaker = akSpeakerRef as Actor
This takes akSpeakerRef which is defined as the broader type ObjectReference and casts it into the more narrow type of Actor and subsequently stores it in the akSpeaker variable which is defined as Actor. Casting can only be done between parent object types and their child object types.
Actor extends ObjectReference and thus an ObjectReference variable can be cast into Actor and if that ObjectReference returns as a valid actor it will then be treated as an Actor for that particular bit of code.
Link to comment
Share on other sites

As always @IsharaMeradin -- thanks again! Replacing OnInit () with OnEffectStart(Actor akTarget, Actor akCaster) worked. The chest appears when you use the spell, disappears when I use the spell again. Perfect!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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