Jump to content

Creating an object reference for an item in a container


realityhidden

Recommended Posts

Is it possible to give an object added to a container an object reference if it doesn't already have one? Ex.

 

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
if akSourceContainer == Game.GetPlayer()
Debug.MessageBox("This item is " + akItemReference)
Debug.MessageBox("the charge ont his item is " + akItemReference.GetItemMaxCharge())
Game.GetPlayer().AddItem(akItemReference)
Game.GetPlayer().AddItem(akBaseItem)
a small snippet from the code i was just putting in to test what would work and what wouldn't. The item reference is none for every weapon I try to add. The better question for me to ask is how do I check/modify the charge of a weapon in any container (including the player's inventory).
Link to comment
Share on other sites

No, but you can use DropObject to put it into the world and store its reference in a variable then put the item back into the container.

 

The shelves in my Storage Helpers mod do that with code similar to this:

 

    Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
       if akItemReference  ; already a reference, so add it to the array if there's still room
            int i = Placed.Find(None)
            if i >= 0
                Placed[i] = akItemReference
            endif
        else  ; not a reference, so drop it to get one
            ObjectReference item = DropObject(akBaseItem, aiItemCount)  ; it could be a stack of items
            Utility.WaitMenuMode(0.1)
            if !item.GetActorOwner() && !item.GetFactionOwner() ; no ownership but will show as stolen
                item.SetActorOwner(Game.GetForm(0x07) as ActorBase) ; Player
            endif
            AddItem(item, 1, true)  ; moves the dropped item (or stack) back into the container
        endif
    EndEvent

If the item is a stack and you try to manipulate its properties like charge I don't know if you would be changing just the top item or the entire group. You probably want to drop them one at a time. And if someone were to add a sword that was a reference then add the same type of sword that wasn't I'm not sure which would get dropped either.

 

You aren't meant to be able to manipulate items in containers and there's no easy or fully reliable way to do it.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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