Jump to content

Scripting help - OnItemUnequipped not firing


SAC020

Recommended Posts

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 another mod

 

 

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, the original mod 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!

Edited by ss_kk
Link to comment
Share on other sites

The error isn't jumping out at me. Try placing a debug messagebox as the first line of OnEffectStart to see if you can isolate the exact point of failure. If the messagebox doesn't show, you'll be a step closer to the source of the problem.

 

Thank you. The rest of the event is working fine, both before and after the unequip.

 

In the meantime, I got F4SE to compile and it has a much easier solution, getwornitem. Basically, this:

 

Actor:WornItem wornItem = target.GetWornItem(3)
;debug.messagebox(wornitem.item)

replaces the whole "contraption". Good enough for me, at this stage. Thanks!

 

If I ever find out what was wrong with the original script, I'll post back with the solution.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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