WHY??? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: WHY??? (
/showthread.php?tid=478002)
WHY??? -
SlonCHL - 27.11.2013
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
Re: WHY??? -
Konstantinos - 27.11.2013
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' )
Re: WHY??? -
SlonCHL - 27.11.2013
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
Re: WHY??? -
Konstantinos - 27.11.2013
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.
Re: WHY??? -
SlonCHL - 27.11.2013
Oo, ok thanks I'll try
Re: WHY??? -
SlonCHL - 26.12.2013
-Delete-
It's very weird, sometimes it works sometimes it doesn't, trying to find out why it doesn't