find player by name? +rep! -
PawnoQ - 29.01.2012
hi,
how can i loop throught all players online and check if there is a player online with a certain name?
Hope you can help me
Re: find player by name? +rep! -
[HiC]TheKiller - 29.01.2012
Using for
pawn Код:
stock FindPlayerByName(name[])
{
new Pname[24];
for(new i; i<MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
GetPlayerName(i, Pname, 24);
if(!strcmp(Pname, name, true)) return i;
}
return -1;
}
Foreach is similar, just replace the for loop.
Respuesta: find player by name? +rep! -
admantis - 29.01.2012
You can use the function I've made
pawn Код:
stock FindPlayerByName( name[] )
{
for( new i = 0; i < MAX_PLAYERS; i += 1 )
{
if ( IsPlayerConnected( i ) )
{
new name2[24];
GetPlayerName( i, name2, 24 );
if ( strcmp ( name2, name, false ) == 0 )
{
return i;
break;
}
}
}
return INVALID_PLAYER_ID;
}
Re: find player by name? +rep! -
PawnoQ - 29.01.2012
thx a lot
And how can i check it with this function then?
With an if statement somehow?
Re: find player by name? +rep! -
jamesbond007 - 29.01.2012
pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
printf("player name %s was found by id: %d",name,FindPlayerByName(name));
Re: find player by name? +rep! -
[HiC]TheKiller - 29.01.2012
pawn Код:
if(FindPlayerByName("PawnoQ") != -1) return 1;
Return 1 if there is someone with the name PawnoQ online.
Re: find player by name? +rep! -
PawnoQ - 29.01.2012
thx a lot + rep
Re: find player by name? +rep! -
PawnoQ - 29.01.2012
sorry for the double post but how could i find out the playerid of a player with a certain name?
Re: find player by name? +rep! -
Babul - 29.01.2012
oh, i should have answered here instead of the other topic, its a link to the sscanf plugin.
Re: find player by name? +rep! -
PawnoQ - 30.01.2012
would this code work to check if a player with a certain id and name is online?
pawn Код:
foreach(Player,i)
{
if(FindPlayerByName(DOMPlayer)!= -1)//if player is online
{
new DOMname[24];
GetPlayerName(i,DOMname,24);
if(strfind(DOMname,"PawnoQ", true) == 0)//if player is the player with the right name
{
SetPlayerScore(i,GetPlayerScore(i)+20);//give only him score
}
}
else
{
//if player is not online
}
}
stock FindPlayerByName(name[])
{
new Pname[24];
foreach(Player,i)
{
GetPlayerName(i, Pname, 24);
if(!strcmp(Pname, name, true)) return i;
}
return -1;
}