byancey Posted July 7, 2021 Share Posted July 7, 2021 Hi, I'm working on my first mod, and have the need to prevent an equipped item from being unequipped, but allow it to be replaced with something else in the inventory...basically once equipped, the armor slot should never be empty, but it's equipped item can be changed for something else in the inventory that is appropriate for that slot. I've got my papyrus script to the point where it can receive and process the events for both OnEquipped and OnUnequipped. Pretty basic. I'm also able to prevent the equipped item from being unequipped by the player by setting abPreventRemoval to true in my call to EquipItem. However, once equipped in this manner, I have not figured out how to change the original items state so that it can be replaced with another item. The OnEquip event is firing for the new item I'm trying to replace it with, but even if I explicitly call EquipItem for the replacement item, it does not equip and the original item remains equipped. Any idea what steps I need to take within my papyrus script to force an item to replace the existing non-removable item? I assume it's not really permanently attached, and that there should be some way to programmatically remove the item and/or change it's state to allow another item to replace it. Any help or suggestions would be greatly appreciated. Thanks! Link to comment Share on other sites More sharing options...
dylbill Posted July 7, 2021 Share Posted July 7, 2021 Hey, instead of setting abPreventRemoval to true, I would just check for when the player unequips an item, and if they no longer have an armor equipped in the slot, re-equip the item: Example: Actor Property PlayerRef Auto Armor Property MyArmor Auto Int Property MyArmorSlot Auto ;the slot that MyArmor uses. Set in the creation kit. Auto State Waiting Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) If akBaseObject == MyArmor GoToState("PreventUnEquip") Endif EndEvent EndState State PreventUnEquip Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) If Game.GetPlayer().GetEquippedArmorInSlot(MyArmorSlot) == None ;if no armor is equipped in MyArmorSlot. Assume player unequipped an armor that uses slot MyArmorSlot. Game.GetPlayer().EquipItem(akBaseObject) Endif EndEvent EndStateNote that this requires special edition and isn't foolproof. A safer way would be to check the unequipped armor slot with skse's GetSlotMask function: https://www.creationkit.com/index.php?title=GetSlotMask_-_Armor Link to comment Share on other sites More sharing options...
byancey Posted July 7, 2021 Author Share Posted July 7, 2021 Hey, instead of setting abPreventRemoval to true, I would just check for when the player unequips an item, and if they no longer have an armor equipped in the slot, re-equip the item: Example: Actor Property PlayerRef Auto Armor Property MyArmor Auto Int Property MyArmorSlot Auto ;the slot that MyArmor uses. Set in the creation kit. Auto State Waiting Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) If akBaseObject == MyArmor GoToState("PreventUnEquip") Endif EndEvent EndState State PreventUnEquip Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) If Game.GetPlayer().GetEquippedArmorInSlot(MyArmorSlot) == None ;if no armor is equipped in MyArmorSlot. Assume player unequipped an armor that uses slot MyArmorSlot. Game.GetPlayer().EquipItem(akBaseObject) Endif EndEvent EndStateNote that this requires special edition and isn't foolproof. A safer way would be to check the unequipped armor slot with skse's GetSlotMask function: https://www.creationkit.com/index.php?title=GetSlotMask_-_Armor Thanks for the quick response and the sample code. Every little snippet that's relevant to what I'm trying to do here is very helpful, as I'm so new to papyrus. I'll take a closer look at your suggestion, as rather than not allowing the slot to be unequipped, I'm considering having a default item hidden from the inventory that just equips instead. That also helps with the case where another script calls UnEquipAll. I have a general idea of what I'm trying to do here, but I do need to experiment a bit and see what works best. May even end up with a combination of both. That said, I did get my initial approach to work...in my script I just had to explicitly unequip the locked item before equipping the replacement item. The problem I'm having now is that while the replacement item is properly equipped on the player, and visually displayed, the UI inventory pointer is not updated to reflect the newly equipped item. After searching around a bit, I believe if I silently add and remove 1 gold coin from the inventory, that might force a menu refresh, so I'll give that a try next. Link to comment Share on other sites More sharing options...
Recommended Posts