Identifying a player in a command
#9

Quote:
Originally Posted by Zeth
Посмотреть сообщение
Using sscanf (u param) it will most likely to get the result which is in lower IDs, lets say you are searching 'Ada` and there are two players with name starting from Ada (likely Adax(1) and Aday(11), then it will return the name with lower id or the name which comes first in the loop search, i.e. Adax(1)
Quote:
Originally Posted by Zeth
Посмотреть сообщение
No it will not, It would have if the player name would have been JohnTest. sscanf dosent search in between name, it starts from the beginning of the name.
No, if you use the array plus the MATCH_NAME_PARTIAL flag

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Users can now optionally return an ARRAY of users instead of just one. This array is just a list of matched IDs, followed by "INVALID_PLAYER_ID". Given the following players:

Код:
0) ******
1) [CLAN]******
2) Jake
3) Alex
4) Hass
This code:

pawn Код:
new ids[3], i;
if (sscanf("Le", "?<MATCH_NAME_PARTIAL=1>u[3]", ids)) printf("Error in input");
for (i = 0; ids[i] != INVALID_PLAYER_ID; ++i)
{
    if (ids[i] == cellmin)
    {
        printf("Too many matches");
        break;
    }
    printf("id = %d", ids[i]);
}
if (i == 0) printf("No matching players found.");
Will output:

Код:
id = 0
id = 1
Too many matches
Searching "Les" instead will give:

Код:
id = 0
id = 1
And searching without "MATCH_NAME_PARTIAL" will give:

Код:
No matching players found.
Basically, if an array of size "N" is passed, this code will return the first N-1 results. If there are less than "N" players whose name matches the given name then that many players will be returned and the next slot will be "INVALID_PLAYER_ID" to indicate the end of the list. On the other hand if there are MORE than "N - 1" players whose name matches the given pattern, then the last slot will be "cellmin" to indicate this fact.

When combined with "U" and returning the default, the first slot is always exactly the default value (even if that's not a valid connected player) and the next slot is always "INVALID_PLAYER_ID".

Note also that user arrays can't be combined with normal arrays or enums, but normal single-return user specifiers still can be.

  • MATCH_NAME_PARTIAL:
Currently sscanf will search for players by name, and will ALWAYS search for player whose name STARTS with the specified string. If you have, say "[CLAN]******" connected and someone types "******", sscanf will not find "[CLAN]******" because there name doesn't start with the specified name. This option, when set to 1, will search ANYWHERE in the player's name for the given string.
  • CELLMIN_ON_MATCHES:
Whatever the value of "MATCH_NAME_PARTIAL", the first found player will always be returned, so if you do a search for "_" on an RP server, you could get almost anyone. To detect this case, if more than one player will match the specified string then sscanf will return an ID of "cellmin" instead. This can be combined with "U" for a lot more power:

pawn Код:
sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", id);
    if (id == -1)
    {
        // No player was entered.
    }
    else if (id == cellmin)
    {
        // Multiple matches found
    }
    else if (id == INVALID_PLAYER_ID)
    {
        // Entered player is not connected.
    }
    else
    {
        // Found just one player.
    }
And for multiple match, since this is a /wave command, it would be best to pick the nearest player to the target, regardless their order or id.


EDIT: the smh reply made me to answer this 8 months old thread, didn't notice
Reply


Messages In This Thread
Identifying a player in a command - by Ducati - 28.04.2018, 00:57
Re: Identifying a player in a command - by Pottus - 28.04.2018, 01:03
Re: Identifying a player in a command - by Kane - 28.04.2018, 02:21
Re: Identifying a player in a command - by ISmokezU - 28.04.2018, 02:29
Re: Identifying a player in a command - by Zeth - 28.04.2018, 02:47
Re: Identifying a player in a command - by Ducati - 28.04.2018, 02:50
Re: Identifying a player in a command - by Zeth - 28.04.2018, 02:53
Re: Identifying a player in a command - by BigETI - 13.12.2018, 07:22
Re: Identifying a player in a command - by RoboN1X - 13.12.2018, 14:06

Forum Jump:


Users browsing this thread: 2 Guest(s)