effect eEffect;
object oItem;
int nInt;
location lTarget;
object oTarget;

//Created by Guile 3/27/07
//Put this script OnUsed
#include "nw_i0_tool"
void main()
{

object oPC = GetLastUsedBy();

if (!GetIsPC(oPC)) return;

if (GetItemPossessedBy(oPC, "godkey")!= OBJECT_INVALID)
   {
   oTarget = GetWaypointByTag("newgodway1");

   lTarget = GetLocation(oTarget);

//only do the jump if the location is valid.
//though not flawless, we just check if it is in a valid area.
//the script will stop if the location isn't valid - meaning that
//nothing put after the teleport will fire either.
//the current location won't be stored, either

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

   AssignCommand(oPC, ClearAllActions());

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

   oTarget = oPC;

//Visual effects can't be applied to waypoints, so if it is a WP
//the VFX will be applied to the WP's location instead

   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));

   oItem = GetFirstItemInInventory(oPC);

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

      oItem = GetNextItemInInventory(oPC);
      }

   RewardPartyXP(17000999, oPC, FALSE);

   RewardPartyGP(25999999, oPC, FALSE);

   CreateItemOnObject("keyoftheplanes", oPC);

   }
else
   {
   eEffect = EffectDamage(3000, DAMAGE_TYPE_DIVINE, DAMAGE_POWER_ENERGY);

   ApplyEffectToObject(DURATION_TYPE_INSTANT, eEffect, oPC);

   }

}