SSCANF
#1

How do I find the names of the players without characters [ and ]?

The player has when entering names: Spenker
After login: [LOK]Spenker
[LOK] = Clan Tag.

/id Spenker => restul: "The player not connected.".
Код HTML:
CMD:id(playerid, params[])
{
    new playerto, test[54];
    if(sscanf(params, "u", playerto)) return SendSyntaxMessage(playerid, "/id [playerid or playername]");
    if(!IsPlayerConnected(playerto)) return SendClientMessage(playerid, COLOR_WHITE1,"The player not connected.");
    format(test, sizeof(test), "Player: %s", GetPName(playerto)), SendClientMessage(playerid, -1, test);
    return 1;
}
Reply
#2

You can use the function strcat to add the clan tag until check if the player is online.

Example:
PHP код:
new clantag[40] = "[LOK]";
strcat(clantagGetPName(playerto)); 
I make a function to seach by string playername:

PHP код:
forward PlayerIsConnectedS(string[]);
public 
PlayerIsConnectedS(string[])
{
    new 
nombre[MAX_PLAYER_NAME];
    for(new 
i=0;i<GetPlayerPoolSize();i++)
    {
        if(
IsPlayerConnected(i) && !IsPlayerNPC(i))
        {
            
GetPlayerName(inombresizeof(nombre));
            if(!
strcmp(nombrestring))
                return 
true;
        }
    }
    return 
false;

Then you can use

PHP код:
if(!PlayerIsConnectedS(clantag)) return SendClientMessage(playeridCOLOR_WHITE1,"The player not connected."); 
Note: Function IsPlayerConnected only accept playerid in params not string.
Reply
#3

I didn't test it out, but it should work:
Код:
SSCANF:playername(string[])
{
    if (isnull(string))
        return INVALID_PLAYER_ID;

    new tmp;
    if (!sscanf(params, "i", tmp))
    {
        if (!IsPlayerConnected(tmp))
            return INVALID_PLAYER_ID;
        return tmp;
    }

    new player_name[25];
    for (new i, j = GetPlayerPoolSize(); i <= j; i++)
    {
        if (IsPlayerConnected(i))
            continue;
        GetPlayerName(i, player_name, 25);
        if (player_name[0] == '[' && (tmp = strfind(player_name, "]", false)) != -1)
        {
            if (!strcmp(player_name[tmp+1], string, true, strlen(string))
            {
                return i;
            }
        }
    }
    return INVALID_PLAYER_ID;
}
But it will bug if there is another ']' inside of the clan tag.
You could improve it if you want.

Use "k<playername>" instead of "u".
Reply
#4

Wouldn't be easier Stigned's way but without a custom specifier?

pawn Код:
new id, tmp;
if (params[0] == '[' && (tmp = strfind(params, "]")) != -1)
{
    if (sscanf(params[tmp + 1], "u", id)) return SendClientMessage(playerid, -1, "usage..");
}
else
{
    if (sscanf(params, "u", id)) return SendClientMessage(playerid, -1, "usage..");
}

if (id == INVALID_PLAYER_ID) return ... // error..

// code..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)