void main()
{
object oPC = GetLastClosedBy();
object oMod = GetModule();
object oItem;
int iSilverCount = 0;
int iGoldCount = 0;
int iBronzeCount = 0;
int iNormCount;
int oGold = 0;

if (GetLocalInt(oMod, "mod_mode")==1)
{
PlaySound("sim_cntresist");
     FloatingTextStringOnCreature
    ("*** This chest is not functional in campaign manager mode ***", oPC);
    return;
}

oItem = GetFirstItemInInventory(OBJECT_SELF);
while (GetIsObjectValid(oItem))
    {
     if ((GetTag(oItem)!="pearl")&&
         (GetTag(oItem)!="coin1")&&
         (GetTag(oItem)!="coin2")){++iNormCount;}
     if (GetTag(oItem)=="pearl") {++iBronzeCount;}
     if (GetTag(oItem)=="coin1") {++iGoldCount;}
     if (GetTag(oItem)=="coin2") {++iSilverCount;}
     oItem = GetNextItemInInventory(OBJECT_SELF);
     }
if (iNormCount==0)
   {
     if ((iSilverCount==0)&&(iGoldCount==0)&&(iBronzeCount==0))return;
     oItem = GetFirstItemInInventory(OBJECT_SELF);
     while (GetIsObjectValid(oItem))
         {
          DestroyObject(oItem);
          oItem = GetNextItemInInventory(OBJECT_SELF);
         }
     SetLocked(OBJECT_SELF, TRUE);
     oGold = ((iBronzeCount*5000)+(iSilverCount*10000)+(iGoldCount*15000));
     DelayCommand(1.0, GiveGoldToCreature(oPC, oGold));
     DelayCommand(1.0, PlaySound("it_coins"));
     DelayCommand(1.5, SetLocked(OBJECT_SELF, FALSE));
    }
else
    {
     FloatingTextStringOnCreature("Tokens only please!", oPC);
     PlaySound("sim_cntresist");
     }
}