I'm experiencing a weird issue.
I have a while loop running inside an OnEquipped event on a script attached to a piece of armor. When certain conditions are met while an NPC is wearing this armor, the script is supposed to add a single item (a different piece of armor) to the NPC's inventory (which they subsequently equip since it is a piece of armor). I have the additem function inside an if statement that explicitly states only to add the item if 0 are found in the NPC's inventory. Problem is, it seems to be adding a random amount of the items (usually 0 through 15) despite this condition. Here's a code snippet (apologies for the formatting... I'm not sure why the board's code display function is cramming it all together....)
Scriptname aaDAFArmorScript extends ObjectReferenceint stageEvent OnEquipped(Actor akActor)stage = 5 ; enter into loop once armor is equipped... While (akActor.IsEquipped(DynamicArmorProperty[0])) float actorsHealth = akActor.GetActorValuePercentage("Health") if actorsHealth >= 0.75 && stage != 1 if stage != 5 akActor.RemoveItem(DynamicArmorProperty[stage], 1, true) endif ; Add a single Stage 1 Token. Let NPC choose to equip it. if (akActor.GetItemCount(DynamicArmorProperty[1]) == 0) akActor.AddItem(DynamicArmorProperty[1], 1, true) endIf stage = 1 elseif actorsHealth < 0.75 && actorsHealth >= 0.50 && stage != 2 if stage != 5 akActor.RemoveItem(DynamicArmorProperty[stage], 1, true) endif ; Equip Stage 2 if (akActor.GetItemCount(DynamicArmorProperty[2]) == 0) akActor.AddItem(DynamicArmorProperty[2], 1, true) endIf stage = 2 elseif actorsHealth < 0.50 && actorsHealth >= 0.25 && stage != 3 if stage != 5 akActor.RemoveItem(DynamicArmorProperty[stage], 1, true) endif ; Equip Stage 3 if (akActor.GetItemCount(DynamicArmorProperty[3]) == 0) akActor.AddItem(DynamicArmorProperty[3], 1, true) endIf stage = 3 elseif actorsHealth < 0.25 && stage != 4 if stage != 5 akActor.RemoveItem(DynamicArmorProperty[stage], 1, true) endif ; Equip Stage 4 if (akActor.GetItemCount(DynamicArmorProperty[4]) == 0) akActor.AddItem(DynamicArmorProperty[4], 1, true) endIf stage = 4 endif EndWhileendEvent; Remove leftover armor piecesEvent OnUnequipped(Actor akActor) akActor.RemoveItem(DynamicArmorProperty[1], 1, true) akActor.RemoveItem(DynamicArmorProperty[2], 1, true) akActor.RemoveItem(DynamicArmorProperty[3], 1, true) akActor.RemoveItem(DynamicArmorProperty[4], 1, true)endEventArmor[] Property DynamicArmorProperty AutoI think it has something to do with the AI possibly equipping and unequipping the involved items to make a check if they are 'better' than what they are wearing already. I notice a flickering of the model for a bit after they equip it, which means to me they keep equipping and unequipping it, before settling on equipping. That however still doesn't explain how the game decides to neglect the condition of adding the item only if there are 0 in the inventory. If anyone has any ideas or needs more information please let me know. Thanks!!
