Advertisement
Guest User

Clan System SA-MP By COD [FIXED]

a guest
Jul 22nd, 2011
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.03 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. cmd = strtok(cmdtext, idx);
  108.  
  109. if(strcmp(cmd, "/commands", true) == 0) {
  110. SendClientMessage(playerid, COLOR_YELLOW,"/clan create [name]");
  111. SendClientMessage(playerid, COLOR_YELLOW,"/clan join");
  112. SendClientMessage(playerid, COLOR_YELLOW,"/clan invite [playerID]");
  113. SendClientMessage(playerid, COLOR_YELLOW,"/clan quit");
  114. SendClientMessage(playerid, COLOR_YELLOW,"/claninfo [number]");
  115. SendClientMessage(playerid, COLOR_YELLOW,"/clans - Displays the current clans");
  116. return 1;
  117. }
  118.  
  119. if(strcmp(cmd, "/clan", true) == 0) {
  120. new tmp[256];
  121. new clancmd, clannum;
  122. tmp = strtok(cmdtext, idx);
  123.  
  124. if(!strlen(tmp)) {
  125. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /clan [create/join/invite/quit] [name/number]");
  126. return 1;
  127. }
  128. giveplayerid = strval(tmp);
  129.  
  130. if(strcmp(tmp, "create", true)==0)
  131. clancmd = 1;
  132. else if(strcmp(tmp, "invite", true)==0)
  133. clancmd = 2;
  134. else if(strcmp(tmp, "join", true)==0)
  135. clancmd = 3;
  136. else if(strcmp(tmp, "quit", true)==0)
  137. clancmd = 4;
  138.  
  139. tmp = strtok(cmdtext, idx);
  140. if(clancmd < 3 && !strlen(tmp)) {
  141. if(clancmd==0)
  142. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /clan [create/join/invite/quit] [name/number]");
  143. else if(clancmd==1)
  144. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /clan [create] [name]");
  145. else if(clancmd==2)
  146. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /clan [invite] [playerID]");
  147. return 1;
  148. }
  149. if(clancmd==1) {
  150. if(playerclan[playerid]>0) {
  151. SendClientMessage(playerid, COLOR_RED, "You are already in a clan!");
  152. return 1;
  153. }
  154.  
  155. for(new i = 1; i < MAX_CLANS; i++) {
  156. if(clanInfo[i][0]==0) {
  157. format(clanNames[i], MAX_CLAN_NAME, "%s", tmp);
  158. clanInfo[i][0]=1;
  159. clanInfo[i][1]=1;
  160. clanInfo[i][2]=playerColors[playerid];
  161. clanMembers[i][0] = playerid;
  162. format(string, sizeof(string),"You have created the clan '%s' (id: %d)", clanNames[i], i);
  163. SendClientMessage(playerid, COLOR_GREEN, string);
  164.  
  165. playerclan[playerid]=i;
  166.  
  167. return 1;
  168. }
  169. }
  170.  
  171. return 1;
  172. } else if (clancmd==3) {
  173. clannum = clanInvite[playerid];
  174.  
  175. if(playerclan[playerid]>0) {
  176. SendClientMessage(playerid, COLOR_RED, "You are already in a clan!");
  177. return 1;
  178. }
  179. if(clanInvite[playerid]==0) {
  180. SendClientMessage(playerid, COLOR_RED, "You have not been invited to a clan.");
  181. return 1;
  182. }
  183. if(clanInfo[clannum][0]==0) {
  184. SendClientMessage(playerid, COLOR_RED, "That clan does not exist!");
  185. return 1;
  186. }
  187.  
  188. if(clanInfo[clannum][1] < MAX_CLAN_MEMBERS) {
  189. new i = clanInfo[clannum][1];
  190.  
  191. clanInvite[playerid]=0;
  192.  
  193. clanMembers[clannum][i] = playerid;
  194.  
  195. GetPlayerName(playerid, sendername, MAX_PLAYER_NAME);
  196. for(new j = 0; j < clanInfo[clannum][1]; j++) {
  197. format(string, sizeof(string),"%s has joined your clan.", sendername);
  198. SendClientMessage(clanMembers[clannum][j], COLOR_ORANGE, string);
  199. }
  200.  
  201. clanInfo[clannum][1]++;
  202. playerclan[playerid] = clannum;
  203.  
  204. SetPlayerColor(playerid,clanInfo[clannum][2]);
  205.  
  206. format(string, sizeof(string),"You have joined the clan '%s' (id: %d)", clanNames[clannum], clannum);
  207. SendClientMessage(playerid, COLOR_GREEN, string);
  208.  
  209. return 1;
  210. }
  211.  
  212. SendClientMessage(playerid, COLOR_RED, "That clan is full.");
  213. return 1;
  214. } else if (clancmd==2) {
  215. giveplayerid = strval(tmp);
  216.  
  217. if(playerclan[playerid]==0) {
  218. SendClientMessage(playerid, COLOR_RED, "You are not in a clan!");
  219. return 1;
  220. }
  221.  
  222. if(IsPlayerConnected(giveplayerid)) {
  223. GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
  224. GetPlayerName(playerid, sendername, sizeof(sendername));
  225.  
  226. format(string, sizeof(string),"You have sent a clan invite to %s.", giveplayer);
  227. SendClientMessage(playerid, COLOR_GREEN, string);
  228. format(string, sizeof(string),"You have recieved a clan invite from %s to '%s' (id: %d)", sendername, clanNames[playerclan[playerid]],playerclan[playerid]);
  229. SendClientMessage(giveplayerid, COLOR_GREEN, string);
  230.  
  231. clanInvite[giveplayerid]=playerclan[playerid];
  232.  
  233. } else
  234. SendClientMessage(playerid, COLOR_RED, "No such player exists!");
  235.  
  236. } else if (clancmd==4) {
  237. PlayerLeaveClan(playerid);
  238. }
  239. return 1;
  240. }
  241.  
  242. if(strcmp(cmd, "/claninfo", true) == 0) {
  243. new tmp[256];
  244. new clannum;
  245. tmp = strtok(cmdtext, idx);
  246.  
  247. if(!strlen(tmp) && playerclan[playerid]==0) {
  248. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /claninfo [number]");
  249. return 1;
  250. } else if (!strlen(tmp))
  251. clannum = playerclan[playerid];
  252. else
  253. clannum = strval(tmp);
  254.  
  255. if(clanInfo[clannum][0]==0) {
  256. SendClientMessage(playerid, COLOR_RED, "No such clan exists!");
  257. return 1;
  258. }
  259.  
  260. format(string, sizeof(string),"'%s' clan Members (id: %d)", clanNames[clannum], clannum);
  261. SendClientMessage(playerid, COLOR_GREEN, string);
  262.  
  263. for(new i = 0; i < clanInfo[clannum][1]; i++) {
  264. GetPlayerName(clanMembers[clannum][i], giveplayer, sizeof(giveplayer));
  265. format(string, sizeof(string),"%s (%d)", giveplayer, clanMembers[clannum][i]);
  266. SendClientMessage(playerid, COLOR_YELLOW, string);
  267. }
  268. return 1;
  269. }
  270.  
  271. if(strcmp(cmd, "/clans", true) == 0)
  272. {
  273. new x;
  274.  
  275. SendClientMessage(playerid, COLOR_GREEN, "Current clan:");
  276. for(new i=0; i < MAX_CLANS; i++) {
  277. if(clanInfo[i][0]==1) {
  278. format(string, sizeof(string), "%s%s(%d) - %d members", string,clanNames[i],i,clanInfo[i][1]);
  279.  
  280. x++;
  281. if(x > 2) {
  282. SendClientMessage(playerid, COLOR_YELLOW, string);
  283. x = 0;
  284. format(string, sizeof(string), "");
  285. } else {
  286. format(string, sizeof(string), "%s, ", string);
  287. }
  288. }
  289. }
  290.  
  291. if(x <= 2 && x > 0) {
  292. string[strlen(string)-2] = '.';
  293. SendClientMessage(playerid, COLOR_YELLOW, string);
  294. }
  295. return 1;
  296. }
  297. return 0;
  298. }
  299.  
  300. strtok(const string[], &index)
  301. {
  302. new length = strlen(string);
  303. while ((index < length) && (string[index] <= ' '))
  304. {
  305. index++;
  306. }
  307.  
  308. new offset = index;
  309. new result[20];
  310. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  311. {
  312. result[index - offset] = string[index];
  313. index++;
  314. }
  315. result[index - offset] = EOS;
  316. return result;
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement