////////////////////////////////////
//Created By:  Genisys / Guile
//Created On:  7/01/08
///////////////////////////////////////////
/*   ***IMPORTANT****

This script goes in the OnUsed Event
of a Placeable Control or Switch, it
should be used on something ALL PCs
must use to enter the module preferrably.

YOU MUST SET THE TAGNAME BELOW!
*/
////////////////////////////////////////////

//Change "home" below to the tagname of
//the waypoint you want the PCs to teleport
//to after they use the scan switch.

const string sWay = "home"; //Always use the " "

/////////////////////////////////////////////
//Main Script (DON'T TOUCH ANYTHING BELOW!)
/////////////////////////////////////////////
void main()
{
//Define Major Variables
object oPC = GetLastUsedBy();

//If it's not a PC Stop here!
if(!GetIsPC(oPC))return;

//Do this only one time per PC per restart..
if(GetLocalInt(oPC, "iSwitchScan")==2)
{
//Stop the script dead here!
return;
}
//Othewise they must have never done this.. continue on!
else
{
//NOTE: You can make it always scan every PC ever time
//Simply type // at the start of the line below to make this always active..
SetLocalInt(oPC, "iSwitchScan", 2);
}


//First make the PC Unequip all items they are wearing
//If the items were not unequipped some might be missed (bug)
object oSlot;
int nSlot;

for (nSlot=0; nSlot<NUM_INVENTORY_SLOTS; nSlot++)
   {
   oSlot = GetItemInSlot(nSlot, oPC);

   AssignCommand(oPC, ActionUnequipItem(oSlot));
   }

//Now scan all of the items in the PCs inventory for...
//Disallowed Item Properties,
//Uber Items
//Items with TOO many properties

//Do it twice just incase we missed something!
DelayCommand(0.1, ExecuteScript("scanitems", oPC));
DelayCommand(2.0, ExecuteScript("scanitems", oPC));

//Let's make sure where the PC is going is valid or stop here!
object oWay = GetObjectByTag(sWay);
location lWay = GetLocation(oWay);
if (GetAreaFromLocation(lWay)==OBJECT_INVALID) return;

//Do a fancy visual to keep the PC occupied :)
object oTarget;
oTarget = oPC;

int nInt;

//Do a fancy healing tornado first..
nInt = GetObjectType(oTarget);
if (nInt != OBJECT_TYPE_WAYPOINT)ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_TORNADO), oTarget);
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_TORNADO), GetLocation(oTarget));


//Also, Do Time Stop next..
nInt = GetObjectType(oTarget);
if (nInt != OBJECT_TYPE_WAYPOINT) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_TIME_STOP), oTarget);
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_TIME_STOP), GetLocation(oTarget));

//After timestop is about done, do an unsummon visual effect..
effect eEffect;
eEffect = EffectVisualEffect(VFX_IMP_UNSUMMON);
DelayCommand(4.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eEffect, oPC));


//Now teleport the PC after the visual effects and scanning are done..
DelayCommand(7.0, AssignCommand(oPC, ClearAllActions()));
DelayCommand(7.1, AssignCommand(oPC, ActionJumpToLocation(lWay)));

//Main Script End
}