Elsidia1 Posted February 24, 2023 Share Posted February 24, 2023 What we have?Function EquipItem(Form akItem, bool abPreventRemoval = false, bool abSilent = false) native Form akItem ?!?!?I need equip specific reference from inventory and ignore other forms as this reference holds variables necessary to remember Anyone knows how EquipItem select reference? - last added to inventory? How i can reinitialize inventory to equip exactly this reference on what i stay in Event OnUnequipped(Actor akActor) to reequip back exactly that reference?At this moment i move all similar items into virtual inventory, thenAdditem(self,1,true) what exactly returns back my reference and then equip it and restore moved items back into inventory.That's sucks and no good as i think.Or there is another way how to equip specific reference? Link to comment Share on other sites More sharing options...
RaidersClamoring Posted February 24, 2023 Share Posted February 24, 2023 Since the parameter specifies "Form", with no mention of being flexible enough to accept an ObjectReference, there's no guarantee it will work. However I do think it will, in which case only a persistent ref will work, otherwise the Ref ID will be obliterated once it is put in a container. So if this thing was created at runtime, the bMakePersistent argument must be True and then it should work, fingers crossed. Link to comment Share on other sites More sharing options...
remosito Posted May 24, 2024 Share Posted May 24, 2024 @Elsidia1 Did it end up working with an object reference? Link to comment Share on other sites More sharing options...
LarannKiar Posted May 26, 2024 Share Posted May 26, 2024 On 5/24/2024 at 7:11 AM, remosito said: @Elsidia1 Did it end up working with an object reference? EquipItem() doesn't work with references (AddItem() does). If one tries to call EquipItem() on a persistent object reference, the Papyrus log would say something like "Item X in Container ActorRefID doesn't have a 3D, thus cannot be equipped." A persistent reference that becomes an inventory item gets marked for deletion when an actor Activates it (but it doesn't get actually deleted). Both the reference and the inventory item recieves a special extra data that links the two together. The native code can identify them but vanilla Papyrus can't. In vanilla, you can: - ( ItemRefID.Drop() ) to force drop the target inventory item from the inventory (native code unsets the deleted flag on the reference and reinitializes it), then - ( InventoryOwnerRef.RemoveItem(ItemBaseForm, aiCount = -1, akOtherContainer = SomeSafeContainerRef) ) on the item inventory's Base Form to remove all items of this base from the inventory, then - ( InventoryOwnerRef.AddItem(ItemRefID) ) to add the target item back to the inventory, then - ( InventoryOwnerRef.EquipItem(ItemBaseForm) to make the owner actor equip it (note: since this is the only item of this base in the actor's inventory it is guaranteed they will equip this one) - ( SomeSafeContainerRef.RemoveAllItems(akTransferTo = InventoryOwnerRef) ) so that the inventory owner will get back all items. Alternatively, Garden of Eden Papyrus Script Extender has EquipNthItem(), if having multiple script extender dependency isn't an issue. No one has requested GetNthItemByRefID yet, let me know if this is of interest, but here's a simple script how to find an item by its name: Scriptname TestScript Function EquipItemByName(Actor inventoryOwner, String ItemName, bool bEquipSound) global Int[] ItemIndexes = GardenOfEden.GetItemIndexesByName(inventoryOwner, ItemName) if ItemIndexes.length == 0 Debug.MessageBox("ItemIndexes.length == 0") Return None endif String sFoundItemName = GardenOfEden.GetNthItemName(inventoryOwner, ItemIndexes[0]); bool equipResult = Gardenofeden.EquipNthItem(inventoryOwner, ItemIndexes[0], bEquipSound) Debug.MessageBox("Called EquipItemByName on: " + sFoundItemName + ". Result = " + equipResult) EndFunction In console, it'd be like [ CGF "TestScript.EquipItemByName" 14 "Deliverer" ] to equip the Deliverer. Link to comment Share on other sites More sharing options...
PJMail Posted May 29, 2024 Share Posted May 29, 2024 An interesting side effect of this "persistent item is marked for deletion when added to an inventory" is that if a mod overrides that persistent ref (say to change the base form to a leveled list) that hidden 'link' is broken and dropping the item from the inventory causes it to disappear. Also it cannot be moved (via removeitem) to another container. Link to comment Share on other sites More sharing options...
LarannKiar Posted May 29, 2024 Share Posted May 29, 2024 Hmm.. interesting. Why the game clears the link between the persistent ref and the inventory item when the ref's base form is a leveled form I don't know.. I can't see any reason why it would be necessary. But I know is BGS prefers the "rather reset/reinitialize everything than miss anything" design especially in the template code so maybe this is the reason. Link to comment Share on other sites More sharing options...
remosito Posted May 29, 2024 Share Posted May 29, 2024 thanks so much for the answer I feared as much. As I am working on a mod for Starfield. Script Extenders with extra functions don't exist yet Link to comment Share on other sites More sharing options...
LarannKiar Posted May 29, 2024 Share Posted May 29, 2024 Starfield and inventories.. that's a different story. Well, in that case, while not conceptually both the linked reference's data struct and the native equip functions have been changed.. Papyrus' EquipItem also received a new blocking condition: "LeveledList Items can not be equipped." if akForm.GetFormType() == LeveledItem. Link to comment Share on other sites More sharing options...
Recommended Posts