SA-MP Forums Archive
Strange Error - Possibly SSCANF/ZCMD related - 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: Strange Error - Possibly SSCANF/ZCMD related (/showthread.php?tid=309332)



Strange Error - Possibly SSCANF/ZCMD related - Rob_Maate - 07.01.2012

So I wrote the following command, to me it looks correct... I can't work out why it's bugging up.
It's causing the server to partially crash (aka all commands stop working) and even though PlayerInfo[receiverid][pAdmin] DOES end up being whatever it was set to, it displays a random number, almost like a strval().

Any suggestions?

pawn Код:
CMD:makeadmin(playerid, params[])
{
    new level;
    if(PlayerInfo[playerid][pAdmin] >= 1337)
    {
        if(sscanf(params, "ud", receiverid, level) == 0)
        {
            if(IsPlayerConnected(receiverid))
            {
                PlayerInfo[receiverid][pAdmin] = level;
                GetPlayerName(receiverid, ReceiverName);
                format(str, sizeof(str), "You have set %s's Admin Level to %d", ReceiverName, PlayerInfo[receiverid][pAdmin]);
                SendClientMessage(playerid, COLOR_YELLOW, str);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, " That player is not connected.");
                return 1;
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /makeadmin [PlayerID/PartOfName] [Level (1 - 9999)]");
            return 1;
        }
    }
    return 1;
}



Re: Strange Error - Possibly SSCANF/ZCMD related - fiki574 - 07.01.2012

Try using "i" instead of "d"!


Re: Strange Error - Possibly SSCANF/ZCMD related - Rob_Maate - 07.01.2012

Tried that... Obviously


Re: Strange Error - Possibly SSCANF/ZCMD related - TheLonelyMoo - 07.01.2012

are you using strcmp with zcmd and the same time if yes don't do it at least if you do the tutorial in script tutorials


Re: Strange Error - Possibly SSCANF/ZCMD related - Rob_Maate - 07.01.2012

Mate... I'm a competent scripter. I haven't ever read a PAWN tutorial lmao.
I know ZCMD and SSCANF like the back of my hand.

I wouldn't have posted the command if the issue was related to my technique


Re: Strange Error - Possibly SSCANF/ZCMD related - fiki574 - 07.01.2012

pawn Код:
COMMAND:makeadmin(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 1337)
    {
       new level;
       new Target;
        if(!sscanf(params, "ui", Target, level))
        {
            if(IsPlayerConnected(Target))
            {
                PlayerInfo[Target][pAdmin] = level;
                GetPlayerName(Target, ReceiverName);
                format(str, sizeof(str), "You have set %s's Admin Level to %d", ReceiverName, PlayerInfo[Target][pAdmin]);
                SendClientMessage(playerid, COLOR_YELLOW, str);
                return 1;
            }
            else SendClientMessage(playerid, COLOR_GREY, " That player is not connected.");
        }
        else SendClientMessage(playerid, COLOR_GREY, "USAGE: /makeadmin [PlayerID/PartOfName] [Level (1 - 9999)]");
    }
    return 1;
}
Try it!


Re: Strange Error - Possibly SSCANF/ZCMD related - FireCat - 07.01.2012

pawn Код:
CMD:makeadmin(playerid, params[])
{
    new level;
    if(PlayerInfo[playerid][pAdmin] >= 1337)
    {
        if(sscanf(params, "ud", receiverid, level)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /makeadmin [PlayerID/PartOfName] [Level (1 - 9999)]");
        if(IsPlayerConnected(receiverid))
        {
            PlayerInfo[receiverid][pAdmin] = level;
            GetPlayerName(receiverid, ReceiverName);
            format(str, sizeof(str), "You have set %s's Admin Level to %d", ReceiverName, PlayerInfo[receiverid][pAdmin]);
            SendClientMessage(playerid, COLOR_YELLOW, str);
            return 1;
    }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, " That player is not connected.");
            return 1;
        }
    }
    return 1;
}



Re: Strange Error - Possibly SSCANF/ZCMD related - Rob_Maate - 07.01.2012

Quote:
Originally Posted by SA-MP SSCANF Wiki Page
c - A character.
d, i - An integer.
h, x - A hex number (e.g. a colour).
f - A float.
s - A string.
z - An optional string.
pX - An additional delimiter where X is another character.
'' - Encloses a litteral string to locate.
u - User, takes a name, part of a name or an id and returns the id if they're connected.
Honestly mate, go learn how to script.

Also, changing CMD: to COMMAND: does shit all.

Within the ZCMD include:

pawn Код:
#define COMMAND:%1(%2)          \
                        forward cmd_%1(%2); \
                        public cmd_%1(%2)              
                       
#define CMD:%1(%2) \
                        COMMAND:%1(%2)
 
#define command(%1,%2,%3) \
                        COMMAND:%1(%2, %3)    
     
#define cmd(%1,%2,%3) \
                        COMMAND:%1(%2, %3)



Re: Strange Error - Possibly SSCANF/ZCMD related - Rob_Maate - 07.01.2012

Quote:
Originally Posted by FireCat
Посмотреть сообщение
pawn Код:
CMD:makeadmin(playerid, params[])
{
    new level;
    if(PlayerInfo[playerid][pAdmin] >= 1337)
    {
        if(sscanf(params, "ud", receiverid, level)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /makeadmin [PlayerID/PartOfName] [Level (1 - 9999)]");
        if(IsPlayerConnected(receiverid))
        {
            PlayerInfo[receiverid][pAdmin] = level;
            GetPlayerName(receiverid, ReceiverName);
            format(str, sizeof(str), "You have set %s's Admin Level to %d", ReceiverName, PlayerInfo[receiverid][pAdmin]);
            SendClientMessage(playerid, COLOR_YELLOW, str);
            return 1;
    }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, " That player is not connected.");
            return 1;
        }
    }
    return 1;
}
This works perfectly... What's changed? Sorry for seeming blind but I can't really see much of a difference other than re-ordering