int FlipSwitch(object oLever = OBJECT_SELF)
{
if (GetLocalInt(OBJECT_SELF, "nToggle") == 0)
 {
 PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE, 1.0, 1.0);
 SetLocalInt(OBJECT_SELF, "nToggle", 1);
 return TRUE;
 }
else
 {
 PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE, 1.0, 1.0);
 SetLocalInt(OBJECT_SELF, "nToggle", 0);
 return FALSE;
 }
}

void main()
{
object oPC = GetLastUsedBy();

if (FlipSwitch())
 {
 // Set variables for chess "game"
 SetLocalInt(oPC, "PCisKNIGHT", 1);
 SetLocalInt(oPC, "RowPC", 7);
 SetLocalInt(oPC, "ColumnPC", 8);
 // Teleport PC to starting square
 object oTarget = GetWaypointByTag("WP_ChessKnightW");
 location lTarget = GetLocation(oTarget);
 // Get variable to see if chess game has already been solved
 int nDisarm = GetLocalInt(oPC, "DisarmChessboard");
 // If chess game has been solved, teleport entire party
 if (nDisarm == 1)
  {
  oTarget=GetFirstFactionMember(oPC, FALSE);
  while (GetIsObjectValid(oTarget))
   {
   AssignCommand(oTarget, ClearAllActions());
   DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_UNSUMMON), oPC));
   DelayCommand(2.5, AssignCommand(oTarget, ActionJumpToLocation(lTarget)));
   oTarget=GetNextFactionMember(oPC, FALSE);
   }
  }
 // If chess game has NOT been solved, only teleport the PC
 else
  {
  AssignCommand(oPC, ClearAllActions());
  DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_UNSUMMON), oPC));
  DelayCommand(2.5, AssignCommand(oPC, ActionJumpToLocation(lTarget)));
  }
 }
// End the script
else return;
}
