CopyItem(object, object, int)

Duplicates an item.

object CopyItem(
    object oItem,
    object oTargetInventory = OBJECT_INVALID,
    int bCopyVars
);

Parameters

oItem

Item to copy.

oTargetInventory

Create the item within this inventory (Default: OBJECT_INVALID)

bCopyVars

If TRUE, local variables on item are copied


Description

Duplicates the item and returns a new object, an exact copy of oItem,

Will normally return the new item, else on error, returns OBJECT_INVALID for non-items.

Can only copy empty item containers (Such as magical bags). will return OBJECT_INVALID if oItem contains other items, and fail.

If it is possible to merge this item with any others in the target location, then it will do so and return the merged object.

Note that if oTargetInventory is OBJECT_INVALID, there may be 2 places an item is created. If it is on the ground, an exact copy will be placed at the same location on the ground. If it is in some kind of inventory (Store, Backpack, Box etc) it will create it inside the inventory.

To force the item to copy to a location, you must use CopyObject() (noting that it doesn't have the bCopyVars parameter).



Remarks

This function doesn't seem to be able to do anything that CopyObject can't do, but it leaves out the mandatory input of a location.

Can be used for custom treasure systems by finding an item in a treasureholder container, and then calling CopyItem to make a copy of the item in the container or creature calling the function.

Note that CopyObject() doesn't have bCopyVars, which is important - any variables (Local's) on an object copied with CopyObject() will not be on the new copied object - a headache for copying creatures with AI variables. Hopefully, CopyObject() will get that parameter sooner or later.


Version

1.62

See Also

functions: CopyItemAndModify | CopyObject | CreateItemOnObject
categories: Item Creation Functions


 author: Charles Feduke, editor: Jasperre, additional contributor(s): Lilac Soul, Jasperre