Advertisement
Leo_Close

Speedometer_by_Leo_Close

Nov 8th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.31 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. new PlayerText:cWspeedo[MAX_PLAYERS][10];
  4. new carfuel[MAX_VEHICLES] = {100, ...}; //
  5. new PlayerSpeedo[MAX_PLAYERS]; // 0 = KM/H, 1 = MP/H
  6. public OnFilterScriptInit()
  7. {
  8. print("\n--------------------------------------");
  9. print("-----Speedometer by Leo_Close-----");
  10. print("--------------------------------------\n");
  11. return 1;
  12. }
  13. new const modelNames[212][] = {
  14. "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel", "Dumper", "Firetruck", "Trashmaster",
  15. "Stretch", "Manana", "Infernus", "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
  16. "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer",
  17. "Securicar", "Banshee", "Predator", "Bus", "Rhino", "Barracks", "Hotknife", "Article Trailer", "Previon", "Coach",
  18. "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral", "Squalo", "Seasparrow",
  19. "Pizzaboy", "Tram", "Article Trailer 2", "Turismo", "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair",
  20. "Berkley's RC Van", "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale", "Oceanic",
  21. "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre", "Rustler", "ZR-350", "Walton",
  22. "Regina", "Comet", "BMX", "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper", "Rancher",
  23. "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking", "Blista Compact", "Police Maverick",
  24. "Boxville", "Benson", "Mesa", "RC Goblin", "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher",
  25. "Super GT", "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stuntplane", "Tanker", "Roadtrain",
  26. "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra", "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck",
  27. "Fortune", "Cadrona", "SWAT Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer", "Remington", "Slamvan",
  28. "Blade", "Streak", "Freight", "Vortex", "Vincent", "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder",
  29. "Primo", "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite", "Windsor", "Monster", "Monster",
  30. "Uranus", "Jester", "Sultan", "Stratum", "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
  31. "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30",
  32. "Huntley", "Stafford", "BF-400", "News Van", "Tug", "Petrol Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
  33. "Freight Box", "Article Trailer 3", "Andromada", "Dodo", "RC Cam", "Launch", "LSPD Car", "SFPD Car", "LVPD Car",
  34. "Police Rancher", "Picador", "S.W.A.T", "Alpha", "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs",
  35. "Boxville", "Tiller", "Utility Trailer"
  36. };
  37. Float:GetVehicleSpeed(vehicleid)
  38. {
  39. new
  40. Float:x,
  41. Float:y,
  42. Float:z;
  43.  
  44. if(GetVehicleVelocity(vehicleid, x, y, z))
  45. {
  46. return floatsqroot((x * x) + (y * y) + (z * z)) * 181.5;
  47. }
  48.  
  49. return 0.0;
  50. }
  51. Float:GetVehicleSpeedMPH(vehicleid)
  52. {
  53. new
  54. Float:x,
  55. Float:y,
  56. Float:z;
  57.  
  58. if(GetVehicleVelocity(vehicleid, x, y, z))
  59. {
  60. return floatsqroot((x * x) + (y * y) + (z * z)) * 100;
  61. }
  62.  
  63. return 0.0;
  64. }
  65. IsAbicycle(vehid)
  66. {
  67. switch(GetVehicleModel(vehid))
  68. {
  69. case 481, 509, 510: return true;
  70. }
  71. return false;
  72. }
  73. GetVehicleName(vehicleid)
  74. {
  75. new
  76. modelid = GetVehicleModel(vehicleid),
  77. name[32];
  78.  
  79. if(400 <= modelid <= 611)
  80. strcat(name, modelNames[modelid - 400]);
  81. else
  82. name = "Unknown";
  83.  
  84. return name;
  85. }
  86. public OnPlayerConnect(playerid)
  87. {
  88. PlayerSpeedo[playerid] = 0; // default speed KM/H
  89. //------------------------------------------------------------------------//
  90. cWspeedo[playerid][0] = CreatePlayerTextDraw(playerid, 525.111389, 394.088836, "kutija");
  91. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][0], 0.000000, -0.044444);
  92. PlayerTextDrawTextSize(playerid, cWspeedo[playerid][0], 623.000000, 0.000000);
  93. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][0], 1);
  94. PlayerTextDrawColor(playerid, cWspeedo[playerid][0], -1);
  95. PlayerTextDrawUseBox(playerid, cWspeedo[playerid][0], 1);
  96. PlayerTextDrawBoxColor(playerid, cWspeedo[playerid][0], 0x000000AA);
  97. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][0], 0);
  98. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][0], 0);
  99. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][0], 255);
  100. PlayerTextDrawFont(playerid, cWspeedo[playerid][0], 1);
  101. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][0], 1);
  102. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][0], 0);
  103.  
  104. cWspeedo[playerid][1] = CreatePlayerTextDraw(playerid, 627.777770, 365.715454, "kutija");
  105. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][1], 0.000000, 6.133327);
  106. PlayerTextDrawTextSize(playerid, cWspeedo[playerid][1], 621.000000, 0.000000);
  107. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][1], 1);
  108. PlayerTextDrawColor(playerid, cWspeedo[playerid][1], -1);
  109. PlayerTextDrawUseBox(playerid, cWspeedo[playerid][1], 1);
  110. PlayerTextDrawBoxColor(playerid, cWspeedo[playerid][1], 0x000000AA);
  111. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][1], 0);
  112. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][1], 0);
  113. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][1], 255);
  114. PlayerTextDrawFont(playerid, cWspeedo[playerid][1], 1);
  115. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][1], 1);
  116. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][1], 0);
  117.  
  118. cWspeedo[playerid][2] = CreatePlayerTextDraw(playerid, 565.889099, 341.168945, "");
  119. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][2], 0.000000, 0.000000);
  120. PlayerTextDrawTextSize(playerid, cWspeedo[playerid][2], 60.000000, 73.000000);
  121. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][2], 1);
  122. PlayerTextDrawColor(playerid, cWspeedo[playerid][2], -1);
  123. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][2], 0);
  124. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][2], 0);
  125. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][2], 0);
  126. PlayerTextDrawFont(playerid, cWspeedo[playerid][2], 5);
  127. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][2], 0);
  128. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][2], 0);
  129. PlayerTextDrawSetPreviewModel(playerid, cWspeedo[playerid][2], 411);
  130. PlayerTextDrawSetPreviewRot(playerid, cWspeedo[playerid][2], 0.000000, 0.000000, -30.000000, 1.000000);
  131. PlayerTextDrawSetPreviewVehCol(playerid, cWspeedo[playerid][2], 1, 1);
  132.  
  133. cWspeedo[playerid][3] = CreatePlayerTextDraw(playerid, 524.222167, 395.582153, "220");
  134. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][3], 0.342222, 1.316266);
  135. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][3], 1);
  136. PlayerTextDrawColor(playerid, cWspeedo[playerid][3], -1);
  137. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][3], 0);
  138. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][3], 1);
  139. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][3], 255);
  140. PlayerTextDrawFont(playerid, cWspeedo[playerid][3], 3);
  141. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][3], 1);
  142. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][3], 0);
  143.  
  144. cWspeedo[playerid][4] = CreatePlayerTextDraw(playerid, 523.777770, 382.142395, "infernus");
  145. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][4], 0.172888, 0.903111);
  146. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][4], 1);
  147. PlayerTextDrawColor(playerid, cWspeedo[playerid][4], -1);
  148. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][4], 0);
  149. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][4], 1);
  150. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][4], 255);
  151. PlayerTextDrawFont(playerid, cWspeedo[playerid][4], 2);
  152. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][4], 1);
  153. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][4], 0);
  154.  
  155. cWspeedo[playerid][5] = CreatePlayerTextDraw(playerid, 526.000244, 408.026733, "KM/H");
  156. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][5], 0.175555, 0.669155);
  157. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][5], 1);
  158. PlayerTextDrawColor(playerid, cWspeedo[playerid][5], -1378294017);
  159. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][5], 0);
  160. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][5], 0);
  161. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][5], 255);
  162. PlayerTextDrawFont(playerid, cWspeedo[playerid][5], 1);
  163. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][5], 1);
  164. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][5], 0);
  165.  
  166. cWspeedo[playerid][6] = CreatePlayerTextDraw(playerid, 572.933105, 396.080047, "100");
  167. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][6], 0.301333, 1.171911);
  168. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][6], 2);
  169. PlayerTextDrawColor(playerid, cWspeedo[playerid][6], -1);
  170. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][6], 0);
  171. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][6], 1);
  172. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][6], 255);
  173. PlayerTextDrawFont(playerid, cWspeedo[playerid][6], 3);
  174. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][6], 1);
  175. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][6], 0);
  176.  
  177. cWspeedo[playerid][7] = CreatePlayerTextDraw(playerid, 572.509460, 407.528869, "Gorivo");
  178. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][7], 0.151111, 0.689067);
  179. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][7], 2);
  180. PlayerTextDrawColor(playerid, cWspeedo[playerid][7], -1378294017);
  181. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][7], 0);
  182. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][7], 0);
  183. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][7], 255);
  184. PlayerTextDrawFont(playerid, cWspeedo[playerid][7], 1);
  185. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][7], 1);
  186. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][7], 0);
  187.  
  188. cWspeedo[playerid][8] = CreatePlayerTextDraw(playerid, 621.111633, 396.080108, "999.0");
  189. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][8], 0.231555, 1.052444);
  190. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][8], 3);
  191. PlayerTextDrawColor(playerid, cWspeedo[playerid][8], -1);
  192. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][8], 0);
  193. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][8], 1);
  194. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][8], 255);
  195. PlayerTextDrawFont(playerid, cWspeedo[playerid][8], 3);
  196. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][8], 1);
  197. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][8], 0);
  198.  
  199. cWspeedo[playerid][9] = CreatePlayerTextDraw(playerid, 618.444335, 406.533325, "Healt");
  200. PlayerTextDrawLetterSize(playerid, cWspeedo[playerid][9], 0.145778, 0.699022);
  201. PlayerTextDrawAlignment(playerid, cWspeedo[playerid][9], 3);
  202. PlayerTextDrawColor(playerid, cWspeedo[playerid][9], -1378294017);
  203. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][9], 0);
  204. PlayerTextDrawSetOutline(playerid, cWspeedo[playerid][9], 0);
  205. PlayerTextDrawBackgroundColor(playerid, cWspeedo[playerid][9], 255);
  206. PlayerTextDrawFont(playerid, cWspeedo[playerid][9], 1);
  207. PlayerTextDrawSetProportional(playerid, cWspeedo[playerid][9], 1);
  208. PlayerTextDrawSetShadow(playerid, cWspeedo[playerid][9], 0);
  209.  
  210. //-------------------------------------------------------------------------//
  211.  
  212. return 1;
  213. }
  214.  
  215. public OnPlayerDisconnect(playerid, reason)
  216. {
  217. for(new i = 0; i < 10; i ++) {
  218. PlayerTextDrawDestroy(playerid, cWspeedo[playerid][i]);
  219. cWspeedo[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  220. }
  221. return 1;
  222. }
  223.  
  224.  
  225. public OnPlayerStateChange(playerid, newstate, oldstate)
  226. {
  227. if(newstate == PLAYER_STATE_DRIVER)
  228. {
  229. new vehicleid = GetPlayerVehicleID(playerid);
  230. if(!IsAbicycle(vehicleid))
  231. {
  232. new vstr[30];
  233. format(vstr, sizeof(vstr), "%s", GetVehicleName(vehicleid));
  234. PlayerTextDrawSetString(playerid, cWspeedo[playerid][4], vstr);
  235.  
  236. PlayerTextDrawSetPreviewModel(playerid, cWspeedo[playerid][2], GetVehicleModel(GetPlayerVehicleID(playerid)));
  237. PlayerTextDrawShow(playerid, cWspeedo[playerid][2]);
  238.  
  239. for(new i = 0; i < 10; i++) {
  240. PlayerTextDrawShow(playerid, cWspeedo[playerid][i]);
  241. }
  242. }
  243. }
  244. else if(oldstate == PLAYER_STATE_DRIVER)
  245. {
  246. for(new i = 0; i < 10; i++) {
  247. PlayerTextDrawHide(playerid, cWspeedo[playerid][i]);
  248. }
  249. }
  250. return 1;
  251. }
  252.  
  253. public OnPlayerUpdate(playerid)
  254. {
  255. new vehicle = GetPlayerVehicleID(playerid);
  256. if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && !IsAbicycle(vehicle)) // Budite sigurni da je igrac na mjestu vozaca u vozilu
  257. {
  258. if(PlayerSpeedo[playerid] == 0)
  259. {
  260. new Float:H;
  261. GetVehicleHealth(vehicle, H);
  262. new speed[24];
  263. format(speed, sizeof(speed), "%.0f", GetVehicleSpeed(vehicle));
  264. PlayerTextDrawSetString(playerid, cWspeedo[playerid][3], speed);
  265. new vehfuel[24];
  266. format(vehfuel, sizeof(vehfuel), "%d", carfuel[vehicle]);
  267. PlayerTextDrawSetString(playerid, cWspeedo[playerid][6], vehfuel);
  268. new vehiclehealth[24];
  269. format(vehiclehealth, sizeof(vehiclehealth), "%.0f", H);
  270. PlayerTextDrawSetString(playerid, cWspeedo[playerid][8], vehiclehealth);
  271. }
  272. else if(PlayerSpeedo[playerid] == 1)
  273. {
  274. new Float:H;
  275. GetVehicleHealth(vehicle, H);
  276. new speed[24];
  277. format(speed, sizeof(speed), "%.0f", GetVehicleSpeedMPH(vehicle));
  278. PlayerTextDrawSetString(playerid, cWspeedo[playerid][3], speed);
  279. new vehfuel[24];
  280. format(vehfuel, sizeof(vehfuel), "%d", carfuel[vehicle]);
  281. PlayerTextDrawSetString(playerid, cWspeedo[playerid][6], vehfuel);
  282. new vehiclehealth[24];
  283. format(vehiclehealth, sizeof(vehiclehealth), "%.0f", H);
  284. PlayerTextDrawSetString(playerid, cWspeedo[playerid][8], vehiclehealth);
  285. PlayerTextDrawSetString(playerid, cWspeedo[playerid][5], "MP/H");
  286. }
  287. }
  288. return 1;
  289. }
  290.  
  291. //-----------------------------------------------------------------------------//
  292. CMD:switchspeedo(playerid, params[])
  293. {
  294. #pragma unused params
  295. if(PlayerSpeedo[playerid] == 0)
  296. {
  297. PlayerSpeedo[playerid] = 1;
  298. SendClientMessage(playerid, -1, "Tvoja brzina je promjenjena na MP/H");
  299. }
  300. else
  301. {
  302. PlayerSpeedo[playerid] = 0;
  303. SendClientMessage(playerid, -1, "Tvoja brzina je promjenjena na KM/H");
  304. }
  305. return 1;
  306. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement