sscanf problem.
#1

Hello.
I'm probably stupid but I've a simple question about sscanf. Let's take the specifer "u". sscanf should return the first player with the name/part of name or return INVALID_PLAYER_ID if nobody is connected/+2 players with the same name. I'm right?
If yes, it doesn't work. It take only the first person with the name and doesn't consider others people.

For testing purposes, I connected two accounts : Player_First (ID 6) & Player_Two (ID 5).
My code:
PHP код:
CMD:test_id(playeridparams[])
{
    new 
targetid[4]; // An array for 'debugging' purpose
    
sscanf(params"u[4]"targetid);
    for(new 
isizeof(targetid); i++)
        
printf("Player's ID %i - Name: %s"targetid[i], GetName(targetid[i]));
    return 
1;

Output:
Код:
[03:01:52] Player's ID 5 - Name: Player_Second
[03:01:52] Player's ID 65535 - Name: 
[03:01:52] Player's ID 0 - Name: Bot_1
[03:01:52] Player's ID 0 - Name: Bot_1
Reply
#2

If there's 2 people with the same bit that's being searched for it returns the one closest to ID 0
Reply
#3

Quote:
Originally Posted by JaydenJason
Посмотреть сообщение
If there's 2 people with the same bit that's being searched for it returns the one closest to ID 0
It not should return INVALID_PLAYER_ID?
Reply
#4

I'm not quite sure I understand what you're trying to do, but why not use strcmp?

PHP код:
CMD:test_id(playeridparams[]) 

    new 
targetid[4];
    if(
sscanf(params,"s[4]"targetid)) return 1// exit
    
for(new i<= MAX_PLAYERSi++) {
        if(!
strcmp(targetidGetName(i), false4)) printf("Player's ID %i - Name: %s"iGetName(i)); }
    return 
1;

Reply
#5

Quote:
Originally Posted by adammal
Посмотреть сообщение
I'm not quite sure I understand what you're trying to do, but why not use strcmp?

PHP код:
CMD:test_id(playeridparams[]) 

    new 
targetid[4];
    if(
sscanf(params,"s[4]"targetid)) return 1// exit
    
for(new i<= MAX_PLAYERSi++) {
        if(!
strcmp(targetidGetName(i), false4)) printf("Player's ID %i - Name: %s"iGetName(i)); }
    return 
1;

Because sscanf is better.
Reply
#6

From sscanf thread:
Quote:

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".

Reply
#7

Quote:

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

Alright! My problem still. Only the first player is detected (as we can see). I missunderstood something I think.
Let's take this basic command with freeze a player. If two players have the same first name, only the lower ID will get 'detected'.
PHP код:
CMD:test_freeze(playeridparams[])
{
    
extract params -> new player:targetid; else return Usage(playerid"/freeze [name/id]");
    
CheckIsValidPlayer(targetid); // isplayerconnected + isplayernpc
    
TogglePlayerControllableEx(targetid0);
    return 
1;

By the way, the code in my first post was for debugging only. I wanted to know if sscanf detect every player with the same first name (on a rp server), and most of it doesn't.
Reply
#8

upupupupupup
Reply
#9

PHP код:
CMD:test_id2(playeridparams[])
{
    new 
targetid;
    
sscanf(params"u"targetid);
    
SCMF(playerid, -1"Player's ID %i - Name: %s"targetidGetName(targetid));
    return 
1;

Return the lowest player's id with the good partial name.
Reply
#10

Definitely a weird problem
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)