VanGans

FS Speed Limit

Aug 28th, 2020 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.60 KB | None | 0 0
  1. //Speedlimit created by VanGans
  2. #include <a_samp>
  3. #include <sscanf>
  4. #define COLOR_WHITE 0xFFFFFFAA
  5. #define COLOR_GREY 0xAFAFAFAA
  6. #define COLOR_LIGHTBLUE 0x33CCFFAA`
  7. // Speedlimit
  8. new Speedlimit[MAX_PLAYERS];
  9. #define SpeedCheck(%0,%1,%2,%3,%4) floatround(floatsqroot(%4?(%0*%0+%1*%1+%2*%2):(%0*%0+%1*%1) ) *%3*1.6)
  10.  
  11.  
  12. public OnFilterScriptInit()
  13. {
  14.     return 1;
  15. }
  16.  
  17. public OnFilterScriptExit()
  18. {
  19.     return 1;
  20. }
  21.  
  22. public OnGameModeInit()
  23. {
  24.  
  25.     return 1;
  26. }
  27.  
  28. public OnGameModeExit()
  29. {
  30.     return 1;
  31. }
  32.  
  33. public OnPlayerRequestClass(playerid, classid)
  34. {
  35.     return 1;
  36. }
  37.  
  38. public OnPlayerConnect(playerid)
  39. {
  40.     Speedlimit[playerid] = 0;
  41.     return 1;
  42. }
  43.  
  44. public OnPlayerDisconnect(playerid, reason)
  45. {
  46.     return 1;
  47. }
  48.  
  49. public OnPlayerSpawn(playerid)
  50. {
  51.     return 1;
  52. }
  53.  
  54. public OnPlayerDeath(playerid, killerid, reason)
  55. {
  56.     return 1;
  57. }
  58.  
  59. public OnVehicleSpawn(vehicleid)
  60. {
  61.     return 1;
  62. }
  63.  
  64. public OnVehicleDeath(vehicleid, killerid)
  65. {
  66.     return 1;
  67. }
  68.  
  69. public OnPlayerText(playerid, text[])
  70. {
  71.     return 1;
  72. }
  73.  
  74. public OnPlayerCommandText(playerid, cmdtext[])
  75. {
  76. if (strcmp("/speedlimit", cmdtext, true, 10) == 0)
  77.     {
  78.     new string[128], speed;
  79.     if(sscanf(cmdtext, "i", speed)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /speedlimit [Max MPH]");
  80.     if(speed < 0) return SendClientMessage(playerid, COLOR_GREY, "Invalid MPH speed.");
  81.     Speedlimit[playerid] = speed;
  82.     if(speed == 0) format(string, sizeof(string), " You have turned your speed limit off.", speed);
  83.     else format(string, sizeof(string), " You have set your speed limit to %d MPH, any vehicle you drive will not go past this limit.", speed);
  84.     SendClientMessage(playerid, COLOR_GREY, string);
  85.     }
  86. return 1;
  87. }
  88. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  89. {
  90.     return 1;
  91. }
  92.  
  93. public OnPlayerExitVehicle(playerid, vehicleid)
  94. {
  95.     return 1;
  96. }
  97.  
  98. public OnPlayerStateChange(playerid, newstate, oldstate)
  99. {
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerEnterCheckpoint(playerid)
  104. {
  105.     return 1;
  106. }
  107.  
  108. public OnPlayerLeaveCheckpoint(playerid)
  109. {
  110.     return 1;
  111. }
  112.  
  113. public OnPlayerEnterRaceCheckpoint(playerid)
  114. {
  115.     return 1;
  116. }
  117.  
  118. public OnPlayerLeaveRaceCheckpoint(playerid)
  119. {
  120.     return 1;
  121. }
  122.  
  123. public OnRconCommand(cmd[])
  124. {
  125.     return 1;
  126. }
  127.  
  128. public OnPlayerRequestSpawn(playerid)
  129. {
  130.     return 1;
  131. }
  132.  
  133. public OnObjectMoved(objectid)
  134. {
  135.     return 1;
  136. }
  137.  
  138. public OnPlayerObjectMoved(playerid, objectid)
  139. {
  140.     return 1;
  141. }
  142.  
  143. public OnPlayerPickUpPickup(playerid, pickupid)
  144. {
  145.     return 1;
  146. }
  147.  
  148. public OnVehicleMod(playerid, vehicleid, componentid)
  149. {
  150.     return 1;
  151. }
  152.  
  153. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  154. {
  155.     return 1;
  156. }
  157.  
  158. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  159. {
  160.     return 1;
  161. }
  162.  
  163. public OnPlayerSelectedMenuRow(playerid, row)
  164. {
  165.     return 1;
  166. }
  167.  
  168. public OnPlayerExitedMenu(playerid)
  169. {
  170.     return 1;
  171. }
  172.  
  173. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  174. {
  175.     return 1;
  176. }
  177.  
  178. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  179. {
  180.     return 1;
  181. }
  182.  
  183. public OnRconLoginAttempt(ip[], password[], success)
  184. {
  185.     return 1;
  186. }
  187.  
  188. public OnPlayerUpdate(playerid)
  189. {
  190.  // Speedlimit
  191.         if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && Speedlimit[playerid])
  192.         {
  193.             new a, b, c;
  194.             GetPlayerKeys(playerid, a, b ,c);
  195.             if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > Speedlimit[playerid])
  196.             {
  197.                 new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - Speedlimit[playerid];
  198.                 ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed);
  199.             }
  200.         }
  201.         return 1;
  202. }
  203.  
  204. public OnPlayerStreamIn(playerid, forplayerid)
  205. {
  206.     return 1;
  207. }
  208.  
  209. public OnPlayerStreamOut(playerid, forplayerid)
  210. {
  211.     return 1;
  212. }
  213.  
  214. public OnVehicleStreamIn(vehicleid, forplayerid)
  215. {
  216.     return 1;
  217. }
  218.  
  219. public OnVehicleStreamOut(vehicleid, forplayerid)
  220. {
  221.     return 1;
  222. }
  223.  
  224. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  225. {
  226.     return 1;
  227. }
  228.  
  229. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  230. {
  231.     return 1;
  232. }
  233. stock GetVehicleSpeed(vehicleid, get3d)
  234. {
  235.     new Float:x, Float:y, Float:z;
  236.     GetVehicleVelocity(vehicleid, x, y, z);
  237.     return SpeedCheck(x, y, z, 100.0, get3d);
  238. }
  239. stock ModifyVehicleSpeed(vehicleid,mph) //Miles Per Hour
  240. {
  241.     new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple;
  242.     GetVehicleVelocity(vehicleid,Vx,Vy,Vz);
  243.     DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
  244.     if(DV > 0) //Directional velocity must be greater than 0 (display strobes if 0)
  245.     {
  246.         multiple = ((mph + DV * 100) / (DV * 100)); //Multiplying DV by 100 calculates speed in MPH
  247.         return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple);
  248.     }
  249.     return 0;
  250. }
Add Comment
Please, Sign In to add comment