Guest User

Untitled

a guest
Mar 3rd, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. ///////////////////////////////////////////////
  4. /////////SETUP
  5. #define SRVR_MAX_SLOT 50 // current max player setting, we could use MAX_PLAYERS but its fix at 200...
  6. // YOU MUST SET THAT TO YOUR SERVER MAX PLAYER
  7. ///////////////////////////////////////////////
  8.  
  9. #define COLOR_TXT 0xC4996DFF
  10. #define OFFSET 1.12 // default distance forward of the surf
  11. #define TIMER_SPEED 75 // Normal timer speed...
  12. #define TIMER_IDLE 750 // Idle timer speed...
  13. #define CHECK_RATE 40 // script will look for offline surefer every XX timer frame
  14. forward public surfing();
  15. forward public killstatustxt();
  16. new surf[SRVR_MAX_SLOT], surfer[SRVR_MAX_SLOT], surftimer, Float:surfoffset[SRVR_MAX_SLOT];
  17. new Float:hashpos[SRVR_MAX_SLOT], isidle[SRVR_MAX_SLOT], systemidle, checker;
  18. /*
  19. =============================================================================
  20. * Magic Surf by www.snoob.net
  21.  
  22. * this script put a surf under a player and update the position of the surf *
  23. * every timer frame. all the surfers use the same timer. if a surfer is *
  24. * idle, the surf will center on the position, if the surfer is moving the *
  25. * surf position will be offset forward. if all the surfer are idle the *
  26. * timer will switch to idle speed. if the ping of a player is higher then *
  27. * 200 he should walk to avoid steping ahead of the surf *
  28.  
  29. * you can find more cool script on my wiki.snoob.net
  30.  
  31. =============================================================================
  32. */
  33. public OnFilterScriptInit()
  34. {
  35. print("\n--------------------------------------");
  36. print(" Magic Surf by www.snoob.net ");
  37. print("--------------------------------------\n");
  38. return 1;
  39. }
  40. public OnFilterScriptExit()
  41. {
  42. for(new b = 0; b < SRVR_MAX_SLOT; b++)
  43. {
  44. if(surfer[b]) {
  45. DestroyObject(surf[b]);
  46. surfer[b] = 0;
  47. }
  48. }
  49. return 1;
  50. }
  51. chkdeadsurf()
  52. {
  53. checker = 0;
  54. for(new b = 0; b < SRVR_MAX_SLOT; b++)
  55. {
  56. if(surfer[b] && !IsPlayerConnected(b)) {
  57. DestroyObject(surf[b]);
  58. surfer[b] = 0;
  59. }
  60. }
  61. return 1;
  62. }
  63. public surfing()
  64. {
  65. new a, idle, allidle;
  66. checker++;
  67. if(checker == CHECK_RATE) chkdeadsurf();
  68. for(new i = 0; i < SRVR_MAX_SLOT; i++)
  69. {
  70. if(IsPlayerConnected(i) && surfer[i]) {
  71. a++;
  72. new Float:playerpos[4], Float:newhashpos;
  73. GetPlayerPos(i,playerpos[0],playerpos[1],playerpos[2]);
  74. GetPlayerFacingAngle(i,playerpos[3]);
  75. newhashpos = (playerpos[0] * playerpos[1]) + (playerpos[2] * playerpos[3]);
  76. if(newhashpos == hashpos[i]) { // the player is idle
  77. idle++, isidle[i]++;
  78. if(isidle[i] == 2) { // the second time the player is idle
  79. SetObjectPos(surf[i],playerpos[0],playerpos[1],playerpos[2]-1.0855);
  80. SetObjectRot(surf[i],-90.0,0.0,playerpos[3]);
  81. }
  82. }
  83. else { // the player is not idle
  84. SetObjectPos(surf[i],playerpos[0]+surfoffset[i]*floatsin(-playerpos[3],degrees),
  85. playerpos[1]+surfoffset[i]*floatcos(-playerpos[3],degrees),playerpos[2]-1.0855);
  86. SetObjectRot(surf[i],-90.0,0.0,playerpos[3]);
  87. isidle[i] = 0;
  88. }
  89. hashpos[i] = newhashpos;
  90. }
  91. }
  92. if(a && (a == idle)) { // ALL player are idle
  93. allidle = 1;
  94. if(systemidle < 20) { // 20 first time it hapen
  95. systemidle++;
  96. }
  97. if(systemidle == 20) { // we switch the timer to idle speed
  98. KillTimer(surftimer);
  99. surftimer = SetTimer("surfing",TIMER_IDLE,true);
  100. systemidle = 21;
  101. }
  102. }
  103. else if((systemidle == 21) && !allidle) {
  104. //system is idle but a player move, we switch the timer back to normal speed
  105. KillTimer(surftimer);
  106. surftimer = SetTimer("surfing",TIMER_SPEED,true);
  107. systemidle = 0;
  108. }
  109. if(!a) { // no player is curently surfing we kill the timer.
  110. KillTimer(surftimer);
  111. surftimer = 0;
  112. for(new b = 0; b < SRVR_MAX_SLOT; b++) // and destroy any left over surf
  113. {
  114. if(surfer[b]) {
  115. DestroyObject(surf[b]);
  116. surfer[b] = 0;
  117. }
  118. }
  119. }
  120. return 1;
  121. }
  122. public OnPlayerCommandText(playerid, cmdtext[])
  123. {
  124. new cmd[256], idx;
  125. cmd = strtok(cmdtext, idx);
  126. if (strcmp("/surf", cmdtext, true, 6) == 0)
  127. {
  128. if(surfer[playerid]) return SendClientMessage(playerid,COLOR_TXT,"You are already on a surf");
  129. SendClientMessage(playerid,COLOR_TXT,"Have fun!");
  130. surfoffset[playerid] = OFFSET;
  131. surf[playerid] = CreateObject(2405,0.0,0.0,0.0,-90.0,0.0,0.0);
  132. surfer[playerid] = 1;
  133. if(!surftimer) {
  134. surftimer = SetTimer("surfing",TIMER_SPEED,true);
  135. }
  136. return 1;
  137. }
  138. if (strcmp("/unsurf", cmdtext, true, 8) == 0)
  139. {
  140. DestroyObject(surf[playerid]);
  141. surfer[playerid] = 0;
  142. return 1;
  143. }
  144. if(strcmp(cmd, "/offset", true) == 0) {
  145. new tmp[256];
  146. tmp = strtok(cmdtext, idx);
  147. if(!surfer[playerid]) return SendClientMessage(playerid,COLOR_TXT,"You must be surfing to use /offset");
  148. if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_TXT,"Usage: /offset [-0.9 to 0.9]");
  149. surfoffset[playerid] = floatstr(tmp);
  150. format(tmp,sizeof(tmp),"Offset set to %f",surfoffset[playerid]);
  151. SendClientMessage(playerid,COLOR_TXT,tmp);
  152. return 1;
  153. }
  154. return 0;
  155. }
  156. strtok(const string[], &index)
  157. {
  158. // more info on strtok are available on the official sa-mp wiki
  159. new length = strlen(string);
  160. while ((index < length) && (string[index] <= ' '))
  161. {
  162. index++;
  163. }
  164. new offset = index;
  165. new result[20];
  166. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  167. {
  168. result[index - offset] = string[index];
  169. index++;
  170. }
  171. result[index - offset] = EOS;
  172. return result;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment