Making faction system more than 1 faction
#1

MAKELEADER
PHP код:
CMD:makeleader(playerid, params[])
{
    new 
targetid, factionid, string[128], targetname[24], playername[24];
    if(
sscanf(params, "ui", targetid, factionid)) return SendClientMessage(playerid, -1, "Usage: /makeleader [playerid][factionid]"); //Checks if they typed in anything for the playerid and factionid parameters, and if they don't, return a client message.
    
if(pInfo[playerid][pAdminLevel] < 5) return SendClientMessage(playerid, -1, "You are not an admin"); //Checks if they are an admin.  Remember, change this to your admin variable, or use !IsPlayerAdmin to check if they aren't rcon admin.
    
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player is not connected
    
if(0 < factionid < 3) //Checks if the factionid is between 0 and 3, and if so, continue.  You can also type this like so: if(factionid >= 1 && factionid <= 2) or if(factionid == 1 || factionid == 2)
    
{
        
GetPlayerName(playerid, playername, sizeof(playername)); //Gets the players name and saves it to the variable playername
        
GetPlayerName(targetid, targetname, sizeof(targetname)); //Gets the targets name and saves it to the variable targetname
        
format(string, sizeof(string), "You made %s leader of faction id %i!", targetname, factionid); //Formats the string that you will receive
        
SendClientMessage(playerid, -1, string); //Sends a message to the person who changes the other persons faction in a random color
        
format(string, sizeof(string), "You were made leader of faction id %i by %s", factionid, playername);//Formats the string that the player will receive
        
SendClientMessage(playerid, -1, string); //Sends a message to the person who is made the faction leader
        
pInfo[targetid][pFaction] = factionid;
        
pInfo[targetid][pRank] = 6; //Leader, use a switch case or if/else if statement if you want to make it so certain factions have seperate highest ranks
    
}
    else return 
SendClientMessage(playerid, -1, "Invalid factionid.  Factionid's: 1-2"); //Sends a message if the faction is NOT between 0 and 3
    
return 1;// Returns 1 to end the command, as we NEED to return a value.
} 
INVITE
PHP код:
CMD:invite(playerid, params[])
{ 
//Open bracket
    
new targetid, targetname[24], playername[24], string[128]; //Create the variables
    
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /removefromfaction [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
    
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
    
if(pInfo[playerid][pRank] != 6) return SendClientMessage(playerid, -1, "You are not the leader of a faction!");
    
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
    
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
    
format(string, sizeof(string), "You invited %s to faction!", targetname);//Formats the message that will be sent to you (the player)
    
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
    
format(string, sizeof(string), "You were invited to faction %s by %s!", playername);//Formats the message that will be sent to the targetid
    
SendClientMessage(targetid, -1, string);//Sends the message that is formatted above to the targetid in a random color
    
pInfo[targetid][pFaction] = pInfo[playerid][pFaction];
    
pInfo[targetid][pRank] = 1; 
    return 
1; //Returns a value
} 
COmmand /f which you talk
PHP код:
CMD:f(playerid,params[])
{
    new 
factionstring[257];
    if(
pInfo[playerid][pFaction] >= 1)
    {
        if(!
strlen(params))
        {
            
SendClientMessage(playerid, -1, ""chat" /f [mesaj]");
            return 
1;
        }
        
format(factionstring, sizeof(factionstring), ""COL_LIGHTBLUE"(( %s %s: %s",GetRankName(playerid),PlayerName(playerid), params);
        
SendMessageToAllFaction(factionstring, -1);
    }
    else {
        
SendClientMessage(playerid,-1,"*"COL_RED" You are not in any faction!");
    }
    return 
1;
} 
SendMessageToAllFaction Function
PHP код:
stock SendMessageToAllFaction(message[], color)
{
    foreach(
Player, i)
    {
        if(
pInfo[i][pFaction] >= 1)
        {
             
SendClientMessage(i, color, message);
         }
     }
    return 
1;
} 
get rank functio

PHP код:
stock GetRankName(playerid)
{
    new 
rankname[128];
    switch(
pInfo[playerid][pRank])
    {
        case 
0: rankname = "Police Officer I";
        case 
1: rankname = "Police Officer II";
        case 
2: rankname = "Police Officer III";
        case 
3: rankname = "Police Officer III+1";
        case 
4: rankname = "Sergeant I";
        case 
5: rankname = "Sergeant II";
        case 
6: rankname = "Lieutenant I";
        case 
7: rankname = "Captain";
    }
    return 
rankname;
} 
My question is, how can i edit that

ID 1 of faction be named Los Santos Police Department
ID 2 of faction be named All Saints General Hospital

ID 1's faction rank's to be named as seen upstair
ID 2's faction rank's to be named as seen upstair (as GetRankName too)


And how to make /f work without faction ID 1 see what faction ID 2 says (And vice versa)


pls help, i give rep
Reply
#2

if you don't have a dynamic faction system, use this at everywhere.
PHP код:
stock GetFactionName(factionid) 
{ 
    new 
factname[128]; 
    switch(
factionid) 
    { 
        case 
0: factname = "None"; 
        case 
1: factname = "Los Santos Police Department"; 
        case 
2: factname = "All Saints General Hospital"; 
    } 
    return 
factname; 
} 
Reply
#3

Quote:
Originally Posted by Mugala
Посмотреть сообщение
if you don't have a dynamic faction system, use this at everywhere.
PHP код:
stock GetFactionName(factionid) 
{ 
    new 
factname[128]; 
    switch(
factionid) 
    { 
        case 
0: factname = "None"; 
        case 
1: factname = "Los Santos Police Department"; 
        case 
2: factname = "All Saints General Hospital"; 
    } 
    return 
factname; 
} 
Thanks, and no, I don't have a dynamic faction system.

I just follow an tutorial here, from forum.
Reply
#4

by the way, GetRankName is not a correct, first you must get the member's current faction ID and than rank depended on that faction.
Reply
#5

Quote:
Originally Posted by Mugala
Посмотреть сообщение
by the way, GetRankName is not a correct, first you must get the member's current faction ID and than rank depended on that faction.
yes, I know, that's why I asked how can I do that, because I tried to do something like adminranks.
PHP код:
stock GetRankName(playerid)
{
    new 
rankname[256];
    switch(
pInfo[playerid][pRank]) && (pInfo[playerid][pFaction == 1)
    {
        case 
0: rankname = "Police Officer I";
        case 
1: rankname = "Police Officer II";
        case 
2: rankname = "Police Officer III";
        case 
3: rankname = "Police Officer III+1";
        case 
4: rankname = "Sergeant I";
        case 
5: rankname = "Sergeant II";
        case 
6: rankname = "Lieutenant I";
        case 
7: rankname = "Captain";
        case 
8: rankname = "Commander";
        case 
9: rankname = "Deputy Chief of Police";
        case 
10: rankname = "Assistant Chief of Police";
        case 
11: rankname = "Chief of Police";
    }
    new 
rankname2[256];
    switch(
pInfo[playerid][pRank]) && (pInfo[playerid][pFaction == 2)
    {
        case 
0: rankname2 = "RankI";
        case 
1: rankname2 = "Rank II";
        case 
2: rankname2 = "Rank III";
        case 
3: rankname2 = "Rank III+1";
        case 
4: rankname2 = "Rank I";
        case 
5: rankname2 = "Rank II";
        case 
6: rankname2 = "Rank I";
        case 
7: rankname2 = "rank";
        case 
8: rankname2 = "rank";
        case 
9: rankname2 = "rank";
        case 
10: rankname2 = "Rank";
        case 
11: rankname2 = "Rank";
    }
    return 
rankname2;
} 
should be like this?
Reply
#6

no, you must first get the faction ID.
PHP код:
stock GetRankName(playerid) 
{ 
    new 
rankname[256];
    switch(
pInfo[playerid][pFaction])
    {
        case 
1:
        {
            switch(
pInfo[playerid][pRank])
            {
                case 
1: rankname = "Police Officer I";//and else.. add by yourself 
Reply
#7

Quote:
Originally Posted by Mugala
Посмотреть сообщение
no, you must first get the faction ID.
Something like this? And what I need to do about cmd:f ?

And how can I set that, at makeleader, if value is 1 rank to be 15. if value is 2, rank to be 17 ?

PHP код:
stock GetRankName(playerid)
{
    new 
rankname[256];
    switch(
pInfo[playerid][pFaction])
    {
        case 
1:
        {
            switch(
pInfo[playerid][pRank])
            {
                case 
1: rankname = "Suspended Employee";
                case 
2: rankname = "Academy Student";
                case 
3: rankname = "Police Officer I";
                case 
4: rankname = "Police Officer II";
                case 
5: rankname = "Police Officer III";
                case 
6: rankname = "Police Officer III+1";
                case 
7: rankname = "Sergeant I";
                case 
8: rankname = "Sergeant II";
                case 
9: rankname = "Lieutenant I";
                case 
10: rankname = "Lieutenant II";
                case 
11: rankname = "Police Captain";
                case 
12: rankname = "Police Commander";
                case 
13: rankname = "Deputy Chief of Police";
                case 
14: rankname = "Assistant Chief of Police";
                case 
15: rankname = "Chief of Police";
            }
        }
           case 
2:
        {
            switch(
pInfo[playerid][pRank])
            {
                case 
1: rankname = "Suspended Employee";
                case 
2: rankname = "Academy Student";
                case 
3: rankname = "Probationary Firefighter";
                case 
4: rankname = "Firefighter I";
                case 
5: rankname = "Firefighter II";
                case 
6: rankname = "Paramedic";
                case 
7: rankname = "EMT";
                case 
8: rankname = "First Responder";
                case 
9: rankname = "Attending Physician";
                case 
10: rankname = "Chief Of Medicine";
                case 
11: rankname = "Lieutenant";
                case 
12: rankname = "Lieutenant II";
                case 
13: rankname = "Captain";
                case 
14: rankname = "Battalion Chief";
                case 
15: rankname = "Division Chief";
                case 
16: rankname = "Deputy Commissioner";
                case 
17: rankname = "Commissioner";
            }
        }
}
    return 
rankname;
} 
Reply
#8

I solved the cmd:f.

PHP код:
CMD:f(playerid,params[])
{
    new 
factionstring[257];
    if(
pInfo[i][pFaction] == pInfo[i][pFaction])
    {
        if(!
strlen(params))
        {
            
SendClientMessage(playerid, -1, ""chat" /f [mesaj]");
            return 
1;
        }
        
format(factionstring, sizeof(factionstring), ""COL_FCHAT"** (( %s %s: %s ))**",GetRankName(playerid),PlayerName(playerid), params);
        
SendMessageToAllFaction(factionstring, -1);
    }
    else {
        
SendClientMessage(playerid,-1,"*"COL_RED" U are not in faction!");
    }
    return 
1;
} 
Thank you. Is there a way to sort faction online members by their case rank ?

PHP код:
CMD:factionon(playerid, params[])
{
    new 
str[128], DUTY_STR[24], COLOR, counter = 0;
    
SendClientMessage(playerid, -1, " - Membrii online - ");
    for(new 
i = 0; i < MAX_PLAYERS; i++)
    {
        if(
IsPlayerConnected(i))
        {
            if(
pInfo[i][pFaction] == pInfo[i][pFaction])
            {
                if(!
pInfo[i][pPoliceDuty])
                {
                    
DUTY_STR = "Off Duty";
                    
COLOR = COLOR_WHITE;
                }
                else
                {
                    
DUTY_STR = "ON DUTY";
                    
COLOR = COLOR_RED;
                }
                
format(str, sizeof(str),"%s: %s - %s",  GetRankName(i), PlayerName(i), DUTY_STR);
                
SendClientMessage(playerid, COLOR, str);
                
counter++;
            }
        }
    }
    return 
1;
} 
Reply
#9

yeah but it's big function, better to search in forums by keyword 'sorting'
you must change the value in command:makeleader
PHP код:
CMD:makeleader(playerid, params[]) 
{ 
    new 
targetid, factionid, string[128], targetname[24], playername[24]; 
    if(
sscanf(params, "ui", targetid, factionid)) return SendClientMessage(playerid, -1, "Usage: /makeleader [playerid][factionid]"); //Checks if they typed in anything for the playerid and factionid parameters, and if they don't, return a client message. 
    
if(pInfo[playerid][pAdminLevel] < 5) return SendClientMessage(playerid, -1, "You are not an admin"); //Checks if they are an admin.  Remember, change this to your admin variable, or use !IsPlayerAdmin to check if they aren't rcon admin. 
    
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player is not connected 
    
if(0 < factionid < 3) //Checks if the factionid is between 0 and 3, and if so, continue.  You can also type this like so: if(factionid >= 1 && factionid <= 2) or if(factionid == 1 || factionid == 2) 
    
{ 
        
GetPlayerName(playerid, playername, sizeof(playername)); //Gets the players name and saves it to the variable playername 
        
GetPlayerName(targetid, targetname, sizeof(targetname)); //Gets the targets name and saves it to the variable targetname 
        
format(string, sizeof(string), "You made %s leader of faction id %i!", targetname, factionid); //Formats the string that you will receive 
        
SendClientMessage(playerid, -1, string); //Sends a message to the person who changes the other persons faction in a random color 
        
format(string, sizeof(string), "You were made leader of faction id %i by %s", factionid, playername);//Formats the string that the player will receive 
        
SendClientMessage(playerid, -1, string); //Sends a message to the person who is made the faction leader 
        
pInfo[targetid][pFaction] = factionid;
        if(
factionid == 1) pInfo[targetid][pRank] = 15; // for lspd
        
else if(factionid == 2) pInfo[targetid][pRank] = 17; // for hospital
        
else pInfo[targetid][pRank] = 6; // for default/other factions.
         //Leader, use a switch case or if/else if statement if you want to make it so certain factions have seperate highest ranks 
    
} 
    else return 
SendClientMessage(playerid, -1, "Invalid factionid.  Factionid's: 1-2"); //Sends a message if the faction is NOT between 0 and 3 
    
return 1;// Returns 1 to end the command, as we NEED to return a value. 
} 
Reply
#10

Quote:
Originally Posted by Mugala
Посмотреть сообщение
yeah but it's big function, better to search in forums by keyword 'sorting'
you must change the value in command:makeleader
PHP код:
CMD:makeleader(playerid, params[]) 
{ 
    new 
targetid, factionid, string[128], targetname[24], playername[24]; 
    if(
sscanf(params, "ui", targetid, factionid)) return SendClientMessage(playerid, -1, "Usage: /makeleader [playerid][factionid]"); //Checks if they typed in anything for the playerid and factionid parameters, and if they don't, return a client message. 
    
if(pInfo[playerid][pAdminLevel] < 5) return SendClientMessage(playerid, -1, "You are not an admin"); //Checks if they are an admin.  Remember, change this to your admin variable, or use !IsPlayerAdmin to check if they aren't rcon admin. 
    
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player is not connected 
    
if(0 < factionid < 3) //Checks if the factionid is between 0 and 3, and if so, continue.  You can also type this like so: if(factionid >= 1 && factionid <= 2) or if(factionid == 1 || factionid == 2) 
    
{ 
        
GetPlayerName(playerid, playername, sizeof(playername)); //Gets the players name and saves it to the variable playername 
        
GetPlayerName(targetid, targetname, sizeof(targetname)); //Gets the targets name and saves it to the variable targetname 
        
format(string, sizeof(string), "You made %s leader of faction id %i!", targetname, factionid); //Formats the string that you will receive 
        
SendClientMessage(playerid, -1, string); //Sends a message to the person who changes the other persons faction in a random color 
        
format(string, sizeof(string), "You were made leader of faction id %i by %s", factionid, playername);//Formats the string that the player will receive 
        
SendClientMessage(playerid, -1, string); //Sends a message to the person who is made the faction leader 
        
pInfo[targetid][pFaction] = factionid;
        if(
factionid == 1) pInfo[targetid][pRank] = 15; // for lspd
        
else if(factionid == 2) pInfo[targetid][pRank] = 17; // for hospital
        
else pInfo[targetid][pRank] = 6; // for default/other factions.
         //Leader, use a switch case or if/else if statement if you want to make it so certain factions have seperate highest ranks 
    
} 
    else return 
SendClientMessage(playerid, -1, "Invalid factionid.  Factionid's: 1-2"); //Sends a message if the faction is NOT between 0 and 3 
    
return 1;// Returns 1 to end the command, as we NEED to return a value. 
} 
Then, at leader commands, if variable should be

PHP код:
    if(factionid == 1) pInfo[targetid][pRank] < 15) return SendClientMessage(playerid, -1, "You are not the leader of a faction!");
if(
factionid == 2) pInfo[targetid][pRank] < 17) return SendClientMessage(playerid, -1, "You are not the leader of a faction!"); 
?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)