Advertisement
Guest User

Velocimetro SA-MP GTA V

a guest
Jul 17th, 2015
7,690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.82 KB | None | 0 0
  1. /*
  2.         Velocimetro estilo GTA V
  3.        by: ForT ou dimmy_scarface
  4.               17/07/2015
  5. */
  6.  
  7. #include <a_samp>
  8.  
  9. // (Global Textdraws velocimetro)
  10. new Text:textVelocimetro[5];
  11.  
  12. // (Player Textdraws velocimetro)
  13. new PlayerText:textPlayerVelocimetro[4][MAX_PLAYERS];
  14.  
  15. // (Vendo o velocimetro ou não)
  16. new bool:PlayerVelocimetro[MAX_PLAYERS];
  17.  
  18. // (Timer velocimetro)
  19. new PlayerVelocimetroTimer[MAX_PLAYERS];
  20.  
  21. stock Float:GetVehicleHealthEx(vehicleid)
  22. {
  23.     new Float:health;
  24.     GetVehicleHealth(vehicleid, health);
  25.    
  26.     if ( health > 900.0) {
  27.         return health / 10.0;
  28.     }
  29.     else return ( health / 10.0 )-(24);
  30. }
  31.  
  32. public UpdatePlayerVelocimetro(playerid) {
  33.  
  34.     new playervehicle;
  35.  
  36.     if ( (playervehicle = GetPlayerVehicleID(playerid)) != INVALID_VEHICLE_ID) {
  37.  
  38.         new string_velo[15];
  39.  
  40.         format(string_velo, sizeof (string_velo), "%02d km/h", GetVehicleSpeed(playervehicle));
  41.         PlayerTextDrawSetString(playerid, textPlayerVelocimetro[1][playerid], string_velo);
  42.  
  43.         format(string_velo, sizeof (string_velo), "%.0f%", GetVehicleHealthEx(playervehicle));
  44.         PlayerTextDrawSetString(playerid, textPlayerVelocimetro[3][playerid], string_velo);
  45.        
  46.         /* Desativado:
  47.         format(string_velo, sizeof (string_velo), "%02d Litros", Combustivel[playervehicle]);
  48.         PlayerTextDrawSetString(playerid, textPlayerVelocimetro[2][playerid], string_velo);
  49.         */
  50.     }
  51.     return 1;
  52. }
  53.  
  54. public OnPlayerStateChange(playerid, newstate, oldstate) {
  55.  
  56.     if ( newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) {
  57.         ShowPlayerVelocimetro(playerid) ;
  58.     } else {
  59.         HidePlayerVelocimetro(playerid) ;
  60.     }
  61.     return 1;
  62. }
  63.  
  64. stock ShowPlayerVelocimetro(playerid) {
  65.     if ( PlayerVelocimetro[playerid] ) {
  66.         return 0;
  67.     }
  68.    
  69.     PlayerTextDrawSetString(playerid, textPlayerVelocimetro[0][playerid], getVehicleName(GetPlayerVehicleID(playerid)));
  70.    
  71.     for( new text; text != 5; text++) TextDrawShowForPlayer(playerid, textVelocimetro[text]);
  72.     for( new text; text != 4; text++) PlayerTextDrawShow(playerid, textPlayerVelocimetro[text][playerid]);
  73.     PlayerVelocimetro[playerid] = true ;
  74.     PlayerVelocimetroTimer[playerid] = SetTimerEx("UpdatePlayerVelocimetro", 100, true, "i", playerid);
  75.     return 1;
  76. }
  77.  
  78. stock HidePlayerVelocimetro(playerid) {
  79.     if ( !PlayerVelocimetro[playerid] ) {
  80.         return 0;
  81.     }
  82.     for( new text; text != 5; text++) TextDrawHideForPlayer(playerid, textVelocimetro[text]);
  83.     for( new text; text != 4; text++) PlayerTextDrawHide(playerid, textPlayerVelocimetro[text][playerid]);
  84.     PlayerVelocimetro[playerid] = false ;
  85.     KillTimer(PlayerVelocimetroTimer[playerid]);
  86.     return 1;
  87. }
  88.  
  89. public OnPlayerConnect(playerid) {
  90.  
  91.     PlayerVelocimetro[playerid] = false ;
  92.  
  93.     textPlayerVelocimetro[0][playerid] = CreatePlayerTextDraw(playerid,615.000000, 385.000000, "Nenhum");
  94.     PlayerTextDrawAlignment(playerid,textPlayerVelocimetro[0][playerid], 3);
  95.     PlayerTextDrawBackgroundColor(playerid,textPlayerVelocimetro[0][playerid], 0);
  96.     PlayerTextDrawFont(playerid,textPlayerVelocimetro[0][playerid], 1);
  97.     PlayerTextDrawLetterSize(playerid,textPlayerVelocimetro[0][playerid], 0.330000, 1.299999);
  98.     PlayerTextDrawColor(playerid,textPlayerVelocimetro[0][playerid], -156);
  99.     PlayerTextDrawSetOutline(playerid,textPlayerVelocimetro[0][playerid], 0);
  100.     PlayerTextDrawSetProportional(playerid,textPlayerVelocimetro[0][playerid], 1);
  101.     PlayerTextDrawSetShadow(playerid,textPlayerVelocimetro[0][playerid], 1);
  102.     PlayerTextDrawSetSelectable(playerid,textPlayerVelocimetro[0][playerid], 0);
  103.  
  104.     textPlayerVelocimetro[1][playerid] = CreatePlayerTextDraw(playerid,615.000000, 399.000000, "000 km/h");
  105.     PlayerTextDrawAlignment(playerid,textPlayerVelocimetro[1][playerid], 3);
  106.     PlayerTextDrawBackgroundColor(playerid,textPlayerVelocimetro[1][playerid], 0);
  107.     PlayerTextDrawFont(playerid,textPlayerVelocimetro[1][playerid], 2);
  108.     PlayerTextDrawLetterSize(playerid,textPlayerVelocimetro[1][playerid], 0.250000, 1.299999);
  109.     PlayerTextDrawColor(playerid,textPlayerVelocimetro[1][playerid], -156);
  110.     PlayerTextDrawSetOutline(playerid,textPlayerVelocimetro[1][playerid], 0);
  111.     PlayerTextDrawSetProportional(playerid,textPlayerVelocimetro[1][playerid], 1);
  112.     PlayerTextDrawSetShadow(playerid,textPlayerVelocimetro[1][playerid], 1);
  113.     PlayerTextDrawSetSelectable(playerid,textPlayerVelocimetro[1][playerid], 0);
  114.  
  115.     textPlayerVelocimetro[2][playerid] = CreatePlayerTextDraw(playerid,615.000000, 413.000000, "0 litros");
  116.     PlayerTextDrawAlignment(playerid,textPlayerVelocimetro[2][playerid], 3);
  117.     PlayerTextDrawBackgroundColor(playerid,textPlayerVelocimetro[2][playerid], 0);
  118.     PlayerTextDrawFont(playerid,textPlayerVelocimetro[2][playerid], 2);
  119.     PlayerTextDrawLetterSize(playerid,textPlayerVelocimetro[2][playerid], 0.250000, 1.299999);
  120.     PlayerTextDrawColor(playerid,textPlayerVelocimetro[2][playerid], -156);
  121.     PlayerTextDrawSetOutline(playerid,textPlayerVelocimetro[2][playerid], 0);
  122.     PlayerTextDrawSetProportional(playerid,textPlayerVelocimetro[2][playerid], 1);
  123.     PlayerTextDrawSetShadow(playerid,textPlayerVelocimetro[2][playerid], 1);
  124.     PlayerTextDrawSetSelectable(playerid,textPlayerVelocimetro[2][playerid], 0);
  125.  
  126.     textPlayerVelocimetro[3][playerid] = CreatePlayerTextDraw(playerid,615.000000, 427.000000, "0%");
  127.     PlayerTextDrawAlignment(playerid,textPlayerVelocimetro[3][playerid], 3);
  128.     PlayerTextDrawBackgroundColor(playerid,textPlayerVelocimetro[3][playerid], 0);
  129.     PlayerTextDrawFont(playerid,textPlayerVelocimetro[3][playerid], 2);
  130.     PlayerTextDrawLetterSize(playerid,textPlayerVelocimetro[3][playerid], 0.250000, 1.299999);
  131.     PlayerTextDrawColor(playerid,textPlayerVelocimetro[3][playerid], -156);
  132.     PlayerTextDrawSetOutline(playerid,textPlayerVelocimetro[3][playerid], 0);
  133.     PlayerTextDrawSetProportional(playerid,textPlayerVelocimetro[3][playerid], 1);
  134.     PlayerTextDrawSetShadow(playerid,textPlayerVelocimetro[3][playerid], 1);
  135.     PlayerTextDrawSetSelectable(playerid,textPlayerVelocimetro[3][playerid], 0);
  136.     return 1;
  137. }
  138.  
  139. public OnPlayerDisconnect(playerid) {
  140.  
  141.     if (PlayerVelocimetro[playerid]) {
  142.         KillTimer(PlayerVelocimetroTimer[playerid]);
  143.     }
  144.     return 1;
  145. }
  146.  
  147. public OnFilterScriptInit() {
  148.  
  149.     textVelocimetro[0] = TextDrawCreate(379.000000, 378.000000, "i");
  150.     TextDrawBackgroundColor(textVelocimetro[0], 0);
  151.     TextDrawFont(textVelocimetro[0], 2);
  152.     TextDrawLetterSize(textVelocimetro[0], 28.800073, 2.600000);
  153.     TextDrawColor(textVelocimetro[0], 80);
  154.     TextDrawSetOutline(textVelocimetro[0], 0);
  155.     TextDrawSetProportional(textVelocimetro[0], 1);
  156.     TextDrawSetShadow(textVelocimetro[0], 1);
  157.     TextDrawSetSelectable(textVelocimetro[0], 0);
  158.  
  159.     textVelocimetro[1] = TextDrawCreate(379.000000, 392.000000, "i");
  160.     TextDrawBackgroundColor(textVelocimetro[1], 0);
  161.     TextDrawFont(textVelocimetro[1], 2);
  162.     TextDrawLetterSize(textVelocimetro[1], 28.800073, 2.600000);
  163.     TextDrawColor(textVelocimetro[1], 80);
  164.     TextDrawSetOutline(textVelocimetro[1], 0);
  165.     TextDrawSetProportional(textVelocimetro[1], 1);
  166.     TextDrawSetShadow(textVelocimetro[1], 1);
  167.     TextDrawSetSelectable(textVelocimetro[1], 0);
  168.  
  169.     textVelocimetro[2] = TextDrawCreate(379.000000, 406.000000, "i");
  170.     TextDrawBackgroundColor(textVelocimetro[2], 0);
  171.     TextDrawFont(textVelocimetro[2], 2);
  172.     TextDrawLetterSize(textVelocimetro[2], 28.800073, 2.600000);
  173.     TextDrawColor(textVelocimetro[2], 80);
  174.     TextDrawSetOutline(textVelocimetro[2], 0);
  175.     TextDrawSetProportional(textVelocimetro[2], 1);
  176.     TextDrawSetShadow(textVelocimetro[2], 1);
  177.     TextDrawSetSelectable(textVelocimetro[2], 0);
  178.  
  179.     textVelocimetro[3] = TextDrawCreate(379.000000, 420.000000, "i");
  180.     TextDrawBackgroundColor(textVelocimetro[3], 0);
  181.     TextDrawFont(textVelocimetro[3], 2);
  182.     TextDrawLetterSize(textVelocimetro[3], 28.800073, 2.600000);
  183.     TextDrawColor(textVelocimetro[3], 80);
  184.     TextDrawSetOutline(textVelocimetro[3], 0);
  185.     TextDrawSetProportional(textVelocimetro[3], 1);
  186.     TextDrawSetShadow(textVelocimetro[3], 1);
  187.     TextDrawSetSelectable(textVelocimetro[3], 0);
  188.  
  189.     textVelocimetro[4] = TextDrawCreate(531.000000, 387.000000, "Carro~n~~n~Velocidade~n~~n~Combustivel~n~~n~Lataria");
  190.     TextDrawAlignment(textVelocimetro[4], 3);
  191.     TextDrawBackgroundColor(textVelocimetro[4], 0);
  192.     TextDrawFont(textVelocimetro[4], 2);
  193.     TextDrawLetterSize(textVelocimetro[4], 0.210000, 0.799999);
  194.     TextDrawColor(textVelocimetro[4], -186);
  195.     TextDrawSetOutline(textVelocimetro[4], 0);
  196.     TextDrawSetProportional(textVelocimetro[4], 1);
  197.     TextDrawSetShadow(textVelocimetro[4], 1);
  198.     TextDrawSetSelectable(textVelocimetro[4], 0);
  199.    
  200.     print("*****************************");
  201.     print("*** Velocimetro carregado ***");
  202.     print("*****************************");
  203.     return 1;
  204. }
  205.  
  206. new VehicleNames[212][] =
  207. {
  208.     {"Landstalker"},{"Bravura"},{"Buffalo"},{"Linerunner"},{"Perrenial"},{"Sentinel"},{"Dumper"},
  209.     {"Firetruck"},{"Trashmaster"},{"Stretch"},{"Manana"},{"Infernus"},{"Voodoo"},{"Pony"},{"Mule"},
  210.     {"Cheetah"},{"Ambulance"},{"Leviathan"},{"Moonbeam"},{"Esperanto"},{"Taxi"},{"Washington"},
  211.     {"Bobcat"},{"Mr Whoopee"},{"BF Injection"},{"Hunter"},{"Premier"},{"Enforcer"},{"Securicar"},
  212.     {"Banshee"},{"Predator"},{"Bus"},{"Rhino"},{"Barracks"},{"Hotknife"},{"Trailer 1"},{"Previon"},
  213.     {"Coach"},{"Cabbie"},{"Stallion"},{"Rumpo"},{"RC Bandit"},{"Romero"},{"Packer"},{"Monster"},
  214.     {"Admiral"},{"Squalo"},{"Seasparrow"},{"Pizzaboy"},{"Tram"},{"Trailer 2"},{"Turismo"},
  215.     {"Speeder"},{"Reefer"},{"Tropic"},{"Flatbed"},{"Yankee"},{"Caddy"},{"Solair"},{"Berkley's RC Van"},
  216.     {"Skimmer"},{"PCJ-600"},{"Faggio"},{"Freeway"},{"RC Baron"},{"RC Raider"},{"Glendale"},{"Oceanic"},
  217.     {"Sanchez"},{"Sparrow"},{"Patriot"},{"Quad"},{"Coastguard"},{"Dinghy"},{"Hermes"},{"Sabre"},
  218.     {"Rustler"},{"ZR-350"},{"Walton"},{"Regina"},{"Comet"},{"BMX"},{"Burrito"},{"Camper"},{"Marquis"},
  219.     {"Baggage"},{"Dozer"},{"Maverick"},{"News Chopper"},{"Rancher"},{"FBI Rancher"},{"Virgo"},{"Greenwood"},
  220.     {"Jetmax"},{"Hotring"},{"Sandking"},{"Blista Compact"},{"Police Maverick"},{"Boxville"},{"Benson"},
  221.     {"Mesa"},{"RC Goblin"},{"Hotring Racer A"},{"Hotring Racer B"},{"Bloodring Banger"},{"Rancher"},
  222.     {"Super GT"},{"Elegant"},{"Journey"},{"Bike"},{"Mountain Bike"},{"Beagle"},{"Cropdust"},{"Stunt"},
  223.     {"Tanker"}, {"Roadtrain"},{"Nebula"},{"Majestic"},{"Buccaneer"},{"Shamal"},{"Hydra"},{"FCR-900"},
  224.     {"NRG-500"},{"HPV1000"},{"Cement Truck"},{"Tow Truck"},{"Fortune"},{"Cadrona"},{"FBI Truck"},
  225.     {"Willard"},{"Forklift"},{"Tractor"},{"Combine"},{"Feltzer"},{"Remington"},{"Slamvan"},
  226.     {"Blade"},{"Freight"},{"Streak"},{"Vortex"},{"Vincent"},{"Bullet"},{"Clover"},{"Sadler"},
  227.     {"Firetruck LA"},{"Hustler"},{"Intruder"},{"Primo"},{"Cargobob"},{"Tampa"},{"Sunrise"},{"Merit"},
  228.     {"Utility"},{"Nevada"},{"Yosemite"},{"Windsor"},{"Monster A"},{"Monster B"},{"Uranus"},{"Jester"},
  229.     {"Sultan"},{"Stratum"},{"Elegy"},{"Raindance"},{"RC Tiger"},{"Flash"},{"Tahoma"},{"Savanna"},
  230.     {"Bandito"},{"Freight Flat"},{"Streak Carriage"},{"Kart"},{"Mower"},{"Duneride"},{"Sweeper"},
  231.     {"Broadway"},{"Tornado"},{"AT-400"},{"DFT-30"},{"Huntley"},{"Stafford"},{"BF-400"},{"Newsvan"},
  232.     {"Tug"},{"Trailer 3"},{"Emperor"},{"Wayfarer"},{"Euros"},{"Hotdog"},{"Club"},{"Freight Carriage"},
  233.     {"Trailer 3"},{"Andromada"},{"Dodo"},{"RC Cam"},{"Launch"},{"Police Car (LSPD)"},{"Police Car (SFPD)"},
  234.     {"Police Car (LVPD)"},{"Police Ranger"},{"Picador"},{"S.W.A.T. Van"},{"Alpha"},{"Phoenix"},{"Glendale"},
  235.     {"Sadler"},{"Luggage Trailer A"},{"Luggage Trailer B"},{"Stair Trailer"},{"Boxville"},{"Farm Plow"},
  236.     {"Utility Trailer"}
  237. };
  238.  
  239. stock getVehicleName(vehicleid){
  240.     new vehmodel = GetVehicleModel(vehicleid);
  241.     new nameVeh[75];
  242.  
  243.     if (vehmodel < 400 || vehmodel > 611) {
  244.         strcat(nameVeh, "Nenhum");
  245.         return nameVeh;
  246.     }
  247.     strcat(nameVeh, VehicleNames[vehmodel - 400]);
  248.     return nameVeh;
  249. }
  250.  
  251. stock GetVehicleSpeed(vehicleid)
  252. {
  253.     new Float:xPos[3];
  254.     GetVehicleVelocity(vehicleid, xPos[0], xPos[1], xPos[2]);
  255.     return floatround(floatsqroot(xPos[0] * xPos[0] + xPos[1] * xPos[1] + xPos[2] * xPos[2]) * 170.00);
  256. }
  257.  
  258. forward UpdatePlayerVelocimetro(playerid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement