Jump to content

Copy item back to player when added to container


Indarello

Recommended Posts

Hi, I am using this for container script:

 

Event OnItemAdded(form itemForm, int count, objectReference itemRef, objectReference sourceContainerRef)

PlayerRef.AddItem(itemForm, count, true)

EndEvent

 

It works, but It loses legendary and other modifications for armor

itemRef is always none, I dont know why

I tried this near container but it finds only armor on floor not in container
ObjectReference[] containerItems = PlayerRef.FindAllReferencesOfType(itemForm, 1000.0)

Link to comment
Share on other sites

ItemRef will only be valid if the object added to the container is persistent. You can pass the specific item back to the player when added to the container using RemoveItem, but then it won't be in the container any longer. Not sure what you are wanting to specifically accomplish.

Link to comment
Share on other sites

ItemRef will only be valid if the object added to the container is persistent. You can pass the specific item back to the player when added to the container using RemoveItem, but then it won't be in the container any longer. Not sure what you are wanting to specifically accomplish.

I need item to be in container and in player inventory

Link to comment
Share on other sites

Scriptname IDItemDuplChestScr extends ObjectReference



Event OnLoad()
   Self.AddInventoryEventFilter(None)
EndEvent


Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

Int Number = aiItemCount

Game.Getplayer().Additem (AkBaseItem, Number)


EndEvent

Bear in mind that modified weapons and armor can come out very differently when you copy them

Link to comment
Share on other sites

There's an F4SE ObjectMod[] function called GetAllMods(). You can use it to add the objects mods of your (container) item into a Papyrus array. Then, use the AttachModToInventoryItem() function to add the objects mods from the array to the (player inventory) item. Note that this function can only add the object mods to a base form and not an object reference (akItem has to be a base form), which means if you have more of this item in your inventory, it will simply add the object mods to one of them.

 

Forgot to mention that before you call AttachModToInventoryItem(), you can remove the object mods from the (player inventory) item with the RemoveModFromInventoryItem() or RemoveAllModsFromInventoryItem() functions.

Edited by LarannKiar
Link to comment
Share on other sites

There's an F4SE ObjectMod[] function called GetAllMods(). You can use it to add the objects mods of your (container) item into a Papyrus array. Then, use the AttachModToInventoryItem() function to add the objects mods from the array to the (player inventory) item. Note that this function can only add the object mods to a base form and not an object reference (akItem has to be a base form), which means if you have more of this item in your inventory, it will simply add the object mods to one of them.

 

Forgot to mention that before you call AttachModToInventoryItem(), you can remove the object mods from the (player inventory) item with the RemoveModFromInventoryItem() or RemoveAllModsFromInventoryItem() functions.

Thanks, But first I dont know how to get ObjRef

Also, forgot to mention, I dont need container to have armor with mods, I need only that player wont lose his armor mods

so it will be also good for me if item in container will be base form item and player have his moded, legendary armor

hope it makes this task simpler

Edited by Indarello
Link to comment
Share on other sites

ItemRef will only be valid if the object added to the container is persistent. You can pass the specific item back to the player when added to the container using RemoveItem, but then it won't be in the container any longer. Not sure what you are wanting to specifically accomplish.

So if I try to use use RemoveItem() on Event OnItemAdded

and then additem() to container -> player will have his modded legendary armor and container will have base form of item?

thanks

Edited by Indarello
Link to comment
Share on other sites

If the player puts the item into the container, you can send it back. If there are no other instances of that object in said container, then the one sent back will be the one put in. If there are other instances of the object in the container, unsure which will be returned, it may be the last added to the stack or the first (testing will be needed) After than you can add a new instance of the object to the container, but this new instance will not have any of the modifications that the player may have made to the initial instance.

 

It is an idea worth exploring, but FO4 may have more available tricks than Skyrim. Feel free to explore some of the other things mentioned.

Link to comment
Share on other sites

If the player puts the item into the container, you can send it back. If there are no other instances of that object in said container, then the one sent back will be the one put in. If there are other instances of the object in the container, unsure which will be returned, it may be the last added to the stack or the first (testing will be needed) After than you can add a new instance of the object to the container, but this new instance will not have any of the modifications that the player may have made to the initial instance.

 

It is an idea worth exploring, but FO4 may have more available tricks than Skyrim. Feel free to explore some of the other things mentioned.

I dont know but with this code, item just deleted and there will not be this item on player or container anymore

 

Event OnItemAdded(form itemForm, int count, objectReference itemRef, objectReference sourceContainerRef)
RemoveItem(itemForm, count, true)
EndEvent
Edited by Indarello
Link to comment
Share on other sites

Try the following and see if it meets your needs.

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  (Self as ObjectReference).RemoveItem(akBaseItem,aiItemCount,false,akSourceContainer) ;remove original instance back to source - should be player
  (Self as ObjectReference).AddItem(akBaseItem,aiItemCount) ;add new instance of the base form to container
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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