Advertisement
Guest User

Speedometer v0.4

a guest
Apr 21st, 2012
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.93 KB | None | 0 0
  1. /* SPEEDOMETER CREATED BY Mr.Walker (Scott_Walker) , INSPIRED BY System32
  2.  
  3.                         THANK YOU System32
  4.                        
  5.                            version 0.4
  6. */
  7.  
  8. #include <a_samp>
  9.  
  10. #define COLOR_BLACK 0x000000FF
  11. #define ORANGE 0xF97804FF
  12. #define COLOR_RED 0xAA3333AA
  13.  
  14. forward WalkerSpeedo();
  15.  
  16. new FORTIMER;
  17. new Walkers[MAX_PLAYERS];
  18.  
  19. new Text: Walkerspeedometer[MAX_PLAYERS];
  20. new Text: snagalinija[MAX_PLAYERS];
  21. new Text: healhtline;
  22.  
  23. new Text: speedo[MAX_PLAYERS];
  24. new Text: kmh[MAX_PLAYERS];
  25. new Text: hp[MAX_PLAYERS];
  26. new Text: hpcol[MAX_PLAYERS];
  27.  
  28. public OnFilterScriptInit()
  29. {
  30.     print("{{{{{{{{{{{{{}}}}}}}}}}}}}");
  31.     print("{{Mr.Walker  SpeedoMeter}}");
  32.     print("{{{{{{{{{{{{{}}}}}}}}}}}}}");
  33.    
  34.     FORTIMER = SetTimer("WalkerSpeedo",300,1);
  35.  
  36.     healhtline = TextDrawCreate(556.000000,420.000000,"_");
  37.     TextDrawUseBox(healhtline,1);
  38.     TextDrawBoxColor(healhtline,0xffffffff);
  39.     TextDrawTextSize(healhtline,551.000000,0.000000);
  40.     TextDrawAlignment(healhtline,0);
  41.     TextDrawBackgroundColor(healhtline,0x000000ff);
  42.     TextDrawFont(healhtline,3);
  43.     TextDrawLetterSize(healhtline,0.199999,-0.000000);
  44.     TextDrawColor(healhtline,0xffffffff);
  45.     TextDrawSetOutline(healhtline,1);
  46.     TextDrawSetProportional(healhtline,1);
  47.     TextDrawSetShadow(healhtline,1);
  48.  
  49.     for(new i=0; i<GetMaxPlayers(); i++)
  50.     {
  51.         Walkers[i] = 1;
  52.         Walkerspeedometer[i] = TextDrawCreate(535.000000,376.000000, " ");
  53.         TextDrawAlignment(Walkerspeedometer[i],0);
  54.         TextDrawBackgroundColor(Walkerspeedometer[i],0x000000ff);
  55.         TextDrawFont(Walkerspeedometer[i],1);
  56.         TextDrawLetterSize(Walkerspeedometer[i],0.199999,0.899999);
  57.         TextDrawSetProportional(Walkerspeedometer[i],1);
  58.         TextDrawSetShadow(Walkerspeedometer[i],1);
  59.         TextDrawColor(Walkerspeedometer[i],0xffff00ff);
  60.  
  61.         snagalinija[i] = TextDrawCreate(538.000000,443.500000,"_");
  62.         TextDrawUseBox(snagalinija[i],1);
  63.         TextDrawBoxColor(snagalinija[i],COLOR_BLACK);
  64.         TextDrawAlignment(snagalinija[i],0);
  65.         TextDrawBackgroundColor(snagalinija[i],0x000000ff);
  66.         TextDrawFont(snagalinija[i],3);
  67.         TextDrawLetterSize(snagalinija[i],1.000000,-0.000000);
  68.         TextDrawColor(snagalinija[i],0xffffffff);
  69.         TextDrawSetOutline(snagalinija[i],1);
  70.         TextDrawSetProportional(snagalinija[i],1);
  71.         TextDrawSetShadow(snagalinija[i],1);
  72.  
  73.     }
  74.     return 1;
  75. }
  76.  
  77. public OnFilterScriptExit()
  78. {
  79.     KillTimer(FORTIMER);
  80.  
  81.     TextDrawDestroy(Text:healhtline);
  82.  
  83.     for(new i=0; i<GetMaxPlayers(); i++)
  84.     {
  85.         TextDrawDestroy(snagalinija[i]);
  86.     }
  87.     return 1;
  88. }
  89.  
  90. public OnPlayerConnect(playerid)
  91. {
  92.     speedo[playerid] = TextDrawCreate(535.000000, 415.000000, "Brzina:");
  93.     TextDrawBackgroundColor(speedo[playerid], 255);
  94.     TextDrawFont(speedo[playerid], 3);
  95.     TextDrawLetterSize(speedo[playerid], 0.350000, 1.100000);
  96.     TextDrawColor(speedo[playerid], ORANGE);
  97.     TextDrawSetOutline(speedo[playerid], 1);
  98.     TextDrawSetProportional(speedo[playerid], 1);
  99.     TextDrawSetShadow(speedo[playerid], 1);
  100.  
  101.     kmh[playerid] = TextDrawCreate(581.000000, 415.000000, "_");
  102.     TextDrawBackgroundColor(kmh[playerid], 255);
  103.     TextDrawFont(kmh[playerid], 3);
  104.     TextDrawLetterSize(kmh[playerid], 0.350000, 1.100000);
  105.     TextDrawColor(kmh[playerid], -1);
  106.     TextDrawSetOutline(kmh[playerid], 1);
  107.     TextDrawSetProportional(kmh[playerid], 1);
  108.     TextDrawSetShadow(kmh[playerid], 1);
  109.  
  110.     hp[playerid] = TextDrawCreate(535.000000, 430.000000, "Snaga:");
  111.     TextDrawBackgroundColor(hp[playerid], 255);
  112.     TextDrawFont(hp[playerid], 3);
  113.     TextDrawLetterSize(hp[playerid], 0.350000, 1.100000);
  114.     TextDrawColor(hp[playerid], ORANGE);
  115.     TextDrawSetOutline(hp[playerid], 1);
  116.     TextDrawSetProportional(hp[playerid], 1);
  117.     TextDrawSetShadow(hp[playerid], 1);
  118.  
  119.     hpcol[playerid] = TextDrawCreate(581.000000, 430.000000, "_");
  120.     TextDrawBackgroundColor(hpcol[playerid], 255);
  121.     TextDrawFont(hpcol[playerid], 3);
  122.     TextDrawLetterSize(hpcol[playerid], 0.350000, 1.100000);
  123.     TextDrawColor(hpcol[playerid], -1);
  124.     TextDrawSetOutline(hpcol[playerid], 1);
  125.     TextDrawSetProportional(hpcol[playerid], 1);
  126.     TextDrawSetShadow(hpcol[playerid], 1);
  127. }
  128.  
  129. public OnPlayerUpdate(playerid)
  130. {
  131.     if(IsPlayerInAnyVehicle(playerid))
  132.     {
  133.         new estr[64],speed = GetSpeed(playerid);
  134.         format(estr,64,"%d km/h", speed);
  135.         TextDrawSetString(kmh[playerid], estr);
  136.        
  137.         new estr1[16], Float: health;
  138.         for(new i = 0; i<MAX_PLAYERS; i++)
  139.         {
  140.             if(IsPlayerConnected(playerid))
  141.             {
  142.                 GetVehicleHealth(GetPlayerVehicleID(i), health);
  143.             }
  144.         }
  145.         format(estr1,16,"%.2f", health);
  146.         TextDrawSetString(hpcol[playerid], estr1);
  147.     }
  148.     else if(!IsPlayerInAnyVehicle(playerid))
  149.     {
  150.         TextDrawHideForPlayer(playerid, speedo[playerid]);
  151.         TextDrawHideForPlayer(playerid, kmh[playerid]);
  152.         TextDrawHideForPlayer(playerid, hp[playerid]);
  153.         TextDrawHideForPlayer(playerid, hpcol[playerid]);
  154.     }
  155.     return 1;
  156. }
  157.  
  158. public OnPlayerCommandText(playerid, cmdtext[])
  159. {
  160.     if (strcmp("/speedo", cmdtext, true, 10) == 0)
  161.     {
  162.         if(Walkers[playerid] == 1)
  163.         {
  164.             Walkers[playerid] = 0;
  165.             SendClientMessage(playerid,COLOR_RED,"<< Speedometer has been disabled.");
  166.         }
  167.         else if(Walkers[playerid] == 0)
  168.         {
  169.             Walkers[playerid] = 1;
  170.             SendClientMessage(playerid,COLOR_RED,">> Speedometer has been enabled.");
  171.         }
  172.         return 1;
  173.     }
  174.     return 1;
  175. }
  176.  
  177. public OnPlayerStateChange(playerid, newstate, oldstate)
  178. {
  179.     if(oldstate-1 && newstate) TextDrawHideForPlayer(playerid, speedo[playerid]); else if(newstate-1) TextDrawShowForPlayer(playerid, speedo[playerid]);
  180.     if(oldstate-1 && newstate) TextDrawHideForPlayer(playerid, kmh[playerid]); else if(newstate-1) TextDrawShowForPlayer(playerid, kmh[playerid]);
  181.     if(oldstate-1 && newstate) TextDrawHideForPlayer(playerid, hp[playerid]); else if(newstate-1) TextDrawShowForPlayer(playerid, hp[playerid]);
  182.     if(oldstate-1 && newstate) TextDrawHideForPlayer(playerid, hpcol[playerid]); else if(newstate-1) TextDrawShowForPlayer(playerid, hpcol[playerid]);
  183.     return 1;
  184. }
  185.  
  186. public WalkerSpeedo()
  187. {
  188.     for(new i=0; i<GetMaxPlayers(); i++)
  189.     {
  190.         if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i) && Walkers[i] == 1)
  191.         {
  192.             new Float:snagavozila;
  193.             GetVehicleHealth(GetPlayerVehicleID(i), snagavozila);
  194.  
  195.             if(snagavozila < 250)
  196.             {
  197.                 TextDrawTextSize(snagalinija[i],538.000000,0.000000);
  198.             }
  199.             else if(snagavozila >= 1000)
  200.             {
  201.                 TextDrawTextSize(snagalinija[i],625.000000,0.000000);
  202.             }
  203.             else
  204.             {
  205.                 TextDrawTextSize(snagalinija[i],floatadd(534.0, floatdiv(snagavozila, 14.6000000)),0.000000);
  206.             }
  207.             TextDrawShowForPlayer(i, snagalinija[i]);
  208.             TextDrawShowForPlayer(i, healhtline);
  209.         }
  210.         else
  211.         {
  212.             TextDrawHideForPlayer(i, Text:Walkerspeedometer[i]);
  213.             TextDrawHideForPlayer(i, Text:snagalinija[i]);
  214.             TextDrawHideForPlayer(i, Text:healhtline);
  215.         }
  216.     }
  217. }
  218.  
  219. stock GetSpeed(playerid)
  220. {
  221.     new Float:ST[3];
  222.     GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
  223.     return floatround(1.61*floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 100.3);
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement