//::///////////////////////////////////////////////
//:: Trap door that takes you to a waypoint that
//:: is stored into the Destination local string.
//:: FileName
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*

*/
//:://////////////////////////////////////////////
//:: Created By: Robert Babiak
//:: Created On: June 25, 2002
//:://////////////////////////////////////////////

void main()
{
    object oidUser;
    object oidDest;
    string sDest;
    int nGotkey=0;
    oidUser = GetLastUsedBy();

    if (!GetLocked(OBJECT_SELF) )
    {
        if ( GetIsOpen(OBJECT_SELF))
        {


            oidUser = GetLastUsedBy();
            oidDest = GetObjectByTag("WP_jw_aisha_frombelow");

            AssignCommand(oidUser, ActionJumpToObject(oidDest,FALSE));
            PlayAnimation(ANIMATION_PLACEABLE_CLOSE );
        } else
        {
            PlayAnimation(ANIMATION_PLACEABLE_OPEN );
        }
    }
     else
    {

     object oInv;

     oInv=GetFirstItemInInventory(oidUser);

     while (GetIsObjectValid(oInv))

         {

          if (GetTag(oInv)=="jw_aisha_key")
           {
            nGotkey=1;

             }
          oInv=GetNextItemInInventory(oidUser);
          }

          if (nGotkey==0)
          {

           AssignCommand(oidUser,PlayAnimation(ANIMATION_LOOPING_GET_LOW,1.0,1.0));

           //CreateObject(OBJECT_TYPE_ITEM,"jw_faketrap",GetLocation(OBJECT_SELF));
           //AssignCommand(oidUser,ActionUnlockObject(GetObjectByTag("jw_faketrap")));
           //DelayCommand(0.5,DestroyObject(GetObjectByTag("jw_faketrap")));
           DelayCommand(0.3,PlaySound("as_dr_locked3"));
            FloatingTextStringOnCreature("*Locked*",oidUser);
              SendMessageToPC(oidUser,"OOC: You discovered the entrance to an interesting place it is not yet open, sorry.");
            //DelayCommand(0.3,SpeakString("This trap door is locked"));
          }

          else
          {

        //AssignCommand(oidUser,PlayAnimation(ANIMATION_LOOPING_GET_LOW,1.0,1.0));


           SetLocked(OBJECT_SELF,FALSE);
 AssignCommand(oidUser,PlayAnimation(ANIMATION_LOOPING_GET_LOW,1.0,1.0));
            SendMessageToPC(oidUser,"You used a key");
           DelayCommand(0.5,PlayAnimation(ANIMATION_PLACEABLE_OPEN));

            DelayCommand(10.0,PlayAnimation(ANIMATION_PLACEABLE_CLOSE));
            DelayCommand(10.0,SetLocked(OBJECT_SELF,TRUE));
            }




    }

}