Quantcast
Channel: SA-MP Forums - Filterscripts
Viewing all articles
Browse latest Browse all 595

[FilterScript] Simple Speedo

$
0
0
Simple Speedo


Whats This now?
Its a simple textdraw based Speedo Meter which shows your speed of your vehicle, its model information and server vehicle id.

Why did I do this?
I know, I know people are thinking there are already many speedo available on forums, why another one? Well, This has nothing special To be honest but, I was getting bored and I thought what is it that I could script this fast? I thought of Speedo so I did this. Took me around 30 mins including making textdraws.

Screens:



Here is the Source:
PHP Code:

/*======================[Simple Speedo by GTLS]=====================================*/

#include <a_samp>
#include <zcmd>

//Forwards
forward ShowPlayerSpeedo(playerid);
forward HidePlayerSpeedo(playerid);
forward SpeedoUpdate(playerid);

//TextDraw
new PlayerText:SpeedoTextDraws[7];

new 
SpeedoTimer[MAX_PLAYERS];

public 
OnFilterScriptInit()
{
    print(
"\nSpeed-o-Meter Loaded.");
    return 
1;
}

public 
OnFilterScriptExit()
{
    
printf("\nSpeed-o-Meter Unloaded.");
    return 
1;
}
new 
VehicleNames[212][] = {
   
"Landstalker",  "Bravura",  "Buffalo""Linerunner""Perennial""Sentinel",
   
"Dumper",  "Firetruck" ,  "Trashmaster" ,  "Stretch",  "Manana",  "Infernus",
   
"Voodoo""Pony",  "Mule""Cheetah""Ambulance",  "Leviathan",  "Moonbeam",
   
"Esperanto""Taxi",  "Washington",  "Bobcat",  "Mr Whoopee""BF Injection",
   
"Hunter""Premier",  "Enforcer",  "Securicar""Banshee""Predator""Bus",
   
"Rhino",  "Barracks",  "Hotknife",  "Trailer",  "Previon""Coach""Cabbie",
   
"Stallion""Rumpo""RC Bandit",  "Romero""Packer""Monster",  "Admiral",
   
"Squalo""Seasparrow""Pizzaboy""Tram""Trailer",  "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""Boxville""Benson","Mesa","RC Goblin",
   
"Hotring Racer""Hotring Racer""Bloodring Banger""Rancher",  "Super GT",
   
"Elegant""Journey""Bike""Mountain Bike""Beagle""Cropdust""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""Hustler""Intruder""Primo""Cargobob",  "Tampa",
   
"Sunrise""Merit",  "Utility Truck",  "Nevada""Yosemite""Windsor",  "Monster",
   
"Monster","Uranus","Jester","Sultan","Stratum","Elegy","Raindance","RCTiger",
   
"Flash","Tahoma","Savanna""Bandito""Freight""Trailer""Kart""Mower",
   
"Dune""Sweeper""Broadway""Tornado""AT-400",  "DFT-30""Huntley",
   
"Stafford""BF-400""Newsvan","Tug","Trailer","Emperor","Wayfarer","Euros",
   
"Hotdog""Club""Trailer""Trailer","Andromada","Dodo","RC Cam""Launch",
   
"Police Car (LSPD)""Police Car (SFPD)","Police Car (LVPD)","Police Ranger",
   
"Picador",   "S.W.A.T. Van",  "Alpha",   "Phoenix",   "Glendale",   "Sadler",
   
"Luggage Trailer","Luggage Trailer","Stair Trailer""Boxville""Farm Plow",
   
"Utility Trailer"
};

stock GetVehicleName(vehicleid//Thanks to Tee
{
    new 
String[25];
    
format(String,sizeof(String),"%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return 
String;
}

LoadSpeedoTextDraws(playerid//Loading TextDraws
{
    
SpeedoTextDraws[0] = CreatePlayerTextDraw(playerid541.250000358.583343"box");
    
PlayerTextDrawLetterSize(playeridSpeedoTextDraws[0], 0.0000001.562500);
    
PlayerTextDrawTextSize(playeridSpeedoTextDraws[0], 540.0000000.000000);
    
PlayerTextDrawAlignment(playeridSpeedoTextDraws[0], 1);
    
PlayerTextDrawColor(playeridSpeedoTextDraws[0], -1);
    
PlayerTextDrawUseBox(playeridSpeedoTextDraws[0], 1);
    
PlayerTextDrawBoxColor(playeridSpeedoTextDraws[0], 8388863);
    
PlayerTextDrawSetShadow(playeridSpeedoTextDraws[0], 0);
    
PlayerTextDrawBackgroundColor(playeridSpeedoTextDraws[0], 255);
    
PlayerTextDrawFont(playeridSpeedoTextDraws[0], 1);
    
PlayerTextDrawSetProportional(playeridSpeedoTextDraws[0], 1);

    
SpeedoTextDraws[1] = CreatePlayerTextDraw(playerid545.000000375.499969"box");
    
PlayerTextDrawLetterSize(playeridSpeedoTextDraws[1], 0.000000, -0.250000);
    
PlayerTextDrawTextSize(playeridSpeedoTextDraws[1], 630.0000000.000000);
    
PlayerTextDrawAlignment(playeridSpeedoTextDraws[1], 1);
    
PlayerTextDrawColor(playeridSpeedoTextDraws[1], -1);
    
PlayerTextDrawUseBox(playeridSpeedoTextDraws[1], 1);
    
PlayerTextDrawBoxColor(playeridSpeedoTextDraws[1], 8388863);
    
PlayerTextDrawSetShadow(playeridSpeedoTextDraws[1], 0);
    
PlayerTextDrawBackgroundColor(playeridSpeedoTextDraws[1], 255);
    
PlayerTextDrawFont(playeridSpeedoTextDraws[1], 1);
    
PlayerTextDrawSetProportional(playeridSpeedoTextDraws[1], 1);

    
SpeedoTextDraws[2] = CreatePlayerTextDraw(playerid540.000000378.416687"box");
    
PlayerTextDrawLetterSize(playeridSpeedoTextDraws[2], 0.0000003.875000);
    
PlayerTextDrawTextSize(playeridSpeedoTextDraws[2], 632.0000000.000000);
    
PlayerTextDrawAlignment(playeridSpeedoTextDraws[2], 1);
    
PlayerTextDrawColor(playeridSpeedoTextDraws[2], -1);
    
PlayerTextDrawUseBox(playeridSpeedoTextDraws[2], 1);
    
PlayerTextDrawBoxColor(playeridSpeedoTextDraws[2], -252645251);
    
PlayerTextDrawSetShadow(playeridSpeedoTextDraws[2], 0);
    
PlayerTextDrawBackgroundColor(playeridSpeedoTextDraws[2], 255);
    
PlayerTextDrawFont(playeridSpeedoTextDraws[2], 1);
    
PlayerTextDrawSetProportional(playeridSpeedoTextDraws[2], 1);

    
SpeedoTextDraws[3] = CreatePlayerTextDraw(playerid538.750000376.083343"");
    
PlayerTextDrawTextSize(playeridSpeedoTextDraws[3], 43.00000036.000000);
    
PlayerTextDrawAlignment(playeridSpeedoTextDraws[3], 1);
    
PlayerTextDrawColor(playeridSpeedoTextDraws[3], -1);
    
PlayerTextDrawSetShadow(playeridSpeedoTextDraws[3], 0);
    
PlayerTextDrawBackgroundColor(playeridSpeedoTextDraws[3], -252645246);
    
PlayerTextDrawFont(playeridSpeedoTextDraws[3], 5);
    
PlayerTextDrawSetProportional(playeridSpeedoTextDraws[3], 0);
    
PlayerTextDrawSetPreviewModel(playeridSpeedoTextDraws[3], 411);
    
PlayerTextDrawSetPreviewRot(playeridSpeedoTextDraws[3], 0.0000000.00000060.0000001.000000);
    
PlayerTextDrawSetPreviewVehCol(playeridSpeedoTextDraws[3], 31);

    
SpeedoTextDraws[4] = CreatePlayerTextDraw(playerid591.250000376.666625"Infernus");
    
PlayerTextDrawLetterSize(playeridSpeedoTextDraws[4], 0.2343741.074999);
    
PlayerTextDrawTextSize(playeridSpeedoTextDraws[4], -44.0000000.000000);
    
PlayerTextDrawAlignment(playeridSpeedoTextDraws[4], 1);
    
PlayerTextDrawColor(playeridSpeedoTextDraws[4], -16776961);
    
PlayerTextDrawSetShadow(playeridSpeedoTextDraws[4], 0);
    
PlayerTextDrawBackgroundColor(playeridSpeedoTextDraws[4], 255);
    
PlayerTextDrawFont(playeridSpeedoTextDraws[4], 1);
    
PlayerTextDrawSetProportional(playeridSpeedoTextDraws[4], 1);

    
SpeedoTextDraws[5] = CreatePlayerTextDraw(playerid603.125000393.583435"65");
    
PlayerTextDrawLetterSize(playeridSpeedoTextDraws[5], 0.2587491.104165);
    
PlayerTextDrawAlignment(playeridSpeedoTextDraws[5], 1);
    
PlayerTextDrawColor(playeridSpeedoTextDraws[5], 41215);
    
PlayerTextDrawSetShadow(playeridSpeedoTextDraws[5], 0);
    
PlayerTextDrawBackgroundColor(playeridSpeedoTextDraws[5], 255);
    
PlayerTextDrawFont(playeridSpeedoTextDraws[5], 1);
    
PlayerTextDrawSetProportional(playeridSpeedoTextDraws[5], 1);

    
SpeedoTextDraws[6] = CreatePlayerTextDraw(playerid560.000000358.583343"0 Mph");
    
PlayerTextDrawLetterSize(playeridSpeedoTextDraws[6], 0.3793751.401666);
    
PlayerTextDrawTextSize(playeridSpeedoTextDraws[6], 655.0000000.000000);
    
PlayerTextDrawAlignment(playeridSpeedoTextDraws[6], 1);
    
PlayerTextDrawColor(playeridSpeedoTextDraws[6], -65281);
    
PlayerTextDrawSetShadow(playeridSpeedoTextDraws[6], 0);
    
PlayerTextDrawBackgroundColor(playeridSpeedoTextDraws[6], 255);
    
PlayerTextDrawFont(playeridSpeedoTextDraws[6], 2);
    
PlayerTextDrawSetProportional(playeridSpeedoTextDraws[6], 1);

}
public 
OnPlayerConnect(playerid)
{
    
SetPVarInt(playerid"SpeedoON"1);
    
SendClientMessage(playerid0xFF00AAFF,"Speedo Enabled. You can use /togspeedo to disable/re-enable it.");
    
LoadSpeedoTextDraws(playerid);
    return 
1;
}

public 
ShowPlayerSpeedo(playerid)
{
    new 
vehname[16],vehid GetPlayerVehicleID(playerid), idstr[4], vehmodel GetVehicleModel(vehid);
    
    
SpeedoTimer[playerid] = SetTimerEx("SpeedoUpdate",1000,1,"i",playerid); //Timer for Updating Speed.

    
    
PlayerTextDrawSetPreviewModel(playeridSpeedoTextDraws[3], vehmodel); //Setting the PreviewModel
    
format(vehnamesizeof(vehname), "%s"GetVehicleName(vehid));
    
format(idstrsizeof(idstr), "%d"vehid);
    
PlayerTextDrawSetString(playeridSpeedoTextDraws[4], vehname); //Setting Vehicle Name
    
PlayerTextDrawSetString(playeridSpeedoTextDraws[5], idstr); //Setting Vehicle ID

    
PlayerTextDrawShow(playeridSpeedoTextDraws[0]);
    
PlayerTextDrawShow(playeridSpeedoTextDraws[1]);
    
PlayerTextDrawShow(playeridSpeedoTextDraws[2]);
    
PlayerTextDrawShow(playeridSpeedoTextDraws[3]);
    
PlayerTextDrawShow(playeridSpeedoTextDraws[4]);
    
PlayerTextDrawShow(playeridSpeedoTextDraws[5]);
    
PlayerTextDrawShow(playeridSpeedoTextDraws[6]);
    return 
1;
}

public 
HidePlayerSpeedo(playerid)
{
    
KillTimer(SpeedoTimer[playerid]); //Killing of Timer
    
    
PlayerTextDrawHide(playeridSpeedoTextDraws[0]);
    
PlayerTextDrawHide(playeridSpeedoTextDraws[1]);
    
PlayerTextDrawHide(playeridSpeedoTextDraws[2]);
    
PlayerTextDrawHide(playeridSpeedoTextDraws[3]);
    
PlayerTextDrawHide(playeridSpeedoTextDraws[4]);
    
PlayerTextDrawHide(playeridSpeedoTextDraws[5]);
    
PlayerTextDrawHide(playeridSpeedoTextDraws[6]);
    return 
1;
}


stock GetVehicleSpeed(vehicleid//Credits someone on SAMP Forums forgot the name
{
    new 
Float:xFloat:yFloat:zvel;

    
GetVehicleVelocity(vehicleidxyz);

    
//vel = floatround( floatsqroot( x*x + y*y + z*z ) * 180 );            // KM/H
    
vel floatroundfloatsqrootx*y*z*) * 180 1.60934); // MPH (Comment this line if you want speed in KM

    
return vel;
}

public 
SpeedoUpdate(playerid)
{
    new 
pSpeed[8], vehid GetPlayerVehicleID(playerid);
    
format(pSpeedsizeof(pSpeed), "%i MPH",GetVehicleSpeed(vehid)); //Mph
//    format(pSpeed, sizeof(pSpeed), "%i KMpH",GetVehicleSpeed(vehid)); //KmpH
    
PlayerTextDrawSetString(playeridSpeedoTextDraws[6], pSpeed);
    return 
1;
}

public 
OnPlayerDisconnect(playeridreason)
{
    
KillTimer(SpeedoTimer[playerid]); //Just a Precaution, not needed.
    
return 1;
}

CMD:togspeedo(playeridparams[])
{
    if(
GetPVarInt(playerid"SpeedoON") == 0)
    {
        
SendClientMessage(playerid, -1"You have enabled the Speedo.");
        
SetPVarInt(playerid"SpeedoON"1);
         if(
IsPlayerInAnyVehicle(playerid)) ShowPlayerSpeedo(playerid);
     }
     else
     {
        
SendClientMessage(playerid, -1"You have disabled the Speedo.");
        
SetPVarInt(playerid"SpeedoON"0);
        
HidePlayerSpeedo(playerid);
     }

    return 
1;
}
public 
OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    if(
GetPVarInt(playerid"SpeedoON") == 0SendClientMessage(playerid, -1"You have disabled Speedo. Use /togspeedo to tog back in.");
    if(
GetPVarInt(playerid"SpeedoON") == 1)
        
ShowPlayerSpeedo(playerid);
    return 
1;
}

public 
OnPlayerExitVehicle(playeridvehicleid)
{
    return 
1;
}

public 
OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        if(
GetPVarInt(playerid"SpeedoON") == 1)
                
ShowPlayerSpeedo(playerid);
    }

    if(
oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER && newstate == PLAYER_STATE_ONFOOT)
    {
        
HidePlayerSpeedo(playerid);
    }
    return 
1;


How to Use?
Well, Here are the steps if you dont know how to start.
  1. Copy this code into a blank .pwn file.
  2. You will need zcmd include to compile this. If you use something else, you can modify the command.
  3. Now, this shows Speed in MpH and Kmph what ever you want. If you want to show speed in KMph, comment the line inside GetVehicleSpeed Function and Uncomment a line inside ShowPlayerSpeedo().
  4. Once its compiled, add it to your filterscripts folder and inside your server.cfg
    Code:

    filterscripts Speedo
    .
  5. Thats it! Enter a Vehicle you want and Speedo will work automatically.

Note: This may or may not be 100% Accurate Speed of a vehicle.

Credits:
Kalcor - SAMP
ZCMD - Zeex
adri1 - I used his TextDraw editor.
Credits for Functions are given inside the code.

If you have any problem running this, ask me here. :)

Viewing all articles
Browse latest Browse all 595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>