GetPlayerIdFromName problem
#1

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
Reply
#2

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)
    {
        // ...
    }
}
Reply
#3

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)