// Used to make units of this team that walk into this trigger deposit
// Mithril, Gold Nuggets, Iron, and Adamantium in the chest.

void main()
{
    object oMe=GetEnteringObject();
    string sID=GetLocalString(oMe,"sTeamID");
    object oChest=GetObjectByTag(sID+"_CHEST");
    if (!GetIsPC(oMe)&&GetLocalInt(oMe,"bDeposit"))
    { // do not effect PCs
        if (GetIsObjectValid(oChest))
        { // chest is valid
            if (GetArea(oChest)==GetArea(oMe))
            { // this is my lair
                object oItem;
                object oCopy;
                int bDeposit=FALSE;
                oItem=GetFirstItemInInventory(oMe);
                while(GetIsObjectValid(oItem))
                { // check for items to transfer to chest
                    if (GetLocalInt(oItem,"bDeposit"))
                    { // deposit
                        oCopy=CreateItemOnObject(GetResRef(oItem),oChest,GetItemStackSize(oItem),GetTag(oItem));
                        DelayCommand(0.1,DestroyObject(oItem));
                        bDeposit=TRUE;
                    } // deposit
                    oItem=GetNextItemInInventory(oMe);
                } // check for items to transfer to chest
                if (bDeposit) AssignCommand(oMe,SpeakString("I deposited items in the "+GetName(oChest)+"."));
                DeleteLocalInt(oMe,"bDeposit");
            } // this is my lair
        } // chest is valid
    } // do not effect PCs
}