// King Ford Town
int Rule = 4;
int RoundTime = 15;
int PlayerSpawn = 249;
int PlayerSpawnDir = 90;
int PlayerWeapon = 24;
int PlayerWeapon2 = 14;
int PlayerHP = 2000;

int g_counter = 0;
int trg0 = 0;
int trg1 = 0;
int trg2 = 0;
int trg3 = 0;
int trg4 = 0;
int trg5 = 0;
int timer0 = 0;
int survivor = -1;

OnStart()
{
	AddNPC("npc13_01");
	AddNPC("npc13_02");
	AddNPC("npc13_03");
	AddNPC("npc13_04");
	AddNPC("npc13_05");
	AddNPC("npc13_06");
	AddNPC("npc13_07");
	AddNPC("npc13_08");
}

OnUpdate()
{	
	int player = GetChar("player");
	if (player < 0)
	{
		return 0;
	}
	
	int c;
	int c2;
	int c3;
	int c4;
	int c5;
	int t;
	
	g_counter = g_counter + 1;

	if (trg0 == 0)
	{
		c = GetChar("Ivy");
		c2 = GetChar("Warder A");
		c3 = GetChar("Warder B");
		c4 = GetChar("Warder C");
		c5 = GetChar("Night Owl");
		if (c>=0 && c2>=0 && c3>=0 && c4>=0 && c5>=0)
		{	
			ChangeBehavior(c, "follow", player);
			Perform(c, "pause", 8);
			Perform(c, "aggress");
			Perform(c, "say", "Come on£¡");
			Perform(c, "pause", 10);
			Perform(c, "faceto", c3);
			
			ChangeBehavior(c2, "follow", c);
			Perform(c2, "pause", 15);
			Perform(c2, "aggress");
			Perform(c2, "say", "Bitch! I get you now, you are not going anywhere£¡");
			Perform(c2, "pause", 2);
			Perform(c2, "faceto", c);
			
			ChangeBehavior(c3, "follow", player);
			Perform(c3, "pause", 5);
			Perform(c3, "aggress");
			Perform(c3, "say", "Go away, little guy, or I will catch you too£¡");
			Perform(c3, "pause", 15);
			Perform(c3, "faceto", c);
			
			ChangeBehavior(c4, "follow", player);
			Perform(c4, "pause", 5);
			Perform(c4, "say", "No matter who he is, go catch him£¡");
			Perform(c4, "pause", 20);
			Perform(c4, "faceto" ,c);

			ChangeBehavior(c5, "patrol", 172, 127, 133, 127);
			Perform(c5, "pause", 10);
			Perform(c5, "faceto", player);
			Perform(c5, "aggress");
			Perform(c5, "pause", 20);
			Perform(c5, "faceto", player);
					
			PlayerPerform("block", 0);
			PlayerPerform("pause", 20);
			PlayerPerform("block", 1);
		
			trg0 = 1;
			timer0 = GetGameTime() + 25;
		}				
	}
	
	if (trg0 == 1)
	{
		c = GetChar("Ivy");
		c2 = GetAnyChar("Warder A");
		c3 = GetAnyChar("Warder B");
		c4 = GetAnyChar("Warder C");
		c5 = -1;
		
		if (GetHP(c2)>0 && GetHP(c3)<=0 && GetHP(c4)<=0)
		{
			c5 = c2;
		}
		if (GetHP(c3)>0 && GetHP(c2)<=0 && GetHP(c4)<=0)
		{
			c5 = c3;
		}
		if (GetHP(c4)>0 && GetHP(c3)<=0 && GetHP(c2)<=0)
		{
			c5 = c4;
		}
		if (GetHP(c2)<=0 && GetHP(c3)<=0 && GetHP(c4)<=0)
		{
			c5 = 9999;
		}
		
		if (c5 >= 0)
		{
			if (c5 != 9999)
			{
				ChangeBehavior(c5, "follow", "vip");
				Perform(c5, "aggress");
				Perform(c5, "say", "Shit! Wait here£¡£¡");
				Perform(c5, "faceto", player);
				
				Perform(c, "aggress");
				Perform(c, "say", "Come on, I am waiting£¡£¡");
				Perform(c, "pause", 2);
				Perform(c, "faceto", c5);
				
				PlayerPerform("say", "©q©q©q©q©q©q");
				PlayerPerform("pause", 5);
				
				survivor = c5;
			}
			
			trg0 = 2;
		}		
	}
	
	if (trg0==2 && survivor>=0)
	{
		c = GetChar("Officer©qJason");
		if (c>=0 && GetHP(survivor)>0)
		{
			SetTarget(0, "char", c);
			SetTarget(1, "char", survivor);
			if (Distance(0, 1) < 150)
			{
				Perform(survivor, "say", "Yes£¡");
				Perform(survivor, "pause", 5);
				Perform(survivor, "say", "I found her, but she gets a strong hand now, so©q©q");
				Perform(survivor, "pause", 5);
				Perform(survivor, "say", "Sir,sir!");
				Perform(survivor, "faceto", c);
				
				ChangeBehavior(c, "follow", player);
				Perform(c, "say", "What£¡Go get him no matter who he is£¡");
				Perform(c, "pause", 5);
				Perform(c, "say", "Just say£¡£¡");
				Perform(c, "pause", 3);
				Perform(c, "faceto", survivor);
				
				c2 = GetChar("Police A");
				if (c2 >= 0)
				{
					Perform(c2, "say", "Yes£¡");
					Perform(c2, "guard", 12);					
					Perform(c2, "faceto", c);
				}
				c2 = GetChar("Police B");
				if (c2 >= 0)
				{
					Perform(c2, "say", "Yes£¡");
					Perform(c2, "guard", 12);					
					Perform(c2, "faceto", c);
				}
				
				trg0 = 3;
			}
		}
	}
	
	if (trg1 == 0)
	{
		c = GetChar("Officer©qJason");
		c2 = GetChar("Ivy");
		
		SetTarget(0, "char", c);
		SetTarget(1, "char", player);
		if (c>=0 && c2>=0 && GetEnemy(c)==player && Distance(0, 1)<200)
		{
			ChangeBehavior(c, "follow", player);
			if (trg0 == 3)
			{			
				Perform(c, "say", "You are that tough? let's go get her£¡");
				Perform(c, "pause", 8);
				Perform(c, "say", "You steal the pledage in One Shot Gate£¡ ");
				Perform(c, "pause", 1);
				Perform(c, "say", "What a big talk£¡");
				Perform(c, "pause", 5);
				Perform(c, "say", "Hey guy, that is you who helps this thief£¡");
				Perform(c, "faceto", player);
				
				Perform(c2, "pause", 5);		
				Perform(c2, "say", "I told you I didn't steal it£¡£¡");
				Perform(c2, "pause", 10);		
				Perform(c2, "say", "I am not  the thief, I am Ivy£¡");
				Perform(c2, "pause", 2);
				Perform(c2, "faceto", c);
				
				PlayerPerform("block", 0);
				PlayerPerform("pause", 5);		
				PlayerPerform("say", "£¨©q©q©qIs that the pledge with me£¿©q©q£©");
				PlayerPerform("pause", 6);
				PlayerPerform("say", "©q©q©q©q©q©q");
				PlayerPerform("pause", 4);
				PlayerPerform("block", 1);

				StopPerform(survivor);
				
				t = 17;
			} else
			{
				Perform(c, "say", "No matter who you are, you are with this thief, you are not gonna go£¡£¡");
				Perform(c, "pause", 3);
				Perform(c, "say", "What a big talk! And you find a helper£¡");
				Perform(c, "pause", 5);
				Perform(c, "say", "Haha, now you can not go anywhere£¡");
				Perform(c, "faceto", player);
				
				Perform(c2, "pause", 5);
				Perform(c2, "say", "I am not the thief, I am Ivy! How come you think I am the thief");
				Perform(c2, "pause", 2);
				Perform(c2, "faceto", c);
				
				PlayerPerform("block", 0);
				PlayerPerform("pause", 4);
				PlayerPerform("say", "©q©q©q©q©q©q");
				PlayerPerform("pause", 4);
				PlayerPerform("block", 1);
				
				survivor = -1;
				t = 10;
			}
			
			c3 = GetChar("Police A");
			if (c3 >= 0)
			{
				StopPerform(c3);
				Perform(c3, "say", "Yes£¡");
				Perform(c3, "guard", t);
				Perform(c3, "faceto", player);
			}
			c3 = GetChar("Police B");
			if (c3 >= 0)
			{
				StopPerform(c3);
				Perform(c3, "say", "Yes£¡");
				Perform(c3, "guard", t);
				Perform(c3, "faceto", player);
			}				
			c3 = GetChar("Warder A");
			if (c3 >= 0)
			{
				Perform(c3, "guard", t);					
				Perform(c3, "faceto", player);
			}
			c3 = GetChar("Warder B");
			if (c3 >= 0)
			{
				Perform(c3, "guard", t);					
				Perform(c3, "faceto", player);
			}
			c3 = GetChar("Warder C");
			if (c3 >= 0)
			{
				Perform(c3, "guard", t);					
				Perform(c3, "faceto", player);
			}
			c3 = GetChar("Night Owl");
			if (c3 >= 0)
			{
				Perform(c3, "guard", t);					
				Perform(c3, "faceto", player);
			}					
						
			trg1 = 1;
			trg5 = 1;
		}
	}	
	
	if (trg5 == 0)
	{
		c = GetChar("Officer©qJason");
		if (c >= 0)
		{
			if (g_counter%45==0 && timer0>0 && GetGameTime()>timer0 && GetEnemy(c)<0)
			{
				Perform(c, "say", "Where are them? Go find them£¡£¡");			
			}
			
			c3 = GetChar("Police A");
			if (c3>=0 && (GetEnemy(c3)==player || GetEnemy(c3)==c2))
			{
				Perform(c3, "say", "I find them£¡£¡");
				Perform(c3, "faceto", player);				
				ChangeBehavior(c, "follow", player);
				trg1 = 1;
			}
			c3 = GetChar("Police B");
			if (c3>=0 && (GetEnemy(c3)==player || GetEnemy(c3)==c2))
			{
				Perform(c3, "say", "I find them£¡£¡");
				Perform(c3, "faceto", player);				
				ChangeBehavior(c, "follow", player);
				trg1 = 1;
			}
			trg5 = 1;
		}
	}	
	
	if (trg2 == 0)
	{
		c = GetChar("Ivy");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			Perform(c, "say", "I am sorry, you involve in it now, I am sorry©q©q");
			Perform(c, "faceto", player);
			trg2 = 1;
		}		
	}
	if (trg2 == 1)
	{
		c = GetAnyChar("Ivy");
		if (c>=0 && GetHP(c)<=0)
		{		
			Say(c, "I am tired, I want to rest©q©q");
			trg2 = 2;
		}	
	}	
		
	if (g_counter%20==0 && timer0>0 && GetGameTime()>timer0)
	{
		c = GetChar("Ivy");
		if (c>=0 && !IsPerforming(player))
		{		
			SetTarget(0, "char", player);
			SetTarget(1, "char", c);
			if (Distance(0, 1) > 500)
			{
				Say(c, "Wait£¡");
			}				
										
			if (g_counter%40 == 0 && trg2==1)
			{
				Perform(c, "guard", 2);
				Perform(c, "faceto", player);
				Perform(c, "pause", 2);
				Perform(c, "faceto", player);
				Perform(c, "say", "I am too tired, I want to rest£¡");
			}
		}
	}	
	
	if (trg3 == 0)
	{
		c = GetChar("Night Owl");
		if (c>=0 && GetEnemy(c)==player)
		{
			SetTarget(0, "char", c);
			SetTarget(1, "char", player);
			if (Distance(0, 1) < 200)
			{
				ChangeBehavior(c, "kill", player);
				Perform(c, "aggress");
				Perform(c, "say", "Haha, come on£¡");
				Perform(c, "say", "I see you again, and you don't have chance to run this time£¡");
				Perform(c, "faceto", player);
				trg3 = 1;
			}			
		}
	}	
	if (trg3 == 1)
	{
		c = GetChar("Night Owl");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			ChangeBehavior(c, "dodge", player);
			Perform(c, "say", "You are not easy, let see how I can play with you£¡");
			Perform(c, "faceto", player);
			trg3 = 2;			
		}		
	}	
	if (trg3 == 2)
	{
		c = GetAnyChar("Night Owl");
		if (c>=0 && GetHP(c)<=0)
		{
			Say(c, "Shit! Don't think this is the end, it will be more©q©q");
			trg3 = 3;
		}	
	}
	
	if (trg4 == 0)
	{
		c = GetChar("Officer©qJason");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			Perform(c, "say", "Shit£¡You make me mad£¡");
			Perform(c, "faceto", player);
			trg4 = 1;
		}
	}
	if (trg4 == 1)
	{
		c = GetAnyChar("Officer©qJason");
		if (c>=0 && GetHP(c)<=0)
		{
			Say(c, "Never thought I will be beaten ©q©q©q");
			trg4 = 2;
		}
	}
}