//Created by Genisys
//This script ports the partymemeber back to where they were before being
//teleported to the party room.

//This script goes in the OnUsed Event of a placeable.

//Put this script OnUsed
void main()
{

object oPC = GetLastUsedBy();


if (!GetIsPC(oPC)) return;

object oItem;
object oTarget;
location lTarget;

//Remove all partyroom tokens from the player!
if (GetItemPossessedBy(oPC, "partyroom")!= OBJECT_INVALID)
   {
   oItem = GetFirstItemInInventory(oPC);

   while (GetIsObjectValid(oItem))
      {
      if (GetTag(oItem)=="partyroom") DestroyObject(oItem);

      oItem = GetNextItemInInventory(oPC);
      }
   }

lTarget = GetLocalLocation(oPC, "ls_stored_loc");

if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;

AssignCommand(oPC, ClearAllActions());

DelayCommand(3.0, AssignCommand(oPC, ActionJumpToLocation(lTarget)));

oTarget = oPC;

//Remove thier power to re-enter the area.
DeleteLocalInt(oPC, "IMemberA");

int nInt;
nInt = GetObjectType(oTarget);

if (nInt != OBJECT_TYPE_WAYPOINT) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_UNSUMMON), oTarget);
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_UNSUMMON), GetLocation(oTarget));

DelayCommand(5.0, ExecuteScript("checkarea1", oPC));
}