Division name problem
#1

So, basically. I have created this:
pawn Код:
stock GetFactionName(playerid)
{
    new astring[50];
    if(PlayerInfo[playerid][pFaction] == 1)format(astring, sizeof(astring), "Fort Carson Sheriffs Department");
    else if(PlayerInfo[playerid][pFaction] == 2)format(astring, sizeof(astring), "Federal Bureau of Investigation");
    else if(PlayerInfo[playerid][pFaction] == 3)format(astring, sizeof(astring), "Fort Carson Fire Department");
    else if(PlayerInfo[playerid][pFaction] == 4)format(astring, sizeof(astring), "International Contract Agency");
    else if(PlayerInfo[playerid][pFaction] == 5)format(astring, sizeof(astring), "Government");
    else if(PlayerInfo[playerid][pFaction] == 6)format(astring, sizeof(astring), "SA News");
    return astring;
}
I am using this stock to show the faction name in /stats.
pawn Код:
format(string, sizeof(string), "Faction: {50BB44}%s",GetFactionName(playerid),PlayerInfo[playerid][pFaction]);
    SendClientMessage(playerid, WHITE, string);
I decided to create a new stock with division names, but here is the problem. I have six factions, and only some of them are using divisions. For example, Fort Carson Sheriffs Department has the following divisions.
pawn Код:
1 (None), 3 (FTO), 4 (S.W.A.T.), 5 (D.E.B.), 7 (TE)
But the Fire Department is not using them.

So here is my question. I want to create a new stock GetDivisionName. I tried and here it is.
pawn Код:
stock GetDivisionName(playerid)
{
    new astring[24];
    if(PlayerInfo[playerid][pFaction] == 1) & [PlayerInfo][playerid][pDivision] == 1)format(astring, sizeof(astring), "None");
    else if(PlayerInfo[playerid][pFaction] == 2) & [PlayerInfo][playerid][pDivision] == 3) format(astring, sizeof(astring), "FTO");
    else if(PlayerInfo[playerid][pFaction] == 3) & [PlayerInfo][playerid][pDivision] == 4) format(astring, sizeof(astring), "S.W.A.T.");
    else if(PlayerInfo[playerid][pFaction] == 4) & [PlayerInfo][playerid][pDivision] == 5) format(astring, sizeof(astring), "D.E.B.");
    else if(PlayerInfo[playerid][pFaction] == 5) & [PlayerInfo][playerid][pDivision] == 7) format(astring, sizeof(astring), "TE");
    return astring;
}
This didnt work tho, I get the following errors when I try to include the stock in /stats: Here is the line.
pawn Код:
format(string, sizeof(string), "Faction Division: {50BB44}%s",GetDivisionName(playerid),PlayerInfo[playerid][pDivision]);
    SendClientMessage(playerid, WHITE, string);
And the errors:
pawn Код:
(915) : error 029: invalid expression, assumed zero
(915) : error 029: invalid expression, assumed zero
(915) : error 001: expected token: ";", but found "]"
(915) : fatal error 107: too many error messages on one line
------------------------------------------------------------------------------
Line 915:   if(PlayerInfo[playerid][pFaction] == 1) & [PlayerInfo][playerid][pDivision] == 1)format(astring, sizeof(astring), "None");
I am not sure what I have to in order to get the right division for the faction. You might be confused. If you know a easier way to input the name of the division in /stats without using these stocks, go ahead and tell me. Either way, I need to know how to not get the division names mixed with other faction's division names.
Reply
#2

PHP код:
stock GetDivisionName(playerid)
{
     new 
astring[24];
    if(
PlayerInfo[playerid][pFaction] == && PlayerInfo[playerid][pDivision] == 1)format(astringsizeof(astring), "None");
    else if(
PlayerInfo[playerid][pFaction] == && PlayerInfo[playerid][pDivision] == 3format(astringsizeof(astring), "FTO");
    else if(
PlayerInfo[playerid][pFaction] == && PlayerInfo[playerid][pDivision] == 4format(astringsizeof(astring), "S.W.A.T.");
    else if(
PlayerInfo[playerid][pFaction] == && PlayerInfo[playerid][pDivision] == 5format(astringsizeof(astring), "D.E.B.");
    else if(
PlayerInfo[playerid][pFaction] == && PlayerInfo[playerid][pDivision] == 7format(astringsizeof(astring), "TE");
    return 
astring;

But I didn't get what values does pDivision stores? In case if for each faction you have several divisions this stock should be written like this:
PHP код:
stock GetDivisionName(playerid)
{
     new 
astring[24];
    if(
PlayerInfo[playerid][pFaction] == 1)
        {
             switch(
PlayerInfo[playerid][pDivision])
             {
                  case 
1format(astringsizeof(astring), "Division1");
                  case 
2format(astringsizeof(astring), "Division2");
                  default:  
format(astringsizeof(astring), "none");
             }
        }
        if(
PlayerInfo[playerid][pFaction] == 2)
        {
             switch(
PlayerInfo[playerid][pDivision])
             {
                  case 
1format(astringsizeof(astring), "Division1");
                  case 
2format(astringsizeof(astring), "Division2");
                  default:  
format(astringsizeof(astring), "none");
             }
        }
        
// And so on for each faction
        
return astring;

I hope you got the idea. And btw it's better not to return arrays from functions.
Reply
#3

I managed to fix it, thank you tho.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)