Author Sticky: Post Working Scripts Here
Tolan Fellowes Posted: Thursday, 04 July 08:37PM
1. Script Name: move_pc_items
2. What it does: Moves the items in the PC's inventory(including slots) and places them in a holder(ex. chest, crate, merchant **anything that contains an inventory)
3. Notes:
For triggered event un-comment out line marked "For Triggered Event" and comment out line "For Converstaion".
For conversation vice versa
4. The Script itself
NWScript:
//:://////////////////////////////////////////////

//:: FileName  move_pc_items

//:: Copyright (c) 2001 Bioware Corp.

//:://////////////////////////////////////////////

//:: Created By: Tolan Fellowes

//:: Created On: 07/02/02

//:://////////////////////////////////////////////

void MovePCItemsToHolder(object oPC, object oHolder);

void main()

{

    object oPC;         //PC object

    object oHolder;     //Object that will hold the PC's items

    oPC = GetEnteringObject(); //For Triggered events

    //oPC = GetPCSpeaker();    //For Converstations

    oHolder = GetObjectByTag("it_pcItemChest");

    MovePCItemsToHolder(oPC, oHolder);

}

/*

Function: void MovePCItemsToHolder(object oPC, object oHolder)

Move all the items in the PC inventory to a holder

inventory(ex. chest, crate, merchant ...)

oPC: player controled charater

oHolder: holder of the PC items. (**Must have an inventory**)

*/

void MovePCItemsToHolder(object oPC, object oHolder)

{

    //used for multiple items which are stackable

    int nStackSize;         

    int nCount;             //used in for loops

    object oPCItem;         //PC inventory items

    //Object used to Set Item properties

    object oHolderItem;

     

    //Check if PC and Holder are valid

    if(!GetIsObjectValid(oPC) || !GetIsObjectValid(oHolder))

        return;

    //Check if player controlled character and if Holder has an inventory

    if(GetIsPC(oPC) && GetHasInventory(oHolder))

    {

        //Get the first item in PC inventory

        oPCItem = GetFirstItemInInventory(oPC);

        //loop thru until PC inventory is empty

        while(oPCItem != OBJECT_INVALID)

        {

            //Get the number of stacked items

            nStackSize = GetNumStackedItems(oPCItem);

            //Create items in the Holder's inventory

            for(nCount = 0; nCount <  nStackSize; nCount++)

            {

                oHolderItem = CreateItemOnObject(GetTag(oPCItem), oHolder);

                //Set item properties

                SetPlotFlag(oHolderItem, GetPlotFlag(oPCItem));

                SetIdentified(oHolderItem, GetIdentified(oPCItem));

            }

            //remove item from PC inventory

            DestroyObject(oPCItem);

            //Get the next item

            oPCItem = GetNextItemInInventory(oPC);

        }

        //loop thru PC slot items and clear

        for(nCount = 0; nCount < NUM_INVENTORY_SLOTS; nCount++)

        {

            oPCItem = GetItemInSlot(nCount, oPC);

            if(oPCItem != OBJECT_INVALID)

            {

                //Create items in the Holder's inventory

                oHolderItem = CreateItemOnObject(GetTag(oPCItem), oHolder);

                //Set items properties

                SetPlotFlag(oHolderItem, GetPlotFlag(oPCItem));

                SetIdentified(oHolderItem, GetIdentified(oPCItem));

                //remove item from PC inventory

                DestroyObject(oPCItem);

            }

        }

    }

}