#define CCOUNT 14
#define COLOR_INTERFACE 0xFFFFFFFF
new IntroObject[MAX_PLAYERS] = {-1, ...};
new IntroTimer[MAX_PLAYERS] = {-1, ...};
new DeathDrawColor[MAX_PLAYERS];
new PlayerText:DeathDraw[MAX_PLAYERS] = {PlayerText:-1, ...};
new Text:IntroLogo[4];
new DeathDrawState[MAX_PLAYERS];
new DeathRandomCode[MAX_PLAYERS] = {-1, ...};

new NamePos[7][] = {
	"Passport Office","Driving school","Parsing Car","Seamstress","Catching Jellyfish","Central Bank","Prison"
};

new Float:C[CCOUNT][6] = {
{1490.164184, -1278.183471, 16.225755, 1490.486694, -1261.657226, 15.820641},
{1494.354370, -1275.600830, 15.346953, 1494.985107, -1263.761230, 15.239350},
{1508.700195, -1551.131103, 3910.014892, 1508.700195, -1551.131103, 3910.014892},
{1509.519165, -1555.938964, 3908.913330, 1513.481689, -1552.122436, 3908.940185},
{53.382328, -303.002655, 960.070251, 52.888427, -267.483917, 960.691162},
{55.637954, -298.900360, 958.314331, 55.549160, -271.335815, 958.935241},
{-51.417938, -188.837341, 930.069885, -51.227920, -152.988540, 929.923217},
{-46.568443, -187.859359, 929.344665, -46.394035, -154.107955, 929.306396},
{215.566421, -1919.258911, 33.583591, 104.119361, -1914.404418, 33.990093},
{212.635437, -1922.822998, 31.658403, 106.799064, -1918.211425, 32.166301},
{155.436096, -1205.066406, 2823.770751, 155.568222, -1186.954101, 2823.606933},
{159.567993, -1202.612426, 2822.390380, 159.578079, -1189.642578, 2822.305664},
{-319.182189, -254.588333, 1084.794067, -319.140625, -276.350494, 1081.875732},
{-316.545959, -258.637176, 1083.506713, -315.951965, -272.519317, 1082.268676}
};

new Text:Intro[4];
new PlayerText:PosInfo[MAX_PLAYERS];
new gCurPos[MAX_PLAYERS];
new NamePosP[MAX_PLAYERS];
new gDelay[CCOUNT] = {5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000};


stock StopDeathEffect(playerid)
{
    new status = DeathDrawState[playerid];
    DeathDrawColor[playerid] = 0x00000000;
	DeathDrawState[playerid] = 0;
	if(status == 1)
	{
	}
	else if(status == 2)
	{
	    PlayerTextDrawHide(playerid, DeathDraw[playerid]);
	}
	CallLocalFunction("OnDeathEffectFinished", "ii", playerid, status);
	return true;
}

forward GoIntro(playerid);
public GoIntro(playerid)
{
	gCurPos[playerid] = 0;	
	NamePosP[playerid] = 0;	
	for(new c = 0; c < 20; c++) SendClientMessage(playerid,0xEAC700AA," ");
	SetPlayerWeather(playerid,1);
	SetTimerEx("StartIntro",100,false,"i",playerid);
	TextDrawShowForPlayer(playerid,Intro[3]);
	
	PosInfo[playerid] = CreatePlayerTextDraw(playerid, 320.333374, 420.622283, "_");
	PlayerTextDrawLetterSize(playerid, PosInfo[playerid], 0.449999, 1.600000);
	PlayerTextDrawAlignment(playerid, PosInfo[playerid], 2);
	PlayerTextDrawColor(playerid, PosInfo[playerid], -356056918);
	PlayerTextDrawSetShadow(playerid, PosInfo[playerid], 0);
	PlayerTextDrawSetOutline(playerid, PosInfo[playerid], 1);
	PlayerTextDrawBackgroundColor(playerid, PosInfo[playerid], 51);
	PlayerTextDrawFont(playerid, PosInfo[playerid], 2);
	PlayerTextDrawSetProportional(playerid, PosInfo[playerid], 1);
	PlayerTextDrawShow(playerid, PosInfo[playerid]);
}

forward StartIntro(playerid);
public StartIntro(playerid)
{
	SetPlayerInterior(playerid,0);
	SetPlayerVirtualWorld(playerid,0);
	TogglePlayerControllable(playerid,0);	
	SetPlayerPos(playerid,1482.4813,-1277.0403,14.5959);
	new p = gCurPos[playerid];
	new d = gDelay[p];
	if(p < 15) 
	{
		new string[65];
		InterpolateCameraPos(playerid,C[p][0],C[p][1],C[p][2],C[p][3],C[p][4],C[p][5],d,CAMERA_MOVE);
		InterpolateCameraLookAt(playerid,C[p+1][0],C[p+1][1],C[p+1][2],C[p+1][3],C[p+1][4],C[p+1][5],d,CAMERA_MOVE);
		format(string,65,"%s", NamePos[NamePosP[playerid]]);
		PlayerTextDrawSetString(playerid, PosInfo[playerid], string);
		SetTimerEx("NextPoint",d,false,"i",playerid);
	}
}

forward NextPoint(playerid);
public NextPoint(playerid)
{
	NamePosP[playerid] += 1;
	gCurPos[playerid] += 2;
	new p = gCurPos[playerid];	
	if(p < 13) 
	{
		new string[65];
		new d = gDelay[p];
		if(p == 2) SetPlayerPos(playerid,1516.1528,-1546.0576,3908.1367), SetPlayerInterior(playerid,1), SetPlayerVirtualWorld(playerid,1);
		if(p == 4) SetPlayerPos(playerid,61.6467,-307.8287,954.9484), SetPlayerInterior(playerid,1), SetPlayerVirtualWorld(playerid,1);
		if(p == 6) SetPlayerPos(playerid,-61.9973,-164.6376,928.7820), SetPlayerInterior(playerid,1), SetPlayerVirtualWorld(playerid,1);
		if(p == 8) SetPlayerPos(playerid,154.1833,-1951.6890,10.7188), SetPlayerInterior(playerid,0), SetPlayerVirtualWorld(playerid,0);
		if(p == 10) SetPlayerPos(playerid,169.9003,-1181.4221,2821.4829), SetPlayerInterior(playerid,0), SetPlayerVirtualWorld(playerid,0);
		if(p == 12) SetPlayerPos(playerid,-326.8011,-254.6889,1082.7289), SetPlayerInterior(playerid,1), SetPlayerVirtualWorld(playerid,1);
		InterpolateCameraPos(playerid,C[p][0],C[p][1],C[p][2],C[p][3],C[p][4],C[p][5],d,CAMERA_MOVE);
		InterpolateCameraLookAt(playerid,C[p+1][0],C[p+1][1],C[p+1][2],C[p+1][3],C[p+1][4],C[p+1][5],d,CAMERA_MOVE);
		SetTimerEx("NextPoint",d,false,"i",playerid);
		format(string,65,"%s", NamePos[NamePosP[playerid]]);
		PlayerTextDrawSetString(playerid, PosInfo[playerid], string);
	}
	else
	{
	    SetPlayerVirtualWorld(playerid, playerid + 1);
	    SetPlayerCameraPos(playerid, 100.90000153,-3350.80004883,1030.50000000);
        SetPlayerCameraLookAt(playerid, -150.90000153,-3350.80004883,1030.50000000);
        MovePlayerObject(playerid, IntroObject[playerid], 120.90000153,-3336.80004883,1036.50000000, 20.0, 0.0, 0.0, 0.0);
		IntroTimer[playerid] = SetTimerEx("StopCameraFly", 4000, false, "i", playerid);
		CancelSelectTextDraw(playerid);
		TextDrawShowForPlayer(playerid, IntroLogo[0]);
  		TextDrawShowForPlayer(playerid, IntroLogo[1]);
   		TextDrawShowForPlayer(playerid, IntroLogo[2]);
    	TextDrawShowForPlayer(playerid, IntroLogo[3]);
    	SendClientMessage(playerid, 0xFFFFFFFF, "[Пилот]: Пристегните ремни безопасности. Самолет идет на посадку.");
	}
}

forward StopCameraFly(playerid);
public StopCameraFly(playerid)
{
    StartDeathEffect(playerid, 1);
    return true;
}

forward StartDeathEffect(playerid, status);
public StartDeathEffect(playerid, status)
{
	DeathDrawColor[playerid] = (status == 1)?0x00000000:0x00000100;
	PlayerTextDrawBoxColor(playerid, DeathDraw[playerid], DeathDrawColor[playerid]);
    DeathDrawState[playerid] = status;
    DeathRandomCode[playerid] = random(10000);
    SetTimerEx("PlayerDeathed", 10, false, "ii", playerid, DeathRandomCode[playerid]);
    return true;
}
forward PlayerDeathed(playerid, code);
public PlayerDeathed(playerid, code)
{
	if(!IsPlayerConnected(playerid)) return true;
	if(code != DeathRandomCode[playerid]) return true;
	new bool:Stop;
	switch(DeathDrawState[playerid])
	{
	    case 1:
		{
			DeathDrawColor[playerid] += 0x1;
			if(DeathDrawColor[playerid] >= 0x100) Stop = true;
		}
	    case 2:
		{
			DeathDrawColor[playerid] -= 0x1;
			if(DeathDrawColor[playerid] <= 0x0) Stop = true;
		}
		default: return false;
	}
    if(Stop)
	{
 		StopDeathEffect(playerid);
	    return true;
	}
 	PlayerTextDrawBoxColor(playerid, DeathDraw[playerid], DeathDrawColor[playerid]);
	PlayerTextDrawShow(playerid, DeathDraw[playerid]);
	DeathRandomCode[playerid] = random(10000);
	SetTimerEx("PlayerDeathed", 10, false, "ii", playerid, DeathRandomCode[playerid]);
    return true;
}

stock IntroTDPlayer(playerid)
{	
    if(DeathDraw[playerid] != PlayerText:-1) PlayerTextDrawDestroy(playerid, DeathDraw[playerid]);
    DeathDraw[playerid] = CreatePlayerTextDraw(playerid,300,0,"New TextDraw");
    PlayerTextDrawUseBox(playerid, DeathDraw[playerid],1);
    PlayerTextDrawAlignment(playerid, DeathDraw[playerid],2);
    PlayerTextDrawSetOutline(playerid, DeathDraw[playerid],1);
	PlayerTextDrawLetterSize(playerid, DeathDraw[playerid],0.0,60.0);
	PlayerTextDrawSetProportional(playerid, DeathDraw[playerid],0);
	PlayerTextDrawTextSize(playerid, DeathDraw[playerid],-180.0,700.0);
	PlayerTextDrawBoxColor(playerid, DeathDraw[playerid],0x00000066);
	PlayerTextDrawFont(playerid, DeathDraw[playerid],3);
	return true;
}

