/* 
 * LuxurY includes
 * Moving & Explosing Vehicles
 * Version 0.1
 * Powered by
             LuxurY Development Team
                        (c) LDT 2007
 */

#include <a_samp>

forward ExploseUp();
forward MoveV();
forward MoveF();
forward AngT();
forward Moving();

new curmv;
new curheight;
new movv;
new movbool;
new curmf;
new movf;
new curnumber;
new elenght[MAX_VEHICLES];
new mvxyz[MAX_VEHICLES];
new mvx[MAX_VEHICLES];
new mvy[MAX_VEHICLES];
new mvz[MAX_VEHICLES];
new mvtime;
new Float:zf[MAX_VEHICLES];
new explosedv[MAX_VEHICLES];
new evt[MAX_VEHICLES];
new exploseup[MAX_VEHICLES];

stock MoveVehicle(vehicleid,Float:X,Float:Y,Float:Z)
{
	mvxyz[vehicleid] = 1;
	mvx[vehicleid] = X;
	mvy[vehicleid] = Y;
	mvz[vehicleid] = Z;
	mvtime = SetTimer("Moving",1,1);
	return 1;
}

public Moving()
{
	for (new v = 1; v < MAX_VEHICLES; v++)
	{
		if (mvxyz[v] == 1)
		{
			new Float:vX, Float:vY, Float:vZ;
			GetVehiclePos(v,vX,vY,vZ);
			if (mvx[v] > vX)
			{
				SetVehiclePos(v,vX+0.01,vY,vZ);
			}
			else if (mvx[v] < vX)
			{
				SetVehiclePos(v,vX-0.01,vY,vZ);
			}
			else if (mvy[v] > vY)
			{
				SetVehiclePos(v,vX,vY+0.01,vZ);
			}
			else if (mvy[v] < vY)
			{
				SetVehiclePos(v,vX,vY-0.01,vZ);
			}
			else if (mvz[v] > vZ)
			{
				SetVehiclePos(v,vX,vY,vZ+0.01);
			}
			else if (mvz[v] < vZ)
			{
				SetVehiclePos(v,vX,vY,vZ-0.01);
			}
			else if (mvz[v] == vZ && mvy[v] == vY && mvx[v] == vX)
			{
				KillTimer(mvtime);
			}
		}
	}
	return 1;
}

stock ExploseVehicle(vehicleid)
{
	for (new i=0; i < MAX_PLAYERS; i++)
	{
		if (GetPlayerVehicleID(i) == vehicleid)
		{
			SetPlayerHealth(i,0);
		}
	}
	new Float:vX, Float:vY, Float:vZ;
	SetVehicleHealth(vehicleid,0);
	GetVehiclePos(vehicleid,vX,vY,vZ);
	zf[vehicleid] = vZ;
	elenght[vehicleid]=100;
	explosedv[vehicleid] = 1;
	evt[vehicleid] = 0;
	exploseup[vehicleid] = SetTimer("ExploseUp",10,1);
	return 1;
}


public ExploseUp()
{
	for (new v = 1; v < MAX_VEHICLES; v++)
	{
		if (explosedv[v] == 1)
		{
			elenght[v]--;
			new Float:vX, Float:vY, Float:vZ;
			GetVehiclePos(v,vX,vY,vZ);
			if (elenght[v] > 50)
			{
				CreateExplosion(vX,vY,vZ,6,1);
				SetVehiclePos(v,vX,vY,vZ+0.1);
			}
			else if (zf[v] == vZ)
			{
				KillTimer(exploseup[v]);
				CreateExplosion(vX,vY,vZ,6,1);
				explosedv[v] = 0;
				DestroyVehicle(v);
			}
			else if (elenght[v] < 50 && elenght[v] > 0)
			{
				CreateExplosion(vX,vY,vZ,6,1);
				SetVehiclePos(v,vX,vY,vZ-0.2);
			}
		}
	}
	return 1;
}

stock MoveVehicleZ(vehicleid,height)
{
	new Float:vX, Float:vY, Float:vZ;
	GetVehiclePos(vehicleid,vX,vY,vZ);
	if (height > vZ)
	{
		movbool = 1;
	}
	else if (height < vZ)
	{
		movbool = 2;
	}
	else
	{
		movbool = 0;
	}
	movv = SetTimer("MoveV",10,1);
	curmv = vehicleid;
	curheight = height;
	return 1;
}

public MoveV()
{
	new Float:vX, Float:vY, Float:vZ;
	GetVehiclePos(curmv,vX,vY,vZ);
	if (movbool == 1)
	{
		if (curheight > vZ)
		{
			SetVehiclePos(curmv,vX,vY,vZ+0.1);
		}
		else
		{
			KillTimer(movv);
		}
	}
	else if (movbool == 2)
	{
		if (curheight < vZ)
		{
			SetVehiclePos(curmv,vX,vY,vZ-0.1);
		}
		else
		{
			KillTimer(movv);
		}
	}
	return 1;
}

stock MoveVehicleForward(vehicleid,number)
{
	new Float:vX, Float:vY, Float:vZ;
	GetVehiclePos(vehicleid,vX,vY,vZ);
	new Float:Xv, Float:Yv;
	GetXYInFrontOfVehicle(vehicleid,Xv,Yv,0.1);
	movf = SetTimer("MoveF",10,1);
	curmf = vehicleid;
	curnumber = number*10;
	return 1;
}

public MoveF()
{
	curnumber--;
	if (curnumber == 0)
	{
		KillTimer(movf);
	}
	else
	{
		new Float:vX, Float:vY, Float:vZ;
		GetVehiclePos(curmf,vX,vY,vZ);
		new Float:Xv, Float:Yv;
		GetXYInFrontOfVehicle(curmf,Xv,Yv,0.1);
		SetVehiclePos(curmf,Xv,Yv,vZ);
	}
	return 1;
}

stock GetXYInFrontOfVehicle(vehicleid, &Float:x, &Float:y, Float:distance)
{
	new Float:a;
	GetVehiclePos(vehicleid, x, y, a);
	GetVehicleZAngle(vehicleid, a);
	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
}