factions names
#1

Hey guys, I have a faction system which recognizes the factions id wise,
here is the makeleader cmd:
Код:
CMD:makeleader(playerid, params[])
{
	if(PlayerInfo[playerid][AdminLevel] >= 1337) 
	{
	    new targetid, facid;
	    if(sscanf(params,"ui",targetid, facid)) return SendClientMessage(playerid, COLOR_ADM,"** Usage: /makeleader [Target ID][Faction ID]");//if the command is misused it will tell them the correct way to use it
	    if(targetid != INVALID_PLAYER_ID)
	    {
	        PlayerInfo[targetid][Faction] = facid; 
	        PlayerInfo[targetid][Facrank] = 10;
	        PlayerInfo[targetid][Facleader] = facid;
	        if(facid == 1)
	        {
				SendClientMessage(targetid,COLOR_LIGHTBLUE,"You have been made the leader of the {F18100}Palomino Creek Police Department!");
			}
			if(facid == 2)
	        {
				SendClientMessage(targetid,COLOR_LIGHTBLUE,"You have been made the leader of the {00B4F0}Federal Bureau of Investigations!");
			}
			if(facid == 3)
	        {
				SendClientMessage(targetid,COLOR_LIGHTBLUE,"You have been made the leader of the {FF9494}Palomino Creek Fire/Medical Department!");
			}
			if(facid == 4)
	        {
				SendClientMessage(targetid,COLOR_LIGHTBLUE,"You have been made the leader of the {A0A0A0}Palomino Creek Goverment!");
			}
			if(facid == 5)
	        {
				SendClientMessage(targetid,COLOR_LIGHTBLUE,"You have been made the leader of the {00EB33}Palomino Creek News Agency!");
			}
			if(facid == 6)
	        {
				SendClientMessage(targetid,COLOR_LIGHTBLUE,"You have been made the leader of the {FFFFFF}Hitman Agency!");
			}
	    }
	}
	else 
	{
	    SendClientMessage(playerid, COLOR_ADM, "* [AdmCMD]: Only administrators level 1337 and higher are able to use this command.");
	}
	return 1;
}
when I use /stats
Код:
CMD:stats(playerid, params[])
{
    new money = PlayerInfo[playerid][Money];
    new deaths = PlayerInfo[playerid][Deaths];
    new kills = PlayerInfo[playerid][Kills];
    new score = PlayerInfo[playerid][Score];
    new admin = PlayerInfo[playerid][AdminLevel];
    new fac = PlayerInfo[playerid][Faction];
    new facrank = PlayerInfo[playerid][Facrank];
    new facleader = PlayerInfo[playerid][Facleader];
    new coca = PlayerInfo[playerid][Cocaine];
    new name[MAX_PLAYER_NAME], string2[64+MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));

    format(string2, sizeof(string2), "* Showing statistics for [%s's] account *", name);
    SendClientMessage(playerid, COLOR_ADM, string2);
    
    
    new string[128];
    format(string, sizeof(string), "[General] - [Money: %d] | [Deaths: %d] | [Kills: %d] | [Score: %d] | [Admin Level: %d]", money, deaths, kills, score, admin);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    
    new string1[128];
    format(string1, sizeof(string1), "[Faction/Family] - [Faction: %d] | [Faction Rank: %d] | [Faction Leader: %d]", fac, facrank, facleader);
    SendClientMessage(playerid, COLOR_GOLD, string1);
    
    new string3[64];
    format(string3, sizeof(string3), "[Narcotics] - [Cocaine: %d]", coca);
    SendClientMessage(playerid, COLOR_ORANGE, string3);
    return 1;
}
it shows the faction id like it should, how can I make it show the faction name instead?
like I have to create an enum for it or use my current playerdata enum?

thanks in advance!


edit: how do I properly code a /factions cmd to see the current factions with current leaders and members?
thanks
Reply
#2

To make it show a faction's name instead of the id, create a string variable in the /stats command and check what faction id the player is in and assign the name of the faction to the string variable based on the faction id of the player

pawn Код:
new string[128],factionname[24];
//using switch to assign the faction name to the string (more efficient than if/else statements)
switch(PlayerInfo[playerid][Faction])
{
    case 0: { factionname = "None"; }
    case 1: { factionname = "Faction A; }
    case 2: { factionname = "
Faction B; }
    //etc.
}
format(string,sizeof(string),"Faction: %s",factionname);
SendClientMessage(playerid,-1,string);
Hopefully, you can gather what I mean from that example and implement something like it in your command. Also, you don't need to create multiple string variables for each line, just have one string variable and reuse it after each line (so no need for string1,string2,etc., just reuse the normal string variable).
Reply
#3

Quote:
Originally Posted by DTV
Посмотреть сообщение
To make it show a faction's name instead of the id, create a string variable in the /stats command and check what faction id the player is in and assign the name of the faction to the string variable based on the faction id of the player

pawn Код:
new string[128],factionname[24];
//using switch to assign the faction name to the string (more efficient than if/else statements)
switch(PlayerInfo[playerid][Faction])
{
    case 0: { factionname = "None"; }
    case 1: { factionname = "Faction A; }
    case 2: { factionname = "
Faction B; }
    //etc.
}
format(string,sizeof(string),"Faction: %s",factionname);
SendClientMessage(playerid,-1,string);
Hopefully, you can gather what I mean from that example and implement something like it in your command. Also, you don't need to create multiple string variables for each line, just have one string variable and reuse it after each line (so no need for string1,string2,etc., just reuse the normal string variable).
Thanks alot! Any chance you can help me with factions cmd?
Reply
#4

Quote:
Originally Posted by MrCesar
Посмотреть сообщение
Thanks alot! Any chance you can help me with factions cmd?
It'd be hard to come up with an example, but basically what you'll need is to create a database (I'm not sure what you use to save/load stats whether it be y_ini, MySQL, or anything like that) that keeps track of the members of each faction and what their rank is. Then you'd simply make the command and order the faction members from highest to lowest rank.
Reply
#5

Quote:
Originally Posted by DTV
Посмотреть сообщение
It'd be hard to come up with an example, but basically what you'll need is to create a database (I'm not sure what you use to save/load stats whether it be y_ini, MySQL, or anything like that) that keeps track of the members of each faction and what their rank is. Then you'd simply make the command and order the faction members from highest to lowest rank.
uh I didnt really understand anything xd sorry, and I am using y_ini as I understood it's good for beginners
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)