Advertisement
Guest User

Untitled

a guest
Aug 14th, 2010
4,842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. // -----------------------------------------------------------------------------
  2. // -----------------------------------------------------------------------------
  3. // Cruise Control FilterScript for SAMP 0.3
  4. // 4th March 2010 (My birthday :)
  5. // By Mick88
  6. // Visit my server:
  7. // Convoy Trucking (Cruise Control implemented)
  8. // 91.204.163.105:7931
  9. // -----------------------------------------------------------------------------
  10. // -----------------------------------------------------------------------------
  11.  
  12. #include <a_samp>
  13.  
  14. #define COLOR_MESSAGE_YELLOW 0xFFDD00AA
  15. #define COLOR_GREY 0xAFAFAFAA
  16.  
  17.  
  18. new Float:PlayerCruiseSpeed[MAX_PLAYERS];
  19. new Float:PlayerHeadingAngle[MAX_PLAYERS];
  20. new CCKey = KEY_ACTION; //Cruise Control Key - change this if you need
  21. /* keys that can be used:
  22. KEY_ACTION (LCTRL)
  23. KEY_FIRE (mouse click)
  24. KEY_SUBMISSION (2)
  25. KEY_LOOK_BEHIND
  26. or others you know
  27. */
  28.  
  29. forward CruiseControl(playerid);
  30.  
  31. public OnFilterScriptInit()
  32. {
  33. print("[Cruise Control system by Mick88: LOADED]");
  34. return 1;
  35. }
  36.  
  37. public OnFilterScriptExit()
  38. {
  39. return 1;
  40. }
  41.  
  42. public OnPlayerCommandText(playerid, cmdtext[])
  43. {
  44. new cmd[256];
  45. new idx;
  46.  
  47. cmd = strtok(cmdtext, idx);
  48.  
  49. if (strcmp(cmd, "/cruisecontrol", true) == 0)
  50. {
  51. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, ":: Cruise Control by mick88 ::");
  52. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*Cruise control will help you keep constant speed without the need of tapping the acceleration key");
  53. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*To use it, set your car to wanted speed and hold the Cruise Control button (default: LCTRL)");
  54. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*Your vehicle will keep that speed regardless of going up hill or downhill as long as Cruise Control");
  55. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "button is held down. You can release the acceleration button.");
  56. return 1;
  57. }
  58. return 0;
  59. }
  60.  
  61. public OnPlayerConnect(playerid)
  62. {
  63. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* Cruise Control by mick88 - type /CruiseControl for more info");
  64. return 1;
  65. }
  66.  
  67. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  68. {
  69. if ((newkeys & CCKey) && !(oldkeys & CCKey) && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  70. {
  71. new vid = GetPlayerVehicleID(playerid);
  72. if (GetVehicleSpeed(vid) == 0) return false;
  73. new Float:x, Float:y, Float:z;
  74. GetVehicleVelocity(vid, x, y, z);
  75. GetVehicleZAngle(vid, PlayerHeadingAngle[playerid]);
  76. DistanceFlat(0, 0, x, y, PlayerCruiseSpeed[playerid]);
  77. SetTimerEx("CruiseControl", 500, false, "d", playerid);
  78. SendClientMessage(playerid, COLOR_GREY, "* Cruise control engaged"); // === Remove this if not needed ===
  79. }
  80. else if (PlayerCruiseSpeed[playerid] != 0.00 && (newkeys & KEY_HANDBRAKE))
  81. {
  82. PlayerCruiseSpeed[playerid] = 0.00;
  83. }
  84. return 1;
  85. }
  86.  
  87. GetVehicleSpeed(vehicleid)
  88. {
  89. new Float:Vx, Float:Vy, Float:Vz;
  90. GetVehicleVelocity(vehicleid, Vx, Vy, Vz);
  91. new Float:rtn;
  92. rtn = floatsqroot(floatpower(Vx*100,2) + floatpower(Vy*100,2));
  93. rtn = floatsqroot(floatpower(rtn,2) + floatpower(Vz*100,2));
  94. return floatround(rtn);
  95. }
  96.  
  97. DistanceFlat(Float:ax, Float:ay, Float:bx,Float:by, &Float:distance)
  98. {
  99. distance = floatsqroot(floatpower(bx-ax,2)+floatpower(by-ay,2));
  100. return floatround(distance);
  101. }
  102.  
  103. public CruiseControl(playerid)
  104. {
  105. new vid = GetPlayerVehicleID(playerid);
  106. new Float:x, Float:y, Float:z;
  107. GetVehicleVelocity(vid, x, y, z);
  108.  
  109. new keys, ud, lr;
  110. GetPlayerKeys(playerid, keys, ud, lr);
  111.  
  112. new Float:angle, Float:heading, Float:speed;
  113. GetVehicleZAngle(vid, angle);
  114. GetVehicleHeadingAngle(vid, heading);
  115. DistanceFlat(0, 0, x, y, speed);
  116.  
  117.  
  118. if (!(keys & CCKey) || PlayerCruiseSpeed[playerid] == 0.00 || //If player released LCTRL or CruiseSpeed got cancelled by other means (spacebar press)
  119. GetPlayerState(playerid) != PLAYER_STATE_DRIVER ||
  120. (speed < 0.7 * PlayerCruiseSpeed[playerid]) || //if player slowed down too much
  121. z > 1 || //if car is going upwards too fast
  122. (floatabs(angle - heading) > 50 && floatabs(angle - heading) < 310))//if vehicle goes sideways
  123. { //Cruise control will turn off:
  124. PlayerCruiseSpeed[playerid] = 0.00;
  125. SendClientMessage(playerid, COLOR_GREY, "*Cruse control disengaged"); // === Remove this if not needed ===
  126. return false;
  127. }
  128. GetVehicleZAngle(vid, PlayerHeadingAngle[playerid]);
  129. GetXYVelocity(vid, x, y, PlayerCruiseSpeed[playerid]);
  130. SetVehicleVelocity(vid, x, y, z);
  131. return SetTimerEx("CruiseControl", 500, false, "d", playerid);
  132. }
  133.  
  134. GetXYVelocity(vehicleid, &Float:x, &Float:y, Float:speed)
  135. {
  136. new Float:a;
  137. x = 0.0;
  138. y = 0.0;
  139. GetVehicleZAngle(vehicleid, a);
  140. x += (speed * floatsin(-a, degrees));
  141. y += (speed * floatcos(-a, degrees));
  142. }
  143.  
  144. GetAngleToXY(Float:X, Float:Y, Float:CurrentX, Float:CurrentY, &Float:Angle)
  145. {
  146. Angle = atan2(Y-CurrentY, X-CurrentX);
  147. Angle = floatsub(Angle, 90.0);
  148. if(Angle < 0.0) Angle = floatadd(Angle, 360.0);
  149. }
  150.  
  151. GetVehicleHeadingAngle(vehicleid, &Float:a)
  152. {
  153. new Float:x, Float:y, Float:z;
  154. GetVehicleVelocity(vehicleid, x, y, z);
  155. GetAngleToXY(x, y, 0, 0, a);
  156. }
  157.  
  158. strtok(const string[], &index)
  159. {
  160. new length = strlen(string);
  161. while ((index < length) && (string[index] <= ' '))
  162. {
  163. index++;
  164. }
  165.  
  166. new offset = index;
  167. new result[20];
  168. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  169. {
  170. result[index - offset] = string[index];
  171. index++;
  172. }
  173. result[index - offset] = EOS;
  174. return result;
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement