Guest User

Basic Commands FS By Avi.

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