Guest User

Clan System SA-MP By COD

a guest
Jul 22nd, 2011
3,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.99 KB | None | 0 0
  1. // Clan System by COD
  2. // Credits : COD For Scripting , Kitten For help on the commands
  3.  
  4. #include <a_samp>
  5.  
  6. // Defines
  7. #define MAX_SAVE 70
  8. #define MAX_CLANS 70 // Change this to amount of the clans you want to have to be created
  9. #define MAX_CLAN_MEMBERS 20 // Change this to amount of members can be in your clan system
  10. #define MAX_CLAN_NAME 16 // Amount of letters for Clan to create cant be longer than that
  11.  
  12. // Color Defines
  13. #define COLOR_ORANGE 0xF97804FF
  14. #define COLOR_WHITE 0xFFFFFFAA
  15. #define COLOR_YELLOW 0xDABB3EAA
  16. #define COLOR_GREEN 0x21DD00FF
  17. #define COLOR_PINK 0xFFC0CBAA
  18. #define COLOR_BLACK 0x000000FF
  19. #define COLOR_RED 0xE60000FF
  20.  
  21. // Variables
  22. new clanMembers[MAX_CLANS][MAX_CLAN_MEMBERS];
  23. new clanNames[MAX_CLANS][MAX_CLAN_NAME];
  24. new clanInfo[MAX_CLANS][3]; //0 created 1-members 2 color
  25. new playerclan[MAX_PLAYERS];
  26. new clanInvite[MAX_PLAYERS];
  27. new playerColors[100] = {
  28. 0xFF8C13FF,0xC715FFFF,0x20B2AAFF,0xDC143CFF,0x6495EDFF,0xf0e68cFF,0x778899FF,0xFF1493FF,0xF4A460FF,0xEE82EEFF,0xFFD720FF,
  29. 0x8b4513FF,0x4949A0FF,0x148b8bFF,0x14ff7fFF,0x556b2fFF,0x0FD9FAFF,0x10DC29FF,0x534081FF,0x0495CDFF,0xEF6CE8FF,0xBD34DAFF,
  30. 0x247C1BFF,0x0C8E5DFF,0x635B03FF,0xCB7ED3FF,0x65ADEBFF,0x5C1ACCFF,0xF2F853FF,0x11F891FF,0x7B39AAFF,0x53EB10FF,0x54137DFF,
  31. 0x275222FF,0xF09F5BFF,0x3D0A4FFF,0x22F767FF,0xD63034FF,0x9A6980FF,0xDFB935FF,0x3793FAFF,0x90239DFF,0xE9AB2FFF,0xAF2FF3FF,
  32. 0x057F94FF,0xB98519FF,0x388EEAFF,0x028151FF,0xA55043FF,0x0DE018FF,0x93AB1CFF,0x95BAF0FF,0x369976FF,0x18F71FFF,0x4B8987FF,
  33. 0x491B9EFF,0x829DC7FF,0xBCE635FF,0xCEA6DFFF,0x20D4ADFF,0x2D74FDFF,0x3C1C0DFF,0x12D6D4FF,0x48C000FF,0x2A51E2FF,0xE3AC12FF,
  34. 0xFC42A8FF,0x2FC827FF,0x1A30BFFF,0xB740C2FF,0x42ACF5FF,0x2FD9DEFF,0xFAFB71FF,0x05D1CDFF,0xC471BDFF,0x94436EFF,0xC1F7ECFF,
  35. 0xCE79EEFF,0xBD1EF2FF,0x93B7E4FF,0x3214AAFF,0x184D3BFF,0xAE4B99FF,0x7E49D7FF,0x4C436EFF,0xFA24CCFF,0xCE76BEFF,0xA04E0AFF,
  36. 0x9F945CFF,0xDCDE3DFF,0x10C9C5FF,0x70524DFF,0x0BE472FF,0x8A2CD7FF,0x6152C2FF,0xCF72A9FF,0xE59338FF,0xEEDC2DFF,0xD8C762FF,
  37. 0x3FE65CFF
  38. };
  39.  
  40. // Forwards
  41. forward PlayerLeaveClan(playerid);
  42.  
  43. public OnFilterScriptInit()
  44. {
  45. print("\n--------------------------------------");
  46. print(" Clan System Loaded");
  47. print("--------------------------------------\n");
  48. return 1;
  49. }
  50.  
  51. public OnFilterScriptExit()
  52. {
  53. print("\n--------------------------------------");
  54. print(" Clan System Unloaded");
  55. print("--------------------------------------\n");
  56. return 1;
  57. }
  58.  
  59.  
  60. public PlayerLeaveClan(playerid) {
  61. new string[256];
  62. new playername[MAX_PLAYER_NAME];
  63. new clannum = playerclan[playerid];
  64.  
  65. if(clannum > 0) {
  66. for(new i = 0; i < clanInfo[clannum][1]; i++) {
  67. if(clanMembers[clannum][i]==playerid) {
  68. clanInfo[clannum][1]--;
  69. for(new j = i; j < clanInfo[clannum][1]; j++) {
  70. clanMembers[clannum][j]=clanMembers[clannum][j+1];
  71. }
  72. if(clanInfo[clannum][1]<1) {
  73. clanInfo[clannum][0]=0;
  74. clanInfo[clannum][1]=0;
  75. }
  76. for(new j = 0; j < clanInfo[clannum][1]; j++) {
  77. GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
  78. format(string, sizeof(string),"%s has quit your clan.", playername);
  79. SendClientMessage(clanMembers[clannum][j], COLOR_ORANGE, string);
  80. }
  81.  
  82. format(string, sizeof(string),"You have quit the clan '%s' (id: %d)", clanNames[clannum], clannum);
  83. SendClientMessage(playerid, COLOR_ORANGE, string);
  84. playerclan[playerid]=0;
  85. SetPlayerColor(playerid,playerColors[playerid]);
  86. return;
  87. }
  88. }
  89. } else {
  90. SendClientMessage(playerid, COLOR_RED, "You are not in a clan.");
  91. }
  92. }
  93.  
  94. public OnPlayerDisconnect(playerid, reason)
  95. {
  96. PlayerLeaveClan(playerid);
  97. return 1;
  98. }
  99.  
  100. public OnPlayerCommandText(playerid, cmdtext[])
  101. {
  102. new string[256];
  103. new sendername[MAX_PLAYER_NAME];
  104. new giveplayer[MAX_PLAYER_NAME];
  105. new cmd[256];
  106. new giveplayerid , idx;
  107.  
  108. if(strcmp(cmd, "/commands", true) == 0) {
  109. SendClientMessage(playerid, COLOR_YELLOW,"/clan create [name]");
  110. SendClientMessage(playerid, COLOR_YELLOW,"/clan join");
  111. SendClientMessage(playerid, COLOR_YELLOW,"/clan invite [playerID]");
  112. SendClientMessage(playerid, COLOR_YELLOW,"/clan quit");
  113. SendClientMessage(playerid, COLOR_YELLOW,"/claninfo [number]");
  114. SendClientMessage(playerid, COLOR_YELLOW,"/clans - Displays the current clans");
  115. return 1;
  116. }
  117.  
  118. if(strcmp(cmd, "/clan", true) == 0) {
  119. new tmp[256];
  120. new clancmd, clannum;
  121. tmp = strtok(cmdtext, idx);
  122.  
  123. if(!strlen(tmp)) {
  124. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /clan [create/join/invite/quit] [name/number]");
  125. return 1;
  126. }
  127. giveplayerid = strval(tmp);
  128.  
  129. if(strcmp(tmp, "create", true)==0)
  130. clancmd = 1;
  131. else if(strcmp(tmp, "invite", true)==0)
  132. clancmd = 2;
  133. else if(strcmp(tmp, "join", true)==0)
  134. clancmd = 3;
  135. else if(strcmp(tmp, "quit", true)==0)
  136. clancmd = 4;
  137.  
  138. tmp = strtok(cmdtext, idx);
  139. if(clancmd < 3 && !strlen(tmp)) {
  140. if(clancmd==0)
  141. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /clan [create/join/invite/quit] [name/number]");
  142. else if(clancmd==1)
  143. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /clan [create] [name]");
  144. else if(clancmd==2)
  145. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /clan [invite] [playerID]");
  146. return 1;
  147. }
  148. if(clancmd==1) {
  149. if(playerclan[playerid]>0) {
  150. SendClientMessage(playerid, COLOR_RED, "You are already in a clan!");
  151. return 1;
  152. }
  153.  
  154. for(new i = 1; i < MAX_CLANS; i++) {
  155. if(clanInfo[i][0]==0) {
  156. format(clanNames[i], MAX_CLAN_NAME, "%s", tmp);
  157. clanInfo[i][0]=1;
  158. clanInfo[i][1]=1;
  159. clanInfo[i][2]=playerColors[playerid];
  160. clanMembers[i][0] = playerid;
  161. format(string, sizeof(string),"You have created the clan '%s' (id: %d)", clanNames[i], i);
  162. SendClientMessage(playerid, COLOR_GREEN, string);
  163.  
  164. playerclan[playerid]=i;
  165.  
  166. return 1;
  167. }
  168. }
  169.  
  170. return 1;
  171. } else if (clancmd==3) {
  172. clannum = clanInvite[playerid];
  173.  
  174. if(playerclan[playerid]>0) {
  175. SendClientMessage(playerid, COLOR_RED, "You are already in a clan!");
  176. return 1;
  177. }
  178. if(clanInvite[playerid]==0) {
  179. SendClientMessage(playerid, COLOR_RED, "You have not been invited to a clan.");
  180. return 1;
  181. }
  182. if(clanInfo[clannum][0]==0) {
  183. SendClientMessage(playerid, COLOR_RED, "That clan does not exist!");
  184. return 1;
  185. }
  186.  
  187. if(clanInfo[clannum][1] < MAX_CLAN_MEMBERS) {
  188. new i = clanInfo[clannum][1];
  189.  
  190. clanInvite[playerid]=0;
  191.  
  192. clanMembers[clannum][i] = playerid;
  193.  
  194. GetPlayerName(playerid, sendername, MAX_PLAYER_NAME);
  195. for(new j = 0; j < clanInfo[clannum][1]; j++) {
  196. format(string, sizeof(string),"%s has joined your clan.", sendername);
  197. SendClientMessage(clanMembers[clannum][j], COLOR_ORANGE, string);
  198. }
  199.  
  200. clanInfo[clannum][1]++;
  201. playerclan[playerid] = clannum;
  202.  
  203. SetPlayerColor(playerid,clanInfo[clannum][2]);
  204.  
  205. format(string, sizeof(string),"You have joined the clan '%s' (id: %d)", clanNames[clannum], clannum);
  206. SendClientMessage(playerid, COLOR_GREEN, string);
  207.  
  208. return 1;
  209. }
  210.  
  211. SendClientMessage(playerid, COLOR_RED, "That clan is full.");
  212. return 1;
  213. } else if (clancmd==2) {
  214. giveplayerid = strval(tmp);
  215.  
  216. if(playerclan[playerid]==0) {
  217. SendClientMessage(playerid, COLOR_RED, "You are not in a clan!");
  218. return 1;
  219. }
  220.  
  221. if(IsPlayerConnected(giveplayerid)) {
  222. GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
  223. GetPlayerName(playerid, sendername, sizeof(sendername));
  224.  
  225. format(string, sizeof(string),"You have sent a clan invite to %s.", giveplayer);
  226. SendClientMessage(playerid, COLOR_GREEN, string);
  227. format(string, sizeof(string),"You have recieved a clan invite from %s to '%s' (id: %d)", sendername, clanNames[playerclan[playerid]],playerclan[playerid]);
  228. SendClientMessage(giveplayerid, COLOR_GREEN, string);
  229.  
  230. clanInvite[giveplayerid]=playerclan[playerid];
  231.  
  232. } else
  233. SendClientMessage(playerid, COLOR_RED, "No such player exists!");
  234.  
  235. } else if (clancmd==4) {
  236. PlayerLeaveClan(playerid);
  237. }
  238. return 1;
  239. }
  240.  
  241. if(strcmp(cmd, "/claninfo", true) == 0) {
  242. new tmp[256];
  243. new clannum;
  244. tmp = strtok(cmdtext, idx);
  245.  
  246. if(!strlen(tmp) && playerclan[playerid]==0) {
  247. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /claninfo [number]");
  248. return 1;
  249. } else if (!strlen(tmp))
  250. clannum = playerclan[playerid];
  251. else
  252. clannum = strval(tmp);
  253.  
  254. if(clanInfo[clannum][0]==0) {
  255. SendClientMessage(playerid, COLOR_RED, "No such clan exists!");
  256. return 1;
  257. }
  258.  
  259. format(string, sizeof(string),"'%s' clan Members (id: %d)", clanNames[clannum], clannum);
  260. SendClientMessage(playerid, COLOR_GREEN, string);
  261.  
  262. for(new i = 0; i < clanInfo[clannum][1]; i++) {
  263. GetPlayerName(clanMembers[clannum][i], giveplayer, sizeof(giveplayer));
  264. format(string, sizeof(string),"%s (%d)", giveplayer, clanMembers[clannum][i]);
  265. SendClientMessage(playerid, COLOR_YELLOW, string);
  266. }
  267. return 1;
  268. }
  269.  
  270. if(strcmp(cmd, "/clans", true) == 0)
  271. {
  272. new x;
  273.  
  274. SendClientMessage(playerid, COLOR_GREEN, "Current clan:");
  275. for(new i=0; i < MAX_CLANS; i++) {
  276. if(clanInfo[i][0]==1) {
  277. format(string, sizeof(string), "%s%s(%d) - %d members", string,clanNames[i],i,clanInfo[i][1]);
  278.  
  279. x++;
  280. if(x > 2) {
  281. SendClientMessage(playerid, COLOR_YELLOW, string);
  282. x = 0;
  283. format(string, sizeof(string), "");
  284. } else {
  285. format(string, sizeof(string), "%s, ", string);
  286. }
  287. }
  288. }
  289.  
  290. if(x <= 2 && x > 0) {
  291. string[strlen(string)-2] = '.';
  292. SendClientMessage(playerid, COLOR_YELLOW, string);
  293. }
  294. return 1;
  295. }
  296. return 0;
  297. }
  298.  
  299. strtok(const string[], &index)
  300. {
  301. new length = strlen(string);
  302. while ((index < length) && (string[index] <= ' '))
  303. {
  304. index++;
  305. }
  306.  
  307. new offset = index;
  308. new result[20];
  309. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  310. {
  311. result[index - offset] = string[index];
  312. index++;
  313. }
  314. result[index - offset] = EOS;
  315. return result;
  316. }
Advertisement
Add Comment
Please, Sign In to add comment