// Script for the obliterator-rod - It allows DMs to destroy a targeted non-PC
// object.
// 4th of August 2005, Alangara, made by -Seeker-

void DestroyAllItems()
{
        object oItem = GetFirstItemInInventory();
        while(GetIsObjectValid(oItem))
        {
            DestroyObject(oItem);
            oItem = GetNextItemInInventory();
        }
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_ARMS)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_ARROWS)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_BELT)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_BOLTS)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_BOOTS)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_BULLETS)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_CARMOUR)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_CHEST)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_CLOAK)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_CWEAPON_B)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_CWEAPON_L)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_CWEAPON_R)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_HEAD)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_LEFTHAND)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_LEFTRING)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_NECK)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_RIGHTHAND)))
            DestroyObject(oItem);
        if(GetIsObjectValid(oItem=GetItemInSlot(INVENTORY_SLOT_RIGHTRING)))
            DestroyObject(oItem);
}

void main()
{
   object oPC = GetItemActivator();
   object oRod = GetItemActivated();
   if (GetIsDM(oPC) || GetIsDMPossessed(oPC))
   {
      object oTarget = GetItemActivatedTarget();
      if ( GetIsPC( oTarget ) || GetIsPossessedFamiliar( oTarget ) )
      {
         // Cannot destroy players
         FloatingTextStringOnCreature( "Cannot eradicate players!", oPC, FALSE );
      }
      else
      {
         // Destroy object
         SetPlotFlag( oTarget, FALSE );
         if ( GetHasInventory( oTarget ) )
         {
            AssignCommand(oTarget, DestroyAllItems());
            DelayCommand(1.0, DestroyObject(oTarget));
         }
         else
         {
            DestroyObject( oTarget, 0.1f );
         }
      }
   }
   else
   {
      string PCname = GetName( oPC );
      SendMessageToAllDMs( "Player "+PCname+" has attempted to activate obliterator rod!" );
      FloatingTextStringOnCreature( "Only DMs can use the obliterator rod!", oPC, FALSE );
      SetPlotFlag( oRod, FALSE );
      DestroyObject( oRod );
   }
}