{
	saved_FirstTime [1]

	saved_DeathToll [0]
	saved_DeathMax [2]
	saved_FiddleDeath [0]
	saved_deathcount [0]

	Init [()
	{
		SetNationality(1);

		if (saved_FirstTime = 1)
		{
			Rgun = Random(0, 1);
			switch(Rgun)
			{
				case 0
				{
					GiveWeapon (53);
				}
				case 1
				{
					GiveWeapon (55);
				}

			}

			PlayAnimation (7);
			SetHealth (256);
			Rdrop = Random(0, 1);
			DropWeaponOnDeath (Rdrop);

			saved_FirstTime = 0;
		}

	}]

	OnDecay[()
	{
		if (GetID()="PakA")
		{
			Boba = Level.GetEntity ("PakA");
			Boba.saved_DeathMax = toInt(Boba.saved_DeathMax);

			if (Boba.saved_DeathToll < Boba.saved_DeathMax)
			{
				Boba.saved_DeathToll = Boba.saved_DeathToll +1;
				Boba.saved_DeathToll = toInt(Boba.saved_DeathToll);
				ReSpawn ();
			}
			else
			{
				Level.saved_PakWaveToll = Level.saved_PakWaveToll +1;
				Level.CheckDead2 ();
			}
		}

		if (GetID()="PakB")
		{

			Boba = Level.GetEntity ("PakB");
			Boba.saved_DeathMax = toInt(Boba.saved_DeathMax);
			if (Boba.saved_DeathToll < Boba.saved_DeathMax)
			{
				Boba.saved_DeathToll = Boba.saved_DeathToll +1;
				Boba.saved_DeathToll = toInt(Boba.saved_DeathToll);
				ReSpawn2();
			}
			else
			{
				Level.saved_PakWaveToll = Level.saved_PakWaveToll +1;

				Level.CheckDead2 ();
			}
		}

		if (GetID()="PakC")
		{
			Boba = Level.GetEntity ("PakC");
			Boba.saved_DeathMax = toInt(Boba.saved_DeathMax);
			if (Boba.saved_DeathToll < Boba.saved_DeathMax)
			{
				Boba.saved_DeathToll = Boba.saved_DeathToll +1;
				Boba.saved_DeathToll = toInt(Boba.saved_DeathToll);
				ReSpawn2 ();
			}
			else
			{
				Level.saved_PakWaveToll = Level.saved_PakWaveToll +1;
				Level.CheckDead2 ();
			}
		}
	}]



	GoPatrol [()
	{
		SetAttackDistance (40, 6);
		SetState_Patrol (0);
		SetLineOfSight(0);
		SetWander (0);
	}]

	GoFiddle [ ()
	{
		TurnToEntity(Level.GetEntity("Pak43"));
		PlayAnimation(27);
			//Level.Log ("---saved_FiddleDeath now equals saved_DeathToll");
		saved_FiddleDeath = toInt(saved_DeathToll+0);
			//Level.Log ("		saved_DeathToll; " # saved_DeathToll);
			//Level.Log ("		saved_FiddleDeath:  " # saved_FiddleDeath);
			//Level.Log ("	~~~~~~~~Starting the Delay");
		Delay(20, 10);
	}]

	DelayReached[ (go)
	{
		if(go = 10)
		{
			//Level.Log ("#####Checking the Delay#####");
			if(not IsDead() )
			{	//Level.Log ("********************He is not Dead.");
				//Level.Log ("	saved_DeathToll:  " # saved_DeathToll);
				//Level.Log ("	saved_FiddleDeath:  " # saved_FiddleDeath);
				if (not (saved_DeathToll > saved_FiddleDeath))
				{
					//Level.Log ("		##@#Inside Victory is Mine.");
					//OpenMenu("AMM2_failure");

					Level.GetPlayer().Kill();
					Level.AMM2Failure();
				}

			}
		}
		if ( go = 20 )
		{
			Level.Log("Pakman");
			if(Level.saved_EnableKillzone = 1)
			{
				if(saved_deathcount = 5 )
				{
					Delay(0, 200);
				}
				else
				{
					Level.Log("increasing DeathCount +1");
					saved_deathcount = saved_deathcount +1;
					Delay(1, 20);
				}
			}
			else
			{
				return;
			}
		}
		if ( go = 200)
		{

			Xpos = Level.GetPlayer().GetPositionX();
			Ypos = Level.GetPlayer().GetPositionY();
			Zpos = Level.GetPlayer().GetPositionZ();

			Level.GetPlayer().PlaySound(3,100,true);
			Level.CreateEffect(55,61,0,Xpos,Ypos,Zpos,128,14,72,72);
			Level.GetPlayer().ShakeHere( Xpos, Ypos );

			Level.GetPlayer().Kill();
		}
	}]

	ReSpawn [()
	{
		who = GetID();

		xpos = Random (17024, 18005);
		ypos = Random (24277, 23408);
		zpos = -647;

		SetPosition (xpos, ypos, zpos);
		SetDead (false);
		SetHealth (256);
		SetRunning ();
		PlayAnimation (7);


		Rgun = Random(0, 1);
		switch(Rgun)
		{
			case 0
			{
				GiveWeapon (53);
			}
			case 1
			{
				GiveWeapon (56);
			}
		}
		GoPath (Random (0, 1));
	}]

	ReSpawn2 [()
	{
		who = GetID();

		xpos = Random (17024, 18005);
		ypos = Random (24277, 23408);
		zpos = -647;

		SetPosition (xpos, ypos, zpos);
		SetDead (false);
		SetHealth (256);
		SetRunning ();
		PlayAnimation (7);


		Rgun = Random(0, 1);
		switch(Rgun)
		{
			case 0
			{
				GiveWeapon (55);
			}
			case 1
			{
				GiveWeapon (55);
			}
		}
		GoPath(0);
	}]

	GoPath [(mode)
	{
		if ( mode = 0 )
		{
			SetRunning ();
			PlayAnimation (0);
			SetState_Patrol (0);
			SetAttackDistance (12, 6);
			SetLineOfSight( 2, 45 );
			SetWander (0);
		}
		else
		{
			SetRunning ();
			PlayAnimation (0);
			SetState_Patrol (0);
			SetAttackDistance (12, 6);
			SetLineOfSight(2, 45 );
			SetWander (0);
		}

		who = GetID();
		switch (who)
		{
			case "PakA"
			{
				FollowPath ("PakA_Path" , 0);
				SetLineOfSight(0);
				SetAttackDistance (11, 6);

				//FollowPathCallback (127, "GoPatrol");
			}
			case "PakB"
			{
				FollowPath ("PakB_Path", 0);
				FollowPathCallback (127, "GoFiddle");
			}
			case "PakC"
			{
				FollowPath ("PakC_Path" , 0);
				FollowPathCallback (127, "GoFiddle");
			}
		}
	}]
}