Guest User

Speedometer by Atom

a guest
Feb 19th, 2013
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.81 KB | None | 0 0
  1. // SPEEDOMETER CREATED BY Atom (Scott_Atkins)
  2. // version 1.15
  3.  
  4. // Copyright
  5.  
  6. #include <a_samp>
  7.  
  8. #define GasMax          100
  9. #define RunOutTime      30000
  10. #define RefuelWait      5000
  11. #define CAR_AMOUNT      700
  12.  
  13. #define COLOR_SPEEDOBLUE 0x0098FFFF
  14.  
  15. new Text:Atomspeedtanktext[MAX_PLAYERS];
  16. new Gas[CAR_AMOUNT];
  17. new Text: Atomkmph[MAX_PLAYERS];
  18. new Text: Atomkmphs;
  19. new Text: Atomvehiclename[MAX_PLAYERS];
  20. new Text: Atompowerline[MAX_PLAYERS];
  21. new Text: Atompowerlines;
  22. new Text: Atombox;
  23. forward UpdateSpeedo();
  24. forward CheckGas();
  25. forward Fillup();
  26. forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
  27. forward AtomSpeedometer();
  28. forward IsABike(carid);
  29. new FORTIMER;
  30. new Float:Velocity [3];
  31. new gGas[MAX_PLAYERS];
  32. new NoFuel[MAX_PLAYERS];
  33. new Vehicles[212][]=
  34. {
  35. {"Landstalker"},
  36. {"Bravura"},
  37. {"Buffalo"},
  38. {"Linerunner"},
  39. {"Perrenial"},
  40. {"Sentinel"},
  41. {"Dumper"},
  42. {"Firetruck"},
  43. {"Trashmaster"},
  44. {"Stretch"},
  45. {"Manana"},
  46. {"Infernus"},
  47. {"Voodoo"},
  48. {"Pony"},
  49. {"Mule"},
  50. {"Cheetah"},
  51. {"Ambulance"},
  52. {"Leviathan"},
  53. {"Moonbeam"},
  54. {"Esperanto"},
  55. {"Taxi"},
  56. {"Washington"},
  57. {"Bobcat"},
  58. {"Mr. Whoopee"},
  59. {"BF.Injection"},
  60. {"Hunter"},
  61. {"Premier"},
  62. {"Enforcer"},
  63. {"Securicar"},
  64. {"Banshee"},
  65. {"Predator"},
  66. {"Bus"},
  67. {"Rhino"},
  68. {"Barracks"},
  69. {"Hotknife"},
  70. {"Article Trailer"},
  71. {"Previon"},
  72. {"Coach"},
  73. {"Cabbie"},
  74. {"Stallion"},
  75. {"Rumpo"},
  76. {"RC Bandit"},
  77. {"Romero"},
  78. {"Packer"},
  79. {"Monster"},
  80. {"Admiral"},
  81. {"Squalo"},
  82. {"Seasparrow"},
  83. {"Pizzaboy"},
  84. {"Tram"},
  85. {"Article Trailer2"},
  86. {"Turismo"},
  87. {"Speeder"},
  88. {"Reefer"},
  89. {"Tropic"},
  90. {"Flatbed"},
  91. {"Yankee"},
  92. {"Caddy"},
  93. {"Solair"},
  94. {"Berkley's RC Van"},
  95. {"Skimmer"},
  96. {"PCJ-600"},
  97. {"Faggio"},
  98. {"Freeway"},
  99. {"RC Baron"},
  100. {"RC Raider"},
  101. {"Glendale"},
  102. {"Oceanic"},
  103. {"Sanchez"},
  104. {"Sparrow"},
  105. {"Patriot"},
  106. {"Quad"},
  107. {"Coastguard"},
  108. {"Dinghy"},
  109. {"Hermes"},
  110. {"Sabre"},
  111. {"Rustler"},
  112. {"ZR-350"},
  113. {"Walton"},
  114. {"Regina"},
  115. {"Comet"},
  116. {"BMX"},
  117. {"Burrito"},
  118. {"Camper"},
  119. {"Marquis"},
  120. {"Baggage"},
  121. {"Dozer"},
  122. {"Maverick"},
  123. {"News Chopper"},
  124. {"Rancher"},
  125. {"FBI Rancher"},
  126. {"Virgo"},
  127. {"Greenwood"},
  128. {"Jetmax"},
  129. {"Hotring"},
  130. {"Sandking"},
  131. {"Blista Compact"},
  132. {"PD Maverick"},
  133. {"Boxville"},
  134. {"Benson"},
  135. {"Mesa"},
  136. {"RC Goblin"},
  137. {"Hotring Racer A"},
  138. {"Hotring Racer B"},
  139. {"Bloodring Banger"},
  140. {"Rancher"},
  141. {"Super GT"},
  142. {"Elegant"},
  143. {"Journey"},
  144. {"Bike"},
  145. {"MountainBike"},
  146. {"Beagle"},
  147. {"Cropdust"},
  148. {"Stunt"},
  149. {"Tanker"},
  150. {"Roadtrain"},
  151. {"Nebula"},
  152. {"Majestic"},
  153. {"Buccaneer"},
  154. {"Shamal"},
  155. {"Hydra"},
  156. {"FCR-900"},
  157. {"NRG-500"},
  158. {"HPV1000"},
  159. {"Cement Truck"},
  160. {"Tow Truck"},
  161. {"Fortune"},
  162. {"Cadrona"},
  163. {"FBI Truck"},
  164. {"Willard"},
  165. {"Forklift"},
  166. {"Tractor"},
  167. {"Combine"},
  168. {"Feltzer"},
  169. {"Remington"},
  170. {"Slamvan"},
  171. {"Blade"},
  172. {"Freight"},
  173. {"Streak"},
  174. {"Vortex"},
  175. {"Vincent"},
  176. {"Bullet"},
  177. {"Clover"},
  178. {"Sadler"},
  179. {"Firetruck"},
  180. {"Hustler"},
  181. {"Intruder"},
  182. {"Primo"},
  183. {"Cargobob"},
  184. {"Tampa"},
  185. {"Sunrise"},
  186. {"Merit"},
  187. {"Utility"},
  188. {"Nevada"},
  189. {"Yosemite"},
  190. {"Windsor"},
  191. {"Monster A"},
  192. {"Monster B"},
  193. {"Uranus"},
  194. {"Jester"},
  195. {"Sultan"},
  196. {"Stratum"},
  197. {"Elegy"},
  198. {"Raindance"},
  199. {"RC Tiger"},
  200. {"Flash"},
  201. {"Tahoma"},
  202. {"Savanna"},
  203. {"Bandito"},
  204. {"Freight Flat"},
  205. {"Streak Carriage"},
  206. {"Kart"},{"Mower"},
  207. {"Dunerider"},
  208. {"Sweeper"},
  209. {"Broadway"},
  210. {"Tornado"},
  211. {"AT-400"},
  212. {"DFT-30"},
  213. {"Huntley"},
  214. {"Stafford"},
  215. {"BF-400"},
  216. {"Newsvan"},
  217. {"Tug"},
  218. {"Article Trailer 3"},
  219. {"Emperor"},
  220. {"Wayfarer"},
  221. {"Euros"},
  222. {"Mobile Hotdog"},
  223. {"Club"},
  224. {"Freight Carriage"},
  225. {"Trailer 3"},
  226. {"Andromada"},
  227. {"Dodo"},
  228. {"RC Cam"},
  229. {"Launch"},
  230. {"Police Car"},
  231. {"Police Car"},
  232. {"Police Car"},
  233. {"Police Ranger"},
  234. {"Picador"},
  235. {"SWAT Van"},
  236. {"Alpha"},
  237. {"Phoenix"},
  238. {"Glendale"},
  239. {"Sadler"},
  240. {"Luggage Trailer A"},
  241. {"Luggage Trailer B"},
  242. {"Stair Trailer"},
  243. {"Boxville"},
  244. {"Farm Plow"},
  245. {"Utility Trailer"}
  246. };
  247. public OnFilterScriptInit()
  248. {
  249.     Atombox = TextDrawCreate(558.000000,375,"_");
  250.     TextDrawLetterSize(Atombox,0.5,9.000000);
  251.     TextDrawUseBox(Atombox,1);
  252.     TextDrawBoxColor(Atombox,0x00000060);
  253.     TextDrawTextSize(Atombox,650,450);
  254.  
  255.     Atomkmphs = TextDrawCreate(615.000000, 425.000000, "km/h");
  256.     TextDrawBackgroundColor(Atomkmphs, 255);
  257.     TextDrawFont(Atomkmphs, 3);
  258.     TextDrawLetterSize(Atomkmphs, 0.200000, 1.000000);
  259.     TextDrawColor(Atomkmphs, 0xFFFFFFFF);
  260.     TextDrawSetOutline(Atomkmphs, 1);
  261.  
  262.     Atompowerlines = TextDrawCreate(559.500000,396.500000,"_");
  263.     TextDrawUseBox(Atompowerlines,1);
  264.     TextDrawBoxColor(Atompowerlines,0x000000ff);
  265.     TextDrawTextSize(Atompowerlines,630.000000,1.000000);
  266.     TextDrawAlignment(Atompowerlines,0);
  267.     TextDrawBackgroundColor(Atompowerlines,0x000000ff);
  268.     TextDrawFont(Atompowerlines,3);
  269.     TextDrawLetterSize(Atompowerlines,0.199999,0.600000);
  270.     TextDrawColor(Atompowerlines,0xffffffff);
  271.     TextDrawSetOutline(Atompowerlines,1);
  272.  
  273.     for(new i=0; i<GetMaxPlayers(); i++)
  274.     {
  275.         FORTIMER = SetTimer("AtomSpeedometer",300,1);
  276.  
  277.         Atompowerline[i] = TextDrawCreate(560.000000,397.000000,"_");
  278.         TextDrawUseBox(Atompowerline[i],1);
  279.         TextDrawBoxColor(Atompowerline[i],COLOR_SPEEDOBLUE);
  280.         TextDrawAlignment(Atompowerline[i],0);
  281.         TextDrawBackgroundColor(Atompowerline[i],0x000000ff);
  282.         TextDrawFont(Atompowerline[i],3);
  283.         TextDrawLetterSize(Atompowerline[i],1.000000,0.300000);
  284.         TextDrawColor(Atompowerline[i],0xffffffff);
  285.         TextDrawSetOutline(Atompowerline[i],1);
  286.  
  287.         Atomkmph[i] = TextDrawCreate(565.000000, 400.000000, "_");
  288.         TextDrawBackgroundColor(Atomkmph[i], 255);
  289.         TextDrawFont(Atomkmph[i], 3);
  290.         TextDrawLetterSize(Atomkmph[i], 0.800000, 4.000000);
  291.         TextDrawColor(Atomkmph[i], 0xFFFFFFFF);
  292.         TextDrawSetOutline(Atomkmph[i], 1);
  293.  
  294.         Atomvehiclename[i] = TextDrawCreate(565.000000, 435.000000, "_");
  295.         TextDrawBackgroundColor(Atomvehiclename[i], 255);
  296.         TextDrawFont(Atomvehiclename[i], 2);
  297.         TextDrawLetterSize(Atomvehiclename[i], 0.200000, 1.000000);
  298.         TextDrawColor(Atomvehiclename[i], 0xFFFFFFFF);
  299.         TextDrawSetOutline(Atomvehiclename[i], 1);
  300.  
  301.         Atomspeedtanktext[i] = TextDrawCreate(580.000000, 380.000000, "_");
  302.         TextDrawBackgroundColor(Atomspeedtanktext[i], 255);
  303.         TextDrawFont(Atomspeedtanktext[i], 3);
  304.         TextDrawLetterSize(Atomspeedtanktext[i], 0.2500000, 1.000000);
  305.         TextDrawColor(Atomspeedtanktext[i], 0xFFFFFFFF);
  306.         TextDrawSetOutline(Atomspeedtanktext[i], 1);
  307.     }
  308.     return 1;
  309. }
  310. public OnPlayerConnect(playerid)
  311. {
  312.     NoFuel[playerid] = 0;
  313.     gGas[playerid] = 0;
  314. }
  315. public OnPlayerCommandText(playerid, cmdtext[])
  316. {
  317.     new cmd[256];
  318.     if(strcmp(cmd, "/exit", true) == 0)
  319.     {
  320.         if(IsPlayerConnected(playerid))
  321.         {
  322.             if(NoFuel[playerid] == 1)
  323.             {
  324.                 TogglePlayerControllable(playerid, 1);
  325.                 RemovePlayerFromVehicle(playerid);
  326.                 NoFuel[playerid] = 0;
  327.             }
  328.         }
  329.         return 1;
  330.     }
  331.     SendClientMessage(playerid, -1, "SERVER: Unknown command!");
  332.     return 1;
  333. }
  334.  
  335. public OnFilterScriptExit()
  336. {
  337.     KillTimer(FORTIMER);
  338.     return 1;
  339. }
  340. public IsABike(carid)
  341. {
  342.     if((carid >= 1 && carid <= 2)) // Unesi ID svojih bicikala
  343.     {
  344.         return 1;
  345.     }
  346.     return 0;
  347. }
  348. public AtomSpeedometer()
  349. {
  350.     for(new i = 0; i<MAX_PLAYERS; i++)
  351.     {
  352.         if(IsPlayerConnected(i))
  353.         {
  354.             if(IsPlayerInAnyVehicle(i))
  355.             {
  356.                 new Float: health;
  357.                 new gasveh[16];
  358.                 new vehicle = GetPlayerVehicleID(i);
  359.                 GetVehicleHealth(GetPlayerVehicleID(i), health);
  360.                 if(health < 250)
  361.                 {
  362.                     TextDrawTextSize(Atompowerline[i],560.000000,0.000000); //gore
  363.                 }
  364.                 else if(health >= 1000)
  365.                 {
  366.                     TextDrawTextSize(Atompowerline[i],629.490000,0.000000); //69,49
  367.                 }
  368.                 else
  369.                 {
  370.                     TextDrawTextSize(Atompowerline[i],floatadd(560.0, floatdiv(health, 14.6000000)),0.000000);
  371.                 }
  372.                 if(Gas[vehicle] <= 1)
  373.                 {
  374.                     format(gasveh, sizeof(gasveh), "Prazno");
  375.                     TextDrawSetString(Atomspeedtanktext[i], gasveh);
  376.                 }
  377.                 else
  378.                 {
  379.                     format(gasveh, sizeof(gasveh), "%d%/100 L", Gas[vehicle]);
  380.                     TextDrawSetString(Atomspeedtanktext[i], gasveh);
  381.                 }
  382.                 TextDrawShowForPlayer(i, Atompowerline[i]);
  383.                 TextDrawShowForPlayer(i, Atompowerlines);
  384.                 TextDrawShowForPlayer(i, Atomkmph[i]);
  385.                 TextDrawShowForPlayer(i, Atomkmphs);
  386.                 TextDrawShowForPlayer(i, Atombox);
  387.                 TextDrawShowForPlayer(i, Atomvehiclename[i]);
  388.                 TextDrawShowForPlayer(i, Atomspeedtanktext[i]);
  389.             }
  390.             else
  391.             {
  392.                 TextDrawHideForPlayer(i, Atompowerline[i]);
  393.                 TextDrawHideForPlayer(i, Atompowerlines);
  394.                 TextDrawHideForPlayer(i, Atomkmph[i]);
  395.                 TextDrawHideForPlayer(i, Atomkmphs);
  396.                 TextDrawHideForPlayer(i, Atombox);
  397.                 TextDrawHideForPlayer(i, Atomvehiclename[i]);
  398.                 TextDrawHideForPlayer(i, Atomspeedtanktext[i]);
  399.             }
  400.         }
  401.     }
  402. }
  403. public OnPlayerUpdate(playerid)
  404. {
  405.     if(IsPlayerInAnyVehicle(playerid))
  406.     {
  407.         new velocityAtom[64],speed = GetSpeed(playerid);
  408.         format(velocityAtom,64,"%d", speed);
  409.         TextDrawSetString(Atomkmph[playerid], velocityAtom);
  410.         new modelAtom[16];
  411.         format(modelAtom,16,"%s", Vehicles[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400]);
  412.         TextDrawSetString(Atomvehiclename[playerid], modelAtom);
  413.     }
  414.     return 1;
  415. }
  416. public CheckGas()
  417. {
  418.     new string[256];
  419.     for(new i = 0; i<MAX_PLAYERS; i++)
  420.     {
  421.         if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
  422.         {
  423.             new vehicle = GetPlayerVehicleID(i);
  424.             if(Gas[vehicle] >= 1)
  425.             {
  426.                 if(Gas[vehicle] <= 13)
  427.                 {
  428.                     PlayerPlaySound(i, 1085, 0.0, 0.0, 0.0);
  429.                     if(gGas[i] == 0) {
  430.                         GameTextForPlayer(i,"~w~~n~~n~~n~~n~~n~~n~~n~~n~~n~Spremnik goriva je skoro prazan",5000,3);
  431.                     }
  432.                 }
  433.                 if(gGas[i] == 1)
  434.                 {
  435.                     if(IsABike(vehicle))
  436.                     {
  437.                         format(string, sizeof(string), "~b~~n~~n~~n~~n~~n~~n~~n~~n~~n~N/A");
  438.                     }
  439.                     else
  440.                     {
  441.                         format(string, sizeof(string), "~b~~n~~n~~n~~n~~n~~n~~n~~n~~n~%d%/100 L",Gas[vehicle]);
  442.                     }
  443.                     GameTextForPlayer(i,string,20500,3);
  444.                 }
  445.                 Gas[vehicle]--;
  446.             }
  447.             else
  448.             {
  449.                 NoFuel[i] = 1;
  450.                 TogglePlayerControllable(i, 0);
  451.                 GameTextForPlayer(i,"~w~~n~~n~~n~~n~~n~~n~~n~~n~~n~Spremnik goriva je prazan",1500,3);
  452.             }
  453.         }
  454.     }
  455.     return 1;
  456. }
  457. stock GetSpeed ( playerid , mode = 1 )
  458. {
  459.     GetVehicleVelocity ( GetPlayerVehicleID ( playerid ) , Velocity [ 0 ] , Velocity [ 1 ] , Velocity [ 2 ] ) ;
  460.     return IsPlayerInAnyVehicle ( playerid ) ? floatround ( ( ( floatsqroot ( ( ( Velocity [ 0 ] * Velocity [ 0 ] ) + ( Velocity [ 1 ] * Velocity [ 1 ] ) + ( Velocity [ 2 ] * Velocity [ 2 ] ) ) ) * ( !mode ? 105.0 : 170.0 ) ) ) * 1 ) : 0;
  461. }
Advertisement
Add Comment
Please, Sign In to add comment