RegisterForUpdate on Unequipped Armor Piece

Post » Mon Jun 18, 2012 11:41 am

Well, me being me I've probably managed to get myself into a situation that is unknown territory for just about everyone, but here goes.

I have this script:
Scriptname RenCrimeGuardRingScript  extends ObjectReferenceimport ActorActor myActorContainerEvent OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)	myActorContainer = akNewContainer as Actor	if (myActorContainer.IsGuard() == 1)		RegisterForUpdate(1.0)		Debug.Notification("Guard registered for update.")		else		akNewContainer.RemoveItem(self, 1)	endifEndEventEvent OnUpdate()   Debug.Notification("Test 1")	Debug.Notification("Guard is updating: " + myActorContainer.HasLOS(Game.GetPlayer()) )	if myActorContainer.HasLOS(Game.GetPlayer()) == 1		Debug.Notification("Guard can see the player")	endifendEvent

It compiles just fine and runs up until the point where the Event OnUpdate is (supposed) to fire. I don't see any of the Debug.Notifications pop up, and I'm stumped as to why. I see the notification "Guard registered for update" pop up.

This script is running on a nonplayable piece of armor that is added to Guards through a neat little trick of using FindRandomActorFromRef. In theory it all should work fine, but my hunch is that RegisterForUpdate isn't working on objects that are inside an actor's inventory.

Any help would be greatly appreciated!

Edit: Also, is there any way to add a script directly to an actor through scripting? For some reason the idea is stuck in my head that it is possible, and that I saw it somewhere, but I can't remember how.
User avatar
tiffany Royal
 
Posts: 3340
Joined: Mon Dec 25, 2006 1:48 pm

Post » Mon Jun 18, 2012 1:25 pm

Try creating an ObjectReference property in your script and initialising it to "Self". That should force the scripted object to be a bit more persistent, even though it's an inventory item, I think.

On a side note, we have proper "bool" types now, so it would be more semantically correct (although just as superfluous, as I'm sure you know) if you did this instead with your conditions:
if myActorContainer.HasLOS(Game.GetPlayer()) == true

Cipscis
User avatar
Devils Cheek
 
Posts: 3561
Joined: Sun Aug 13, 2006 10:24 pm

Post » Mon Jun 18, 2012 3:01 pm

Try creating an ObjectReference property in your script and initialising it to "Self". That should force the scripted object to be a bit more persistent, even though it's an inventory item, I think.

On a side note, we have proper "bool" types now, so it would be more semantically correct (although just as superfluous, as I'm sure you know) if you did this instead with your conditions:
if myActorContainer.HasLOS(Game.GetPlayer()) == true

Cipscis
I'll give that a shot - didn't even think about permanence being an issue.

Edit: You mean like,
ObjectReference mySelf = self
or
ObjectReference Property mySelf = self
?
User avatar
Darlene DIllow
 
Posts: 3403
Joined: Fri Oct 26, 2007 5:34 am

Post » Mon Jun 18, 2012 7:54 am

I haven't done the same performance tests as I did in Fallout 3 - as far as I know the compilation might be optimised now. Just thought it might be worth mentioning.

Cipscis
User avatar
Alba Casas
 
Posts: 3478
Joined: Tue Dec 12, 2006 2:31 pm

Post » Mon Jun 18, 2012 8:31 am

Well, so far nothing I've tried has worked, which is rather disappointing. Is there any way to simply add a script to an NPC through code?
User avatar
Chantelle Walker
 
Posts: 3385
Joined: Mon Oct 16, 2006 5:56 am

Post » Sun Jun 17, 2012 11:57 pm

Well, so far nothing I've tried has worked, which is rather disappointing. Is there any way to simply add a script to an NPC through code?
The script slot for actors is all the tabs rather than in a separate one like it is for many other form typess (evaded me too). You can also add a script(s) to actors' ACHR(s).

Edit: Reads "through code" Sorry. Can't find anything like Get/Set/RemoveScript(). There's another function to add to my SKSE wishlist.
Edit2: Perhaps try without the 'As Actor' or 'as ObjectReference' instead? IIRC, both an Actor and ObjectReference property can point to an actor's REF, but only one or the other worked.
User avatar
Dylan Markese
 
Posts: 3513
Joined: Sat Dec 01, 2007 11:58 am

Post » Mon Jun 18, 2012 12:42 am

The script slot for actors is all the tabs rather than in a separate one like it is for many other form typess (evaded me too). You can also add a script(s) to actors' ACHR(s).

Edit: Reads "through code" Sorry. Can't find anything like Get/Set/RemoveScript(). There's another function to add to my SKSE wishlist.
Edit2: Perhaps try without the 'As Actor' or 'as ObjectReference' instead? IIRC, both an Actor and ObjectReference property can point to an actor's REF, but only one or the other worked.
Well, that's not the issue. I'm not trying to get the actor to be RegisteredForUpdate, but the armor piece that is in their inventory. Unless there's a way to add scripts directly to actors through code, of course.

Or are you referring to something else?
User avatar
JUDY FIGHTS
 
Posts: 3420
Joined: Fri Jun 23, 2006 4:25 am

Post » Mon Jun 18, 2012 6:15 am

I'm pretty sure the problem is that, because it's an inventory item, it doesn't have a persistent handle that could be used for updates. However, there are (supposedly) some ways in which you can force a reference to be persistent, and I'd been told that assigning it to a property was one of those ways. Since persistence is handled by the Creation Kit, however, I'm not sure that assigning it to a property via script is enough to make it persistent.

Perhaps a developer could add something to this conversation? Is this the reason why registering an inventory item for updates doesn't work? Is there a reliable way to force an inventory item to be persistent? To be honest, I'd almost have expected that they'd be made persistent so long as they were registered for updates.

Cipscis
User avatar
Margarita Diaz
 
Posts: 3511
Joined: Sun Aug 12, 2007 2:01 pm

Post » Mon Jun 18, 2012 6:19 am

Indeed. It's how it worked in Oblivion and FO3, and those were certainly not persistent items (since they were in an inventory).

Ah, and you mean assigning the armor piece to a script / quest property?
User avatar
Brooks Hardison
 
Posts: 3410
Joined: Fri Sep 07, 2007 3:14 am

Post » Mon Jun 18, 2012 2:17 pm

I meant creating an ObjectReference property and using it to store the value of the reference that you want to be made persistent. I'm sure that would work if you assigned the value in the Creation Kit, and I'm hoping it would also work if you assign the value via script.

Cipscis
User avatar
Matthew Aaron Evans
 
Posts: 3361
Joined: Wed Jul 25, 2007 2:59 am

Post » Mon Jun 18, 2012 1:08 am

After reading http://www.creationkit.com/Persistence_%28Papyrus%29, my script should be making the reference persistent, but it appears not to be working. Though I'm starting to think that this isn't due to object persistence.
User avatar
Lexy Dick
 
Posts: 3459
Joined: Mon Feb 12, 2007 12:15 pm


Return to V - Skyrim