Jump to content

Scripting help - OnItemUnequipped not firing


SAC

Recommended Posts

Posted

Hi,


 


I am trying to write a script which identifies the outfit an NPC is wearing (and do some stuff based on this).


 


Since I've got no idea where to start, I am trying to adapt a script from Leito's gun (which works perfectly)


 




Scriptname abc extends activemagiceffect

Form[] TargetEquippedArmor
Armor Property DummyNudeArmor Auto Const
actor caster
actor target

Event OnEffectStart(Actor akTarget, Actor akCaster)
caster = akCaster
target = akTarget

RegisterForRemoteEvent(target, "OnItemUnequipped")
utility.wait(0.5)
TargetEquippedArmor = new Form[0]
target.unequipitemslot(3)
;target.equipitem(DummyNudeArmor as form, true, true)
Utility.Wait(0.5)
UnregisterForRemoteEvent(target, "OnItemUnequipped")

end event

Event Actor.OnItemUnequipped(Actor akSender, Form akBaseObject, ObjectReference akReference)
debug.messagebox("remote event fired") ; <= this doesn't fire
If (akReference)
TargetEquippedArmor.Add(akReference as Form, 1)
debug.messagebox(akreference as form)
Else
TargetEquippedArmor.Add(akBaseObject, 1)
debug.messagebox(akbaseobject)
EndIf
EndEvent


 


Basically, this variant unequips the current outfit and stores it into an array, for later manipulation. Which would be fine by me.


 


Problem is that OnItemUnequipped never fires, no matter if I use unequipitemslot, or if I make the NPC equip an alternate outfit (thus unequiping its original one). Even more frustrating, Leito's gun, where I took the code from, does work, and I cannot spot any difference.


 


Any idea what I am doing wrong?


 


I also tried to use a F4SE function, getwornitem, but I've been unable to compile it. I set up some paths in the creationkitprefs, but no luck so far.


 


Thanks!


Posted

Utility.Wait is latent, it holds up everything in that script before executing the next line. So:

 

1. UnregisterForRemoteEvent(target, "OnItemUnequipped")
 
will happen before
 
2. Event Actor.OnItemUnequipped(Actor akSender, Form akBaseObject, ObjectReference akReference)
 
use StartTimer instead of Utility.Wait, if you must. I don't see why you can't just put 1 below 2

 

Posted

 

Utility.Wait is latent, it holds up everything in that script before executing the next line. So:

 

1. UnregisterForRemoteEvent(target, "OnItemUnequipped")
 
will happen before
 
2. Event Actor.OnItemUnequipped(Actor akSender, Form akBaseObject, ObjectReference akReference)
 
use StartTimer instead of Utility.Wait, if you must. I don't see why you can't just put 1 below 2

 

 

Tried without the waits, tried both by unequipitemslot(3) and by equipping a different outfit

RegisterForRemoteEvent(target, "OnItemUnequipped")
TargetEquippedArmor = new Form[0]
target.equipitem(DummyNudeArmor as form, true, true)
UnregisterForRemoteEvent(target, "OnItemUnequipped")

Still no workie, onitemunequipped doesn't fire.

 

In the meantime I'll start looking into why I cannot compile F4SE, maybe I can get getwornitem to work. Although, for the life of me, I can't understand why Leito's version works and mine doesn't, it's just his code stripped down to essentials. Mind boggling.

Posted

 

 

Utility.Wait is latent, it holds up everything in that script before executing the next line. So:

 

1. UnregisterForRemoteEvent(target, "OnItemUnequipped")
 
will happen before
 
2. Event Actor.OnItemUnequipped(Actor akSender, Form akBaseObject, ObjectReference akReference)
 
use StartTimer instead of Utility.Wait, if you must. I don't see why you can't just put 1 below 2

 

 

Tried without the waits, tried both by unequipitemslot(3) and by equipping a different outfit

RegisterForRemoteEvent(target, "OnItemUnequipped")
TargetEquippedArmor = new Form[0]
target.equipitem(DummyNudeArmor as form, true, true)
UnregisterForRemoteEvent(target, "OnItemUnequipped")

Still no workie, onitemunequipped doesn't fire.

 

In the meantime I'll start looking into why I cannot compile F4SE, maybe I can get getwornitem to work. Although, for the life of me, I can't understand why Leito's version works and mine doesn't, it's just his code stripped down to essentials. Mind boggling.

 

 

 

Of course that wouldn't change anything, the

UnregisterForRemoteEvent(target, "OnItemUnequipped")

 

is still there

 

It needs to happen after the event is received 

Posted

 

Of course that wouldn't change anything, the

UnregisterForRemoteEvent(target, "OnItemUnequipped")

 

is still there

 

It needs to happen after the event is received 

 

 

I'm confused, isn't the event triggered as soon as the unequip happens? where should I put the unregister, at the end of the event?

 

In the meantime, I got F4SE to compile (turns out I reinstalled CK and overwritten the base mods, so I had to overwrite the F4SE base scripts again). 

 

This:

 

Actor:WornItem wornItem = target.GetWornItem(3)
;debug.messagebox(wornitem.item)
 
works like an absolute charm, problem solved as far as I'm concerned, I can proceed further with my mod (which is about switching current outfits to my version of outfits on trigger).
 
But I am still curious about how to properly handle onitemunequipped.
Posted

 

 

I'm confused, isn't the event triggered as soon as the unequip happens? where should I put the unregister, at the end of the event?

 

Yes. At end of  Actor.OnItemUnequipped

 

It's the same script instance. It can only read things down one line at a time. It can't jump from your unequipitemslot, ignoring the unregisterforremoteevent right below it, down to the Event first

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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