Guest User

Group system by verlaj

a guest
Aug 26th, 2017
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.54 KB | None | 0 0
  1. //====================================================================[includes]
  2. #include <a_samp>
  3. #include <a_mysql>
  4. #include <izcmd>
  5. #include <sscanf2>
  6. #include <easydialog>
  7. #include <foreach>
  8. #include <y_iterate>
  9. #include <strlib>
  10. //=================================================================[definitions]
  11. //root 7IMe0bx7BrG4dexg
  12. #define mysql_host "164.132.4.245"
  13. #define mysql_user "paruni_samp"
  14. #define mysql_pass "2fkFEAQ3TAeqU4Vp"
  15. #define mysql_data "ParUni_V5.2"
  16.  
  17. #define MAX_PERMISSION 5
  18. #define MAX_GROUPP 10
  19.  
  20.  
  21. #define SCM SendClientMessage
  22.  
  23. #define COLOR_GREY 0xAFAFAFAA
  24. #define COLOR_RED 0xB22222FF
  25. #define COLOR_GREEN 0x9ACD32AA
  26. #define SERVER_CLIENT 0x22A1E0FF
  27. #define COLOR_FIREBRICK 0xC90000FF
  28.  
  29. #define MAX_RANKS 5000//increase this if you like. Tho i'd prefer to put a limit for max player's group ranks.
  30. #define MAX_GROUPS 500//you can change it, if you know what you are doing.
  31. #undef MAX_PLAYERS
  32. #define MAX_PLAYERS 100
  33. #if !defined isnull
  34. #define isnull(%1) \
  35. ((%1[0] == 0) || (%1[0] == 1 && %1[1] == 0))
  36. #endif
  37.  
  38.  
  39. //=======================[variables etc]========================================
  40. new RankSelected[MAX_PLAYERS];
  41. new TempGroupID[MAX_PLAYERS];
  42. new InfoOnly[MAX_PLAYERS];
  43. new MySQL:SQL;
  44. new PerkUpgrading[MAX_PLAYERS];
  45. //==============================================================================
  46. enum groupsDATA
  47. {
  48. ORM:ORM_ID,
  49. gID,
  50. gName[128],
  51. gLeaderName[32],
  52. gchat,
  53. gCredits,
  54. gResources,
  55. gSkillpoints,//ised as skill points atm
  56. gWarWins,
  57. gWarlosses,
  58. gScore,
  59. gLevel,
  60. perk1,
  61. perk2,
  62. perk3,
  63. perk4,
  64. perk5
  65. };
  66. new GroupInfo[MAX_GROUPS][groupsDATA];
  67.  
  68. enum ranksDATA
  69. {
  70. ORM:ORM_ID2,
  71. rID,
  72. rgID,//group id
  73. rName[56],
  74. rLevel,
  75. rPermission[MAX_PERMISSION]// 0-NO 1-YES
  76. };
  77. new RankInfo[MAX_RANKS][ranksDATA];
  78. //==============================================================================
  79.  
  80. enum playerDATA
  81. {
  82. ORM:ORM_ID3,
  83. pID,
  84. pName[MAX_PLAYER_NAME],
  85. grouppid[MAX_GROUPP],//here [MAX_GROUPP] represents maximum number of groups for a player
  86. prID[MAX_GROUPP],//useful for locating rank id instead of name.
  87. groupcontribution,
  88. gWarKills,
  89. pGroups //should be limited to the number of MAX player groups.
  90. };
  91. new pInfo[MAX_PLAYERS][playerDATA];
  92. new groupvariables[MAX_PLAYERS][2];
  93. new Iterator:Groups<MAX_PLAYERS>;
  94. new Iterator:Ranks<MAX_RANKS>;
  95.  
  96. //==============================================================================
  97. //==========================[USEFUL FUNCTIONS]==================================
  98. //==============================================================================
  99. GetGroupID(gropname[])//very useful for getting the groupid for the functions below and in cmds.
  100. {
  101. foreach(new x : Groups)
  102. {
  103. if(!strcmp(gropname, GroupInfo[x][gName], true) && strlen(GroupInfo[x][gName]) != 0) return x;
  104. }
  105. return -1;
  106. }
  107.  
  108. GroupLoopCheckName(playerid, grpname[]) //I rarely use this.
  109. {
  110. for(new i=0; i < (MAX_GROUPP-1); ++i)
  111. {
  112. if(!strcmp(grpname, GroupInfo[pInfo[playerid][grouppid][i]][gName], true))
  113. {
  114. return i; //returns the group slotid of player, [grouppid][slotid]
  115. }
  116. }
  117. return 11; //11 = invalid as the max loop is 10
  118. }
  119.  
  120. GroupLoopCheck(playerid, groupid)//a must to use.
  121. {
  122. for(new i=0; i < (MAX_GROUPP-1); ++i)
  123. {
  124. if(pInfo[playerid][grouppid][i] == GroupInfo[groupid][gID])
  125. {
  126. return i; //returns the group slotid of player, [grouppid][slotid]
  127. }
  128. }
  129. return 11;//11 = invalid
  130. }
  131.  
  132. ReturnGroupName(playerid, groupslot) //1-10
  133. {
  134. new name[128];
  135. if(pInfo[playerid][grouppid][groupslot] > -1)
  136. {
  137. name = GroupInfo[pInfo[playerid][grouppid][groupslot]][gName];
  138. return name;
  139. }
  140. return 0;
  141. }
  142.  
  143. forward DisplayGroupMembers(groupid, playerid);
  144. public DisplayGroupMembers(groupid, playerid)
  145. {
  146. new query[200], dialogstr[556];
  147. mysql_format(SQL, query, sizeof(query), "SELECT * FROM `players2` WHERE `grouppid1` = %d OR `grouppid2` = %d OR `grouppid3` = %d OR `grouppid4` = %d OR `grouppid5` = %d OR `grouppid6` = %d OR `grouppid7` = %d OR `grouppid8` = %d OR `grouppid9` = %d OR `grouppid10` = %d", groupid);
  148. new Cache:result = mysql_query(SQL, query, true);
  149. new strings[76];
  150. format(strings,sizeof(strings),"Group Members for %s(%d)",GroupInfo[groupid][gName],groupid);
  151. new row;
  152. cache_get_result_count(row);
  153. if(row > 0)
  154. {
  155. new field_name[32];
  156. new TempString[MAX_PLAYER_NAME], tempid, levelf, groupstr[32], rankname[56], ralevel;
  157. cache_get_field_name(row, field_name);
  158. strtrim(field_name, "grouppid");
  159. strimplode("", groupstr, sizeof(groupstr), "prID", field_name);
  160.  
  161. for(new r = 0; r < row; r++)
  162. {
  163. cache_get_value_name(r, "pName", TempString);
  164. cache_get_value_name_int(r, groupstr, levelf);
  165.  
  166. foreach(new ra : Ranks)
  167. {
  168. if(RankInfo[ra][rID] == levelf)
  169. {
  170. format(rankname,sizeof(rankname),RankInfo[ra][rName]);
  171. ralevel = RankInfo[ra][rLevel];
  172. }
  173. }
  174.  
  175. tempid = GetID(TempString);
  176. if(IsPlayerConnected(tempid))
  177. {
  178. strcat(dialogstr, "{33EE22}(ONLINE) ");
  179. }
  180. else
  181. {
  182. strcat(dialogstr, "{FF8080}(OFFLINE) ");
  183. }
  184.  
  185.  
  186. strcat(dialogstr, sprintf("{FFFF00}(Level:%d)%s {FFFFFF}%s(%d)\n", rankname, ralevel, TempString, tempid));
  187. }
  188. ShowDialog(playerid,0, DIALOG_STYLE_TABLIST, strings, dialogstr, "Select", "Close");
  189. cache_delete(result);
  190. }
  191. return 1;
  192. }
  193.  
  194. forward CheckPlayerGroup(playerid, groupid);//groupid = group array in foreach iterator
  195. public CheckPlayerGroup(playerid, groupid)
  196. {
  197. new i = GroupLoopCheck(playerid, groupid);
  198. if(i == 11)
  199. {
  200. return 0;
  201. }
  202. else
  203. {
  204. return 1;
  205. }
  206. }
  207.  
  208. forward CheckPlayerGroupPermission(playerid, groupid, permission);//should be used for checking rank's permission
  209. public CheckPlayerGroupPermission(playerid, groupid, permission)//returns 1 if everything matches
  210. {
  211. new i = GroupLoopCheck(playerid, groupid);
  212. if(i == 11)
  213. {
  214. return 0;
  215. }
  216. else
  217. {
  218. foreach(new r : Ranks)
  219. {
  220. if(RankInfo[r][rID] == pInfo[playerid][prID][i] && RankInfo[r][rgID] == pInfo[playerid][grouppid][i])
  221. {
  222. if(RankInfo[r][rPermission][permission] == 1) //if he has the permission
  223. {
  224. return 1;
  225. }
  226. }
  227. }
  228. }
  229. return 0;
  230. }
  231.  
  232. forward CheckPlayerGroupRankLevel(playerid,groupid,level);//any usage?
  233. public CheckPlayerGroupRankLevel(playerid,groupid,level)
  234. {
  235. new i = GroupLoopCheck(playerid, groupid);
  236. if(i == 11)
  237. {
  238. return 0;
  239. }
  240. else
  241. {
  242. foreach(new r : Ranks)
  243. {
  244. if(RankInfo[r][rID] == pInfo[playerid][prID][i] && RankInfo[r][rgID] == pInfo[playerid][grouppid][i])//RankInfo[r][rgID] == pInfo[playerid][grouppid][i] .... you can remove this.. its just an extra check.
  245. {
  246. if(RankInfo[r][rLevel] == level) //level
  247. {
  248. return 1;
  249. }
  250. }
  251. }
  252. }
  253. return 0;
  254. }
  255.  
  256. forward ReturnGroupLevel(playerid, groupid); //same as above but returns level
  257. public ReturnGroupLevel(playerid, groupid)
  258. {
  259. new count = 0;
  260. new i = GroupLoopCheck(playerid, groupid);
  261. if(i == 11)
  262. {
  263. return 0;
  264. }
  265. else
  266. {
  267. foreach(new r : Ranks)
  268. {
  269. if(RankInfo[r][rID] == pInfo[playerid][prID][i] && RankInfo[r][rgID] == pInfo[playerid][grouppid][i])//RankInfo[r][rgID] == pInfo[playerid][grouppid][i] .... you can remove this.. its just an extra check.
  270. {
  271. count = RankInfo[r][rLevel];
  272. break;
  273. }
  274. }
  275. }
  276. return count;
  277. }
  278. //==============================================================================
  279.  
  280. forward PlayerLoaded(playerid);
  281. public PlayerLoaded(playerid)
  282. {
  283. switch(orm_errno(pInfo[playerid][ORM_ID3]))
  284. {
  285. case ERROR_OK:
  286. {
  287. //stuff
  288. }
  289. case ERROR_NO_DATA:
  290. {
  291. orm_insert(pInfo[playerid][ORM_ID3], "CreatePlayerData", "d", playerid);
  292. }
  293. }
  294. orm_setkey(pInfo[playerid][ORM_ID3], "pID");
  295. return 1;
  296. }
  297.  
  298. forward CreatePlayerData(playerid);
  299. public CreatePlayerData(playerid)
  300. {
  301. orm_update(pInfo[playerid][ORM_ID3]);
  302. pInfo[playerid][grouppid][0] = -1;
  303. pInfo[playerid][prID][0] = -1;
  304. pInfo[playerid][grouppid][1] = -1;
  305. pInfo[playerid][prID][1] = -1;
  306. pInfo[playerid][grouppid][2] = -1;
  307. pInfo[playerid][prID][2] = -1;
  308. pInfo[playerid][grouppid][3] = -1;
  309. pInfo[playerid][prID][3] = -1;
  310. pInfo[playerid][grouppid][4] = -1;
  311. pInfo[playerid][prID][4] = -1;
  312. pInfo[playerid][grouppid][5] = -1;
  313. pInfo[playerid][prID][5] = -1;
  314. pInfo[playerid][grouppid][6] = -1;
  315. pInfo[playerid][prID][6] = -1;
  316. pInfo[playerid][grouppid][7] = -1;
  317. pInfo[playerid][prID][7] = -1;
  318. pInfo[playerid][grouppid][8] = -1;
  319. pInfo[playerid][prID][8] = -1;
  320. pInfo[playerid][grouppid][9] = -1;
  321. pInfo[playerid][prID][9] = -1;
  322. pInfo[playerid][groupcontribution] = 0;
  323. pInfo[playerid][gWarKills] = 0;
  324. pInfo[playerid][pGroups] = 0;
  325. orm_save(pInfo[playerid][ORM_ID3]);
  326. return 1;
  327. }
  328.  
  329. stock SavePlayerGStats(playerid)
  330. {
  331. if(pInfo[playerid][pID] != 0)
  332. {
  333. orm_update(pInfo[playerid][ORM_ID3]);
  334. }
  335. return 1;
  336. }
  337.  
  338. forward ShowRankEditingMenu(playerid, rank);
  339. public ShowRankEditingMenu(playerid, rank)
  340. {
  341. new dialogstr[556], string1[56], string2[56];
  342. format(string1,sizeof(string1),"Rank Name\t%s\n",RankInfo[rank][rName]);
  343. format(string2,sizeof(string2),"Rank Level\t%d\n",RankInfo[rank][rLevel]);
  344. strcat(dialogstr,string1);
  345. strcat(dialogstr,string2);
  346. if(RankInfo[rank][rPermission][0] == 1)
  347. {
  348. strcat(dialogstr,"Use Group Chat?\t{00FF00}YES\n");
  349. }
  350. else
  351. {
  352. strcat(dialogstr,"Use Group Chat?\t{FF0000}NO\n");
  353. }
  354.  
  355. if(RankInfo[rank][rPermission][1] == 1)
  356. {
  357. strcat(dialogstr,"Invite Members to the Group?\t{00FF00}YES\n");
  358. }
  359. else
  360. {
  361. strcat(dialogstr,"Invite Members to the Group?\t{FF0000}NO\n");
  362. }
  363.  
  364. if(RankInfo[rank][rPermission][2] == 1)
  365. {
  366. strcat(dialogstr,"Kick Members from the Group?\t{00FF00}YES\n");
  367. }
  368. else
  369. {
  370. strcat(dialogstr,"Kick Members from the Group?\t{FF0000}NO\n");
  371. }
  372.  
  373. if(RankInfo[rank][rPermission][3] == 1)
  374. {
  375. strcat(dialogstr,"Change members rank?\t{00FF00}YES\n");
  376. }
  377. else
  378. {
  379. strcat(dialogstr,"Change members rank?\t{FF0000}NO\n");
  380. }
  381.  
  382. if(RankInfo[rank][rPermission][4] == 1)
  383. {
  384. strcat(dialogstr,"Edit Group rank? And stuff.\t{00FF00}YES\n");
  385. }
  386. else
  387. {
  388. strcat(dialogstr,"Edit Group rank? And stuff.\t{FF0000}NO\n");
  389. }
  390.  
  391. ShowDialog(playerid,GroupEditRank,DIALOG_STYLE_TABLIST,"Edit Rank Permissions",dialogstr,"Change","Close");
  392. return 1;
  393. }
  394.  
  395. // =============================================================================
  396. public OnFilterScriptInit()
  397. {
  398. print("_________________________________________________________________________");
  399. print("> Group System by Heller");
  400. print("> Script Name : Group System");
  401. print("> Script Version : BETA");
  402. print("> Script Coder : Heller");
  403. print("> Last Update : 7/31/2017");
  404. print("> mySQL Version : R41 - ORM queries");
  405. print("_________________________________________________________________________");
  406.  
  407. mysql_log();
  408.  
  409. SQL = mysql_connect(mysql_host, mysql_user, mysql_data, mysql_pass);
  410.  
  411. //load groups & ranks
  412. mysql_tquery(SQL, "SELECT * FROM `groups2`", "GroupsInformation", "");
  413. mysql_tquery(SQL, "SELECT * FROM `ranks2`", "RanksInformation", "");
  414. return 1;
  415. }
  416.  
  417. public OnFilterScriptExit()
  418. {
  419. foreach(new b : Groups)
  420. {
  421. if(GroupInfo[b][gID] != 0) {
  422. orm_update(GroupInfo[b][ORM_ID]);
  423. }
  424. orm_destroy(GroupInfo[b][ORM_ID]);
  425.  
  426. for(new groupsDATA:e; e < groupsDATA; ++e)
  427. GroupInfo[b][e] = 0;
  428. }
  429. foreach(new i : Ranks)
  430. {
  431. if(RankInfo[i][rID] != 0) {
  432. orm_update(RankInfo[i][ORM_ID2]);
  433. }
  434. orm_destroy(RankInfo[i][ORM_ID2]);
  435.  
  436. for(new ranksDATA:e; e < ranksDATA; ++e)
  437. RankInfo[i][e] = 0;
  438. }
  439.  
  440. foreach(new players : Player)
  441. {
  442. if(pInfo[players][pID] != 0)
  443. {
  444. orm_update(pInfo[players][ORM_ID3]);
  445. }
  446. orm_destroy(pInfo[players][ORM_ID3]);
  447.  
  448. for(new playerDATA:e; e < playerDATA; ++e)
  449. pInfo[players][e] = 0;
  450. }
  451. return 1;
  452. }
  453.  
  454. public OnPlayerConnect(playerid)
  455. {
  456. groupvariables[playerid][0] = -1;
  457. groupvariables[playerid][1] = 0;
  458. GetPlayerName(playerid, pInfo[playerid][pName], MAX_PLAYER_NAME);
  459. new ORM:ormid = pInfo[playerid][ORM_ID3] = orm_create("players2", SQL);
  460.  
  461. orm_addvar_int(ormid, pInfo[playerid][pID], "pID");
  462. orm_addvar_string(ormid, pInfo[playerid][pName], 32, "pName");
  463. orm_addvar_int(ormid, pInfo[playerid][grouppid][0], "grouppid1");
  464. orm_addvar_int(ormid, pInfo[playerid][grouppid][1], "grouppid2");
  465. orm_addvar_int(ormid, pInfo[playerid][grouppid][2], "grouppid3");
  466. orm_addvar_int(ormid, pInfo[playerid][grouppid][3], "grouppid4");
  467. orm_addvar_int(ormid, pInfo[playerid][grouppid][4], "grouppid5");
  468. orm_addvar_int(ormid, pInfo[playerid][grouppid][5], "grouppid6");
  469. orm_addvar_int(ormid, pInfo[playerid][grouppid][6], "grouppid7");
  470. orm_addvar_int(ormid, pInfo[playerid][grouppid][7], "grouppid8");
  471. orm_addvar_int(ormid, pInfo[playerid][grouppid][8], "grouppid9");
  472. orm_addvar_int(ormid, pInfo[playerid][grouppid][9], "grouppid10");
  473. orm_addvar_int(ormid, pInfo[playerid][prID][0], "prID1");
  474. orm_addvar_int(ormid, pInfo[playerid][prID][1], "prID2");
  475. orm_addvar_int(ormid, pInfo[playerid][prID][2], "prID3");
  476. orm_addvar_int(ormid, pInfo[playerid][prID][3], "prID4");
  477. orm_addvar_int(ormid, pInfo[playerid][prID][4], "prID5");
  478. orm_addvar_int(ormid, pInfo[playerid][prID][5], "prID6");
  479. orm_addvar_int(ormid, pInfo[playerid][prID][6], "prID7");
  480. orm_addvar_int(ormid, pInfo[playerid][prID][7], "prID8");
  481. orm_addvar_int(ormid, pInfo[playerid][prID][8], "prID9");
  482. orm_addvar_int(ormid, pInfo[playerid][prID][9], "prID10");
  483. orm_addvar_int(ormid, pInfo[playerid][groupcontribution], "groupcontribution");
  484. orm_addvar_int(ormid, pInfo[playerid][gWarKills], "gWarKills");
  485. orm_addvar_int(ormid, pInfo[playerid][pGroups], "pGroups");
  486.  
  487. orm_setkey(ormid, "pName");
  488. orm_select(ormid, "PlayerLoaded", "d", playerid);
  489. return 1;
  490. }
  491.  
  492. public OnPlayerDisconnect(playerid,reason)
  493. {
  494. groupvariables[playerid][0] = -1;
  495. groupvariables[playerid][1] = 0;
  496. RankSelected[playerid] = -1;
  497. TempGroupID[playerid] = -1;
  498. if(pInfo[playerid][pID] != 0)
  499. {
  500. orm_update(pInfo[playerid][ORM_ID3]);
  501. }
  502. orm_destroy(pInfo[playerid][ORM_ID3]);
  503.  
  504. for(new playerDATA:e; e < playerDATA; ++e)
  505. pInfo[playerid][e] = 0;
  506. return 1;
  507. }
  508.  
  509. stock SendGroupMessage(color, groupID, string[])
  510. {
  511. foreach(new i : Player)
  512. {
  513. if(pInfo[i][grouppid][GroupLoopCheck(i, groupID)] == groupID)
  514. {
  515. SendClientMessage(i, color, string);
  516. }
  517. }
  518. return 1;
  519. }
  520.  
  521. forward RanksInformation();
  522. public RanksInformation()
  523. {
  524. new row;
  525. cache_get_row_count(row);
  526. for(new r=0; r < row; ++r)
  527. {
  528. new ORM:ormid = RankInfo[r][ORM_ID2] = orm_create("ranks2", SQL);
  529.  
  530. orm_addvar_int(ormid, RankInfo[r][rID], "rID"); //this is the key
  531. orm_setkey(ormid, "rID"); //here we declare it as the key
  532. orm_addvar_string(ormid, RankInfo[r][rName],128, "rName");
  533. orm_addvar_int(ormid, RankInfo[r][rgID], "rgID");
  534. orm_addvar_int(ormid, RankInfo[r][rLevel], "rLevel");
  535. orm_addvar_int(ormid, RankInfo[r][rPermission][0], "rPermission1");
  536. orm_addvar_int(ormid, RankInfo[r][rPermission][1], "rPermission2");
  537. orm_addvar_int(ormid, RankInfo[r][rPermission][2], "rPermission3");
  538. orm_addvar_int(ormid, RankInfo[r][rPermission][3], "rPermission4");
  539. orm_addvar_int(ormid, RankInfo[r][rPermission][4], "rPermission5");
  540. orm_apply_cache(ormid, r);
  541. orm_select(ormid, "LoadGroupRank", "d", r);
  542. }
  543. return 1;
  544. }
  545.  
  546. forward LoadGroupRank(rid);
  547. public LoadGroupRank(rid)
  548. {
  549. switch(orm_errno(RankInfo[rid][ORM_ID2]))
  550. {
  551. case ERROR_OK:
  552. {
  553. Iter_Add(Ranks, rid);//active ranks
  554. }
  555. case ERROR_NO_DATA:
  556. {
  557. }
  558. }
  559. return 1;
  560. }
  561.  
  562. forward GroupsInformation();
  563. public GroupsInformation()
  564. {
  565. new row;
  566. cache_get_row_count(row);
  567. for(new r=0; r < row; ++r)
  568. {
  569. new ORM:ormid = GroupInfo[r][ORM_ID] = orm_create("groups2", SQL);
  570.  
  571. orm_addvar_int(ormid, GroupInfo[r][gID], "gID"); //this is the key
  572. orm_setkey(ormid, "gID"); //here we declare it as the key
  573. orm_addvar_string(ormid, GroupInfo[r][gName],128, "gName");
  574. orm_addvar_string(ormid, GroupInfo[r][gLeaderName],32, "gLeaderName");
  575. orm_addvar_int(ormid, GroupInfo[r][gchat], "gchat");
  576. orm_addvar_int(ormid, GroupInfo[r][gCredits], "gCredits");
  577. orm_addvar_int(ormid, GroupInfo[r][gResources], "gResources");
  578. orm_addvar_int(ormid, GroupInfo[r][gWarWins], "gWarWins");
  579. orm_addvar_int(ormid, GroupInfo[r][gWarLosses], "gWarLosses");
  580. orm_addvar_int(ormid, GroupInfo[r][gSkillPoints], "gSkillPoints");
  581. orm_addvar_int(ormid, GroupInfo[r][gScore], "gScore");
  582. orm_addvar_int(ormid, GroupInfo[r][perk1], "perk1");
  583. orm_addvar_int(ormid, GroupInfo[r][perk2], "perk2");
  584. orm_addvar_int(ormid, GroupInfo[r][perk3], "perk3");
  585. orm_addvar_int(ormid, GroupInfo[r][perk4], "perk4");
  586. orm_addvar_int(ormid, GroupInfo[r][perk5], "perk5");
  587. orm_apply_cache(ormid, r);
  588. orm_select(ormid, "LoadGroup", "d", r);
  589. }
  590. return 1;
  591. }
  592.  
  593. forward LoadGroup(gid);
  594. public LoadGroup(gid)
  595. {
  596. switch(orm_errno(GroupInfo[gid][ORM_ID]))
  597. {
  598. case ERROR_OK:
  599. {
  600. Iter_Add(Groups, gid);//active groups
  601. }
  602. case ERROR_NO_DATA:
  603. {
  604. }
  605. }
  606. return 1;
  607. }
  608.  
  609. forward MYSQL_SaveGroups(b);
  610. public MYSQL_SaveGroups(b)
  611. {
  612. if(GroupInfo[b][gID] != 0)
  613. {
  614. orm_update(GroupInfo[b][ORM_ID]);
  615. }
  616. return 1;
  617. }
  618.  
  619. forward GroupCreated(id, playerid, str[], playeridz);
  620. public GroupCreated(id, playerid, str[], playeridz)
  621. {
  622. orm_update(GroupInfo[id][ORM_ID]);
  623. GroupInfo[id][gchat] = 0;
  624. format(GroupInfo[id][gName],128,str);
  625. format(GroupInfo[id][gLeaderName],32,GetPlayerNamee(playerid));
  626. orm_save(GroupInfo[id][ORM_ID]);
  627. pInfo[playeridz][grouppid][pInfo[playeridz][pGroups]-1] = GroupInfo[id][gID];
  628. printf("New Group is created: [%d]", id);
  629. return 1;
  630. }
  631.  
  632. forward RankCreated(id, gid, name[], levl, playeridz);
  633. public RankCreated(id, gid, name[], levl, playeridz)
  634. {
  635. orm_update(RankInfo[id][ORM_ID2]);
  636. RankInfo[id][rgID] = GroupInfo[gid][gID];
  637. RankInfo[id][rLevel] = levl;
  638. format(RankInfo[id][rName],32,name);
  639. RankInfo[id][rPermission][0] = 1;
  640. RankInfo[id][rPermission][1] = 1;
  641. RankInfo[id][rPermission][2] = 1;
  642. RankInfo[id][rPermission][3] = 1;
  643. RankInfo[id][rPermission][4] = 1;
  644. orm_save(RankInfo[id][ORM_ID2]);
  645. pInfo[playeridz][prID][pInfo[playeridz][pGroups]-1] = RankInfo[id][rID];
  646. printf("New Rank is created for Group id:%d: [%d]",gid, id );
  647. return 1;
  648. }
  649.  
  650. forward RankCreated2(id, gid, name[], levl, playeridz);
  651. public RankCreated2(id, gid, name[], levl, playeridz)
  652. {
  653. orm_update(RankInfo[id][ORM_ID2]);
  654. RankInfo[id][rgID] = GroupInfo[gid][gID];
  655. RankInfo[id][rLevel] = levl;
  656. format(RankInfo[id][rName],32,name);
  657. RankInfo[id][rPermission][0] = 1;
  658. RankInfo[id][rPermission][1] = 1;
  659. RankInfo[id][rPermission][2] = 1;
  660. RankInfo[id][rPermission][3] = 1;
  661. RankInfo[id][rPermission][4] = 1;
  662. orm_save(RankInfo[id][ORM_ID2]);
  663. printf("New Rank is created for Group id:%d: [%d]",gid, id );
  664. return 1;
  665. }
  666.  
  667. stock GetPlayerNamee(playerid)
  668. {
  669. new name[MAX_PLAYER_NAME];
  670. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  671. return name;
  672. }
  673.  
  674.  
  675. //===========================[Commands]=========================================
  676. CMD:grouphelp(playerid,params[])
  677. {
  678. SCM(playerid,COLOR_GREY,"Group Commands");
  679. SCM(playerid,COLOR_GREY,"/groups /groupinfo(ID) /creategroup /groupinvite /g /groupkick /groupranks");
  680. SCM(playerid,COLOR_GREY,"/GroupEditRank /GroupSetRank /GroupMembers /GCP");
  681. return 1;
  682. }
  683.  
  684. CMD:groups(playerid,params[])
  685. {
  686. if(Iter_Count(Groups) > 0)
  687. {
  688. foreach(new i : Groups)
  689. {
  690. new string[56];
  691. format(string,sizeof(string),"Groups:[%d]%s",i,GroupInfo[i][gName]);
  692. SCM(playerid,COLOR_GREEN,string);
  693. }
  694. }
  695. else
  696. {
  697. SCM(playerid,COLOR_RED,"ERROR: No groups were found.");
  698. }
  699. return 1;
  700. }
  701.  
  702. CMD:groupinfoid(playerid, params[])
  703. {
  704. new id, string[250];
  705. if(sscanf(params, "i", id)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /GroupInfoID [Group ID]");
  706. else if(!Iter_Contains(Groups, id)) return SendClientMessage(playerid,COLOR_RED,"[SERVER]: Group Does not exist");
  707. else
  708. {
  709. format(string,sizeof(string),"Group[%d]:%s\nLeader:%s\nGroup Score:%d\nWar Wins:%d\nWar Losses:%d\nDraws:%d\nCredits:%d\nResources:%d\n",
  710. GroupInfo[id][gID],
  711. GroupInfo[id][gName],
  712. GroupInfo[id][gLeaderName],
  713. GroupInfo[id][gScore],
  714. GroupInfo[id][gWarWins],
  715. GroupInfo[id][gWarLosses],
  716. GroupInfo[id][gSkillPoints],
  717. GroupInfo[id][gCredits],
  718. GroupInfo[id][gResources]);
  719. }
  720. return ShowDialog(playerid,GroupInfoDialog, DIALOG_STYLE_MSGBOX, "{808080}Group Info", string, "Close", "");
  721. }
  722.  
  723. CMD:groupinfo(playerid, params[])
  724. {
  725. new str[128], string[250];
  726. if(sscanf(params, "s[128]", str)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /GroupInfo [Group Name]");
  727. else if(IsGroupNameTaken(str) == 0) return SendClientMessage(playerid,COLOR_RED,"[SERVER]: Group Does not exist");
  728. else
  729. {
  730. new i = GetGroupID(str);
  731. format(string,sizeof(string),"Group[%d]:%s\nLeader:%s\nGroup Score:%d\nWar Wins:%d\nWar Losses:%d\SkillPoints:%d\nCredits:%d\nResources:%d\n",
  732. GroupInfo[i][gID],
  733. GroupInfo[i][gName],
  734. GroupInfo[i][gLeaderName],
  735. GroupInfo[i][gScore],
  736. GroupInfo[i][gWarWins],
  737. GroupInfo[i][gWarLosses],
  738. GroupInfo[i][gSkillPoints],
  739. GroupInfo[i][gCredits],
  740. GroupInfo[i][gResources]);
  741. }
  742. return ShowDialog(playerid,GroupInfoDialog, DIALOG_STYLE_MSGBOX, "{808080}Group Info", string, "Close", "");
  743. }
  744.  
  745. CMD:creategroup(playerid, params[])
  746. {
  747. new player,str[128];
  748. if(!IsPlayerAdmin(playerid)) return 0;
  749. if(sscanf(params, "us[128]", player, str)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /creategroup [Player ID/Player Name] [Group Name]");
  750. if(!IsPlayerConnected(player)) return SendClientMessage(playerid,COLOR_RED,"[ERROR]: Player hasn't connected to server yet.");
  751. if(pInfo[player][pGroups] == 10) return SendClientMessage(playerid,COLOR_RED,"[ERROR]: Player's Max Group Limit Reached.");
  752. if(IsGroupNameTaken(str) == 1) return SendClientMessage(playerid,COLOR_RED,"[ERROR]: Group Name is already taken.");
  753.  
  754. pInfo[playerid][pGroups] += 1;
  755. new i = Iter_Free(Groups);
  756. Iter_Add(Groups, i);
  757.  
  758. new ORM:ormid1 = GroupInfo[i][ORM_ID] = orm_create("groups2", SQL);
  759. orm_addvar_int(ormid1, GroupInfo[i][gID], "gID"); //this is the key
  760. orm_setkey(ormid1, "gID"); //here we declare it as the key
  761. orm_addvar_string(ormid1, GroupInfo[i][gName],128, "gName");
  762. orm_addvar_string(ormid1, GroupInfo[i][gLeaderName],32, "gLeaderName");
  763. orm_addvar_int(ormid1, GroupInfo[i][gchat], "gchat");
  764. orm_addvar_int(ormid1, GroupInfo[i][gCredits], "gCredits");
  765. orm_addvar_int(ormid1, GroupInfo[i][gResources], "gResources");
  766. orm_addvar_int(ormid1, GroupInfo[i][gWarWins], "gWarWins");
  767. orm_addvar_int(ormid1, GroupInfo[i][gWarLosses], "gWarLosses");
  768. orm_addvar_int(ormid1, GroupInfo[i][gSkillPoints], "gSkillPoints");
  769. orm_addvar_int(ormid1, GroupInfo[i][gScore], "gScore");
  770. orm_apply_cache(ormid1, i);
  771. orm_insert(GroupInfo[i][ORM_ID], "GroupCreated", "ddsi", i, player, str, player);
  772. new string[158];
  773. format(string,sizeof(string),"[SUCCESS]: '%s' named group has been created for '%s'.",str,GetPlayerNamee(playerid));
  774. SendClientMessage(playerid,COLOR_GREEN,string);
  775.  
  776. new o = Iter_Free(Ranks);
  777. Iter_Add(Ranks, o);
  778. new ORM:ormid = RankInfo[o][ORM_ID2] = orm_create("ranks2", SQL);
  779. orm_addvar_int(ormid, RankInfo[o][rID], "rID"); //this is the key
  780. orm_setkey(ormid, "rID"); //here we declare it as the key
  781. orm_addvar_string(ormid, RankInfo[o][rName],128, "rName");
  782. orm_addvar_int(ormid, RankInfo[o][rgID], "rgID");
  783. orm_addvar_int(ormid, RankInfo[o][rLevel], "rLevel");
  784. orm_addvar_int(ormid, RankInfo[o][rPermission][0], "rPermission1");
  785. orm_addvar_int(ormid, RankInfo[o][rPermission][1], "rPermission2");
  786. orm_addvar_int(ormid, RankInfo[o][rPermission][2], "rPermission3");
  787. orm_addvar_int(ormid, RankInfo[o][rPermission][3], "rPermission4");
  788. orm_addvar_int(ormid, RankInfo[o][rPermission][4], "rPermission5");
  789. orm_apply_cache(ormid, o);
  790. orm_insert(RankInfo[o][ORM_ID2], "RankCreated", "ddsdi", o, i, "Leader", 100, player);
  791. return 1;
  792. }
  793.  
  794. CMD:groupinvite(playerid, params[])
  795. {
  796. new grpname[128],player, str[158];
  797. if(sscanf(params, "s[128]u",grpname,player)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /groupinvite [Group Name] [Player ID]");
  798. {
  799. new i = GetGroupID(grpname);
  800. if(i != -1)
  801. {
  802. if(!CheckPlayerGroup(playerid, i)) return SCM(playerid,COLOR_RED,"You are not the member of that group.");
  803. else if(CheckPlayerGroup(player, i)) return SCM(playerid,COLOR_RED,"Player is already in your group.");
  804. else if(pInfo[player][pGroups] == 10) return SCM(playerid,COLOR_RED,"Player max group limit reached.");
  805. else if(!CheckPlayerGroupPermission(playerid, i, 1)) return SCM(playerid,COLOR_RED,"You Do not have the permission to use this command.");
  806. else
  807. {
  808. groupvariables[player][0] = playerid;
  809. groupvariables[player][1] = i;
  810. format(str,sizeof(str),"'%s' named group member is inviting you to '%s' named group, what is your answer?",GetPlayerNamee(playerid),GroupInfo[i][gName]);
  811. ShowDialog(player,GInviteDialog, DIALOG_STYLE_MSGBOX, "{808080}Group System", str, "Accept", "Decline");
  812. }
  813. }
  814. else return SCM(playerid,COLOR_RED,"Group Does not exists.");
  815. }
  816. return 1;
  817. }
  818.  
  819. CMD:g(playerid,params[])
  820. {
  821. new grpname[128],str[128];
  822. if(sscanf(params, "s[128]s[128]",grpname,str)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /g [Group Name] [Chat]");
  823. {
  824. new i = GetGroupID(grpname);
  825. if(i != -1)
  826. {
  827. if(!CheckPlayerGroup(playerid, i)) return SCM(playerid,COLOR_RED,"You are not the member of that group.");
  828. else if(!CheckPlayerGroupPermission(playerid, i, 0)) return SCM(playerid,COLOR_RED,"You Do not have the permission to use this command.");
  829. else
  830. {
  831. new string[128];
  832. format(string,sizeof(string),"[%s][%s(%d)]:{FFFFFF}%s.",GroupInfo[i][gName],GetPlayerNamee(playerid),playerid,str);
  833. SendGroupMessage(COLOR_GREEN,i,string);
  834. }
  835. }
  836. else return SCM(playerid,COLOR_RED,"Group Does not exists.");
  837. }
  838. return 1;
  839. }
  840.  
  841. CMD:groupkick(playerid, params[])
  842. {
  843. new grpname[128],player, str[158];
  844. if(sscanf(params, "s[128]u",grpname,player)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /groupkick [Group Name] [Player ID]");
  845. {
  846. new i = GetGroupID(grpname);
  847. if(i != -1)
  848. {
  849. if(!CheckPlayerGroup(playerid, i)) return SCM(playerid,COLOR_RED,"You are not the member of that group.");
  850. else if(!CheckPlayerGroup(player, i)) return SCM(playerid,COLOR_RED,"Player is not in your group.");
  851. else if(!CheckPlayerGroupPermission(playerid, i, 2)) return SCM(playerid,COLOR_RED,"You Do not have the permission to use this command.");
  852. else if(ReturnGroupLevel(playerid, i) < ReturnGroupLevel(player, i)) return SCM(playerid,COLOR_RED,"You cannot kick your seniors.");
  853. else
  854. {
  855. format(str,sizeof(str),"[%s]:%s(%d) has been kicked from the group.",grpname,GetPlayerNamee(player),player);
  856. SendGroupMessage(COLOR_RED,pInfo[playerid][grouppid][i],str);
  857. pInfo[player][grouppid][GroupLoopCheck(playerid, i)] = -1;
  858. pInfo[player][prID][GroupLoopCheck(playerid, i)] = -1;
  859. }
  860. }
  861. else return SCM(playerid,COLOR_RED,"Group Does not exists.");
  862. }
  863. return 1;
  864. }
  865.  
  866. CMD:gcp(playerid,params[])
  867. {
  868. new grpname[128];
  869. if(sscanf(params, "s[128]",grpname)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /GCP [Group Name]");
  870. {
  871. new i = GetGroupID(grpname);
  872. if(i != -1)
  873. {
  874. if(!CheckPlayerGroup(playerid, i)) return SCM(playerid,COLOR_RED,"You are not the member of that group.");
  875. else if(!CheckPlayerGroupPermission(playerid, i, 5)) return SCM(playerid,COLOR_RED,"You Do not have the permission to use this command.");
  876. else
  877. {
  878. TempGroupID[playerid] = i;
  879. GroupPanel(playerid,i);
  880. }
  881. }
  882. else return SCM(playerid,COLOR_RED,"Group Does not exists.");
  883. }
  884. return 1;
  885. }
  886.  
  887. stock Name(playerid)
  888. {
  889. new name[MAX_PLAYER_NAME];
  890. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  891. return name;
  892. }
  893.  
  894. stock GetID(const name[])
  895. {
  896. foreach(new i : Player)
  897. {
  898. if(!strcmp(name, Name(i)))
  899. return i;
  900. }
  901. return -1;
  902. }
  903.  
  904. IsGroupNameTaken(grpname[])
  905. {
  906. foreach(new x : Groups)
  907. {
  908. if(!strcmp(grpname, GroupInfo[x][gName], true) && strlen(GroupInfo[x][gName]) != 0) return 1;
  909. }
  910. return 0;
  911. }
  912.  
  913. ReturnGroupID(grpname[])
  914. {
  915. foreach(new x : Groups)
  916. {
  917. if(!strcmp(grpname, GroupInfo[x][gName], true) && strlen(GroupInfo[x][gName]) != 0) return GroupInfo[x][gID];
  918. }
  919. return 0;
  920. }
  921.  
  922. ReturnGroupArray(grpname[])
  923. {
  924. foreach(new x : Groups)
  925. {
  926. if(!strcmp(grpname, GroupInfo[x][gName], true) && strlen(GroupInfo[x][gName]) != 0) return x;
  927. }
  928. return -1;
  929. }
  930.  
  931. CMD:groupranks(playerid, params[])
  932. {
  933. new str[128];
  934. if(sscanf(params, "s[128]", str)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /GroupRanks [Group Name]");
  935. else if(IsGroupNameTaken(str) == 0) return SendClientMessage(playerid,COLOR_RED,"[SERVER]: Group Does not exist");
  936. else
  937. {
  938. new dialogstr[512];
  939. foreach(new r : Ranks)
  940. {
  941. if(ReturnGroupID(str) == RankInfo[r][rgID])
  942. {
  943. strcat(dialogstr,sprintf("(Level:%d) %s\n",RankInfo[r][rLevel], RankInfo[r][rName]));
  944. }
  945. }
  946. ShowDialog(playerid,groupranklist,DIALOG_STYLE_TABLIST,"Group Ranks",dialogstr,"Close","");
  947. }
  948. return 1;
  949. }
  950.  
  951. CMD:groupmembers(playerid, params[])
  952. {
  953. new str[128];
  954. if(sscanf(params, "s[128]", str)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /GroupMembers [Group Name]");
  955. else if(IsGroupNameTaken(str) == 0) return SendClientMessage(playerid,COLOR_RED,"[SERVER]: Group Does not exist");
  956. else
  957. {
  958. DisplayGroupMembers(ReturnGroupArray(str),playerid);
  959. }
  960. return 1;
  961. }
  962.  
  963. CMD:groupcreaterank(playerid,params[])
  964. {
  965. new grpname[128],str[32], level;
  966. if(sscanf(params, "s[128]s[32]i",grpname, str, level)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /GroupCreateRank [Group Name] [New Rank Name] [Level]");
  967. else if(level < 100 && level > 0)
  968. {
  969. new i = GetGroupID(grpname);
  970. if(i != -1)
  971. {
  972. if(!CheckPlayerGroup(playerid, i)) return SCM(playerid,COLOR_RED,"You are not the member of that group.");
  973. else if(!CheckPlayerGroupPermission(playerid, i, 4)) return SCM(playerid,COLOR_RED,"You Do not have the permission to use this command.");
  974. else if(ReturnGroupLevel(playerid, i) < level) return SCM(playerid,COLOR_RED,"Rank must be of lower level to that of yours.");
  975. else
  976. {
  977. new o = Iter_Free(Ranks);
  978. Iter_Add(Ranks, o);
  979. new ORM:ormid = RankInfo[o][ORM_ID2] = orm_create("ranks2", SQL);
  980. orm_addvar_int(ormid, RankInfo[o][rID], "rID"); //this is the key
  981. orm_setkey(ormid, "rID"); //here we declare it as the key
  982. orm_addvar_string(ormid, RankInfo[o][rName],128, "rName");
  983. orm_addvar_int(ormid, RankInfo[o][rgID], "rgID");
  984. orm_addvar_int(ormid, RankInfo[o][rLevel], "rLevel");
  985. orm_addvar_int(ormid, RankInfo[o][rPermission][0], "rPermission1");
  986. orm_addvar_int(ormid, RankInfo[o][rPermission][1], "rPermission2");
  987. orm_addvar_int(ormid, RankInfo[o][rPermission][2], "rPermission3");
  988. orm_addvar_int(ormid, RankInfo[o][rPermission][3], "rPermission4");
  989. orm_addvar_int(ormid, RankInfo[o][rPermission][4], "rPermission5");
  990. orm_apply_cache(ormid, o);
  991. orm_insert(RankInfo[o][ORM_ID2], "RankCreated2", "ddsd", o, i, str, level);
  992.  
  993. new string[158];
  994. format(string,sizeof(string),"[%s]: Successfully created the rank %s(Level:%d).",grpname,str,level);
  995. SendGroupMessage(COLOR_GREEN,pInfo[playerid][grouppid][i],string);
  996. }
  997. }
  998. else return SCM(playerid,COLOR_RED,"Group Does not exists.");
  999. }
  1000. else return SCM(playerid,COLOR_RED,"Level limit is between 0 to 100.");
  1001. return 1;
  1002. }
  1003.  
  1004. CMD:groupeditrank(playerid,params[])
  1005. {
  1006. new grpname[128],str[32];
  1007. if(sscanf(params, "s[128]s[32]",grpname, str)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /GroupEditRank [Group Name] [Rank Name]");
  1008. else
  1009. {
  1010. new i = GetGroupID(grpname);
  1011. if(i != -1)
  1012. {
  1013. if(!CheckPlayerGroup(playerid, i)) return SCM(playerid,COLOR_RED,"You are not the member of that group.");
  1014. else if(!CheckPlayerGroupPermission(playerid, i, 4)) return SCM(playerid,COLOR_RED,"You Do not have the permission to use this command.");
  1015. else
  1016. {
  1017. foreach(new rn : Ranks)
  1018. {
  1019. if(RankInfo[rn][rID] == pInfo[playerid][prID][GroupLoopCheck(playerid,i)] && RankInfo[rn][rgID] == i && !strcmp(RankInfo[rn][rName], str,true))
  1020. {
  1021. if(ReturnGroupLevel(playerid, i) < RankInfo[rn][rLevel]) return SCM(playerid,COLOR_RED,"Rank must be of lower level to that of yours.");
  1022. else
  1023. {
  1024. RankSelected[playerid] = rn;
  1025. TempGroupID[playerid] = i;
  1026. ShowRankEditingMenu(playerid, rn);
  1027. break;
  1028. }
  1029. }
  1030. else if(i == Iter_Last(Ranks))
  1031. {
  1032. SCM(playerid,COLOR_RED,"Invalid Rank.");
  1033. }
  1034. }
  1035. }
  1036. }
  1037. else return SCM(playerid,COLOR_RED,"Group Does not exists.");
  1038. }
  1039. return 1;
  1040. }
  1041.  
  1042. CMD:groupsetrank(playerid,params[])
  1043. {
  1044. new grpname[128],str[32], player;
  1045. if(sscanf(params, "us[128]s[32]",player, grpname, str)) return SendClientMessage(playerid,COLOR_GREY,"[USAGE]: /GroupSetRank [playerid] [Group Name] [Rank Name]");
  1046. else
  1047. {
  1048. new i = GetGroupID(grpname);
  1049. if(i != -1)
  1050. {
  1051. if(!CheckPlayerGroup(playerid, i)) return SCM(playerid,COLOR_RED,"You are not the member of that group.");
  1052. else if(!CheckPlayerGroup(player, i)) return SCM(playerid,COLOR_RED,"Player is not in your group.");
  1053. else if(!CheckPlayerGroupPermission(playerid, i, 3)) return SCM(playerid,COLOR_RED,"You Do not have the permission to use this command.");
  1054. else if(ReturnGroupLevel(playerid, i) < ReturnGroupLevel(player, i)) return SCM(playerid,COLOR_RED,"You cannot boss your seniors.");
  1055. else
  1056. {
  1057. foreach(new rn : Ranks)
  1058. {
  1059. if(RankInfo[rn][rID] == pInfo[playerid][prID][GroupLoopCheck(playerid,i)] && RankInfo[rn][rgID] == i)
  1060. {
  1061. pInfo[player][prID][GroupLoopCheck(playerid, i)] = RankInfo[rn][rID];
  1062. new string[158];
  1063. format(string,sizeof(string),"[%s]:Rank of %s(%d) has been changed to %s.",grpname,GetPlayerNamee(player),player,str);
  1064. SendGroupMessage(COLOR_GREEN,pInfo[playerid][grouppid][i],string);
  1065. break;
  1066. }
  1067. else if(i == Iter_Last(Ranks))
  1068. {
  1069. SCM(playerid,COLOR_RED,"Invalid Rank.");
  1070. }
  1071. }
  1072. }
  1073. }
  1074. else return SCM(playerid,COLOR_RED,"Group Does not exists.");
  1075. }
  1076. return 1;
  1077. }
  1078. //=========================================================================[END]
  1079.  
  1080. Dialog:GInviteDialog(playerid, dialogid, response, listitem, inputtext[])
  1081. {
  1082. new str[128];
  1083. if(!response)
  1084. {
  1085. format(str,sizeof(str),"[SYSTEM]: '%s' has declined your invite.",GetPlayerNamee(playerid));
  1086. SendClientMessage(groupvariables[playerid][0],COLOR_RED,str);
  1087. SendClientMessage(playerid,COLOR_RED,"[SERVER]: You have declined the invite.");
  1088. groupvariables[playerid][0] = -1;
  1089. groupvariables[playerid][1] = 0;
  1090. }
  1091. if(response)
  1092. {
  1093. format(str,sizeof(str),"[SYSTEM]: '%s' has accepted your invite.",GetPlayerNamee(playerid));
  1094. SendClientMessage(groupvariables[playerid][0],COLOR_GREEN,str);
  1095. SendClientMessage(playerid,COLOR_RED,"[SERVER]: You have accepted the invite.");
  1096. pInfo[playerid][grouppid][pInfo[playerid][pGroups]-1] = groupvariables[playerid][1];
  1097. groupvariables[playerid][0] = -1;
  1098. groupvariables[playerid][1] = 0;
  1099. }
  1100. return 1;
  1101. }
  1102.  
  1103. Dialog:GroupEditRank(playerid, dialogid, response, listitem, inputtext[])
  1104. {
  1105. if(!response)
  1106. {
  1107. return 0;
  1108. }
  1109. else if(response)
  1110. {
  1111. switch(listitem)
  1112. {
  1113. case 0:
  1114. {
  1115. ShowDialog(playerid,RankNameChange,DIALOG_STYLE_INPUT,"Change Rank Name","Are you Sure about changing rank name?","Change","No");
  1116. }
  1117. case 1:
  1118. {
  1119. ShowDialog(playerid,RankLevelChange,DIALOG_STYLE_INPUT,"Change Rank Level","Are you Sure about changing rank level?","Change","No");
  1120. }
  1121. case 2:
  1122. {
  1123. if(RankInfo[RankSelected[playerid]][rPermission][0] == 1)
  1124. {
  1125. RankInfo[RankSelected[playerid]][rPermission][0] = 0;
  1126. }
  1127. else
  1128. {
  1129. RankInfo[RankSelected[playerid]][rPermission][0] = 1;
  1130. }
  1131. ShowRankEditingMenu(playerid, RankSelected[playerid]);
  1132. }
  1133. case 3:
  1134. {
  1135. if(RankInfo[RankSelected[playerid]][rPermission][1] == 1)
  1136. {
  1137. RankInfo[RankSelected[playerid]][rPermission][1] = 0;
  1138. }
  1139. else
  1140. {
  1141. RankInfo[RankSelected[playerid]][rPermission][1] = 1;
  1142. }
  1143. ShowRankEditingMenu(playerid, RankSelected[playerid]);
  1144. }
  1145. case 4:
  1146. {
  1147. if(RankInfo[RankSelected[playerid]][rPermission][2] == 1)
  1148. {
  1149. RankInfo[RankSelected[playerid]][rPermission][2] = 0;
  1150. }
  1151. else
  1152. {
  1153. RankInfo[RankSelected[playerid]][rPermission][2] = 1;
  1154. }
  1155. ShowRankEditingMenu(playerid, RankSelected[playerid]);
  1156. }
  1157. case 5:
  1158. {
  1159. if(RankInfo[RankSelected[playerid]][rPermission][3] == 1)
  1160. {
  1161. RankInfo[RankSelected[playerid]][rPermission][3] = 0;
  1162. }
  1163. else
  1164. {
  1165. RankInfo[RankSelected[playerid]][rPermission][3] = 1;
  1166. }
  1167. ShowRankEditingMenu(playerid, RankSelected[playerid]);
  1168. }
  1169. case 6:
  1170. {
  1171. if(RankInfo[RankSelected[playerid]][rPermission][4] == 1)
  1172. {
  1173. RankInfo[RankSelected[playerid]][rPermission][4] = 0;
  1174. }
  1175. else
  1176. {
  1177. RankInfo[RankSelected[playerid]][rPermission][4] = 1;
  1178. }
  1179. ShowRankEditingMenu(playerid, RankSelected[playerid]);
  1180. }
  1181. }
  1182. }
  1183. return 1;
  1184. }
  1185.  
  1186. Dialog:RankNameChange(playerid, dialogid, response, listitem, inputtext[])
  1187. {
  1188. if(!response)
  1189. {
  1190. return ShowRankEditingMenu(playerid, RankSelected[playerid]);
  1191. }
  1192. else if(response)
  1193. {
  1194. strcat(RankInfo[RankSelected[playerid]][rName],inputtext);
  1195. ShowRankEditingMenu(playerid, RankSelected[playerid]);
  1196. }
  1197. return 1;
  1198. }
  1199.  
  1200. Dialog:RankLevelChange(playerid, dialogid, response, listitem, inputtext[])
  1201. {
  1202. if(!response)
  1203. {
  1204. return ShowRankEditingMenu(playerid, RankSelected[playerid]);
  1205. }
  1206. else if(response)
  1207. {
  1208. new level = strval(inputtext);
  1209. if(level > 100 || level < 1)
  1210. {
  1211. ShowDialog(playerid,RankLevelChange,DIALOG_STYLE_INPUT,"Change Rank Level","Rank level should be between 1 to 100.","Change","No");
  1212. }
  1213. else
  1214. {
  1215. RankInfo[RankSelected[playerid]][rLevel] = level;
  1216. ShowRankEditingMenu(playerid, RankSelected[playerid]);
  1217. }
  1218. }
  1219. return 1;
  1220. }
  1221.  
  1222. //============================[Group panel]=====================================
  1223. stock SendGroupChatMessage(groupid, message[])
  1224. {
  1225. foreach(new i : Player)
  1226. {
  1227. if(CheckPlayerGroup(i, groupid))
  1228. {
  1229. SendClientMessage(i, SERVER_CLIENT, message);
  1230. }
  1231. }
  1232. return 1;
  1233. }
  1234.  
  1235.  
  1236. GroupPanel(playerid, groupid)
  1237. {
  1238. new dialogstr[556], i = GroupInfo[groupid][gLevel];
  1239. if(i == 0)
  1240. {
  1241. i = 1;
  1242. }
  1243. strcat(dialogstr, "{59D983}Option\tValue\n");
  1244. strcat(dialogstr, sprintf("{59D983}Group Name\t%s(ID:%d)\n", GroupInfo[groupid][gName], groupid));
  1245. strcat(dialogstr, sprintf("{22A1E0}Group Leader\t%s\n", GroupInfo[groupid][gLeaderName]));
  1246. strcat(dialogstr, sprintf("{59D983}Credits\t%i\n", GroupInfo[groupid][gCredits]));
  1247. strcat(dialogstr, sprintf("{59D983}Resources\t%i\n", GroupInfo[groupid][gResources]));
  1248. strcat(dialogstr, sprintf("{59D983}Perks\n"));
  1249. strcat(dialogstr, sprintf("{59D983}Color\n"));
  1250. strcat(dialogstr, sprintf("{59D983}War Wins\t%i\n", GroupInfo[groupid][gWarWins]));
  1251. strcat(dialogstr, sprintf("{22A1E0}Group Level\t%i\n", GroupInfo[groupid][gLevel]));
  1252. strcat(dialogstr, sprintf("{22A1E0}Group Scores\t[%i / %i]\n", GroupInfo[groupid][gScore], ((50+i)*i)));
  1253. strcat(dialogstr, sprintf("{22A1E0}Group Points\t%i\n", GroupInfo[groupid][gWarWins]));
  1254. strcat(dialogstr, sprintf("{59D983}Group Members\n"));
  1255. return ShowDialog(playerid,groupcontrolpanelV, DIALOG_STYLE_TABLIST_HEADERS, "Group Control Panel", dialogstr, "Select", "Close");
  1256. }
  1257.  
  1258. //admin group panel check
  1259.  
  1260. //functions
  1261. ReturnPerkCost(perk, level)
  1262. {
  1263. new amount;
  1264. if(level == 0)
  1265. {
  1266. level = 1;
  1267. }
  1268. switch(perk)
  1269. {
  1270. case 0: amount = (1*level);
  1271. case 1: amount = (10*level);
  1272. case 2: amount = (4*level);
  1273. case 3: amount = (6*level);
  1274. case 4: amount = (10*level);
  1275. }
  1276. return amount;
  1277. }
  1278.  
  1279. ReturnGroupPerkLevel(groupid, perk)
  1280. {
  1281. new level;
  1282. if(perk == 0)
  1283. {
  1284. level = GroupInfo[groupid][perk1];
  1285. }
  1286. if(perk == 1)
  1287. {
  1288. level = GroupInfo[groupid][perk2];
  1289. }
  1290. if(perk == 2)
  1291. {
  1292. level = GroupInfo[groupid][perk3];
  1293. }
  1294. if(perk == 3)
  1295. {
  1296. level = GroupInfo[groupid][perk4];
  1297. }
  1298. if(perk == 4)
  1299. {
  1300. level = GroupInfo[groupid][perk5];
  1301. }
  1302. return level;
  1303. }
  1304.  
  1305. UpgradeGroupPerk(groupid, perk)
  1306. {
  1307. if(perk == 0)
  1308. {
  1309. GroupInfo[groupid][perk1]++;
  1310. }
  1311. if(perk == 1)
  1312. {
  1313. GroupInfo[groupid][perk2]++;
  1314. }
  1315. if(perk == 2)
  1316. {
  1317. GroupInfo[groupid][perk3]++;
  1318. }
  1319. if(perk == 3)
  1320. {
  1321. GroupInfo[groupid][perk4]++;
  1322. }
  1323. if(perk == 4)
  1324. {
  1325. GroupInfo[groupid][perk5]++;
  1326. }
  1327. return 1;
  1328. }
  1329.  
  1330. GroupPerkMsgInfo(perk, groupid)
  1331. {
  1332. new level = ReturnGroupPerkLevel(groupid, perk);
  1333. new output[156];
  1334. if(perk == 0)
  1335. {
  1336. strcat(output,"Squad Bonus allows players in the same team to earn rewards on each other's kill\n");
  1337. new strings[128];
  1338. format(strings,sizeof(strings),"The current level of this perk is %i, upgrade Cost %i skillpoints. Upgrading will increase the bonus variant.\n",level, ReturnPerkCost(perk, level));
  1339. strcat(output,strings);
  1340. }
  1341. if(perk == 1)
  1342. {
  1343. strcat(output,"Group Score Kill Bonus allows the group to earn scores upon player's kill.\n");
  1344. new strings[128];
  1345. format(strings,sizeof(strings),"The current level of this perk is %i, upgrade Cost %i skillpoints. Upgrading will increase the bonus ratio.\n",level, ReturnPerkCost(perk, level));
  1346. strcat(output,strings);
  1347. }
  1348. //more to come edit here
  1349. return output;
  1350. }
  1351.  
  1352. ShowPlayerGroupPerk(playerid)
  1353. {
  1354. new dialogstr[556];
  1355. strcat(dialogstr,"{7F40FF}Perk\tLevel\n");
  1356. new string[56];
  1357. format(string,sizeof(string),"{59D983}Squad Bonus\t[%i / 5]\n", GroupInfo[TempGroupID[playerid]][perk1]);
  1358. strcat(dialogstr, string);
  1359. new string2[56];
  1360. format(string2,sizeof(string2),"{59D983}Group Score Kill Bonus\t%i\n", GroupInfo[TempGroupID[playerid]][perk2]);
  1361. strcat(dialogstr, string2);
  1362. return ShowDialog(playerid,perkgroupperkV, DIALOG_STYLE_TABLIST_HEADERS, "Group Perks", dialogstr, "Select", "Back");
  1363. }
  1364.  
  1365. ShowPlayerResourceDialog(playerid)
  1366. {
  1367. new dialogstr[556];
  1368. strcat(dialogstr,"{7F40FF}Resource Objects\tCost\n");
  1369. strcat(dialogstr, "{59D983}Barbed Grill\t1000R\n"); //0
  1370. strcat(dialogstr, "{59D983}Medic Chamber\t5000R\n"); //1
  1371. strcat(dialogstr, "{59D983}Bunker\t15000R\n"); //2
  1372. strcat(dialogstr, "{59D983}Ladder\t100R\n"); //3
  1373. strcat(dialogstr, "{59D983}Gate\t10000R\n"); //7
  1374. strcat(dialogstr, "{59D983}Reinforced Wall\t3000R\n"); //9
  1375. strcat(dialogstr, "{59D983}Tower\t12000R\n"); //10
  1376. strcat(dialogstr, "{59D983}Rein Wodden Wall\t500R\n"); //11
  1377. strcat(dialogstr, "{59D983}Rein Barbed Grill\t3000R\n"); //12
  1378. strcat(dialogstr, "{59D983}Rein Gate\t15000R\n"); //13
  1379. strcat(dialogstr, "{59D983}Wodden Roof\t200R\n"); //15
  1380. return ShowDialog(playerid,perkresourcediaV, DIALOG_STYLE_TABLIST_HEADERS, "Resource Objects", dialogstr, "Purchase", "Back");
  1381. }
  1382.  
  1383. ReturnPObjectCost(array)
  1384. {
  1385. new cost;
  1386. switch(array)
  1387. {
  1388. case 0: cost = 1000;
  1389. case 1: cost = 5000;
  1390. case 2: cost = 15000;
  1391. case 3: cost = 100;
  1392. case 7: cost = 10000;
  1393. case 9: cost = 3000;
  1394. case 10: cost = 12000;
  1395. case 11: cost = 500;
  1396. case 12: cost = 3000;
  1397. case 13: cost = 15000;
  1398. case 15: cost = 200;
  1399. }
  1400. return cost;
  1401. }
  1402.  
  1403. //[dialogs]
  1404. //resources
  1405. Dialog:perkresourcediaV(playerid, response, listitem, inputtext[])
  1406. {
  1407. if(!response)
  1408. {
  1409. return GroupPanel(playerid, TempGroupID[playerid]);
  1410. }
  1411. if(response)
  1412. {
  1413. new array;
  1414. if(listitem >= 0 && listitem < 4)
  1415. {
  1416. array = (listitem);
  1417. }
  1418. if(listitem == 4)
  1419. {
  1420. array = 7;
  1421. }
  1422. if(listitem >= 5 && listitem < 10)
  1423. {
  1424. array = (listitem+4);
  1425. }
  1426. if(listitem == 10)
  1427. {
  1428. array = 15;
  1429. }
  1430. new cost = ReturnPObjectCost(array);
  1431. if(GroupInfo[TempGroupID[playerid]][gResources] >= cost)
  1432. {
  1433. new strings[128];
  1434. format(strings,sizeof(strings),"[GROUP NOTIFICATION]: {FFFFFF}%s(%d) has Successfully bought a %s. Cost %i resources.",GetPlayerNameEx(playerid),playerid, "item",cost);
  1435. SendGroupChatMessage(GroupInfo[TempGroupID[playerid]][gID], strings);
  1436. GroupInfo[TempGroupID[playerid]][gResources] -= cost;
  1437. }
  1438. else
  1439. {
  1440. SCM(playerid,SERVER_CLIENT,"SERVER: Not enough resources are available.");
  1441. }
  1442. }
  1443. return 1;
  1444. }
  1445.  
  1446. stock GetPlayerNameEx(playerid)
  1447. {
  1448. new name[MAX_PLAYER_NAME+1];
  1449. GetPlayerName(playerid,name,sizeof(name));
  1450. return name;
  1451. }
  1452.  
  1453. //perks
  1454. Dialog:perkgroupperkV(playerid, response, listitem, inputtext[])
  1455. {
  1456. if(!response)
  1457. {
  1458. return GroupPanel(playerid, TempGroupID[playerid]);
  1459. }
  1460. if(response)
  1461. {
  1462. if(!CheckPlayerGroupPermission(playerid, TempGroupID[playerid], 4)) return SendClientMessage(playerid, COLOR_FIREBRICK, "You do not have the permission, you cannot use this Panel!");
  1463. PerkUpgrading[playerid] = listitem;
  1464. ShowDialog(playerid,perkupgradeV, DIALOG_STYLE_MSGBOX, inputtext, GroupPerkMsgInfo(listitem, TempGroupID[playerid]), "Upgrade", "Back");
  1465. }
  1466. return 1;
  1467. }
  1468.  
  1469. Dialog:perkupgradeV(playerid, response, listitem, inputtext[])
  1470. {
  1471. if(!response)
  1472. {
  1473. return ShowPlayerGroupPerk(playerid);
  1474. }
  1475. if(response)
  1476. {
  1477. new groupids = TempGroupID[playerid];
  1478. new cost = ReturnPerkCost(PerkUpgrading[playerid], ReturnGroupPerkLevel(groupids, PerkUpgrading[playerid]));
  1479. new credits = GroupInfo[groupids][gWarWins];
  1480. if(credits >= cost)
  1481. {
  1482. UpgradeGroupPerk(groupids, PerkUpgrading[playerid]);
  1483. ShowPlayerGroupPerk(playerid);
  1484. GroupInfo[groupids][gWarWins] -= cost;
  1485. new strings[128];
  1486. format(strings,sizeof(strings),"[GROUP NOTIFICATION]: {FFFFFF}%s(%d) has Successfully upgraded group perk %i. Cost %i Skillpoints.",GetPlayerNameEx(playerid),playerid,(PerkUpgrading[playerid]+1),cost);
  1487. SendGroupChatMessage(GroupInfo[TempGroupID[playerid]][gID], strings);
  1488. }
  1489. else
  1490. {
  1491. SCM(playerid,SERVER_CLIENT,"SERVER: Not enough skill points are available.");
  1492. }
  1493. }
  1494. return 1;
  1495. }
  1496.  
  1497. //main panel
  1498. Dialog:groupcontrolpanelV(playerid, response, listitem, inputtext[])
  1499. {
  1500. if(!response)
  1501. {
  1502. TempGroupID[playerid] = -1;
  1503. return 0;
  1504. }
  1505. if(response)
  1506. {
  1507. if(InfoOnly[playerid] == 1) return 0;
  1508. if(listitem == 0)//group name
  1509. {
  1510. if(!CheckPlayerGroupPermission(playerid, TempGroupID[playerid], 5)) return SendClientMessage(playerid, COLOR_FIREBRICK, "You do not have the permission, you cannot use this Panel!");
  1511. ShowDialog(playerid,grouprenamedialogV,DIALOG_STYLE_INPUT,"Enter New Name","Character limit is 3-25","Enter","Back");
  1512. }
  1513. if(listitem == 2)//credits
  1514. {
  1515. if(!CheckPlayerGroupPermission(playerid, TempGroupID[playerid], 5)) return SendClientMessage(playerid, COLOR_FIREBRICK, "You do not have the permission, you cannot use this Panel!");
  1516. ShowDialog(playerid,creditconvertV,DIALOG_STYLE_INPUT,"Credit Conversion","1 credit = 1000$","Convert","Back");
  1517. }
  1518. if(listitem == 3)//resources
  1519. {
  1520. if(!CheckPlayerGroupPermission(playerid, TempGroupID[playerid], 5)) return SendClientMessage(playerid, COLOR_FIREBRICK, "You do not have the permission, you cannot use this Panel!");
  1521. ShowPlayerResourceDialog(playerid);
  1522. }
  1523. if(listitem == 4)//perks
  1524. {
  1525. ShowPlayerGroupPerk(playerid);
  1526. }
  1527. if(listitem == 5)//color
  1528. {
  1529. if(!CheckPlayerGroupPermission(playerid, TempGroupID[playerid], 5)) return SendClientMessage(playerid, COLOR_FIREBRICK, "You do not have the permission, you cannot use this Panel!");
  1530. SCM(playerid,SERVER_CLIENT,"SERVER: Please use the following command. /EditGroupColor");
  1531. }
  1532. if(listitem == 6)//war wins
  1533. {
  1534. //
  1535. }
  1536. if(listitem == 10) //group members
  1537. {
  1538. new params[5];
  1539. format(params,5,"%d",TempGroupID[playerid]);
  1540. return cmd_groupmembers(playerid, params);
  1541. }
  1542. }
  1543. return 1;
  1544. }
  1545. //credit convert
  1546. Dialog:creditconvertV(playerid, response, listitem, inputtext[])
  1547. {
  1548. if(!response)
  1549. {
  1550. GroupPanel(playerid, TempGroupID[playerid]);
  1551. }
  1552. if(response)
  1553. {
  1554. new amount = strval(inputtext);
  1555. if(amount <= GroupInfo[TempGroupID[playerid]][gCredits] && amount > 0)
  1556. {
  1557. new strings[128];
  1558. format(strings,sizeof(strings),"[GROUP NOTIFICATION]: {FFFFFF}%s(%d) has Successfully converted %i credits to %i$.",GetPlayerNameEx(playerid),playerid,amount,amount*1000);
  1559. SendGroupChatMessage(GroupInfo[TempGroupID[playerid]][gID], strings);
  1560. GroupInfo[TempGroupID[playerid]][gCredits] -= amount;
  1561. GivePlayerMoney(playerid,amount*1000);
  1562. }
  1563. else if(amount < 0 && GetPlayerMoney(playerid) >= (-1*amount*1000))
  1564. {
  1565. new strings[128];
  1566. format(strings,sizeof(strings),"[GROUP NOTIFICATION]: {FFFFFF}%s(%d) has Successfully converted %i$ to %i Credits.",GetPlayerNameEx(playerid),playerid,-amount*1000,-amount);
  1567. SendGroupChatMessage(GroupInfo[TempGroupID[playerid]][gID], strings);
  1568. GroupInfo[TempGroupID[playerid]][gCredits] += -amount;
  1569. GivePlayerMoney(playerid,amount*1000);
  1570. }
  1571. else
  1572. {
  1573. ShowDialog(playerid,creditconvertV,DIALOG_STYLE_INPUT,"Credit Conversion","Not Enough credits are avilable","Convert","Back");
  1574. }
  1575. }
  1576. return 1;
  1577. }
  1578. //army status
  1579.  
  1580. //group name
  1581. Dialog:grouprenamedialogV(playerid, response, listitem, inputtext[])
  1582. {
  1583. if(!response)
  1584. {
  1585. GroupPanel(playerid, TempGroupID[playerid]);
  1586. }
  1587. if(response)
  1588. {
  1589. if(strlen(inputtext) > 2 || strlen(inputtext) < 26)
  1590. {
  1591. format(GroupInfo[TempGroupID[playerid]][gName],128,"%s",inputtext);
  1592. GroupPanel(playerid, TempGroupID[playerid]);
  1593. }
  1594. else
  1595. {
  1596. ShowDialog(playerid,grouprenamedialogV,DIALOG_STYLE_INPUT,"Enter New Name","Character limit is 3-25","Enter","Back");
  1597. }
  1598. }
  1599. return 1;
  1600. }
  1601. //==============================================================================
Add Comment
Please, Sign In to add comment