Darky

Darky's Speedometer

Feb 23rd, 2012
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.88 KB | None | 0 0
  1. //______________________________________________________________________________
  2. #include <a_samp>
  3. //______________________________________________________________________________
  4. #define SLOTS 200
  5. //______________________________________________________________________________
  6. new Text:Vehicle    [MAX_PLAYERS];
  7. new Text:MPH        [MAX_PLAYERS];
  8. new Text:Health     [MAX_PLAYERS];
  9. //______________________________________________________________________________
  10. new SpeedometerActivated[MAX_PLAYERS];
  11. new Float:sVehicle_X[MAX_VEHICLES];
  12. new Float:sVehicle_Y[MAX_VEHICLES];
  13. new Float:sVehicle_Z[MAX_VEHICLES];
  14. //______________________________________________________________________________
  15. enum SpeedometerPosition
  16. {
  17.     Float:sX,
  18.     Float:sY,
  19.     Float:sZ
  20. }
  21. new SavePlayerPos[SLOTS][SpeedometerPosition];
  22. //______________________________________________________________________________
  23. new VehicleNames[][] =
  24. {
  25.     "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
  26.     "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
  27.     "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
  28.     "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
  29.     "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
  30.     "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
  31.     "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
  32.     "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
  33.     "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
  34.     "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
  35.     "Oceanic","Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
  36.     "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
  37.     "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
  38.     "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
  39.     "Blista Compact", "Police Maverick", "Boxvillde", "Benson", "Mesa", "RC Goblin",
  40.     "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
  41.     "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
  42.     "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
  43.     "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
  44.     "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer",
  45.     "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
  46.     "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo",
  47.     "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
  48.     "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
  49.     "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
  50.     "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
  51.     "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
  52.     "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
  53.     "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
  54.     "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
  55.     "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
  56.     "Tiller", "Utility Trailer"
  57. };
  58. //______________________________________________________________________________
  59. forward SpeedometerUpdate();
  60. //______________________________________________________________________________
  61. public OnFilterScriptInit()
  62. {
  63.     print("               ,        ,");
  64.     print("              /(        )`");
  65.     print("              | |___   / ||");
  66.     print("              /- _  `-/  '");
  67.     print("             (/|/ | |   /|");
  68.     print("             / /   | `    |");
  69.     print("             O O   ) /    |");
  70.     print("             `-^--'`<     '");
  71.     print("            (_.)  _  )   /");
  72.     print("             `.___/`    /");
  73.     print("               `-----' /");
  74.     print("  <----.     __ / __   |");
  75.     print("  <----|====O)))==) |) /====");
  76.     print("  <----'    `--' `.__,' |");
  77.     print("               |        |");
  78.     print("                |       /");
  79.     print("           ______( (_  / |______");
  80.     print("         ,'  ,-----'   |        |");
  81.     print("         `--{__________)       //");
  82.     print("+----------------------------+");
  83.     print("|     Darky's Speedometer    |");
  84.     print("|         WAS LOADED!        |");
  85.     print("+----------------------------+");
  86.     print("|   Copyright @ 2012 Darky   |");
  87.     print("+----------------------------+");
  88.     SetTimer("SpeedometerUpdate", 200, 1);
  89.     for(new v=0; v<MAX_VEHICLES; v++)
  90.     {
  91.         SaveLastPosition(v);
  92.     }
  93.     for(new i=0; i<SLOTS; i++)
  94.     {
  95.         Vehicle[i] = TextDrawCreate(445.000000, 379.000000," ");
  96.         TextDrawBackgroundColor(Vehicle[i], 255);
  97.         TextDrawFont(Vehicle[i], 1);
  98.         TextDrawLetterSize(Vehicle[i], 0.500000, 1.000000);
  99.         TextDrawColor(Vehicle[i], -1);
  100.         TextDrawSetOutline(Vehicle[i], 0);
  101.         TextDrawSetProportional(Vehicle[i], 1);
  102.         TextDrawSetShadow(Vehicle[i], 1);
  103.         TextDrawUseBox(Vehicle[i], 1);
  104.         TextDrawBoxColor(Vehicle[i], 252645200);
  105.         TextDrawTextSize(Vehicle[i], 661.000000, -33.000000);
  106. //______________________________________________________________________________
  107.         MPH[i] = TextDrawCreate(445.000000, 397.000000," ");
  108.         TextDrawBackgroundColor(MPH[i], 255);
  109.         TextDrawFont(MPH[i], 1);
  110.         TextDrawLetterSize(MPH[i], 0.500000, 1.000000);
  111.         TextDrawColor(MPH[i], -1);
  112.         TextDrawSetOutline(MPH[i], 0);
  113.         TextDrawSetProportional(MPH[i], 1);
  114.         TextDrawSetShadow(MPH[i], 1);
  115.         TextDrawUseBox(MPH[i], 1);
  116.         TextDrawBoxColor(MPH[i], 252645200);
  117.         TextDrawTextSize(MPH[i], 661.000000, -33.000000);
  118. //______________________________________________________________________________
  119.         Health[i] = TextDrawCreate(445.000000,415.000000," ");
  120.         TextDrawBackgroundColor(Health[i], 255);
  121.         TextDrawFont(Health[i], 1);
  122.         TextDrawLetterSize(Health[i], 0.500000, 1.000000);
  123.         TextDrawColor(Health[i], -1);
  124.         TextDrawSetOutline(Health[i], 0);
  125.         TextDrawSetProportional(Health[i], 1);
  126.         TextDrawSetShadow(Health[i], 1);
  127.         TextDrawUseBox(Health[i], 1);
  128.         TextDrawBoxColor(Health[i], 252645200);
  129.         TextDrawTextSize(Health[i], 661.000000, -33.000000);
  130.     }
  131.     return 1;
  132. }
  133. //______________________________________________________________________________
  134. public SpeedometerUpdate()
  135. {
  136.     new Float:Speedo_X,Float:Speedo_Y,Float:Speedo_Z;
  137.     new Float:PlayerSpeedDistance,value;
  138.     new Float:Speedometer_HP;
  139.    
  140.     for(new i=0; i<SLOTS; i++)
  141.     {
  142.         if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
  143.         {
  144.             GetPlayerPos(i, Speedo_X, Speedo_Y, Speedo_Z);
  145.             GetPlayerVehicleID(i);
  146.             GetVehicleHealth(GetPlayerVehicleID(i), Speedometer_HP);
  147.             PlayerSpeedDistance = floatsqroot(floatpower(floatabs(floatsub(Speedo_X,SavePlayerPos[i][sX])),2)+floatpower(floatabs(floatsub(Speedo_Y,SavePlayerPos[i][sY])),2)+floatpower(floatabs(floatsub(Speedo_Z,SavePlayerPos[i][sZ])),2));
  148.             value = floatround(PlayerSpeedDistance * 5000);
  149.            
  150.             new str1[256],str2[256],str3[256];
  151.             if(SpeedometerActivated[i] == 0)
  152.             {
  153.                 TextDrawShowForPlayer(i, Vehicle[i]); TextDrawShowForPlayer(i, MPH[i]);
  154.                 TextDrawShowForPlayer(i, Health[i]);
  155.                 SpeedometerActivated[i] = 1;
  156.             }
  157.             new MPH_Speed = floatround(value/1000);
  158.            
  159.             format(str1,sizeof(str1),"Vehicle: ~y~%s",VehicleNames[GetVehicleModel(GetPlayerVehicleID(i))-400]);
  160.             TextDrawSetString(Vehicle[i], str1);
  161.            
  162.             if(MPH_Speed >= 200)
  163.             {
  164.                 format(str2,sizeof(str2),"MP/H: ~r~%d",MPH_Speed);
  165.                 TextDrawSetString(MPH[i], str2);
  166.             }
  167.             else if(MPH_Speed >= 150)
  168.             {
  169.                 format(str2,sizeof(str2),"MP/H: ~y~%d",MPH_Speed);
  170.                 TextDrawSetString(MPH[i], str2);
  171.             }
  172.             else if(MPH_Speed >= 100)
  173.             {
  174.                 format(str2,sizeof(str2),"MP/H: ~g~%d",MPH_Speed);
  175.                 TextDrawSetString(MPH[i], str2);
  176.             }
  177.             else
  178.             {
  179.                 format(str2,sizeof(str2),"MP/H: ~b~%d",MPH_Speed);
  180.                 TextDrawSetString(MPH[i], str2);
  181.             }
  182.            
  183.             if(Speedometer_HP >= 551)
  184.             {
  185.                 format(str3,sizeof(str3),"Health: ~g~%.2f", Speedometer_HP);
  186.                 TextDrawSetString(Health[i], str3);
  187.             }
  188.             else if(Speedometer_HP >= 361)
  189.             {
  190.                 format(str3,sizeof(str3),"Health: ~y~%.2f", Speedometer_HP);
  191.                 TextDrawSetString(Health[i], str3);
  192.             }
  193.             else
  194.             {
  195.                 format(str3,sizeof(str3),"Health: ~r~%.2f", Speedometer_HP);
  196.                 TextDrawSetString(Health[i], str3);
  197.             }
  198.         }
  199.         SavePlayerPos[i][sX] = Speedo_X, SavePlayerPos[i][sY] = Speedo_Y, SavePlayerPos[i][sZ] = Speedo_Z;
  200.     }
  201.     for(new i=0; i<SLOTS; i++)
  202.     {
  203.         if(!IsPlayerInAnyVehicle(i))
  204.         {
  205.             TextDrawHideForPlayer(i, Vehicle[i]); TextDrawHideForPlayer(i, MPH[i]);
  206.             TextDrawHideForPlayer(i, Health[i]);
  207.             SpeedometerActivated[i] = 0;
  208.         }
  209.     }
  210. }
  211. //______________________________________________________________________________
  212. public OnVehicleSpawn(vehicleid)
  213. {
  214.     SaveLastPosition(vehicleid);
  215.     return 1;
  216. }
  217. //______________________________________________________________________________
  218. stock GetDistanceToLastPoint(vehicleid)
  219. {
  220.     new Float:x2, Float:y2, Float:z2, Float:output;
  221.     GetVehiclePos(vehicleid, x2, y2, z2);
  222.     output = floatsqroot(floatpower(floatabs(floatsub(x2, sVehicle_X[vehicleid])), 2)+floatpower(floatabs(floatsub(y2, sVehicle_Y[vehicleid])), 2)+floatpower(floatabs(floatsub(z2, sVehicle_Z[vehicleid])), 2));
  223.     return floatround(output);
  224. }
  225. //______________________________________________________________________________
  226. stock SaveLastPosition(vehicleid)
  227. {
  228.     new Float:SaveCoord_X, Float:SaveCoord_Y, Float:SaveCoord_Z;
  229.     GetVehiclePos(vehicleid, SaveCoord_X, SaveCoord_Y, SaveCoord_Z);
  230.     sVehicle_X[vehicleid]=SaveCoord_X;
  231.     sVehicle_Y[vehicleid]=SaveCoord_Y;
  232.     sVehicle_Z[vehicleid]=SaveCoord_Z;
  233. }
  234. //______________________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment