/*--------------------------------------------------------

Script Name: stoneportshome
----------------------------------------------------------
Created By: Genisys(Guile)
Created On: 2/09/09
----------------------------------------------------------
This Recall's the PC Speaker to the waypoint tagnamed "home"
Then it's stores thier location in a database location!

If the PC is in combat, they cannot recall for any reason!

If the PC is in a PVP Area they cannot recall!
(check's for local int "PVP" of 1 or higher)
----------------------------------------------------------*/

void main()
{
    // uncomment one of the next 3 lines depending where you use the script:
    object oPC = GetPCSpeaker();     // for conversations
    object oWay = GetNearestObjectByTag("no_recall", oPC);

    if(GetIsPC(oPC))
    {
     if(GetIsInCombat(oPC))
     {
      FloatingTextStringOnCreature("You cannot recall while in combat!", oPC, TRUE);
      return;
     }

     else if(GetLocalInt(GetArea(oPC), "PVP")>=3)
     {
      FloatingTextStringOnCreature("You cannot recall from a PVP area!", oPC, TRUE);
      return;
     }
    }

object oToken = oPC;
string sName = GetName(oToken);
object oArea = GetArea(oPC);
location lSaved = GetLocation(oPC);
object oSaved = GetAreaFromLocation(lSaved);
int nMulti = GetLocalInt(GetModule(), "multi");

    // set to 1 if you want to teleport the whole party of the player, whereever every member is:
    int iTeleportWholeParty = 0;
    // set to 1 if you want the Associates of the player to be teleported as well, otherwise to 0:
    int iTeleportAssociateToo = 1;
    // Enter the destination Waypoint in here:
    object oDWP = GetWaypointByTag("home");

//--DEBUGGING-----------------------
//If the way point is not there..
if (oDWP==OBJECT_INVALID)
{ FloatingTextStringOnCreature("No Destination Found.", oPC);
  return; }

  else
   {
     if(oSaved==OBJECT_INVALID)
     {
      FloatingTextStringOnCreature("Location invalid.", oPC);
      return;
     }

     //Don't store information if the location is invalid!
     if(oArea!=OBJECT_INVALID)
     {
      if(oWay==OBJECT_INVALID)
      {
       SetLocalLocation(oToken, "RECALL_LOC", lSaved);
       FloatingTextStringOnCreature("Location Saved!", oPC, FALSE);
       if(nMulti) //If Multiplayer, Save Their Toon!
       {
         ExportSingleCharacter(oPC);
       }
      }
     }

    effect eVis = EffectVisualEffect(472);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oPC, 0.0f);

    eVis = EffectDisappear(1);
    DelayCommand(1.1, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oPC, 0.0f));

    DelayCommand(2.5, AssignCommand(oPC, ClearAllActions()));

    //Allow for the visual effect to finish.
    DelayCommand(2.6, AssignCommand(oPC, ActionJumpToObject(oDWP)));

   }
}