Problem about nickname - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem about nickname (
/showthread.php?tid=72100)
Problem about nickname -
Diablo1st - 06.04.2009
hello

today i was reading a code to take only the name in the nick (only nick with this format Name_Surname) and it work really grat with this code:
pawn Код:
new playername2[MAX_PLAYER_NAME];
new playernamesplit[3][MAX_PLAYER_NAME];
GetPlayerName(playerid, playername2, sizeof(playername2));
split(playername2, playernamesplit, '_');
so if the nick is
Adam_Smith it will take only "Adam" part of the nick, i would know if is possibile take the other part (Smith part), so the part is after the "_"
thanks
Re: Problem about nickname -
Nubotron - 06.04.2009
Use function like this
pawn Код:
chrfind(string[], chr, start = 0)
{
while (string[start])
if (string[start++] == chr)
return start - 1;
return -1;
}
to get position of "_", and use this position + 1 as string index
pawn Код:
new idx = chrfind(playername2, '_') + 1;
printf("%s", playername2[idx]);
Re: Problem about nickname -
Diablo1st - 06.04.2009
Quote:
Originally Posted by Nubotron
Use function like this
pawn Код:
chrfind(string[], chr, start = 0) { while (string[start]) if (string[start++] == chr) return start - 1;
return -1; }
to get position of "_", and use this position + 1 as string index
pawn Код:
new idx = chrfind(playername2, '_') + 1; printf("%s", playername2[idx]);
|
can't understand very well this part "new idx = chrfind(playername2, '_') + 1"
what +1 stands for?
edit: i got it now

, i'm a lil slow