sscanf User specifiers not working properly
#1

When using q, r or u as specifiers, no matter what I do they will not search properly for a name.

I have a command that allows admins to give money to players, using the specifier "i" for money and "r" for player name or ID. Using an ID works fine but putting in a name is where it falls apart.

If I join my server as "AdmiralSpeedy" and then on my other PC join as "AdmiralSpeedy2", running the command with or without <MATCH_NAME_PARTIAL=0> and providing the name "Admiral", always gives "AdmiralSpeedy" the money. That's fine, but now if I provide the name "AdmiralSpeedy2", is still gives "AdmiralSpeedy" the money even though the two don't match. Now, if I join as "Test" on the second PC and provide the command "Test", or even "T", it works fine.

This started happening to me a long time ago when I updated sscanf years ago. Because of this issue, I've had to resort to simply requesting just an ID as an integer, which works but it would be nice to be able to use a name or and ID.
Reply
#2

Accidentally replied instead of edited.
Reply
#3

What version of sscanf are you using? Can we see your exact code where you're having the issue?
Reply
#4

Try using "u"
Reply
#5

Quote:
Originally Posted by mirou123
View Post
Try using "u"
If you'd read his post yoi'd see he tried "u".
Reply
#6

And using "u" makes no difference anyways. It just tells sscanf what names to search. "u" means it'll search NPCs and players, which I don't want.

Code:
YCMD:agive(playerid, params[], help)
{
	if(PlayerData[playerid][LoggedIn] == 0 || PlayerData[playerid][Admin] == 0)
	{
		return 0;
	}
	else
	{
	    new id, money;
	    
	    if(sscanf(params, "ir", money, id) || money == 0)
	    {
			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /give [Amount] [Player ID]");
  		}
		else if(!IsPlayerConnected(id) || PlayerData[id][LoggedIn] == 0 || id == INVALID_PLAYER_ID)
		{
			SendClientMessage(playerid, COLOR_WHITE, "ERROR: Player not found.");
		}
	    else
		{
		    new Message[52];
			
   			GivePlayerMoney(id, money);
   			
			if(money > 0)
			{
				if(id == playerid)
				{
					format(Message, sizeof(Message), "You have given yourself $%i.", money);
					SendClientMessage(playerid, COLOR_YELLOW, Message);
				}
				else
				{
			        format(Message, sizeof(Message), "You have given %s $%i.", PlayerData[id][Username], money);
					SendClientMessage(playerid, COLOR_YELLOW, Message);
					format(Message, sizeof(Message), "%s has given you $%i.", PlayerData[playerid][Username], money);
			        SendClientMessage(id, COLOR_YELLOW, Message);
				}
			}
			else
			{
   				if(id == playerid)
				{
					format(Message, sizeof(Message), "You have taken $%i from yourself.", money);
					SendClientMessage(playerid, COLOR_YELLOW, Message);
				}
				else
				{
			        format(Message, sizeof(Message), "You have taken $%i from %s.", money, PlayerData[id][Username]);
					SendClientMessage(playerid, COLOR_YELLOW, Message);
					format(Message, sizeof(Message), "%s has taken $%i from you.", PlayerData[playerid][Username], money);
			        SendClientMessage(id, COLOR_YELLOW, Message);
				}
			}
		}

	    return 1;
	}
}
That's the code but it likely isn't going to help. I'm using sscanf 2.8.1 and I remember a long time ago it worked but when I updated, it stopped working. Now I can't find any older versions and I don't know what version worked because it could have stopped working from a different update and not necessarily 2.8.1
Reply
#7

bump
Reply
#8

bump
Reply
#9

pawn Code:
YCMD:agive(playerid, params[], help)
{
    new lookupid;
    sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", lookupid);
    if(lookupid == -1)
    {
        // No player was entered.
    }
    else if(lookupid == cellmin)
    {
        // Multiple matches found.
    }
    else if(lookupid == INVALID_PLAYER_ID)
    {
        // Entered player is not connected.
    }
    else
    {
        // Found just one player.
    }
    return 1;
}
Reply
#10

Quote:
Originally Posted by SickAttack
View Post
pawn Code:
YCMD:agive(playerid, params[], help)
{
    new lookupid;
    sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", lookupid);
    if(lookupid == -1)
    {
        // No player was entered.
    }
    else if(lookupid == cellmin)
    {
        // Multiple matches found.
    }
    else if(lookupid == INVALID_PLAYER_ID)
    {
        // Entered player is not connected.
    }
    else
    {
        // Found just one player.
    }
    return 1;
}
That still doesn't solve the fact that it doesn't properly search names. If my name is "Test" and I try to give money to "Test2", it shouldn't give "Test" the money, but it does because it searching to see if "Test" is in "Test2" rather than if "Test2" is in "Test" like it should be. It's backwards.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)