stock IntroTextDraw()
{
    Intro[0] = TextDrawCreate(320.000000, 180.000000, "SanAndreas");
    TextDrawAlignment(Intro[0], 2);
	TextDrawFont(Intro[0], 1);
	TextDrawColor(Intro[0], 0xFF8501FF);
	TextDrawSetShadow(Intro[0], 0);
	TextDrawSetOutline(Intro[0], -1);
	TextDrawBackgroundColor(Intro[0], 51);
	TextDrawLetterSize(Intro[0], 1.14, 3.599998);

	Intro[1] = TextDrawCreate(180.000030, 207.5, ".");
	TextDrawLetterSize(Intro[1], 30.247341, 0.650074);
	TextDrawAlignment(Intro[1], 1);
	TextDrawColor(Intro[1], -1);
	TextDrawSetShadow(Intro[1], 0);
	TextDrawSetOutline(Intro[1], -1);
	TextDrawBackgroundColor(Intro[1], 51);
	TextDrawFont(Intro[1], 3);
	TextDrawSetProportional(Intro[1], 1);

	Intro[2] = TextDrawCreate(320.00, 210.0, "Role Play");
	TextDrawAlignment(Intro[2], 2);
	TextDrawFont(Intro[2], 1);
	TextDrawColor(Intro[2], 0xFF8501FF);
	TextDrawSetShadow(Intro[2], 0);
	TextDrawSetOutline(Intro[2], -1);
	TextDrawBackgroundColor(Intro[2], 51);
	TextDrawLetterSize(Intro[2], 1.14, 3.599998);
	
	Intro[3] = TextDrawCreate(448.666687, 408.018890, "usebox");
	TextDrawLetterSize(Intro[3], 0.000000, 4.338477);
	TextDrawTextSize(Intro[3], 192.000000, 0.000000);
	TextDrawAlignment(Intro[3], 1);
	TextDrawColor(Intro[3], 0);
	TextDrawUseBox(Intro[3], true);
	TextDrawBoxColor(Intro[3], 102);
	TextDrawSetShadow(Intro[3], 0);
	TextDrawSetOutline(Intro[3], 0);
	TextDrawFont(Intro[3], 0);
	
	IntroLogo[0] = TextDrawCreate(217.000000, 196.000000, "SanAndreas");
	TextDrawBackgroundColor(IntroLogo[0], 255);
	TextDrawFont(IntroLogo[0], 1);
	TextDrawLetterSize(IntroLogo[0], 1.500000, 7.199997);
	TextDrawColor(IntroLogo[0], -1876547841);
	TextDrawSetOutline(IntroLogo[0], 1);
	TextDrawSetProportional(IntroLogo[0], 1);
	TextDrawSetSelectable(IntroLogo[0], 0);

	IntroLogo[1] = TextDrawCreate(357.000000, 249.000000, "Role Play");
	TextDrawBackgroundColor(IntroLogo[1], 255);
	TextDrawFont(IntroLogo[1], 2);
	TextDrawLetterSize(IntroLogo[1], 0.400000, 2.000000);
	TextDrawColor(IntroLogo[1], -1);
	TextDrawSetOutline(IntroLogo[1], 1);
	TextDrawSetProportional(IntroLogo[1], 1);
	TextDrawSetSelectable(IntroLogo[1], 0);

	IntroLogo[2] = TextDrawCreate(219.000000, 191.000000, "Welcome to");
	TextDrawBackgroundColor(IntroLogo[2], 255);
	TextDrawFont(IntroLogo[2], 0);
	TextDrawLetterSize(IntroLogo[2], 1.029999, 3.000000);
	TextDrawColor(IntroLogo[2], -1);
	TextDrawSetOutline(IntroLogo[2], 1);
	TextDrawSetProportional(IntroLogo[2], 1);
	TextDrawSetSelectable(IntroLogo[2], 0);

	IntroLogo[3] = TextDrawCreate(119.000000, 131.000000, "Icon1");
	TextDrawBackgroundColor(IntroLogo[3], 0);
	TextDrawFont(IntroLogo[3], 5);
	TextDrawLetterSize(IntroLogo[3], 0.500000, 1.000000);
	TextDrawColor(IntroLogo[3], -1);
	TextDrawSetOutline(IntroLogo[3], 0);
	TextDrawSetProportional(IntroLogo[3], 1);
	TextDrawSetShadow(IntroLogo[3], 1);
	TextDrawUseBox(IntroLogo[3], 1);
	TextDrawBoxColor(IntroLogo[3], 255);
	TextDrawTextSize(IntroLogo[3], 244.000000, 286.000000);
	TextDrawSetPreviewModel(IntroLogo[3], 592);
	TextDrawSetPreviewRot(IntroLogo[3], -10.000000, 10.000000, 10.000000, 1.000000);
	TextDrawSetSelectable(IntroLogo[3], 0);
	
	return true;
}

stock CheckIntro(playerid)
{
    if(IntroTimer[playerid] != -1)
	{
		KillTimer(IntroTimer[playerid]);
	}
	if(IntroObject[playerid] != -1)
	{
		DestroyPlayerObject(playerid, IntroObject[playerid]);
	}
	IntroTimer[playerid] = -1; //qweqwe
	IntroObject[playerid] = -1;
    return true;
}

forward OnDeathEffectFinished(playerid, drawstate);
public OnDeathEffectFinished(playerid, drawstate)
{
	switch(drawstate)
	{
	    PlayerTextDrawBoxColor(playerid, DeathDraw[playerid], 0x000000FF);
		PlayerTextDrawShow(playerid, DeathDraw[playerid]);
	    SetTimerEx("StartIntroDeathEffect", 1500, false, "i", playerid);
	}
 	else
	{
		StartDeathEffect(playerid, 2);
		SetPlayerVirtualWorld(playerid, 0);
		SpawnPlayer(playerid);
		CheckIntro(playerid);
		TextDrawHideForPlayer(playerid, IntroLogo[0]);
		TextDrawHideForPlayer(playerid, IntroLogo[1]);
		TextDrawHideForPlayer(playerid, IntroLogo[2]);
		TextDrawHideForPlayer(playerid, IntroLogo[3]);
	}
	return true;
}