SA-MP Forums Archive
SSCANF player not online bug! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SSCANF player not online bug! (/showthread.php?tid=600481)



SSCANF player not online bug! - Dusan01 - 08.02.2016

Hi guys, im using sscanf 0.3d-R2 and i have 1 command, and for some reasons, for some players this command wont work,
Код:
new id;
new string[126];
if(sscanf(params, "u", id)) return SCM(playerid, -1, ""SCMD"/check [ID/Name]");
if(!IsPlayerConnected(id)) return SCM(playerid,GRAD2,"Not Online.");
it says Not Online. and player is there, he is on server...

Is that because im using older version of sscanf, or?


Re: SSCANF player not online bug! - GangstaSunny - 08.02.2016

PHP код:
new id;
new 
string[126];
if(
sscanf(params"u"id)) return SCM(playerid, -1""SCMD"/check [ID/Name]");
if(!
IsPlayerConnected(id))
{
    
format(string,sizeof(string),"Params: 'id' is '%d'",id);
    
SendCllientMessage(playerid,-1,string);

Just for debug. I recommend to use debug-method before asking here.


Re: SSCANF player not online bug! - ikey07 - 08.02.2016

Maybe you have an old sscanf which only works on playerids, not part of names as parameter.


Re: SSCANF player not online bug! - Dusan01 - 08.02.2016

Ahh, okay, i will try to update sscanf and try to debug, TNX!


Re: SSCANF player not online bug! - Dusan01 - 09.02.2016

UPDATE:

i tryed it with this:
Код:
format(string,sizeof(string),"Params: 'id' is '%d'",id);
and i get: Params: 'id' is '65535' and player is on server, but for id i get 65535 itk why...


my sscanf version is: 2.8.1


Re: SSCANF player not online bug! - ikey07 - 09.02.2016

Did you tried both, with playerid and with name ?
Just for curiousity try to print(params);

Also there is some "r" parameter ( https://sampforum.blast.hk/showthread.php?tid=570927 )

As I have never used sscanf, for me its hard to tell what exactlly is wrong.


Re: SSCANF player not online bug! - Dusan01 - 09.02.2016

Yeah, i tryed with player name and with id, now i found this:
Quote:
Originally Posted by Pottus
Посмотреть сообщение
Yeah there is sometimes a problem using the "u" specifier it's rare but can happen it was actually happening on the DayZ server. The beauty of sscanf() is you can define your own specifiers so I wrote an custom "u" specifier to address this issue.

Yes you will need YSI or you can use an alternative hooking method

You will need to update the sscanf()'s in your script where you use the "u" specifier with this.

pawn Код:
sscanf(params, "k<u>", pid);
pawn Код:
#include <YSI\y_hooks>

static PlayerNames[MAX_PLAYERS][MAX_PLAYER_NAME];

// Store players name
hook OnPlayerConnect(playerid)
{
    if(IsPlayerNPC(playerid)) return 1;
    GetPlayerName(playerid, PlayerNames[playerid], MAX_PLAYER_NAME);
    return 1;
}

// Search for players name
SSCANF:u(name[])
{
    // No name specified
    if(isnull(name)) return INVALID_PLAYER_ID;

    new id;

    // Was a part of name provided?
    if(sscanf(name, "i", id))
    {
        new matches;
       
        // Find a player return the id
        foreach(new i : Player)
        {
            // Search for part of the players name
            if(strfind(PlayerNames[i], name, true) != -1)
            {
                matches++;
                id = i;
                if(matches > 1) return INVALID_PLAYER_ID;
            }
        }
        // Found a match
        if(matches) return id;

        // No player found return invalid player id
        return INVALID_PLAYER_ID;
    }

    // Player supplied a id

    // Make sure the id is greater than 0
    if(id < 0) return INVALID_PLAYER_ID;

    // Make sure the id is connected
    if(!IsPlayerConnected(id)) return INVALID_PLAYER_ID;

    // Return the id
    return id;
}
i will try this, and if it does not work, i will try to put R, THANKS!