[Tutorial] Advanced '/spec' Command [Updated 11/21/2011 | Virtual World & Interior Support | Beginner Friendly]
#10

Quote:
Originally Posted by Jochemd
View Post
Nice tutorial, however I wouldn't use sscanf for such a thing.

pawn Code:
CMD:spec(playerid, params[])
{
    new id = strlen( params );
    if( isnull( params )) return SendClientMessage( playerid, -1, "Syntax Error: /spec [ID].");
    if(! IsPlayerConnected( id )) return SendClientMessage( playerid, -1, "Syntax Error: /spec [ID].");
    // Gah
}
sscanf would be the best choice. 'u' specifier is names/ids. The other way of doing the same thing is;

pawn Code:
if(isnumeric(params))
{
    id = strval(params);
}
else
{
    new
        szName[MAX_PLAYER_NAME];
    id = INVALID_PLAYER_ID;
   
    for(new i=0; i < MAX_PLAYERS; ++i)
    {
        if(!IsPlayerConnected(i))continue;
        GetPlayerName(i, szName, MAX_PLAYER_NAME);
        if(!strcmp(szName, params))
        {
            id = i;
            break;
        }
    }
}
I prefer one sscanf line to that.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)