Guest User

[FILTERSCRIPT]Vehicle Velocity Control by NealPeteros

a guest
Apr 3rd, 2017
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. CREDITS:
  3. mick88 - Got the idea from mick88, and I somewhat learned from his Cruise Control FS
  4. NealPeteros - Created the whole script from basic scratch
  5. SAMP Community - Providing the necessary needs for this filterscript(Self-explainable)
  6. PAWN - Programming Language used for this filterscript(Self-explainable)
  7. PAWNO - Provided program that is responsible for PAWN, and all contents of this filterscript(Self-explainable)
  8. */
  9. #define FILTERSCRIPT
  10.  
  11. #include <a_samp>
  12.  
  13. //Colors
  14. #define COLOR_MESSAGE_YELLOW 0xFFDD00AA
  15. #define COLOR_GREY 0xAFAFAFAA
  16.  
  17. #define startkey KEY_FIRE // Change to desired key (DEFAULT: LALT)
  18. #define endkey KEY_HANDBRAKE // Change to desired key (DEFAULT: SPACE)
  19.  
  20. // Variables
  21. new Float:PlayerSpeed[MAX_PLAYERS];
  22. new Float:PlayerAngle[MAX_PLAYERS];
  23.  
  24. //forwards
  25. forward VelocityControl(playerid);
  26.  
  27. public OnFilterScriptInit()
  28. {
  29. print("\n--------------------------------------");
  30. print(" Blank Filterscript by your name here");
  31. print("--------------------------------------\n");
  32. return 1;
  33. }
  34.  
  35. public OnFilterScriptExit()
  36. {
  37. return 1;
  38. }
  39.  
  40. public OnGameModeInit()
  41. {
  42. // Don't use these lines if it's a filterscript
  43. SetGameModeText("Blank Script");
  44. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  45. return 1;
  46. }
  47.  
  48. public OnGameModeExit()
  49. {
  50. return 1;
  51. }
  52.  
  53. public OnPlayerRequestClass(playerid, classid)
  54. {
  55. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  56. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  57. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  58. return 1;
  59. }
  60.  
  61. public OnPlayerConnect(playerid)
  62. {
  63. return 1;
  64. }
  65.  
  66. public OnPlayerDisconnect(playerid, reason)
  67. {
  68. return 1;
  69. }
  70.  
  71. public OnPlayerSpawn(playerid)
  72. {
  73. return 1;
  74. }
  75.  
  76. public OnPlayerDeath(playerid, killerid, reason)
  77. {
  78. return 1;
  79. }
  80.  
  81. public OnVehicleSpawn(vehicleid)
  82. {
  83. return 1;
  84. }
  85.  
  86. public OnVehicleDeath(vehicleid, killerid)
  87. {
  88. return 1;
  89. }
  90.  
  91. public OnPlayerText(playerid, text[])
  92. {
  93. return 1;
  94. }
  95.  
  96. public OnPlayerCommandText(playerid, cmdtext[])
  97. {
  98. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  99. {
  100. // Do something here
  101. return 1;
  102. }
  103. return 0;
  104. }
  105.  
  106. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  107. {
  108. return 1;
  109. }
  110.  
  111. public OnPlayerExitVehicle(playerid, vehicleid)
  112. {
  113. return 1;
  114. }
  115.  
  116. public OnPlayerStateChange(playerid, newstate, oldstate)
  117. {
  118. return 1;
  119. }
  120.  
  121. public OnPlayerEnterCheckpoint(playerid)
  122. {
  123. return 1;
  124. }
  125.  
  126. public OnPlayerLeaveCheckpoint(playerid)
  127. {
  128. return 1;
  129. }
  130.  
  131. public OnPlayerEnterRaceCheckpoint(playerid)
  132. {
  133. return 1;
  134. }
  135.  
  136. public OnPlayerLeaveRaceCheckpoint(playerid)
  137. {
  138. return 1;
  139. }
  140.  
  141. public OnRconCommand(cmd[])
  142. {
  143. return 1;
  144. }
  145.  
  146. public OnPlayerRequestSpawn(playerid)
  147. {
  148. return 1;
  149. }
  150.  
  151. public OnObjectMoved(objectid)
  152. {
  153. return 1;
  154. }
  155.  
  156. public OnPlayerObjectMoved(playerid, objectid)
  157. {
  158. return 1;
  159. }
  160.  
  161. public OnPlayerPickUpPickup(playerid, pickupid)
  162. {
  163. return 1;
  164. }
  165.  
  166. public OnVehicleMod(playerid, vehicleid, componentid)
  167. {
  168. return 1;
  169. }
  170.  
  171. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  172. {
  173. return 1;
  174. }
  175.  
  176. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  177. {
  178. return 1;
  179. }
  180.  
  181. public OnPlayerSelectedMenuRow(playerid, row)
  182. {
  183. return 1;
  184. }
  185.  
  186. public OnPlayerExitedMenu(playerid)
  187. {
  188. return 1;
  189. }
  190.  
  191. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  192. {
  193. return 1;
  194. }
  195.  
  196. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  197. {
  198. if ((newkeys & startkey) && !(oldkeys & startkey) && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  199. {
  200. new vid = GetPlayerVehicleID(playerid);
  201. if (GetCarSpeed(vid) == 0) return false;
  202. new Float:x, Float:y, Float:z;
  203. GetVehicleVelocity(vid, x, y, z);
  204. GetVehicleZAngle(vid, PlayerAngle[playerid]);
  205. FloatDistance(0, 0, x, y, PlayerSpeed[playerid]);
  206. SetTimerEx("VelocityControl", 500, false, "d", playerid);
  207. GameTextForPlayer(playerid, "Velocity Control Enabled", 3000, 5);
  208. }
  209. else if (PlayerSpeed[playerid] != 0.00 && (newkeys & endkey))
  210. {
  211. PlayerSpeed[playerid] = 0.00;
  212. }
  213. return 1;
  214. }
  215.  
  216. public OnRconLoginAttempt(ip[], password[], success)
  217. {
  218. return 1;
  219. }
  220.  
  221. public OnPlayerUpdate(playerid)
  222. {
  223. return 1;
  224. }
  225.  
  226. public OnPlayerStreamIn(playerid, forplayerid)
  227. {
  228. return 1;
  229. }
  230.  
  231. public OnPlayerStreamOut(playerid, forplayerid)
  232. {
  233. return 1;
  234. }
  235.  
  236. public OnVehicleStreamIn(vehicleid, forplayerid)
  237. {
  238. return 1;
  239. }
  240.  
  241. public OnVehicleStreamOut(vehicleid, forplayerid)
  242. {
  243. return 1;
  244. }
  245.  
  246. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  247. {
  248. return 1;
  249. }
  250.  
  251. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  252. {
  253. return 1;
  254. }
  255.  
  256. /* Custom Callbacks */
  257. public VelocityControl(playerid)
  258. {
  259. new veh = GetPlayerVehicleID(playerid);
  260. new Float:x, Float:y, Float:z;
  261. GetVehicleVelocity(veh, x, y, z);
  262.  
  263. new keys, akey, bkey;
  264. GetPlayerKeys(playerid, keys, akey, bkey);
  265.  
  266. new Float:angle, Float:heading, Float:speed;
  267. GetVehicleZAngle(veh, angle);
  268. GetVehicleFacingAngle(veh, heading);
  269. FloatDistance(0, 0, x, y, speed);
  270.  
  271.  
  272. if (!(keys & startkey) || PlayerSpeed[playerid] == 0.00 || GetPlayerState(playerid) != PLAYER_STATE_DRIVER || (speed < 0.7 * PlayerSpeed[playerid]) || z > 1 || (floatabs(angle - heading) > 50 && floatabs(angle - heading) < 310))
  273. {
  274. PlayerSpeed[playerid] = 0.00;
  275. GameTextForPlayer(playerid, "Velocity Control Disabled", 3000, 5);
  276. return false;
  277. }
  278. GetVehicleZAngle(veh, PlayerAngle[playerid]);
  279. GetSpeedXY(veh, x, y, PlayerSpeed[playerid]);
  280. SetVehicleVelocity(veh, x, y, z);
  281. return SetTimerEx("VelocityControl", 500, false, "d", playerid);
  282. }
  283.  
  284. /* Stocks */
  285.  
  286. GetCarSpeed(vehid)
  287. {
  288. new Float:Vx, Float:Vy, Float:Vz;
  289. GetVehicleVelocity(vehid, Vx, Vy, Vz);
  290. new Float:rtn;
  291. rtn = floatsqroot(floatpower(Vx*100,2) + floatpower(Vy*100,2));
  292. rtn = floatsqroot(floatpower(rtn,2) + floatpower(Vz*100,2));
  293. return floatround(rtn);
  294. }
  295.  
  296. FloatDistance(Float:ax, Float:ay, Float:bx,Float:by, &Float:distance)
  297. {
  298. distance = floatsqroot(floatpower(bx-ax,2)+floatpower(by-ay,2));
  299. return floatround(distance);
  300. }
  301.  
  302. GetSpeedXY(vehicleid, &Float:x, &Float:y, Float:speed)
  303. {
  304. new Float:a;
  305. x = 0.0;
  306. y = 0.0;
  307. GetVehicleZAngle(vehicleid, a);
  308. x += (speed * floatsin(-a, degrees));
  309. y += (speed * floatcos(-a, degrees));
  310. }
  311.  
  312. GetAngleToXY(Float:X, Float:Y, Float:CurrentX, Float:CurrentY, &Float:Angle)
  313. {
  314. Angle = atan2(Y-CurrentY, X-CurrentX);
  315. Angle = floatsub(Angle, 90.0);
  316. if(Angle < 0.0) Angle = floatadd(Angle, 360.0);
  317. }
  318.  
  319. GetVehicleFacingAngle(vehicleid, &Float:a)
  320. {
  321. new Float:x, Float:y, Float:z;
  322. GetVehicleVelocity(vehicleid, x, y, z);
  323. GetAngleToXY(x, y, 0, 0, a);
  324. }
Add Comment
Please, Sign In to add comment