SAMP Gitlab CI Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
5.8 KiB

5 years ago
  1. //
  2. // Base FS for Sanandreas Multiplayer 0.3
  3. // Contains /pm /kick /ban commands - it also features
  4. // a basic anti flood system, and admin chatting for rcon admins
  5. // using # <message>
  6. #include <a_samp>
  7. #include "../include/gl_common.inc"
  8. #define ADMINFS_MESSAGE_COLOR 0xFF444499
  9. #define PM_INCOMING_COLOR 0xFFFF22AA
  10. #define PM_OUTGOING_COLOR 0xFFCC2299
  11. static iPlayerChatTime[MAX_PLAYERS];
  12. static szPlayerChatMsg[MAX_PLAYERS][128];
  13. //------------------------------------------------
  14. stock IsPlayerFlooding(playerid)
  15. {
  16. if(GetTickCount() - iPlayerChatTime[playerid] < 2000)
  17. return 1;
  18. return 0;
  19. }
  20. //------------------------------------------------
  21. public OnFilterScriptInit()
  22. {
  23. print("\n--Base FS loaded.\n");
  24. return 1;
  25. }
  26. //------------------------------------------------
  27. public OnPlayerText(playerid, text[])
  28. {
  29. // Is the player flooding?
  30. if(IsPlayerFlooding(playerid) && !IsPlayerAdmin(playerid))
  31. {
  32. SendClientMessage(playerid, 0xFF0000FF, "* You can only send a message once every two seconds.");
  33. return 0;
  34. }
  35. // Now we handle the admin chat, will be #<message>.
  36. if( (text[0] == '#' || text[0] == '@') && strlen(text) > 1)
  37. {
  38. new str[128];
  39. new szPlayerName[MAX_PLAYER_NAME];
  40. GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
  41. if(IsPlayerAdmin(playerid))
  42. {
  43. format(str, 128, "Admin %s: %s", szPlayerName, text[1]);
  44. for(new iPlayerID; iPlayerID < MAX_PLAYERS; iPlayerID++)
  45. {
  46. if(!IsPlayerConnected(iPlayerID)) continue;
  47. if(!IsPlayerAdmin(iPlayerID)) continue;
  48. SendClientMessage(iPlayerID, PM_INCOMING_COLOR, str);
  49. }
  50. }
  51. return 0;
  52. }
  53. // Okay, now it's time for anti repeating.
  54. if(!IsPlayerAdmin(playerid))
  55. {
  56. if(strlen(text) == strlen(szPlayerChatMsg[playerid]) && !strcmp(szPlayerChatMsg[playerid], text, false))
  57. {
  58. SendClientMessage(playerid, 0xFF0000FF, "* Please do not repeat yourself.");
  59. format(szPlayerChatMsg[playerid], 128, "%s", text);
  60. return 0;
  61. }
  62. }
  63. format(szPlayerChatMsg[playerid], 128, "%s", text);
  64. iPlayerChatTime[playerid] = GetTickCount();
  65. return 1;
  66. }
  67. //------------------------------------------------
  68. public OnPlayerDisconnect(playerid, reason)
  69. {
  70. #pragma unused reason
  71. iPlayerChatTime[playerid] = 0;
  72. szPlayerChatMsg[playerid] = "";
  73. return 1;
  74. }
  75. //------------------------------------------------
  76. public OnPlayerCommandText(playerid, cmdtext[])
  77. {
  78. if(IsPlayerFlooding(playerid) && !IsPlayerAdmin(playerid))
  79. {
  80. SendClientMessage(playerid, 0xFF0000FF, "* You can only use commands once every two seconds.");
  81. return 1;
  82. }
  83. iPlayerChatTime[playerid] = GetTickCount();
  84. new cmd[256];
  85. new tmp[256];
  86. new Message[256];
  87. new gMessage[256];
  88. new pName[MAX_PLAYER_NAME+1];
  89. new iName[MAX_PLAYER_NAME+1];
  90. new idx;
  91. cmd = strtok(cmdtext, idx);
  92. // PM Command
  93. if(strcmp("/pm", cmd, true) == 0)
  94. {
  95. tmp = strtok(cmdtext,idx);
  96. if(!strlen(tmp) || strlen(tmp) > 5) {
  97. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
  98. return 1;
  99. }
  100. new id = strval(tmp);
  101. gMessage = strrest(cmdtext,idx);
  102. if(!strlen(gMessage)) {
  103. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
  104. return 1;
  105. }
  106. if(!IsPlayerConnected(id)) {
  107. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/pm : Bad player ID");
  108. }
  109. if(playerid != id) {
  110. GetPlayerName(id,iName,sizeof(iName));
  111. GetPlayerName(playerid,pName,sizeof(pName));
  112. format(Message,sizeof(Message),">> %s(%d): %s",iName,id,gMessage);
  113. SendClientMessage(playerid,PM_OUTGOING_COLOR,Message);
  114. format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage);
  115. SendClientMessage(id,PM_INCOMING_COLOR,Message);
  116. PlayerPlaySound(id,1085,0.0,0.0,0.0);
  117. printf("PM: %s",Message);
  118. }
  119. else {
  120. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"You cannot PM yourself");
  121. }
  122. return 1;
  123. }
  124. //Kick Command
  125. if(strcmp("/kick", cmd, true) == 0)
  126. {
  127. if(IsPlayerAdmin(playerid)) {
  128. tmp = strtok(cmdtext,idx);
  129. if(!strlen(tmp) || strlen(tmp) > 5) {
  130. return SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /kick (id) [reason]");
  131. }
  132. new id = strval(tmp);
  133. if(!IsPlayerConnected(id)) {
  134. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/kick : Bad player ID");
  135. return 1;
  136. }
  137. gMessage = strrest(cmdtext,idx);
  138. GetPlayerName(id,iName,sizeof(iName));
  139. SendClientMessage(id,ADMINFS_MESSAGE_COLOR,"-- You have been kicked from the server.");
  140. if(strlen(gMessage) > 0) {
  141. format(Message,sizeof(Message),"Reason: %s",gMessage);
  142. SendClientMessage(id,ADMINFS_MESSAGE_COLOR,Message);
  143. }
  144. format(Message,sizeof(Message),">> %s(%d) has been kicked.",iName,id);
  145. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,Message);
  146. Kick(id);
  147. return 1;
  148. } else {
  149. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/kick : You are not an admin");
  150. return 1;
  151. }
  152. }
  153. //Ban Command
  154. if(strcmp("/ban", cmd, true) == 0)
  155. {
  156. if(IsPlayerAdmin(playerid)) {
  157. tmp = strtok(cmdtext,idx);
  158. if(!strlen(tmp) || strlen(tmp) > 5) {
  159. return SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /ban (id) [reason]");
  160. }
  161. new id = strval(tmp);
  162. if(!IsPlayerConnected(id)) {
  163. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/ban : Bad player ID");
  164. return 1;
  165. }
  166. gMessage = strrest(cmdtext,idx);
  167. GetPlayerName(id,iName,sizeof(iName));
  168. SendClientMessage(id,ADMINFS_MESSAGE_COLOR,"-- You have been banned from the server.");
  169. if(strlen(gMessage) > 0) {
  170. format(Message,sizeof(Message),"Reason: %s",gMessage);
  171. SendClientMessage(id,ADMINFS_MESSAGE_COLOR,Message);
  172. }
  173. format(Message,sizeof(Message),">> %s(%d) has been banned.",iName,id);
  174. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,Message);
  175. Ban(id);
  176. return 1;
  177. } else {
  178. SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/ban : You are not an admin");
  179. return 1;
  180. }
  181. }
  182. return 0;
  183. }
  184. //-----------------------------------------------