Help with Counting Strings
#1

I have never tried to do this before:

pawn Код:
PlayerInfo[playerid][soldier]
PlayerInfo[playerid][sniper]
PlayerInfo[playerid][assault]
These are 3 player classes, by default, the player has the first one, that does mean total classes = 1, so we will get this:

pawn Код:
PlayerInfo[playerid][soldier] = "Soldier"
PlayerInfo[playerid][sniper] = ""
PlayerInfo[playerid][assault] = ""
When the player makes progress in-game, he can unlock more classes.
For example, he will unlock sniper class, which does mean that total classes are equal to 2, so we will get this:

pawn Код:
PlayerInfo[playerid][soldier] = "Soldier"
PlayerInfo[playerid][sniper] = "Sniper"
PlayerInfo[playerid][assault] = ""
ok, now im gonna send the total classes number in a client message to the player.
My problem is how to count them?

SOLUTION:
[QUOTE=Konstantinos;2966974]I wouldn't use:
pawn Код:
PlayerInfo[playerid][sniper] = "";
but:
pawn Код:
PlayerInfo[playerid][sniper][0] = EOS;
// OR
PlayerInfo[playerid][sniper][0] = '\0';
When you want to make the string empty, use the above instead of "".
Now it's null so:
pawn Код:
new
    count; // it doesn't need to be an array as you said in your above post.

if (!isnull(PlayerInfo[playerid][soldier])) ++count;
if (!isnull(PlayerInfo[playerid][sniper])) ++count;
if (!isnull(PlayerInfo[playerid][assault])) ++count;

// format(...);
// Using "count" as argument will give the total classes.
and
pawn Код:
#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
Reply


Messages In This Thread
Help with Counting Strings - by Battlezone - 25.03.2014, 15:23
Re: Help with Counting Strings - by BroZeus - 25.03.2014, 15:31
Re: Help with Counting Strings - by Battlezone - 25.03.2014, 15:33
Re: Help with Counting Strings - by Konstantinos - 25.03.2014, 15:34
Re: Help with Counting Strings - by Battlezone - 25.03.2014, 15:36
Re: Help with Counting Strings - by BroZeus - 25.03.2014, 15:39
Re: Help with Counting Strings - by Battlezone - 25.03.2014, 15:41
Re: Help with Counting Strings - by newbienoob - 25.03.2014, 15:44
Re: Help with Counting Strings - by Konstantinos - 25.03.2014, 15:44
Re: Help with Counting Strings - by BroZeus - 25.03.2014, 15:45

Forum Jump:


Users browsing this thread: 1 Guest(s)