Guest User

Untitled

a guest
Jun 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. // -----------------------------------------------------------------------------
  2. // Tempomat by Zalakaka45 Betöltve!
  3. // -----------------------------------------------------------------------------
  4. // Készült: 13/02/2012
  5. // -----------------------------------------------------------------------------
  6.  
  7. #include <a_samp>
  8.  
  9. #define COLOR_MESSAGE_YELLOW 0xFFDD00AA
  10. #define COLOR_GREY 0xAFAFAFAA
  11.  
  12.  
  13. new Float:PlayerCruiseSpeed[MAX_PLAYERS];
  14. new Float:PlayerHeadingAngle[MAX_PLAYERS];
  15. new CCKey = KEY_ACTION;
  16.  
  17. forward CruiseControl(playerid);
  18.  
  19. public OnFilterScriptInit()
  20. {
  21. print("[Tempomat by Zalakaka45 Betöltve!]");
  22. return 1;
  23. }
  24.  
  25. public OnFilterScriptExit()
  26. {
  27. return 1;
  28. }
  29.  
  30. public OnPlayerCommandText(playerid, cmdtext[])
  31. {
  32. new cmd[256];
  33. new idx;
  34.  
  35. cmd = strtok(cmdtext, idx);
  36.  
  37. if (strcmp(cmd, "/tempomat", true) == 0)
  38. {
  39. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*Ha az ujjadat a BAL CONTROLON tartod akkor a jármü tartani fogja a megadott sebességet!");
  40. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*Csak Járműben Használhatod!");
  41. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "::A tempomatért köszönet Zalakaka45-nek!");
  42. return 1;
  43. }
  44. return 0;
  45. }
  46.  
  47. public OnPlayerConnect(playerid)
  48. {
  49. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* Tempomat Betöltve - Ird be /tempomat az infókért! ");
  50. return 1;
  51. }
  52.  
  53. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  54. {
  55. if ((newkeys & CCKey) && !(oldkeys & CCKey) && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  56. {
  57. new vid = GetPlayerVehicleID(playerid);
  58. if (GetVehicleSpeed(vid) == 0) return false;
  59. new Float:x, Float:y, Float:z;
  60. GetVehicleVelocity(vid, x, y, z);
  61. GetVehicleZAngle(vid, PlayerHeadingAngle[playerid]);
  62. DistanceFlat(0, 0, x, y, PlayerCruiseSpeed[playerid]);
  63. SetTimerEx("CruiseControl", 500, false, "d", playerid);
  64. SendClientMessage(playerid, COLOR_GREY, "* Tempomat Bekapcsolva");
  65. }
  66. else if (PlayerCruiseSpeed[playerid] != 0.00 && (newkeys & KEY_HANDBRAKE))
  67. {
  68. PlayerCruiseSpeed[playerid] = 0.00;
  69. }
  70. return 1;
  71. }
  72.  
  73. GetVehicleSpeed(vehicleid)
  74. {
  75. new Float:Vx, Float:Vy, Float:Vz;
  76. GetVehicleVelocity(vehicleid, Vx, Vy, Vz);
  77. new Float:rtn;
  78. rtn = floatsqroot(floatpower(Vx*100,2) + floatpower(Vy*100,2));
  79. rtn = floatsqroot(floatpower(rtn,2) + floatpower(Vz*100,2));
  80. return floatround(rtn);
  81. }
  82.  
  83. DistanceFlat(Float:ax, Float:ay, Float:bx,Float:by, &Float:distance)
  84. {
  85. distance = floatsqroot(floatpower(bx-ax,2)+floatpower(by-ay,2));
  86. return floatround(distance);
  87. }
  88.  
  89. public CruiseControl(playerid)
  90. {
  91. new vid = GetPlayerVehicleID(playerid);
  92. new Float:x, Float:y, Float:z;
  93. GetVehicleVelocity(vid, x, y, z);
  94.  
  95. new keys, ud, lr;
  96. GetPlayerKeys(playerid, keys, ud, lr);
  97.  
  98. new Float:angle, Float:heading, Float:speed;
  99. GetVehicleZAngle(vid, angle);
  100. GetVehicleHeadingAngle(vid, heading);
  101. DistanceFlat(0, 0, x, y, speed);
  102.  
  103.  
  104. if (!(keys & CCKey) || PlayerCruiseSpeed[playerid] == 0.00 ||
  105. GetPlayerState(playerid) != PLAYER_STATE_DRIVER ||
  106. (speed < 0.7 * PlayerCruiseSpeed[playerid]) ||
  107. z > 1 ||
  108. (floatabs(angle - heading) > 50 && floatabs(angle - heading) < 310))
  109. {
  110. PlayerCruiseSpeed[playerid] = 0.00;
  111. SendClientMessage(playerid, COLOR_GREY, "*Tempomat Kikapcsolva");
  112. return false;
  113. }
  114. GetVehicleZAngle(vid, PlayerHeadingAngle[playerid]);
  115. GetXYVelocity(vid, x, y, PlayerCruiseSpeed[playerid]);
  116. SetVehicleVelocity(vid, x, y, z);
  117. return SetTimerEx("CruiseControl", 500, false, "d", playerid);
  118. }
  119.  
  120. GetXYVelocity(vehicleid, &Float:x, &Float:y, Float:speed)
  121. {
  122. new Float:a;
  123. x = 0.0;
  124. y = 0.0;
  125. GetVehicleZAngle(vehicleid, a);
  126. x += (speed * floatsin(-a, degrees));
  127. y += (speed * floatcos(-a, degrees));
  128. }
  129.  
  130. GetAngleToXY(Float:X, Float:Y, Float:CurrentX, Float:CurrentY, &Float:Angle)
  131. {
  132. Angle = atan2(Y-CurrentY, X-CurrentX);
  133. Angle = floatsub(Angle, 90.0);
  134. if(Angle < 0.0) Angle = floatadd(Angle, 360.0);
  135. }
  136.  
  137. GetVehicleHeadingAngle(vehicleid, &Float:a)
  138. {
  139. new Float:x, Float:y, Float:z;
  140. GetVehicleVelocity(vehicleid, x, y, z);
  141. GetAngleToXY(x, y, 0, 0, a);
  142. }
  143.  
  144. strtok(const string[], &index)
  145. {
  146. new length = strlen(string);
  147. while ((index < length) && (string[index] <= ' '))
  148. {
  149. index++;
  150. }
  151.  
  152. new offset = index;
  153. new result[20];
  154. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  155. {
  156. result[index - offset] = string[index];
  157. index++;
  158. }
  159. result[index - offset] = EOS;
  160. return result;
  161. }
Add Comment
Please, Sign In to add comment