SA-MP Forums Archive
GetPlayerIdFromName problem - 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: GetPlayerIdFromName problem (/showthread.php?tid=498700)



GetPlayerIdFromName problem - ancezas - 04.03.2014

i have problem with this script GetPlayerIdFromName,
pawn Код:
stock GetPlayerIdFromName( playername[ ] )
    {
        for( new i = 0; i <= MAX_PLAYERS; i++ )
        {
            if( IsPlayerConnected( i ) )
            {
                new
                    playername2[ MAX_PLAYER_NAME ];
                GetPlayerName( i, playername2, sizeof( playername2 ) );
                if( strcmp( playername2, playername, true, strlen( playername ) ) == 0 )
                {
                    return i;
                }
            }
        }
        return INVALID_PLAYER_ID;
    }
i need to get playerid from this script but it gives me nonsense numbers
pawn Код:
new id = GetPlayerIdFromName( Vardukas );
the veriable Vardukas is like this:
pawn Код:
new
                msg[ 21 ],
                pos = strfind( inputtext, "-" );
            strmid( msg, inputtext, 0, pos, 21 );
            new name[ MAX_PLAYER_NAME ];
            format( name, 24, "%s", msg );
            Vardukas = name;
the "name" is good, i use it to other script witch is connected with this


Re: GetPlayerIdFromName problem - Konstantinos - 04.03.2014

If you want to just copy the name to Vardukas why do you do all the above. By the way doing "Vardukas = name;" is wrong; hence you get "nonsense" numbers.

You can just do:
pawn Код:
new szName[21], pos = strfind(inputtext, "-");
if (pos != -1)
{
    strmid(szName, inputtext, 0, pos, 21);
    new id = GetPlayerIdFromName(szName);
    if (id != INVALID_PLAYER_ID)
    {
        // ...
    }
}



Re: GetPlayerIdFromName problem - ancezas - 04.03.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
If you want to just copy the name to Vardukas why do you do all the above. By the way doing "Vardukas = name;" is wrong; hence you get "nonsense" numbers.

You can just do:
pawn Код:
new szName[21], pos = strfind(inputtext, "-");
if (pos != -1)
{
    strmid(szName, inputtext, 0, pos, 21);
    new id = GetPlayerIdFromName(szName);
    if (id != INVALID_PLAYER_ID)
    {
        // ...
    }
}
i understand this but i need to bring that veriable to another script, it is not dialog at all, its TextDrawSelect