Strange Error - Possibly SSCANF/ZCMD related
#1

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;
}
Reply
#2

Try using "i" instead of "d"!
Reply
#3

Tried that... Obviously
Reply
#4

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
Reply
#5

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
Reply
#6

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!
Reply
#7

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;
}
Reply
#8

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)
Reply
#9

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)