WHY???
#1

Why the heck can't I get the first character of a player name when they connect?

pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid,name,sizeof(name));
    printf("Name0: %s", name[0]);
    printf("Name1: %s", name[1]);
    if(name[0] == 0 || name[0] == 1 || name[0] == 2 || name[0] == 3 || name[0] == 4 || name[0] == 5 || name[0] == 6 || name[0] == 7 || name[0] == 8 || name[1] == 9)
    {
        SendClientMessage(playerid, 0xFF5E81FF, "The first character of your name cannot be a number");
        SetTimerEx("InitiateKick", 500, false, "i", playerid);
    }
return 1;
}
Код:
[23:41:25] [join] 1SlonCHL has joined the server (0:192.168.1.2)
[23:41:25] Name0: 1SlonCHL 
[23:41:25] Name1: SlonCHL
name[0] = 1SlonCHL, name[1] = SlonCHL, WTF
Reply
#2

0 is not same as '0' character, the same goes for every other number.

Replace:
pawn Код:
if(name[0] == 0 || name[0] == 1 || name[0] == 2 || name[0] == 3 || name[0] == 4 || name[0] == 5 || name[0] == 6 || name[0] == 7 || name[0] == 8 || name[1] == 9)
with:
pawn Код:
if( name[ 0 ] >= '0' && name[ 0 ] <= '9' )
Reply
#3

But I'm getting name[0] as my full name, not only the first character. BTW thanks for the >= <= code, I was so dumb to define all 10 number lol
Reply
#4

Well, if you use an index for the array then it will return a number. You're not supposed to use %s but %c in order to see the correct character of the number which is 1 in the example above and 49 as a value.
Reply
#5

Oo, ok thanks I'll try
Reply
#6

-Delete-

It's very weird, sometimes it works sometimes it doesn't, trying to find out why it doesn't
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)