Advertisement
JonathanFeitosa2

[PAWN]jVelocimetro Simples para DRIFT/DM/CORRIDA/4FUN

Aug 2nd, 2016
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.94 KB | None | 0 0
  1. /*
  2.  
  3. Criado Por: [JFS]: Jonathan Feitosa
  4. Publicado: 02/08/2016
  5. Contato: http://forum.sa-mp.com/member.php?u=116320
  6.  
  7. */
  8.  
  9. #include <a_samp>
  10. #include <progressbar>
  11.  
  12. #define ATUALIZACAOVELO 1 // EM SEGUNDOS E NAO EM MILISEGUNDOS.
  13.  
  14. new
  15.     PlayerText:TDjVelocimetro[MAX_PLAYERS][6],
  16.     bool:EntrouVeiculo[MAX_PLAYERS],
  17.     StringJFS[128],
  18.     tdstring[50],
  19.     TimerVelocimetro[MAX_PLAYERS],
  20.     PlayerBar:BarjVelocimetro[MAX_PLAYERS] = {INVALID_PLAYER_BAR_ID, ...}
  21. ;
  22.  
  23. stock GetPlayerSpeed(playerid)
  24. {
  25.     new Float:ST[4];
  26.     if(IsPlayerInAnyVehicle(playerid))
  27.     GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
  28.     else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
  29.     ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 179.28625;
  30.     return floatround(ST[3]);
  31. }
  32.  
  33. new CarModelNameFromID[][] =
  34.     {"Landstalker","Bravura","Buffalo","Linerunner","Pereniel","Sentinel","Dumper","Firetruck","Trashmaster",
  35.     "Stretch","Manana","Infernus","Voodoo","Pony","Mule","Cheetah","Ambulancia","Leviathan","Moonbeam","Esperanto",
  36.     "Taxi","Washington","Bobcat","Mr Whoopee","BF Injection","Hunter","Premier","Enforcer","Securicar","Banshee",
  37.     "Predator","Bus","Rhino","Barracks","Hotknife","Trailer","Previon","Coach","Cabbie","Stallion","Rumpo",
  38.     "RC Bandit","Romero","Packer","Monster","Admiral","Squalo","Seasparrow","Pizzaboy","Tram","Trailer",
  39.     "Turismo","Speeder","Reefer","Tropic","Flatbed","Yankee","Caddy","Solair","Berkley's RC Van","Skimmer",
  40.     "PCJ-600","Faggio","Freeway","RC Baron","RC Raider","Glendale","Oceanic","Sanchez","Sparrow","Patriot",
  41.     "Quad","Coastguard","Dinghy","Hermes","Sabre","Rustler","ZR-350","Walton","Regina","Comet","BMX",
  42.     "Burrito","Camper","Marquis","Baggage","Dozer","Maverick","News Chopper","Rancher","FBI Rancher","Virgo",
  43.     "Greenwood","Jetmax","Hotring","Sandking","Blista Compact","Maverick Policial","Boxville","Benson","Mesa",
  44.     "RC Goblin","Hotring Racer A","Hotring Racer B","Bloodring Banger","Rancher","Super GT","Elegant",
  45.     "Journey","Bike","Mountain Bike","Beagle","Cropdust","Stunt","Tanker","RoadTrain","Nebula","Majestic",
  46.     "Buccaneer","Shamal","Hydra","FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune","Cadrona",
  47.     "FBI Truck","Willard","Forklift","Tractor","Combine","Feltzer","Remington","Slamvan","Blade","Freight",
  48.     "Streak","Vortex","Vincent","Bullet","Clover","Sadler","Firetruck","Hustler","Intruder","Primo","Cargobob",
  49.     "Tampa","Sunrise","Merit","Utility","Nevada","Yosemite","Windsor","Monster A","Monster B","Uranus",
  50.     "Jester","Sultan","Stratum","Elegy","Raindance","RC Tiger","Flash","Tahoma","Savanna","Bandito","Freight",
  51.     "Trailer","Kart","Mower","Duneride","Sweeper","Broadway","Tornado","AT-400","DFT-30","Huntley","Stafford",
  52.     "BF-400","Newsvan","Tug","Trailer A","Emperor","Wayfarer","Euros","Hotdog","Club","Trailer B","Trailer C",
  53.     "Andromada","Dodo","RC Cam","Launch","Viatura (LSPD)","Viatura (SFPD)","Viatura (LVPD)","Police Ranger",
  54.     "Picador","S.W.A.T. Van","Alpha","Phoenix","Glendale","Sadler","Luggage Trailer A","Luggage Trailer B",
  55.     "Stair Trailer","Boxville","Farm Plow","Utility Trailer"
  56. };
  57.  
  58. public OnPlayerStateChange(playerid, newstate, oldstate)
  59. {
  60.     if(newstate == PLAYER_STATE_DRIVER && !EntrouVeiculo[playerid]) {
  61.             PlayerTextDrawSetPreviewModel(playerid, TDjVelocimetro[playerid][3], GetVehicleModel(GetPlayerVehicleID(playerid)));
  62.  
  63.             format(StringJFS, sizeof(StringJFS), "]_%s_]", CarModelNameFromID[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400]);
  64.             PlayerTextDrawSetString(playerid, TDjVelocimetro[playerid][1], StringJFS);
  65.  
  66.  
  67.             AbrirjVelocimetro(playerid);
  68.     }
  69.     return 1;
  70. }
  71. public OnPlayerConnect(playerid){
  72.     CarregarjVelocimetro(playerid);
  73.     return true;
  74. }
  75. public OnPlayerDisconnect(playerid, reason){
  76.  
  77.     // Caso necessário, botar também no OnGameModeExit com um Loop trocando os playerid por i.
  78.     if(EntrouVeiculo[playerid]){
  79.         KillTimer(TimerVelocimetro[playerid]);
  80.         DestroyPlayerProgressBar(playerid, BarjVelocimetro[playerid]);
  81.         EntrouVeiculo[playerid] = false;
  82.         for(new i; i<6; i++)
  83.             PlayerTextDrawDestroy(playerid,  TDjVelocimetro[playerid][i]);
  84.     }
  85.     return true;
  86. }
  87.  
  88. stock CarregarjVelocimetro(playerid){
  89. //Player TextDraws:
  90.  
  91.     TDjVelocimetro[playerid][0] = CreatePlayerTextDraw(playerid, 502.000000, 387.120117, "box");
  92.     PlayerTextDrawLetterSize(playerid, TDjVelocimetro[playerid][0], 0.000000, 5.120001);
  93.     PlayerTextDrawTextSize(playerid, TDjVelocimetro[playerid][0], 633.000000, 0.000000);
  94.     PlayerTextDrawAlignment(playerid, TDjVelocimetro[playerid][0], 1);
  95.     PlayerTextDrawColor(playerid, TDjVelocimetro[playerid][0], -1);
  96.     PlayerTextDrawUseBox(playerid, TDjVelocimetro[playerid][0], 1);
  97.     PlayerTextDrawBoxColor(playerid, TDjVelocimetro[playerid][0], 102);
  98.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][0], 0);
  99.     PlayerTextDrawSetOutline(playerid, TDjVelocimetro[playerid][0], 0);
  100.     PlayerTextDrawBackgroundColor(playerid, TDjVelocimetro[playerid][0], 1090519142);
  101.     PlayerTextDrawFont(playerid, TDjVelocimetro[playerid][0], 3);
  102.     PlayerTextDrawSetProportional(playerid, TDjVelocimetro[playerid][0], 1);
  103.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][0], 0);
  104.  
  105.     TDjVelocimetro[playerid][1] = CreatePlayerTextDraw(playerid, 499.599670, 395.900512, "]_INFERNUS_]");
  106.     PlayerTextDrawLetterSize(playerid, TDjVelocimetro[playerid][1], 0.243999, 0.815994);
  107.     PlayerTextDrawAlignment(playerid, TDjVelocimetro[playerid][1], 1);
  108.     PlayerTextDrawColor(playerid, TDjVelocimetro[playerid][1], -1);
  109.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][1], 0);
  110.     PlayerTextDrawSetOutline(playerid, TDjVelocimetro[playerid][1], 0);
  111.     PlayerTextDrawBackgroundColor(playerid, TDjVelocimetro[playerid][1], 409855);
  112.     PlayerTextDrawFont(playerid, TDjVelocimetro[playerid][1], 2);
  113.     PlayerTextDrawSetProportional(playerid, TDjVelocimetro[playerid][1], 1);
  114.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][1], 0);
  115.  
  116.     TDjVelocimetro[playerid][2] = CreatePlayerTextDraw(playerid, 502.299865, 398.607482, "box");
  117.     PlayerTextDrawLetterSize(playerid, TDjVelocimetro[playerid][2], 0.000000, 0.385003);
  118.     PlayerTextDrawTextSize(playerid, TDjVelocimetro[playerid][2], 633.000000, 0.000000);
  119.     PlayerTextDrawAlignment(playerid, TDjVelocimetro[playerid][2], 1);
  120.     PlayerTextDrawColor(playerid, TDjVelocimetro[playerid][2], -1);
  121.     PlayerTextDrawUseBox(playerid, TDjVelocimetro[playerid][2], 1);
  122.     PlayerTextDrawBoxColor(playerid, TDjVelocimetro[playerid][2], 102);
  123.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][2], 0);
  124.     PlayerTextDrawSetOutline(playerid, TDjVelocimetro[playerid][2], 0);
  125.     PlayerTextDrawBackgroundColor(playerid, TDjVelocimetro[playerid][2], 1090519142);
  126.     PlayerTextDrawFont(playerid, TDjVelocimetro[playerid][2], 1);
  127.     PlayerTextDrawSetProportional(playerid, TDjVelocimetro[playerid][2], 1);
  128.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][2], 0);
  129.  
  130.     TDjVelocimetro[playerid][3] = CreatePlayerTextDraw(playerid, 549.799743, 335.693756, "_");
  131.     PlayerTextDrawLetterSize(playerid, TDjVelocimetro[playerid][3], 0.000000, 0.000000);
  132.     PlayerTextDrawTextSize(playerid, TDjVelocimetro[playerid][3], 90.000000, 90.000000);
  133.     PlayerTextDrawAlignment(playerid, TDjVelocimetro[playerid][3], 1);
  134.     PlayerTextDrawColor(playerid, TDjVelocimetro[playerid][3], -1);
  135.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][3], 0);
  136.     PlayerTextDrawSetOutline(playerid, TDjVelocimetro[playerid][3], 0);
  137.     PlayerTextDrawBackgroundColor(playerid, TDjVelocimetro[playerid][3], 0);
  138.     PlayerTextDrawFont(playerid, TDjVelocimetro[playerid][3], 5);
  139.     PlayerTextDrawSetProportional(playerid, TDjVelocimetro[playerid][3], 0);
  140.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][3], 0);
  141.     PlayerTextDrawSetPreviewModel(playerid, TDjVelocimetro[playerid][3], 411);
  142.     PlayerTextDrawSetPreviewRot(playerid, TDjVelocimetro[playerid][3], 0.000000, 0.000000, 40.000000, 1.000000);
  143.     PlayerTextDrawSetPreviewVehCol(playerid, TDjVelocimetro[playerid][3], 1, 1);
  144.  
  145.     TDjVelocimetro[playerid][4] = CreatePlayerTextDraw(playerid, 501.900238, 415.880126, "box");
  146.     PlayerTextDrawLetterSize(playerid, TDjVelocimetro[playerid][4], 0.000000, 0.400002);
  147.     PlayerTextDrawTextSize(playerid, TDjVelocimetro[playerid][4], 633.000000, 0.000000);
  148.     PlayerTextDrawAlignment(playerid, TDjVelocimetro[playerid][4], 1);
  149.     PlayerTextDrawColor(playerid, TDjVelocimetro[playerid][4], -1);
  150.     PlayerTextDrawUseBox(playerid, TDjVelocimetro[playerid][4], 1);
  151.     PlayerTextDrawBoxColor(playerid, TDjVelocimetro[playerid][4], 102);
  152.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][4], 0);
  153.     PlayerTextDrawSetOutline(playerid, TDjVelocimetro[playerid][4], 0);
  154.     PlayerTextDrawBackgroundColor(playerid, TDjVelocimetro[playerid][4], 1090519142);
  155.     PlayerTextDrawFont(playerid, TDjVelocimetro[playerid][4], 1);
  156.     PlayerTextDrawSetProportional(playerid, TDjVelocimetro[playerid][4], 1);
  157.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][4], 0);
  158.  
  159.     TDjVelocimetro[playerid][5] = CreatePlayerTextDraw(playerid, 501.299896, 414.533569, "]_VELOCIDADE:_200KM_]");
  160.     PlayerTextDrawLetterSize(playerid, TDjVelocimetro[playerid][5], 0.203997, 0.718931);
  161.     PlayerTextDrawAlignment(playerid, TDjVelocimetro[playerid][5], 1);
  162.     PlayerTextDrawColor(playerid, TDjVelocimetro[playerid][5], -1);
  163.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][5], 0);
  164.     PlayerTextDrawSetOutline(playerid, TDjVelocimetro[playerid][5], 0);
  165.     PlayerTextDrawBackgroundColor(playerid, TDjVelocimetro[playerid][5], 255);
  166.     PlayerTextDrawFont(playerid, TDjVelocimetro[playerid][5], 2);
  167.     PlayerTextDrawSetProportional(playerid, TDjVelocimetro[playerid][5], 1);
  168.     PlayerTextDrawSetShadow(playerid, TDjVelocimetro[playerid][5], 0);
  169.  
  170. }
  171.  
  172. stock AbrirjVelocimetro(playerid){
  173.  
  174.     BarjVelocimetro[playerid] = CreatePlayerProgressBar(playerid, 504.00, 426.00, 127.50, 7.19, -1, 100.0);
  175.  
  176.     SetPlayerProgressBarMaxValue(playerid, BarjVelocimetro[playerid], 250.0);
  177.     SetPlayerProgressBarValue(playerid, BarjVelocimetro[playerid], 0.0);
  178.     ShowPlayerProgressBar(playerid, BarjVelocimetro[playerid]);
  179.     TimerVelocimetro[playerid] = SetTimerEx("TimerjVelocimetro", ATUALIZACAOVELO*1000, true, "i", playerid);
  180.  
  181.     EntrouVeiculo[playerid] = true;
  182.     for(new i; i<6; i++)
  183.         PlayerTextDrawShow(playerid, TDjVelocimetro[playerid][i]);
  184.  
  185. }
  186.  
  187. stock FecharjVelocimetro(playerid){
  188.  
  189.     KillTimer(TimerVelocimetro[playerid]);
  190.     DestroyPlayerProgressBar(playerid, BarjVelocimetro[playerid]);
  191.     EntrouVeiculo[playerid] = false;
  192.     for(new i; i<6; i++)
  193.         PlayerTextDrawHide(playerid,  TDjVelocimetro[playerid][i]);
  194. }
  195.  
  196. forward TimerjVelocimetro(playerid);
  197. public TimerjVelocimetro(playerid){
  198.  
  199.     if(EntrouVeiculo[playerid] && !IsPlayerInAnyVehicle(playerid)){
  200.         FecharjVelocimetro(playerid);
  201.         return true;
  202.     }
  203.        
  204.     format(tdstring, sizeof(tdstring), "]_VELOCIDADE:_%dKM_]", GetPlayerSpeed(playerid));
  205.     PlayerTextDrawSetString(playerid, TDjVelocimetro[playerid][5], tdstring);
  206.  
  207.     SetPlayerProgressBarValue(playerid, BarjVelocimetro[playerid],  GetPlayerSpeed(playerid));
  208.  
  209.     return true;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement