Most likely problem is that you're using GetObjectByTag, which, while fast, will get the first item in the mod with that tag, and not necessarily the one the pc just equipped. Use instead:
object oItem = GetPCItemLastEquipped();
and check to see if oItem shoudl be unequipped however you like (in this case checking tag, for example).
Also, you'll want to use a custom function to force the unequip, or players will be able to circumvent it, both intentionally and by mistake. This is what we use:
void ForceUnequip (object oTarget, object oItem) {
if (!GetIsObjectValid(oTarget) || GetObjectType(oTarget) != OBJECT_TYPE_CREATURE)
return;
if (!GetIsObjectValid(GetArea(oTarget))) {
DelayCommand(5.0, ForceUnequip(oTarget, oItem));
return;
}
if (GetIsDead(oTarget)) {
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectResurrection(), oTarget);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(GetMaxHitPoints(oTarget)), oTarget);
if (GetIsPC(oTarget))
AssignCommand(oTarget, ExecuteScript("fky_deathprocess", oTarget));
DelayCommand(0.1, ForceUnequip(oTarget, oItem));
} else {
AssignCommand(oTarget, ClearAllActions(TRUE));
SetLocalInt(oItem, "ForceUnequipped", TRUE);
AssignCommand(oTarget, ActionUnequipItem(oItem));
AssignCommand(oTarget, ActionDoCommand(SetCommandable(TRUE)));
AssignCommand(oTarget, SetCommandable(FALSE));
}
}
You can remove this bit, unless you have another script you like to execute when a player is brought back to life, in which case you can swap it out with "fky_deathprocess":
if (GetIsPC(oTarget))
AssignCommand(oTarget, ExecuteScript("fky_deathprocess", oTarget));
Funky