Jump to content

Attaching Enable/Disable Script to object


bientje

Recommended Posts

Hi guys!

 

I'm having a similar problem right now. I have several static displays that should enable after specific quests are completed (Companions, Thieves Guild, ...).
I used a script, similar to yours, Poepkat, but it just won't work. :sad:

Scriptname oc_EnableDisplayThievesGuild extends ObjectReference
{Quest property TG04 auto

Event OnCellAttach()
  If TG04.IsCompleted()
    Self.Enable()
  endif
EndEvent}

I wondered if it was, because I set the static object to be "Initially Disabled" but when I "inverted" my script for it to be enabled and then disable with the script, it won't work either.

Then I tried you approach with the queststage but that didn't help either.

 

Am I completely overlooking something?

Link to comment
Share on other sites

Jup! I'm a doofus.

 

I came to the same conclusion about 2 minutes ago.

Hence, I tried to use a marker and link my static. Then attach the script to the marker.

It still won't do as I tell it.

 

I'm fiddling around some more and see what I can come up with.

 

Thanks for your reply, maxarturo! :)

Link to comment
Share on other sites

For reference, to test I placed a new basket in breezehome, checked the initially disabled box and attached this script to it:

Scriptname TM_ObjectRefScript extends ObjectReference

Event OnInit() 
    Utility.Wait(1)
    Game.GetPlayer().MoveTo(Self)
EndEvent

Event OnCellAttach() 
    Self.Enable() 
    Debug.MessageBox("CellAttach")
    
EndEvent

I was moved there and got the messagebox.

Link to comment
Share on other sites

As dylbill said, i don'y know how i missed that...??!!


Also try to avoid using scripts that uses "OnCellAttach()", "OnLoad()"... etc, on too many references, if we are talking about 'Collectible Displays' it can easily get out of hand and end up with an excessive number of scripts that will execute once the player enters that cell, execution of scripts chaos is the last thing that a mod needs.

Link to comment
Share on other sites

@ dylbill

 

Not that i've tested it or need it in the past, but i do remember reading in CK wiki that scripts will not execute on disabled objects.
Well, this prove the thing i keep saying, CK wiki is full of inaccuracies... and you should never bet on it!!!...
Link to comment
Share on other sites

 

@ dylbill

 

Not that i've tested it or need it in the past, but i do remember reading in CK wiki that scripts will not execute on disabled objects.
Well, this prove the thing i keep saying, CK wiki is full of inaccuracies... and you should never bet on it!!!...

 

 

Yes I've found this to be true. Never just take the word of the wiki, you should always test it out for yourself.

Link to comment
Share on other sites

Alright. After some fiddling I came up with this:

Scriptname oc_EnableDisplay extends ObjectReference
Quest property QuestInQuestion auto

ObjectReference Property LinkedObject01 auto
ObjectReference Property LinkedObject02 auto
ObjectReference Property LinkedObject03 auto
ObjectReference Property LinkedObject04 auto
ObjectReference Property LinkedObject05 auto

Event OnCellAttach()
	If QuestInQuestion.IsCompleted()
		LinkedObject01.Enable(true)
		LinkedObject02.Enable(true)
		LinkedObject03.Enable(true)
		LinkedObject04.Enable(true)
		LinkedObject05.Enable(true)
	endif
EndEvent

QuestInQuestion and LinkedObject01 - 05 will now be filled via the property editor which (I just realised^^) allows me to have a single script for all displays.

I attached the script to an XMarker and set the marker as a parent of my static.

 

Still, it doesn't want to appear once I load a save where the quest is completed. I'm really starting to have fun with this. I love tricky scripting. :)

 

 

@maxarturo: There are about 15 - 20 Displays, so I hope it's not too many.

@dylbill: Trying you test script next. :)

Link to comment
Share on other sites

"OnCellAttach()" will not fire in the first cells when a save is loaded.

It's better to use "OnLoad()", but this event will not fire if a save is loaded when the player is in the same cell that the script holding the "OnLoad()" event is in.


If you have a lot of references that you need to check their corresponding quest to enable your display, it's better to have them all in one script than to have a lot of scripts firing for the same 'Event' and 'Functions', one script executing everything in order.



If using the "OnLoad" event in a cell that has other references using the same event, like a lot of mannequins, add to it a "Wait()" function so that the mannequiens fires first and then your 'Display Collectible' script.

Event OnLoad()

Utility.Wait(2.0)

Etc.....

EndEvent


Also add a "State AllDone" to your script so that when all of the script's references are 'Completed', it will no longer execute the script (Optimization).



Also use a save file that hasn't seen the script in question.

Edited by maxarturo
Link to comment
Share on other sites

  • Recently Browsing   0 members

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