Faction rank problem
#1

So I want it so if your rank is set to 16, in /r it's 'Chief of police [yourname]: hi' etc.. but it displays nothing, here's my code..

My stock..

Код:
stock GetFactionRankName(playerid)
{
	new rankname[26];
	
	if(pInfo[playerid][Faction] == 1)
	{
		if(pInfo[playerid][FactionRank] == 0)
		    rankname = "Police Officer I";
		    
		else if(pInfo[playerid][FactionRank] == 1)
		    rankname = "Police Officer II";
		    
        else if(pInfo[playerid][FactionRank] == 2)
		    rankname = "Police Officer III";
		    
      	else if(pInfo[playerid][FactionRank] == 3)
		    rankname = "Lead Police Officer";
		    
     	else if(pInfo[playerid][FactionRank] == 4)
		    rankname = "Sergeant I";
		    
     	else if(pInfo[playerid][FactionRank] == 5)
		    rankname = "Sergeant II";
		    
  		else if(pInfo[playerid][FactionRank] == 6)
		    rankname = "Sergeant III";
		    
 		else if(pInfo[playerid][FactionRank] == 7)
		    rankname = "Lieutenant I";

        else if(pInfo[playerid][FactionRank] == 8)
		    rankname = "Lieutenant II";

      	else if(pInfo[playerid][FactionRank] == 9)
		    rankname = "Lieutenant III";

     	else if(pInfo[playerid][FactionRank] == 10)
		    rankname = "Captain I";

     	else if(pInfo[playerid][FactionRank] == 11)
		    rankname = "Captain II";

  		else if(pInfo[playerid][FactionRank] == 12)
		    rankname = "Captain III";
		    
     	else if(pInfo[playerid][FactionRank] == 13)
		    rankname = "Commander";

     	else if(pInfo[playerid][FactionRank] == 14)
		    rankname = "Assistant Chief of Police";

  		else if(pInfo[playerid][FactionRank] == 15)
		    rankname = "Deputy Chief of Police";
		    
  		else if(pInfo[playerid][FactionRank] == 16)
		    rankname = "Chief of Police";
	
	}

	return rankname;
}
RADIO EXAMPLE:

Код:
CMD:r(playerid, params[])
{
	new string[128], pname[MAX_PLAYER_NAME+1], factionid = pInfo[playerid][Faction];
	if(pInfo[playerid][Faction] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER:{FFFFFF} You're not in a faction!");
	
	GetPlayerName(playerid, pname, sizeof(pname));
	
	
	{format(string, sizeof(string), "%s %s: %s", GetFactionRankName(playerid), pname, params);}
	SendFactionRadioMessage(factionid, string);
	return 1;
}
It just doesn't input anything..
Reply
#2

PHP код:
stock GetFactionRankName(playerid)
{
    new
        
rankName[26]
    ;
    
    switch(
pInfo[playerid][FactionRank])
    {
        case 
0:  strcat(rankName"Police Officer I"sizeof(rankName));
        case 
1:  strcat(rankName"Police Officer II"sizeof(rankName));
        case 
2:  strcat(rankName"Police Officer III"sizeof(rankName));
        case 
3:  strcat(rankName"Lead Police Office"sizeof(rankName));
        case 
4:  strcat(rankName"Sergeant I"sizeof(rankName));
        case 
5:  strcat(rankName"Sergeant II"sizeof(rankName));
        case 
6:  strcat(rankName"Sergeant III"sizeof(rankName));
        case 
7:  strcat(rankName"Lieutenant I"sizeof(rankName));
        case 
8:  strcat(rankName"Lieutenant II"sizeof(rankName));
        case 
9:  strcat(rankName"Lieutenant III"sizeof(rankName));
        case 
10strcat(rankName"Captain I"sizeof(rankName));
        case 
11strcat(rankName"Captain II"sizeof(rankName));
        case 
12strcat(rankName"Captain III"sizeof(rankName));
        case 
13strcat(rankName"Commander"sizeof(rankName));
        case 
14strcat(rankName"Assistant Chief of Police"sizeof(rankName));
        case 
15strcat(rankName"Deputy Chief of Police"sizeof(rankName));
        case 
16strcat(rankName"Chief of Police"sizeof(rankName));
    }
    return 
rankName;
}
CMD:r(playeridparams[])
{
    if(
pInfo[playerid][Faction] == 0) return SendClientMessage(playeridCOLOR_LIGHTRED"SERVER:{FFFFFF} You're not in a faction!");
    
    new
        
string[128],
        
pName[MAX_PLAYER_NAME],
        
factionID pInfo[playerid][Faction]
    ;
    
GetPlayerName(playeridpNamesizeof(pName));
    
format(stringsizeof(string), "%s %s: %s"GetFactionRankName(playerid), pNameparams);
    
SendFactionRadioMessage(factionIDstring);
    return 
1;

Give a try.
Reply
#3

Quote:
Originally Posted by ]Rafaellos[
Посмотреть сообщение
PHP код:
stock GetFactionRankName(playerid)
{
    new
        
rankName[26]
    ;
    
    switch(
pInfo[playerid][FactionRank])
    {
        case 
0:  strcat(rankName"Police Officer I"sizeof(rankName));
        case 
1:  strcat(rankName"Police Officer II"sizeof(rankName));
        case 
2:  strcat(rankName"Police Officer III"sizeof(rankName));
        case 
3:  strcat(rankName"Lead Police Office"sizeof(rankName));
        case 
4:  strcat(rankName"Sergeant I"sizeof(rankName));
        case 
5:  strcat(rankName"Sergeant II"sizeof(rankName));
        case 
6:  strcat(rankName"Sergeant III"sizeof(rankName));
        case 
7:  strcat(rankName"Lieutenant I"sizeof(rankName));
        case 
8:  strcat(rankName"Lieutenant II"sizeof(rankName));
        case 
9:  strcat(rankName"Lieutenant III"sizeof(rankName));
        case 
10strcat(rankName"Captain I"sizeof(rankName));
        case 
11strcat(rankName"Captain II"sizeof(rankName));
        case 
12strcat(rankName"Captain III"sizeof(rankName));
        case 
13strcat(rankName"Commander"sizeof(rankName));
        case 
14strcat(rankName"Assistant Chief of Police"sizeof(rankName));
        case 
15strcat(rankName"Deputy Chief of Police"sizeof(rankName));
        case 
16strcat(rankName"Chief of Police"sizeof(rankName));
    }
    return 
rankName;
}
CMD:r(playeridparams[])
{
    if(
pInfo[playerid][Faction] == 0) return SendClientMessage(playeridCOLOR_LIGHTRED"SERVER:{FFFFFF} You're not in a faction!");
    
    new
        
string[128],
        
pName[MAX_PLAYER_NAME],
        
factionID pInfo[playerid][Faction]
    ;
    
GetPlayerName(playeridpNamesizeof(pName));
    
format(stringsizeof(string), "%s %s: %s"GetFactionRankName(playerid), pNameparams);
    
SendFactionRadioMessage(factionIDstring);
    return 
1;

Give a try.
Nope, the bit where its supposed to show the rank is blank :/
Reply
#4

Any help? :/
Reply
#5

Quote:
Originally Posted by izeatfishz
Посмотреть сообщение
Any help? :/
Pretty certain there was a rule against bumping topics within 24/48 hours. Either way...

Your script lacks a ton of debug lines. Also, you may not want to use switch / if ( x ) statements when you can use an array. And I'm pretty sure using strcat this way isn't really efficient... I'm also not a fan of huge functions like the one you use to return your rank.

Why not something like this?

PHP код:
enum RankInfo {
    
fRankID,
    
fRank 32 ]
};
ReturnFactionRankfidrank ) {
    new
        
rankEx 32 ];
    switch ( 
fid ) { // switch through faction ids
        
case FACTION_POLICE: { // Case FACTION_POLICE aka 1...
            
new const RankArray[ ][ RankInfo ] = { // Matter of fact, you may not even need to add the IDs to the array
                
1"Police Officer I" }, { 2"Police Officer II" }, { 3"Police Officer III" }, { 4"Lead Police Officer" }, { 5"Sergeant I" },
                { 
6"Sergeant II" }, { 7"Sergeant III" }, { 8"Lieutenant I" }, { 9"Lieutenant II" }, { 10"Lieutenant III" }, { 11"Captain I" },
                { 
12"Captain II" }, { 13"Captain III" }, { 14"Commander" }, { 15"Assistant Chief of Police" }, { 16"Deputy Chief of Police" },
                { 
17"Chief of Police" }
            };
        }
        
        
// case FACTION_MEDIC: { etc...
    
}
    
format rankExsizeof rankEx ), "%s"RankArray rank ] [ fRank ] );
    if ( ! 
fid || ! rank )
        
rankEx "None" ;
    return 
rankEx;

And for the rest of your script, I rewrote it with means of showing you how to use the above function. I tested it to some degrees and it seems to work but I haven't done any thorough testing so I advice against mindless copy and pasting. PS: It's been ages since I actually scripted so this may not be the most efficient way of doing things.

PHP код:
new
    
p_fac MAX_PLAYERS char ],
    
p_facRank MAX_PLAYERS char ];
CMD:ranktestpidparams [ ] ) {
    new
        
str 144 ],
        
name MAX_PLAYER_NAME ] ;
    
GetPlayerNamepidnamesizeof name ) ) ;
    if ( ! 
p_fac pid } )
        return 
SendClientMessage pid, -1"You're not in a faction!" );
    if ( 
isnull params ) )
        return 
SendClientMessage pid, -1"/ranktest [ text ]" );
    if ( 
strlen params ) > 110 // Perserving space for rank and name...
        
return SendClientMessage pid, -1"Text can't have more than 110 characters!" );
    
format strsizeof str ) , "%s %s: %s"ReturnFactionRank p_fac pid }, p_facRank pid } ), nameparams);
    
ReturnFactionMsg p_fac pid }, str );
    return 
true;
}
ReturnFactionMsg fidtext [ ] )
{
    foreach ( new 
iPlayer)
    {
        if ( 
p_fac } == fid )
        {
            return 
SendClientMessage i, -1text );
        }
    }
    
    return 
false;

In your code, you are also randomly using brackets. I wouldn't be surprised if that contributed to the problem. You should also consider using dynamic ranks, not hard coded ones.
Reply
#6

Quote:
Originally Posted by Satori_Komeiji
Посмотреть сообщение
Pretty certain there was a rule against bumping topics within 24/48 hours. Either way...

Your script lacks a ton of debug lines. Also, you may not want to use switch / if ( x ) statements when you can use an array. And I'm pretty sure using strcat this way isn't really efficient... I'm also not a fan of huge functions like the one you use to return your rank.

Why not something like this?

PHP код:
enum RankInfo {
    
fRankID,
    
fRank 32 ]
};
ReturnFactionRankfidrank ) {
    new
        
rankEx 32 ];
    switch ( 
fid ) { // switch through faction ids
        
case FACTION_POLICE: { // Case FACTION_POLICE aka 1...
            
new const RankArray[ ][ RankInfo ] = { // Matter of fact, you may not even need to add the IDs to the array
                
1"Police Officer I" }, { 2"Police Officer II" }, { 3"Police Officer III" }, { 4"Lead Police Officer" }, { 5"Sergeant I" },
                { 
6"Sergeant II" }, { 7"Sergeant III" }, { 8"Lieutenant I" }, { 9"Lieutenant II" }, { 10"Lieutenant III" }, { 11"Captain I" },
                { 
12"Captain II" }, { 13"Captain III" }, { 14"Commander" }, { 15"Assistant Chief of Police" }, { 16"Deputy Chief of Police" },
                { 
17"Chief of Police" }
            };
        }
        
        
// case FACTION_MEDIC: { etc...
    
}
    
format rankExsizeof rankEx ), "%s"RankArray rank ] [ fRank ] );
    if ( ! 
fid || ! rank )
        
rankEx "None" ;
    return 
rankEx;

And for the rest of your script, I rewrote it with means of showing you how to use the above function. I tested it to some degrees and it seems to work but I haven't done any thorough testing so I advice against mindless copy and pasting. PS: It's been ages since I actually scripted so this may not be the most efficient way of doing things.

PHP код:
new
    
p_fac MAX_PLAYERS char ],
    
p_facRank MAX_PLAYERS char ];
CMD:ranktestpidparams [ ] ) {
    new
        
str 144 ],
        
name MAX_PLAYER_NAME ] ;
    
GetPlayerNamepidnamesizeof name ) ) ;
    if ( ! 
p_fac pid } )
        return 
SendClientMessage pid, -1"You're not in a faction!" );
    if ( 
isnull params ) )
        return 
SendClientMessage pid, -1"/ranktest [ text ]" );
    if ( 
strlen params ) > 110 // Perserving space for rank and name...
        
return SendClientMessage pid, -1"Text can't have more than 110 characters!" );
    
format strsizeof str ) , "%s %s: %s"ReturnFactionRank p_fac pid }, p_facRank pid } ), nameparams);
    
ReturnFactionMsg p_fac pid }, str );
    return 
true;
}
ReturnFactionMsg fidtext [ ] )
{
    foreach ( new 
iPlayer)
    {
        if ( 
p_fac } == fid )
        {
            return 
SendClientMessage i, -1text );
        }
    }
    
    return 
false;

In your code, you are also randomly using brackets. I wouldn't be surprised if that contributed to the problem. You should also consider using dynamic ranks, not hard coded ones.
I'd like to use that function but have never really tried using one, and I doubt you would be willing to show me how via teamviewer or something :/
Reply
#7

I get a bunch of errors with that code, anyone else? please?
Reply
#8

Hello!

Write it so:
PHP код:
stock GetFactionRankName(playerid)
{
    new 
rankname[30];
    switch(
pInfo[playerid][Faction])
    {
        case 
1:
        {
            
//Faction 1
            
if(!pInfo[playerid][FactionRank])strcat(rankname,"Police Officer I");
            else if(
pInfo[playerid][FactionRank] == 1)strcat(rankname,"Police Officer II");
            else if(
pInfo[playerid][FactionRank] == 2)strcat(rankname,"Police Officer III");
            else if(
pInfo[playerid][FactionRank] == 3)strcat(rankname,"Lead Police Officer");
            else if(
pInfo[playerid][FactionRank] == 4)strcat(rankname,"Sergeant I");
            else if(
pInfo[playerid][FactionRank] == 5)strcat(rankname,"Sergeant II");
            else if(
pInfo[playerid][FactionRank] == 6)strcat(rankname,"Sergeant III");
            else if(
pInfo[playerid][FactionRank] == 7)strcat(rankname,"Lieutenant I");
            else if(
pInfo[playerid][FactionRank] == 8)strcat(rankname,"Lieutenant II");
            else if(
pInfo[playerid][FactionRank] == 9)strcat(rankname,"Lieutenant III");
            else if(
pInfo[playerid][FactionRank] == 10)strcat(rankname,"Captain I");
            else if(
pInfo[playerid][FactionRank] == 11)strcat(rankname,"Captain II");
            else if(
pInfo[playerid][FactionRank] == 12)strcat(rankname,"Captain III");
            else if(
pInfo[playerid][FactionRank] == 13)strcat(rankname,"Commander");
            else if(
pInfo[playerid][FactionRank] == 14)strcat(rankname,"Assistant Chief of Police");
            else if(
pInfo[playerid][FactionRank] == 15)strcat(rankname,"Deputy Chief of Police");
            else if(
pInfo[playerid][FactionRank] == 16)strcat(rankname,"Chief of Police");
            return 
rankname;
        }
    }
    return 
1;
}
CMD:r(playerid,params[])
{
    new 
string[145],pName[MAX_PLAYER_NAME],factionid pInfo[playerid][Faction];
    if(!
factionid)return SendClientMessage(playeridCOLOR_LIGHTRED"SERVER:{FFFFFF} You're not in a faction!");
    
GetPlayerName(playerid,pname,sizeof pname);
    
format(string,sozeof string,"%s %s: %s",GetFactionRankName(playerid),pname,params);
    
SendFactionRadioMessage(factionid,string);
    return 
1;

Do you get errors?

Mencent
Reply
#9

Код:
C:\Users\Nathan\Desktop\Downtown Roleplay\gamemodes\core.pwn(4342) : error 079: inconsistent return types (array & non-array)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Код:
stock GetFactionRankName(playerid)
{
    new rankname[30];
    switch(pInfo[playerid][Faction])
    {
        case 1:
        {
            //Faction 1
            if(!pInfo[playerid][FactionRank])strcat(rankname,"Police Officer I");
            else if(pInfo[playerid][FactionRank] == 1)strcat(rankname,"Police Officer II");
            else if(pInfo[playerid][FactionRank] == 2)strcat(rankname,"Police Officer III");
            else if(pInfo[playerid][FactionRank] == 3)strcat(rankname,"Lead Police Officer");
            else if(pInfo[playerid][FactionRank] == 4)strcat(rankname,"Sergeant I");
            else if(pInfo[playerid][FactionRank] == 5)strcat(rankname,"Sergeant II");
            else if(pInfo[playerid][FactionRank] == 6)strcat(rankname,"Sergeant III");
            else if(pInfo[playerid][FactionRank] == 7)strcat(rankname,"Lieutenant I");
            else if(pInfo[playerid][FactionRank] == 8)strcat(rankname,"Lieutenant II");
            else if(pInfo[playerid][FactionRank] == 9)strcat(rankname,"Lieutenant III");
            else if(pInfo[playerid][FactionRank] == 10)strcat(rankname,"Captain I");
            else if(pInfo[playerid][FactionRank] == 11)strcat(rankname,"Captain II");
            else if(pInfo[playerid][FactionRank] == 12)strcat(rankname,"Captain III");
            else if(pInfo[playerid][FactionRank] == 13)strcat(rankname,"Commander");
            else if(pInfo[playerid][FactionRank] == 14)strcat(rankname,"Assistant Chief of Police");
            else if(pInfo[playerid][FactionRank] == 15)strcat(rankname,"Deputy Chief of Police");
            else if(pInfo[playerid][FactionRank] == 16)strcat(rankname,"Chief of Police");
            return rankname;
        }
    }
    return 1;
}
Reply
#10

PHP код:
stock GetFactionRankName(playerid)
{
    new 
rankname[30];
    switch(
pInfo[playerid][Faction])
    {
        case 
1:
        {
            
//Faction 1
            
if(!pInfo[playerid][FactionRank])rankname="Police Officer I";
            else if(
pInfo[playerid][FactionRank] == 1)rankname="Police Officer II";
            else if(
pInfo[playerid][FactionRank] == 2)rankname="Police Officer III";
            else if(
pInfo[playerid][FactionRank] == 3)rankname="Lead Police Officer";
            else if(
pInfo[playerid][FactionRank] == 4)rankname="Sergeant I";
            else if(
pInfo[playerid][FactionRank] == 5)rankname="Sergeant II";
            else if(
pInfo[playerid][FactionRank] == 6)rankname="Sergeant III";
            else if(
pInfo[playerid][FactionRank] == 7)rankname="Lieutenant I";
            else if(
pInfo[playerid][FactionRank] == 8)rankname="Lieutenant II";
            else if(
pInfo[playerid][FactionRank] == 9)rankname="Lieutenant III";
            else if(
pInfo[playerid][FactionRank] == 10)rankname="Captain I";
            else if(
pInfo[playerid][FactionRank] == 11)rankname="Captain II";
            else if(
pInfo[playerid][FactionRank] == 12)rankname="Captain III";
            else if(
pInfo[playerid][FactionRank] == 13)rankname="Commander";
            else if(
pInfo[playerid][FactionRank] == 14)rankname="Assistant Chief of Police";
            else if(
pInfo[playerid][FactionRank] == 15)rankname="Deputy Chief of Police";
            else if(
pInfo[playerid][FactionRank] == 16)rankname="Chief of Police";
        }
    }
    return 
rankname;

Try this please.

Mencent
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)