Guest User

Untitled

a guest
Nov 6th, 2024
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.59 KB | None | 0 0
  1. CMD:afaction(playerid, params[])
  2. {
  3. if(PlayerInfo[playerid][pAdmin] < 1337)
  4. {
  5. SendClientMessage(playerid, COLOR_RED, "Niste ovlasteni za koristenje ove komande.");
  6. return 1;
  7. }
  8.  
  9. new option[16], otext[128], string[1024];
  10. if(sscanf(params, "s[16] ",option))
  11. {
  12. SendClientMessage(playerid, COLOR_RED, "[?]: /afaction [OPCIJA]");
  13. SendClientMessage(playerid, COLOR_RED, "[!] create, list, type, changename, ranks, rankname, checkranks");
  14. SendClientMessage(playerid, COLOR_RED, "[!] delete, makeleader, removeleader, checkonline, save");
  15. return 1;
  16. }
  17.  
  18. if(!strcmp(option, "create", true))
  19. {
  20. // TODO: make it a per-player variable and just use the input faction ID like EditingFactionID[playerid]
  21. // Remove this check and setting of this variable and place it in DIALOG_AFACTIONC where the ID is input
  22. if(creatingFaction == 1) return SendClientMessage(playerid, COLOR_RED, "Vec netko pravi organizaciju!");
  23.  
  24. // TODO: remove hardcoded limit, use va_ShowPlayerDialog
  25. ShowPlayerDialog(playerid, DIALOG_AFACTIONC, DIALOG_STYLE_INPUT, "Unos ID-a", "Unesi ID na kojem ce organizacija da bude.\nDozvoljeni IDovi: 1-20", "Next", "Abort");
  26. creatingFaction = 1;
  27. return 1;
  28. }
  29. else if(!strcmp(option, "delete", true))
  30. {
  31. new fid;
  32. if(sscanf(params, "s[16]i", option, fid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction delete [ID]");
  33. if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
  34. fid--;
  35. if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
  36.  
  37. va_ShowPlayerDialog(playerid, DIALOG_FDELETE, DIALOG_STYLE_MSGBOX, "Obrisi fakciju", "Jesi li siguran da zelis obrisati organizaciju iz slota ID "COL_WHITE"%d (%s)"COL_DEFAULT"?", "Yes", "No", fid+1, FactionInfo[fid][fName]);
  38. // TODO: EditingFactionID
  39. deletingFaction[playerid] = fid;
  40. return 1;
  41. }
  42. else if(!strcmp(option, "checkonline", true))
  43. {
  44. new fid, name[MAX_PLAYER_NAME];
  45. if(sscanf(params, "s[16]i", option, fid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction checkoline [ID]");
  46. if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
  47. fid--;
  48. if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
  49.  
  50. SendClientMessage(playerid, COLOR_WHITE, "");
  51. format(string, sizeof(string), "Online clanovi organizacije ID %d - %s", fid+1, FactionInfo[fid][fName]);
  52. SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  53.  
  54. foreach(new i : Player)
  55. {
  56. if(PlayerFaction[i][pMember] == fid)
  57. {
  58. GetPlayerName(i, name, sizeof(name));
  59. format(string, sizeof(string), "%s, %s (( Rank: %d))", name, ReturnPlayerRankName(i), PlayerFaction[i][pRank]);
  60. SendClientMessage(playerid, COLOR_WHITE, string);
  61. }
  62. }
  63. SendClientMessage(playerid, COLOR_WHITE, "");
  64. return 1;
  65. }
  66. else if(!strcmp(option, "list", true))
  67. {
  68. new
  69. tip[16],
  70. count = 0;
  71. foreach(new i : Faction)
  72. {
  73. // TODO: extract to helper function, GetFactionName(factionid)
  74. if(FactionInfo[i][fType] == FACTION_TYPE_NONE) { tip = "Nema"; }
  75. if(FactionInfo[i][fType] == FACTION_TYPE_LAW) { tip = "Law1"; }
  76. if(FactionInfo[i][fType] == FACTION_TYPE_LAW2) { tip = "Law2"; }
  77. if(FactionInfo[i][fType] == FACTION_TYPE_FD) { tip = "Medic"; }
  78. if(FactionInfo[i][fType] == FACTION_TYPE_LEGAL) { tip = "Legalna"; }
  79. if(FactionInfo[i][fType] == FACTION_TYPE_MAFIA) { tip = "Mafija"; }
  80. if(FactionInfo[i][fType] == FACTION_TYPE_GANG) { tip = "Banda"; }
  81. if(FactionInfo[i][fType] == FACTION_TYPE_RACERS) { tip = "Racer"; }
  82. if(FactionInfo[i][fType] == FACTION_TYPE_NEWS) { tip = "News"; }
  83.  
  84. if(FactionInfo[i][fUsed] != 0)
  85. {
  86. // TODO: choose, shall you display the Faction SQLID, or some human-friendly ID from 1..N or
  87. // the internal script (FactionInfo array) ID 0..N-1 and then use that throughout.
  88. // For better player experience just use normalised ID's from 1..N (personal opinion).
  89. format(otext, sizeof(otext), ""COL_DEFAULT"ID: "COL_WHITE"%d"COL_DEFAULT"Ime: "COL_WHITE"%s"COL_DEFAULT"-- Tip: %s\n", i+1, FactionInfo[i][fName], tip);
  90. }
  91. else
  92. {
  93. format(otext, sizeof(otext), "ID: %d Nije iskoristeno\n", i+1);
  94. }
  95. strcat(string, otext, sizeof(string));
  96. count++;
  97. }
  98. if(!count)
  99. {
  100. SendClientMessage(playerid, COLOR_RED, "Nema kreiranih fakcija!");
  101. return 1;
  102. }
  103. ShowPlayerDialog(playerid, DIALOG_FLIST, DIALOG_STYLE_MSGBOX, "Fakcije", string, "Close", "");
  104. return 1;
  105. }
  106. else if(!strcmp(option, "type", true))
  107. {
  108. // TODO: refactor this whole thing, make a generic type function which gets types from SQLID database
  109. // fetch the type names, list them
  110. new type, fid;
  111. if(sscanf(params, "s[16]ii", option, fid, type))
  112. {
  113. SendClientMessage(playerid, COLOR_WHITE, "[?]: /afaction type [ID][TIP FAKCIJE] ");
  114. SendClientMessage(playerid, COLOR_WHITE, "Tipovi: 1 - Law, 2 - FireDept, 3 - Legalna, 4 - Mafija, 5 - Banda, 6 - Raceri, 7 - News, 8 - Law2");
  115. return 1;
  116. }
  117. if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
  118. if(type < 1 || type > 9) return SendClientMessage(playerid, COLOR_RED, "Tipovi su od 1-7.");
  119. fid--;
  120. if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
  121.  
  122. // TODO: make another helper function for this, make an array of faction names and print it out once,
  123. // don't repeat yourself!
  124. FactionInfo[fid][fType] = type;
  125. switch (type)
  126. {
  127. case FACTION_TYPE_LAW: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na law1!");
  128. case FACTION_TYPE_FD: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na firedept!");
  129. case FACTION_TYPE_LEGAL: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na legalnu!");
  130. case FACTION_TYPE_MAFIA: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na mafija!");
  131. case FACTION_TYPE_GANG: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na banda!");
  132. case FACTION_TYPE_RACERS: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na raceri!");
  133. case FACTION_TYPE_NEWS: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na News!");
  134. case FACTION_TYPE_LAW2: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na law2!");
  135. }
  136.  
  137. mysql_fquery(SQL_Handle(), "UPDATE server_factions SET type = '%d' WHERE id = '%d'",
  138. FactionInfo[fid][fType],
  139. FactionInfo[fid][fID]
  140. );
  141. return 1;
  142. }
  143. else if(!strcmp(option, "changename", true))
  144. {
  145. new newname[64], fid;
  146. if(sscanf(params, "s[16]is[64]", option, fid, newname)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction changename [ID][NOVO IME]");
  147. if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
  148. fid--;
  149. if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
  150. // TODO: strcpy
  151. format(FactionInfo[fid][fName],24,"%s",newname);
  152. va_SendMessage(playerid, MESSAGE_TYPE_INFO, "Promjenio si ime fakcije ID %d na %s.", fid+1, newname);
  153.  
  154. mysql_fquery(SQL_Handle(), "UPDATE server_factions SET name = '%e' WHERE id = '%d'",
  155. newname,
  156. FactionInfo[fid][fID]
  157. );
  158. return 1;
  159. }
  160. else if(!strcmp(option, "ranks", true))
  161. {
  162. new ranks, fid;
  163. if(sscanf(params, "s[16]ii", option, fid, ranks)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction ranks [ID][Broj rankova (1-15)]");
  164. if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
  165. FactionInfo[fid][fRanks] = ranks;
  166. va_SendMessage(playerid, MESSAGE_TYPE_INFO, "Promjenio si broj rankova fakcije ID %d na %d.", fid+1, ranks);
  167.  
  168. mysql_fquery(SQL_Handle(), "UPDATE server_factions SET ranks = '%d' WHERE id = '%d'",
  169. FactionInfo[fid][fRanks],
  170. FactionInfo[fid][fID]
  171. );
  172. return 1;
  173. }
  174. else if(!strcmp(option, "makeleader", true))
  175. {
  176. new
  177. targetid,
  178. fid;
  179.  
  180. if(sscanf(params, "s[16]ui", option, targetid, fid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction makeleader [ID / Part of name][ID Organizacije]");
  181. if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID igraca!");
  182. if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
  183.  
  184. PlayerFaction[targetid][pLeader] = fid;
  185. PlayerFaction[targetid][pMember] = fid;
  186. PlayerFaction[targetid][pRank] = FactionInfo[fid][fRanks];
  187.  
  188. #if defined MODULE_LOGS
  189. Log_Write("/logfiles/orgs_leader.txt", "(%s) %s(%s) made %s(%s) the leader of faction %s.",
  190. ReturnDate(),
  191. GetName(playerid, false),
  192. ReturnPlayerIP(playerid),
  193. GetName(targetid, false),
  194. ReturnPlayerIP(targetid),
  195. FactionInfo[fid][fName]
  196. );
  197. #endif
  198.  
  199. mysql_fquery(SQL_Handle(), "UPDATE player_faction SET facLeadId = '%d', facMemId = '%d', facRank = '%d' WHERE sqlid = '%d'",
  200. PlayerFaction[targetid][pLeader],
  201. PlayerFaction[targetid][pMember],
  202. PlayerFaction[targetid][pRank],
  203. PlayerInfo[targetid][pSQLID]
  204. );
  205.  
  206. va_SendClientMessage(playerid, COLOR_LIGHTBLUE, "Postavio si %s (ID: %d) za lidera organizacije ID %d (%s).", GetName(targetid, true), targetid, fid, FactionInfo[fid][fName]);
  207. va_SendClientMessage(targetid, COLOR_LIGHTBLUE, "Postavljen si za lidera organizacije %s od strane Admina %s.", FactionInfo[fid][fName], GetName(playerid, true));
  208. return 1;
  209. }
  210. else if(!strcmp(option, "removeleader", true))
  211. {
  212. new targetid;
  213. if(sscanf(params, "s[16]u", option, targetid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction removeleader [ID / Part of name]");
  214. if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID igraca!");
  215. if(PlayerFaction[targetid][pLeader] == 0) return SendClientMessage(playerid, COLOR_RED, "Taj igrac nije lider!");
  216.  
  217. mysql_fquery(SQL_Handle(), "UPDATE player_faction SET facLeadId = '0', facMemId = '0', facRank = '0' WHERE sqlid = '%d'",
  218. PlayerInfo[targetid][pSQLID]
  219. );
  220.  
  221. #if defined MODULE_LOGS
  222. Log_Write("/logfiles/orgs_leader.txt", "(%s) %s(%s) removed %s(%s) the leader of faction %s status.",
  223. ReturnDate(),
  224. GetName(playerid, false),
  225. ReturnPlayerIP(playerid),
  226. GetName(targetid, false),
  227. ReturnPlayerIP(targetid),
  228. FactionInfo[PlayerFaction[targetid][pMember]][fName]
  229. );
  230. #endif
  231.  
  232. PlayerFaction[targetid][pLeader] = 0;
  233. PlayerFaction[targetid][pMember] = 0;
  234. PlayerFaction[targetid][pRank] = 0;
  235.  
  236. va_SendClientMessage(playerid, COLOR_LIGHTBLUE, "Skinuo si %s sa lidera organizacije.", GetName(targetid, true));
  237. va_SendClientMessage(targetid, COLOR_LIGHTBLUE, "Skinut si sa lidera organizacije od strane Admina %s.", GetName(playerid, true));
  238. return 1;
  239. }
  240. else if(!strcmp(option, "rankname", true))
  241. {
  242. new rankid, rankname[24], fid;
  243. if(sscanf(params, "s[16]iis[24]", option, fid, rankid, rankname))
  244. {
  245. SendClientMessage(playerid, COLOR_RED, "[?]: /afaction rankname [ID][Broj ranka (1-11)][Ime ranka]");
  246. return 1;
  247. }
  248. if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
  249. fid--;
  250. // TODO: doing len is pointless as sscanf will cutoff the string at 23 characters
  251. new rankname_len = strlen(rankname);
  252. if(rankname_len < 1 || rankname_len > 24) return SendClientMessage(playerid, COLOR_RED, "Prevelik ili premal broj slova!");
  253. if(rankid < 1 || rankid > FactionInfo[fid][fRanks]) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID ranka!");
  254. if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
  255.  
  256. // TODO: extract into a function which gets the rank name given the rank index
  257. if(rankid == 1) { format(FactionInfo[fid][fRankName1],24,"%s",rankname); }
  258. if(rankid == 2) { format(FactionInfo[fid][fRankName2],24,"%s",rankname); }
  259. if(rankid == 3) { format(FactionInfo[fid][fRankName3],24,"%s",rankname); }
  260. if(rankid == 4) { format(FactionInfo[fid][fRankName4],24,"%s",rankname); }
  261. if(rankid == 5) { format(FactionInfo[fid][fRankName5],24,"%s",rankname); }
  262. if(rankid == 6) { format(FactionInfo[fid][fRankName6],24,"%s",rankname); }
  263. if(rankid == 7) { format(FactionInfo[fid][fRankName7],24,"%s",rankname); }
  264. if(rankid == 8) { format(FactionInfo[fid][fRankName8],24,"%s",rankname); }
  265. if(rankid == 9) { format(FactionInfo[fid][fRankName9],24,"%s",rankname); }
  266. if(rankid == 10) { format(FactionInfo[fid][fRankName10],24,"%s",rankname); }
  267. if(rankid == 11) { format(FactionInfo[fid][fRankName11],24,"%s",rankname); }
  268. if(rankid == 12) { format(FactionInfo[fid][fRankName12],24,"%s",rankname); }
  269. if(rankid == 13) { format(FactionInfo[fid][fRankName13],24,"%s",rankname); }
  270. if(rankid == 14) { format(FactionInfo[fid][fRankName14],24,"%s",rankname); }
  271. if(rankid == 15) { format(FactionInfo[fid][fRankName15],24,"%s",rankname); }
  272.  
  273. mysql_fquery(SQL_Handle(), "UPDATE server_factions SET rank%d = '%e' WHERE id = '%d'",
  274. rankid,
  275. rankname,
  276. FactionInfo[fid][fID]
  277. );
  278.  
  279. format(string, sizeof(string), "[!] Promjenio si ime ranka fakcije ID %d (ID RANKA: %d) na %s.", fid+1, rankid, rankname);
  280. SendClientMessage(playerid, COLOR_RED, string);
  281. return 1;
  282. }
  283. else if(!strcmp(option, "checkranks", true))
  284. {
  285. new fid;
  286. if(sscanf(params, "s[16]i", option, fid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction checkranks [ID fakcije]");
  287. if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
  288. fid--;
  289. if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
  290.  
  291. // TODO: va_ShowPlayerDialog
  292. // TODO: extract into a function and refactor FactionInfo rankNames
  293. format(string, sizeof(string), "Rankovi fakcije ID %d\n\nRank 1: %s\nRank 2: %s\nRank 3: %s\nRank 4: %s\nRank 5: %s\n\
  294. Rank 6: %s\nRank 7: %s\nRank 8: %s\nRank 9: %s\nRank 10: %s\nRank 11: %s\nRank 12: %s\nRank 13: %s\nRank 14: %s\nRank 15: %s",
  295. fid+1,
  296. FactionInfo[fid][fRankName1],
  297. FactionInfo[fid][fRankName2],
  298. FactionInfo[fid][fRankName3],
  299. FactionInfo[fid][fRankName4],
  300. FactionInfo[fid][fRankName5],
  301. FactionInfo[fid][fRankName6],
  302. FactionInfo[fid][fRankName7],
  303. FactionInfo[fid][fRankName8],
  304. FactionInfo[fid][fRankName9],
  305. FactionInfo[fid][fRankName10],
  306. FactionInfo[fid][fRankName11],
  307. FactionInfo[fid][fRankName12],
  308. FactionInfo[fid][fRankName13],
  309. FactionInfo[fid][fRankName14],
  310. FactionInfo[fid][fRankName15]
  311. );
  312. ShowPlayerDialog(playerid, DIALOG_RLIST, DIALOG_STYLE_MSGBOX, "Rankovi", string, "Close", "");
  313. return 1;
  314. }
  315. return 1;
  316. }
  317.  
Advertisement
Add Comment
Please, Sign In to add comment