#include <a_samp>

new Text:SpeedText[3];
new PlayerVehicle[212][] = {
"Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel", "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana",
"Infernus", "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam", "Esperanto", "Taxi", "Washington", "Bobcat",
"Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus", "Rhino", "Barracks", "Hotknife",
"Trailer 1", "Previon", "Coach", "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral", "Squalo",
"Seasparrow", "Pizzaboy", "Tram", "Trailer 2", "Turismo", "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair",
"Berkley's RC Van", "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale", "Oceanic", "Sanchez", "Sparrow",
"Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX", "Burrito",
"Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper", "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring",
"Sandking", "Blista Compact", "Police Maverick", "Boxvillde", "Benson", "Mesa", "RC Goblin", "Hotring Racer A", "Hotring Racer B",
"Bloodring Banger", "Rancher", "Super GT", "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster","Stunt",  "Tanker",
"Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra", "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
"Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer", "Remington", "Slamvan", "Blade", "Freight", "Streak",
"Vortex", "Vincent", "Bullet", "Clover", "Sadler", "Firetruck LA", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa", "Sunrise", "Merit",
"Utility", "Nevada", "Yosemite", "Windsor", "Monster A", "Monster B", "Uranus", "Jester", "Sultan", "Stratum", "Elegy", "Raindance",
"RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito", "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper", "Broadway",
"Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400", "News Van", "Tug", "Trailer 3", "Emperor", "Wayfarer", "Euros", "Hotdog",
"Club", "Freight Carriage", "Trailer 4", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car (LSPD)", "Police Car (SFPD)",
"Police Car (LVPD)", "Police Ranger", "Picador", "S.W.A.T", "Alpha", "Phoenix", "Glendale", "Sadler", "Luggage Trailer A",
"Luggage Trailer B", "Stairs", "Boxville", "Tiller", "Utility Trailer" };

public OnFilterScriptInit()
{
	print("-----------------------");
	print(" Speed Info by Elfuego ");
	print("-----------------------");
	SpeedText[0] = TextDrawCreate(543.000000,419.000000,"speedo");
	TextDrawUseBox(SpeedText[0],1);
	TextDrawBoxColor(SpeedText[0],0x00000066);
	TextDrawTextSize(SpeedText[0],624.000000,0.000000);
	TextDrawAlignment(SpeedText[0],0);
	TextDrawBackgroundColor(SpeedText[0],0x000000ff);
	TextDrawFont(SpeedText[0],2);
	TextDrawLetterSize(SpeedText[0],0.299999,1.000000);
	TextDrawColor(SpeedText[0],0xffffffff);
	TextDrawSetOutline(SpeedText[0],1);
	TextDrawSetOutline(SpeedText[0],1);
	TextDrawSetProportional(SpeedText[0],1);
	TextDrawSetShadow(SpeedText[0],1);
	SpeedText[1] = TextDrawCreate(543.000000,417.000000,".");
	TextDrawUseBox(SpeedText[1],1);
	TextDrawBoxColor(SpeedText[1],0x000000ff);
	TextDrawTextSize(SpeedText[1],624.000000,-8.000000);
	TextDrawAlignment(SpeedText[1],0);
	TextDrawBackgroundColor(SpeedText[1],0x000000ff);
	TextDrawFont(SpeedText[1],3);
	TextDrawLetterSize(SpeedText[1],0.099999,-0.200000);
	TextDrawColor(SpeedText[1],0x000000ff);
	TextDrawSetOutline(SpeedText[1],1);
	TextDrawSetProportional(SpeedText[1],1);
	TextDrawSetShadow(SpeedText[1],1);
	SpeedText[2] = TextDrawCreate(543.000000,442.000000,".");
	TextDrawUseBox(SpeedText[2],1);
	TextDrawBoxColor(SpeedText[2],0x000000ff);
	TextDrawTextSize(SpeedText[2],624.000000,-8.000000);
	TextDrawAlignment(SpeedText[2],0);
	TextDrawBackgroundColor(SpeedText[2],0x000000ff);
	TextDrawFont(SpeedText[2],3);
	TextDrawLetterSize(SpeedText[2],0.099999,-0.200000);
	TextDrawColor(SpeedText[2],0x000000ff);
	TextDrawSetOutline(SpeedText[2],1);
	TextDrawSetProportional(SpeedText[2],1);
	TextDrawSetShadow(SpeedText[2],1);
	return 1;
}

stock GetVehicleSpeed(carid)
{
    new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
    GetVehicleVelocity(carid,Vx,Vy,Vz);
    rtn = floatsqroot(Vx*Vx+Vy*Vy+Vz*Vz);
    return floatround(rtn * 100);
}

public OnPlayerUpdate(playerid)
{
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		new string[128]; new PlayerVehicleModelID = GetVehicleModel(GetPlayerVehicleID(playerid)); PlayerVehicleModelID -= 400;
		format(string,sizeof(string),"~w~km/h: ~r~%i~n~~y~%s",GetVehicleSpeed(GetPlayerVehicleID(playerid)),PlayerVehicle[PlayerVehicleModelID]);
		TextDrawSetString(SpeedText[0],string);
    }
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(newstate == PLAYER_STATE_DRIVER)
	{
        TextDrawShowForPlayer(playerid,Text:SpeedText[0]);
        TextDrawShowForPlayer(playerid,Text:SpeedText[1]);
        TextDrawShowForPlayer(playerid,Text:SpeedText[2]);
	}
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
  TextDrawHideForPlayer(playerid,Text:SpeedText[0]);
  TextDrawHideForPlayer(playerid,Text:SpeedText[1]);
  TextDrawHideForPlayer(playerid,Text:SpeedText[2]);
  return 1;
}
