Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CMD:afaction(playerid, params[])
- {
- if(PlayerInfo[playerid][pAdmin] < 1337)
- {
- SendClientMessage(playerid, COLOR_RED, "Niste ovlasteni za koristenje ove komande.");
- return 1;
- }
- new option[16], otext[128], string[1024];
- if(sscanf(params, "s[16] ",option))
- {
- SendClientMessage(playerid, COLOR_RED, "[?]: /afaction [OPCIJA]");
- SendClientMessage(playerid, COLOR_RED, "[!] create, list, type, changename, ranks, rankname, checkranks");
- SendClientMessage(playerid, COLOR_RED, "[!] delete, makeleader, removeleader, checkonline, save");
- return 1;
- }
- if(!strcmp(option, "create", true))
- {
- // TODO: make it a per-player variable and just use the input faction ID like EditingFactionID[playerid]
- // Remove this check and setting of this variable and place it in DIALOG_AFACTIONC where the ID is input
- if(creatingFaction == 1) return SendClientMessage(playerid, COLOR_RED, "Vec netko pravi organizaciju!");
- // TODO: remove hardcoded limit, use va_ShowPlayerDialog
- ShowPlayerDialog(playerid, DIALOG_AFACTIONC, DIALOG_STYLE_INPUT, "Unos ID-a", "Unesi ID na kojem ce organizacija da bude.\nDozvoljeni IDovi: 1-20", "Next", "Abort");
- creatingFaction = 1;
- return 1;
- }
- else if(!strcmp(option, "delete", true))
- {
- new fid;
- if(sscanf(params, "s[16]i", option, fid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction delete [ID]");
- if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
- fid--;
- if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
- 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]);
- // TODO: EditingFactionID
- deletingFaction[playerid] = fid;
- return 1;
- }
- else if(!strcmp(option, "checkonline", true))
- {
- new fid, name[MAX_PLAYER_NAME];
- if(sscanf(params, "s[16]i", option, fid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction checkoline [ID]");
- if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
- fid--;
- if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
- SendClientMessage(playerid, COLOR_WHITE, "");
- format(string, sizeof(string), "Online clanovi organizacije ID %d - %s", fid+1, FactionInfo[fid][fName]);
- SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
- foreach(new i : Player)
- {
- if(PlayerFaction[i][pMember] == fid)
- {
- GetPlayerName(i, name, sizeof(name));
- format(string, sizeof(string), "%s, %s (( Rank: %d))", name, ReturnPlayerRankName(i), PlayerFaction[i][pRank]);
- SendClientMessage(playerid, COLOR_WHITE, string);
- }
- }
- SendClientMessage(playerid, COLOR_WHITE, "");
- return 1;
- }
- else if(!strcmp(option, "list", true))
- {
- new
- tip[16],
- count = 0;
- foreach(new i : Faction)
- {
- // TODO: extract to helper function, GetFactionName(factionid)
- if(FactionInfo[i][fType] == FACTION_TYPE_NONE) { tip = "Nema"; }
- if(FactionInfo[i][fType] == FACTION_TYPE_LAW) { tip = "Law1"; }
- if(FactionInfo[i][fType] == FACTION_TYPE_LAW2) { tip = "Law2"; }
- if(FactionInfo[i][fType] == FACTION_TYPE_FD) { tip = "Medic"; }
- if(FactionInfo[i][fType] == FACTION_TYPE_LEGAL) { tip = "Legalna"; }
- if(FactionInfo[i][fType] == FACTION_TYPE_MAFIA) { tip = "Mafija"; }
- if(FactionInfo[i][fType] == FACTION_TYPE_GANG) { tip = "Banda"; }
- if(FactionInfo[i][fType] == FACTION_TYPE_RACERS) { tip = "Racer"; }
- if(FactionInfo[i][fType] == FACTION_TYPE_NEWS) { tip = "News"; }
- if(FactionInfo[i][fUsed] != 0)
- {
- // TODO: choose, shall you display the Faction SQLID, or some human-friendly ID from 1..N or
- // the internal script (FactionInfo array) ID 0..N-1 and then use that throughout.
- // For better player experience just use normalised ID's from 1..N (personal opinion).
- 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);
- }
- else
- {
- format(otext, sizeof(otext), "ID: %d Nije iskoristeno\n", i+1);
- }
- strcat(string, otext, sizeof(string));
- count++;
- }
- if(!count)
- {
- SendClientMessage(playerid, COLOR_RED, "Nema kreiranih fakcija!");
- return 1;
- }
- ShowPlayerDialog(playerid, DIALOG_FLIST, DIALOG_STYLE_MSGBOX, "Fakcije", string, "Close", "");
- return 1;
- }
- else if(!strcmp(option, "type", true))
- {
- // TODO: refactor this whole thing, make a generic type function which gets types from SQLID database
- // fetch the type names, list them
- new type, fid;
- if(sscanf(params, "s[16]ii", option, fid, type))
- {
- SendClientMessage(playerid, COLOR_WHITE, "[?]: /afaction type [ID][TIP FAKCIJE] ");
- SendClientMessage(playerid, COLOR_WHITE, "Tipovi: 1 - Law, 2 - FireDept, 3 - Legalna, 4 - Mafija, 5 - Banda, 6 - Raceri, 7 - News, 8 - Law2");
- return 1;
- }
- if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
- if(type < 1 || type > 9) return SendClientMessage(playerid, COLOR_RED, "Tipovi su od 1-7.");
- fid--;
- if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
- // TODO: make another helper function for this, make an array of faction names and print it out once,
- // don't repeat yourself!
- FactionInfo[fid][fType] = type;
- switch (type)
- {
- case FACTION_TYPE_LAW: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na law1!");
- case FACTION_TYPE_FD: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na firedept!");
- case FACTION_TYPE_LEGAL: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na legalnu!");
- case FACTION_TYPE_MAFIA: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na mafija!");
- case FACTION_TYPE_GANG: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na banda!");
- case FACTION_TYPE_RACERS: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na raceri!");
- case FACTION_TYPE_NEWS: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na News!");
- case FACTION_TYPE_LAW2: SendClientMessage(playerid, COLOR_RED, "[!] Promijenio si tip fakcije na law2!");
- }
- mysql_fquery(SQL_Handle(), "UPDATE server_factions SET type = '%d' WHERE id = '%d'",
- FactionInfo[fid][fType],
- FactionInfo[fid][fID]
- );
- return 1;
- }
- else if(!strcmp(option, "changename", true))
- {
- new newname[64], fid;
- if(sscanf(params, "s[16]is[64]", option, fid, newname)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction changename [ID][NOVO IME]");
- if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
- fid--;
- if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
- // TODO: strcpy
- format(FactionInfo[fid][fName],24,"%s",newname);
- va_SendMessage(playerid, MESSAGE_TYPE_INFO, "Promjenio si ime fakcije ID %d na %s.", fid+1, newname);
- mysql_fquery(SQL_Handle(), "UPDATE server_factions SET name = '%e' WHERE id = '%d'",
- newname,
- FactionInfo[fid][fID]
- );
- return 1;
- }
- else if(!strcmp(option, "ranks", true))
- {
- new ranks, fid;
- if(sscanf(params, "s[16]ii", option, fid, ranks)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction ranks [ID][Broj rankova (1-15)]");
- if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
- FactionInfo[fid][fRanks] = ranks;
- va_SendMessage(playerid, MESSAGE_TYPE_INFO, "Promjenio si broj rankova fakcije ID %d na %d.", fid+1, ranks);
- mysql_fquery(SQL_Handle(), "UPDATE server_factions SET ranks = '%d' WHERE id = '%d'",
- FactionInfo[fid][fRanks],
- FactionInfo[fid][fID]
- );
- return 1;
- }
- else if(!strcmp(option, "makeleader", true))
- {
- new
- targetid,
- fid;
- if(sscanf(params, "s[16]ui", option, targetid, fid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction makeleader [ID / Part of name][ID Organizacije]");
- if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID igraca!");
- if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
- PlayerFaction[targetid][pLeader] = fid;
- PlayerFaction[targetid][pMember] = fid;
- PlayerFaction[targetid][pRank] = FactionInfo[fid][fRanks];
- #if defined MODULE_LOGS
- Log_Write("/logfiles/orgs_leader.txt", "(%s) %s(%s) made %s(%s) the leader of faction %s.",
- ReturnDate(),
- GetName(playerid, false),
- ReturnPlayerIP(playerid),
- GetName(targetid, false),
- ReturnPlayerIP(targetid),
- FactionInfo[fid][fName]
- );
- #endif
- mysql_fquery(SQL_Handle(), "UPDATE player_faction SET facLeadId = '%d', facMemId = '%d', facRank = '%d' WHERE sqlid = '%d'",
- PlayerFaction[targetid][pLeader],
- PlayerFaction[targetid][pMember],
- PlayerFaction[targetid][pRank],
- PlayerInfo[targetid][pSQLID]
- );
- va_SendClientMessage(playerid, COLOR_LIGHTBLUE, "Postavio si %s (ID: %d) za lidera organizacije ID %d (%s).", GetName(targetid, true), targetid, fid, FactionInfo[fid][fName]);
- va_SendClientMessage(targetid, COLOR_LIGHTBLUE, "Postavljen si za lidera organizacije %s od strane Admina %s.", FactionInfo[fid][fName], GetName(playerid, true));
- return 1;
- }
- else if(!strcmp(option, "removeleader", true))
- {
- new targetid;
- if(sscanf(params, "s[16]u", option, targetid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction removeleader [ID / Part of name]");
- if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID igraca!");
- if(PlayerFaction[targetid][pLeader] == 0) return SendClientMessage(playerid, COLOR_RED, "Taj igrac nije lider!");
- mysql_fquery(SQL_Handle(), "UPDATE player_faction SET facLeadId = '0', facMemId = '0', facRank = '0' WHERE sqlid = '%d'",
- PlayerInfo[targetid][pSQLID]
- );
- #if defined MODULE_LOGS
- Log_Write("/logfiles/orgs_leader.txt", "(%s) %s(%s) removed %s(%s) the leader of faction %s status.",
- ReturnDate(),
- GetName(playerid, false),
- ReturnPlayerIP(playerid),
- GetName(targetid, false),
- ReturnPlayerIP(targetid),
- FactionInfo[PlayerFaction[targetid][pMember]][fName]
- );
- #endif
- PlayerFaction[targetid][pLeader] = 0;
- PlayerFaction[targetid][pMember] = 0;
- PlayerFaction[targetid][pRank] = 0;
- va_SendClientMessage(playerid, COLOR_LIGHTBLUE, "Skinuo si %s sa lidera organizacije.", GetName(targetid, true));
- va_SendClientMessage(targetid, COLOR_LIGHTBLUE, "Skinut si sa lidera organizacije od strane Admina %s.", GetName(playerid, true));
- return 1;
- }
- else if(!strcmp(option, "rankname", true))
- {
- new rankid, rankname[24], fid;
- if(sscanf(params, "s[16]iis[24]", option, fid, rankid, rankname))
- {
- SendClientMessage(playerid, COLOR_RED, "[?]: /afaction rankname [ID][Broj ranka (1-11)][Ime ranka]");
- return 1;
- }
- if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
- fid--;
- // TODO: doing len is pointless as sscanf will cutoff the string at 23 characters
- new rankname_len = strlen(rankname);
- if(rankname_len < 1 || rankname_len > 24) return SendClientMessage(playerid, COLOR_RED, "Prevelik ili premal broj slova!");
- if(rankid < 1 || rankid > FactionInfo[fid][fRanks]) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID ranka!");
- if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
- // TODO: extract into a function which gets the rank name given the rank index
- if(rankid == 1) { format(FactionInfo[fid][fRankName1],24,"%s",rankname); }
- if(rankid == 2) { format(FactionInfo[fid][fRankName2],24,"%s",rankname); }
- if(rankid == 3) { format(FactionInfo[fid][fRankName3],24,"%s",rankname); }
- if(rankid == 4) { format(FactionInfo[fid][fRankName4],24,"%s",rankname); }
- if(rankid == 5) { format(FactionInfo[fid][fRankName5],24,"%s",rankname); }
- if(rankid == 6) { format(FactionInfo[fid][fRankName6],24,"%s",rankname); }
- if(rankid == 7) { format(FactionInfo[fid][fRankName7],24,"%s",rankname); }
- if(rankid == 8) { format(FactionInfo[fid][fRankName8],24,"%s",rankname); }
- if(rankid == 9) { format(FactionInfo[fid][fRankName9],24,"%s",rankname); }
- if(rankid == 10) { format(FactionInfo[fid][fRankName10],24,"%s",rankname); }
- if(rankid == 11) { format(FactionInfo[fid][fRankName11],24,"%s",rankname); }
- if(rankid == 12) { format(FactionInfo[fid][fRankName12],24,"%s",rankname); }
- if(rankid == 13) { format(FactionInfo[fid][fRankName13],24,"%s",rankname); }
- if(rankid == 14) { format(FactionInfo[fid][fRankName14],24,"%s",rankname); }
- if(rankid == 15) { format(FactionInfo[fid][fRankName15],24,"%s",rankname); }
- mysql_fquery(SQL_Handle(), "UPDATE server_factions SET rank%d = '%e' WHERE id = '%d'",
- rankid,
- rankname,
- FactionInfo[fid][fID]
- );
- format(string, sizeof(string), "[!] Promjenio si ime ranka fakcije ID %d (ID RANKA: %d) na %s.", fid+1, rankid, rankname);
- SendClientMessage(playerid, COLOR_RED, string);
- return 1;
- }
- else if(!strcmp(option, "checkranks", true))
- {
- new fid;
- if(sscanf(params, "s[16]i", option, fid)) return SendClientMessage(playerid, COLOR_RED, "[?]: /afaction checkranks [ID fakcije]");
- if(fid < 1 || fid > MAX_FACTIONS) return SendClientMessage(playerid, COLOR_RED, "Invalidan ID fakcije");
- fid--;
- if(IsFreeSlot(fid)) return SendClientMessage(playerid, COLOR_RED, "Na tom slotu nije kreirana fakcija!");
- // TODO: va_ShowPlayerDialog
- // TODO: extract into a function and refactor FactionInfo rankNames
- 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\
- 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",
- fid+1,
- FactionInfo[fid][fRankName1],
- FactionInfo[fid][fRankName2],
- FactionInfo[fid][fRankName3],
- FactionInfo[fid][fRankName4],
- FactionInfo[fid][fRankName5],
- FactionInfo[fid][fRankName6],
- FactionInfo[fid][fRankName7],
- FactionInfo[fid][fRankName8],
- FactionInfo[fid][fRankName9],
- FactionInfo[fid][fRankName10],
- FactionInfo[fid][fRankName11],
- FactionInfo[fid][fRankName12],
- FactionInfo[fid][fRankName13],
- FactionInfo[fid][fRankName14],
- FactionInfo[fid][fRankName15]
- );
- ShowPlayerDialog(playerid, DIALOG_RLIST, DIALOG_STYLE_MSGBOX, "Rankovi", string, "Close", "");
- return 1;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment