string Name	= "TEST";
int Model =	10;
int Weapon = 4;
int Weapon2 = 7;
int Team = 2;
int View = 500;
int Think = 2000;
int	Attack1	= 35;
int Attack2 = 35;
int Attack3 = 30;
int	Guard =	0;
int	Dodge =	80;
int Jump = 4;
int Look = 10;
int Burst = 80;
int Aim = 100;
int GetItem = 0;
int Spawn = 1;
int HP = 8000;	

int g_selfAddr;
int g_self;
int s;
int timer;
int t1;
int t2;
int p;
int life;
OnInit(int this)
{
	g_selfAddr = this;
}

OnStart()
{
	g_self = GetSelf(g_selfAddr);
	ChangeBehavior(g_self, "patrol",Rand(3),Rand(5),Rand(5)+3,Rand(5)+10);
}

SaySub(int id, int sd, string say1, string say2, string say3, string say4, string say5)
{
       if (sd == 0)
       {
           Say(id, say1);
       }
       if (sd == 1 )
       {
           Say(id, say2);
       }
       if (sd == 2 )
       {
           Say(id, say3);
       }
       if (sd == 3)
       {
           Say(id, say4);
       }
       if (sd == 4)
       {
           Say(id, say5);
       }
       return 0;
}
actionmodel(int si)
{
	//ATK MODE
	if (si==0)
	{
		Think = 30000;
		Attack1 = 30;
		Attack2 = 25;
		Attack3 = 25;
		Guard = 20;
		Dodge = 0;
		Jump = Rand(6);
		Look = 100;
		Burst = Rand(100);
	}
	//ATK-2
	if (si >= 1 && si <= 3)
	{
		Think = 100;
	}
	//Guard
	if (si==4)
	{
		Think = 100;
		Attack1 = 0;
		Attack2 = 0;
		Attack3 = 0;
		Guard = 100;
		Dodge = 0;
		Jump = Rand(6);
		Look = 80;
		Burst = Rand(100);
	}
	//Burst
	if (si==5)
	{
		Think = 80;
		Attack1 = 0;
		Attack2 = 0;
		Attack3 = 0;
		Guard = 0;
		Dodge = 100;
		Jump = 30;
		Look = 30;
		Burst = 60;
	}
	UpdateAIAttrib(g_self);
}

callman()
{
            
	    if (GetChar("BUG-1")<1 || GetChar("BUG-2")<1)
	    {
		SaySub(g_self,Rand(5),"~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~");
		if (GetChar("BUG-1")<1){AddNPC("21");}
	        if (GetChar("BUG-2")<1){AddNPC("22");}
            }
}
OnUpdate()
{

	if (GetAnger(1) == 0 && p == 100)
        {
		
		/*(if (GetWeaponType(1) != 1)
		{
			int i;
			for (i=0;i<=20;i++)
			{
 				SetTarget(0, "waypoint", i);
 				SetTarget(1, "char", 1);
	 			SetTarget(2, "char", g_self);
				if(Distance(0,1) < Distance(0,2) && Distance(0,2) > Distance(2,1))
				{
					ChangeBehavior(g_self, "attacktarget", 0);
					Say(g_self,"RUN!");
					int Dodge = 100;
					int Burst = 90;
					UpdateAIAttrib(g_self);
					i=30;
				}
			}
			if (GetWeaponType(1) == 0 || GetWeaponType(1) == 11){timer = GetGameTime() + 5;}
			if (GetWeaponType(1) == 4 || GetWeaponType(1) == 8 || GetWeaponType(1) == 9 || GetWeaponType(1) == 10){timer = GetGameTime() + 10;}
			if (GetWeaponType(1) == 5 || GetWeaponType(1) == 7){timer = GetGameTime() + 8;}
		}*/
		
		if (GetWeaponType(1) == 1)
		{
			Perform(g_self,"guard",2);
			actionmodel(4);
			timer = GetGameTime() + 3;
		}
		p = GetAnger(1);
	}
	
	if (GetAnger(1) < p - 50 && p >= 50)
        {
		
		if (GetWeaponType(1) != 9)
		{
			Perform(g_self,"guard",2);
			actionmodel(4);
		}
		timer = GetGameTime() + 2;
		p = GetAnger(1);
	}
	
	if (GetAnger(1) > p)
        {
		p = GetAnger(1);
		if (life==0){life = GetHP(1);}
	}
	if(GetGameTime()>15 && GetHP(1) > life && life > 0)
	{
		Say(g_self,"FUCK YOU");
		Perform(g_self,"use",20);
		int i;
		for (i=1;i<=5;i++)
		{
			Perform(g_self,"use",15);
		}
		Perform(g_self,"use",8);
		life = GetHP(1);
	}
	
	if (GetHP(1) < life)
        {
		life = GetHP(1);
	}
	
	if (GetGameTime()>timer)
	{
		if (p<100){actionmodel(0);}
		if (p==100){actionmodel(Rand(4));}
	}
	if (Rand(100) == 1)
	{
		Perform(g_self,"guard",2);
	}
	if (GetWeaponType(g_self) == 4 && Rand(25) == 1)
	{
		Perform(g_self,"guard",1);
	}
    if (GetGameTime() > t1 && GetGameTime()>5)
    {
       if (GetHP(g_self) < GetMaxHP(g_self) && GetHP(g_self) > GetMaxHP(g_self)/2)
        {
            SaySub(g_self,Rand(5),"~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~");
            Output("transfer", g_self, "to", 0);
            t1 = GetGameTime() + 40;
            Perform(g_self,"use", 4);
            Perform(g_self,"use", 8);
        }
        if (GetHP(g_self) < GetMaxHP(g_self)/3 && GetHP(g_self) > GetMaxHP(g_self)/4)
        {
            SaySub(g_self,Rand(5),"~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~");
            Output("transfer", g_self, "to", 0);
            t1 = GetGameTime() + 45;
            Perform(g_self,"use", 4);
            Perform(g_self,"use", 34);
            Perform(g_self,"use", 8);
	    callman();
        }
        if (GetHP(g_self) < GetMaxHP(g_self)/5)
        {
            SaySub(g_self,Rand(5),"~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~","~~~XXXOOO~~~");
            Output("transfer", g_self, "to", 0);
            t1 = GetGameTime() + 50;
            Perform(g_self,"use", 4);
            Perform(g_self,"use", 34);
            Perform(g_self,"use", 30);
            Perform(g_self,"use", 19);
            Perform(g_self,"use", 15);
	    callman();
        }
    }
    if (GetHP(3)<=0){RemoveNPC(3);}
    if (GetHP(4)<=0){RemoveNPC(4);}
	if (GetGameTime() < 5 && t1 > 5)
	{
		timer = 0;
		p = 0;
		life = GetHP(1);
		t1 = GetGameTime();
		if (GetChar("BUG-1")>0){RemoveNPC(3);}
	        if (GetChar("BUG-2")>0){RemoveNPC(4);}
		Perform(g_self,"use", 20);
		for (i=1;i<=5;i++)
		{
			Perform(g_self,"use", 15);
		}
	}
}