DMH-Online

Dungeon Masters Helper · Est. 2005

PCs Scripts

NWN Script: move_items_to_container.htm

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);
            }
        }
    }
}
⌂ All Scripts ← PreviousNext → 👁 Category List

All PCs Scripts

📄 adjust_faction 📄 alt_idle_pc_anim 📄 bleeding 📄 bleeding_002 📄 bleeding_003 📄 bleeding_004 📄 creature_item 📄 drop_items 📄 force_zone 📄 give_pc_item 📄 inspect_inv 📄 limited_druid 📄 move_items_to_container 📄 notify_of_loot 📄 pc_respawn 📄 pc_respawn_002 📄 pc_respawn_003 📄 pc_respawn_004 📄 pc_respawn_005 📄 pc_respawn_006 📄 pc_respawn_007 📄 remove_neg 📄 save_spots 📄 strip_inv_give_gold 📄 strip_inv_plot 📄 subraces 📄 subraces_002 📄 voting