//pchest lever
void main()
{
    int iMyType = GetObjectType(OBJECT_SELF);
    object oPC;

    if (iMyType == OBJECT_TYPE_CREATURE)
        oPC = GetPCSpeaker();
    else
        {
        oPC = GetLastUsedBy();
        PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
        DelayCommand(3.0, PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
        }

    //ActionSpeakString("Lever activated.");

    if (GetLocalInt(GetModule(), "iAllowPChest") == TRUE)
        {
        object oChest = GetObjectByTag("CS_PCHEST");
        string sDB = GetTag(GetModule())+"_PCHEST";

        DestroyCampaignDatabase(sDB);

        int iCount = 0;
        object oItem = GetFirstItemInInventory(oChest);

            while (GetIsObjectValid(oItem))
            {
                if (GetBaseItemType(oItem) != BASE_ITEM_LARGEBOX)
                {
                    StoreCampaignObject(sDB, "PITEM_" + IntToString(iCount), oItem);
                }
                else
                {
                string sName = GetName(oItem);
                SendMessageToPC(oPC, "Container item " + sName + " was not saved.");
                }
                //DestroyObject(oItem);
                iCount++;
                oItem = GetNextItemInInventory(oChest);
            }

            if (iCount > 0)
            {
                SetCampaignInt(sDB, "iCount", iCount);
            }
        FloatingTextStringOnCreature("The contents of the Storage Chest have been saved.", oPC);
        }
    else
        {
        FloatingTextStringOnCreature("Persistant storage has been deactivated by the server host or a DM.", oPC);
        }
}
