I am new to sscanf
#1

Well, Hello everyone. I just started using zcmd & sscanf instead of strcmp & strtok and I am having some problems. I will explain everything below. Here are two commands I took for example:

PHP Code:
CMD:makeadmin(playeridparams[])
{
    if(
PlayerInfo[playerid][AdminLevel] < && !IsPlayerAdmin(playerid)) return SendClientMessage(playeridCOLOR_WHITE"You are not authorized to use this command!");
    new 
giveplayeridamountstring[128], sendername[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
    if(
sscanf(params"ui"giveplayeridamount)) return SendClientMessage(playerid, -1"USAGE: /makeadmin [playerid] [rank[1 - 6]]");
    {
        if(
IsPlayerConnected(playerid))
        {
        
GetPlayerName(playerid,sendername,sizeof(sendername));
        
GetPlayerName(giveplayerid,name,sizeof(name));
        
format(stringsizeof(string), "AdmCmd: %s was made a level %d administrator by %s."nameamountsendername);
        
//ABroadCast(COLOR_LIGHTRED,string,1);
        
PlayerInfo[giveplayerid][AdminLevel] = amount;
           
format(stringsizeof(string), "MAKE-ADMIN: %s has made %s a level %i adminstrator.",playerid,giveplayeridPlayerInfo[giveplayerid][AdminLevel]);
        
//Log("logs/administration.log", string);
        
}
    }
    if(
amount 6) return SendClientMessage(playeridCOLOR_WHITE,"There are only 6 administrator levels!");
    if(
amount 0) return SendClientMessage(playeridCOLOR_WHITE"Invalid administrator level!");
    
//    if(!IsPlayerConnected(giveplayerid)) return SendClientMessage(playerid, -1, "Error: Player Not Connected");
    
if(giveplayerid == INVALID_PLAYER_ID)
    {
        
SendClientMessage(playeridCOLOR_RED" That player id/name doesnt exist or that player isnt online atm.");
    }
    
//if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_WHITE,"Invalid player ID.");
    
return 1;
}
CMD:givemoney(playeridparams[])
{
    new 
targetidammount;
    if(
sscanf(params,"ui"targetidammount)) return SendClientMessage(playerid0xFFFFFFF,"Syntax error.Correct usage: /givemoney [PlayerID] [Ammount]");
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid0xFFFFFFF,"Error: This command is only for RCON Admins");
    if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid0xFFFFFFF,"That player is not connected to your server!");
    else
    {
    
GivePlayerMoney(targetidammount); // So it will give the targetid the ammount you want.
    
}
    return 
1;

Those both command's second character "u" is working perfectly, example, when you type /givemoney, it shows its return. But when it comes to third character "i" It sends me "Unknown command" or Command return I made if(giveplayerid == INVALID_PLAYER_ID).

NOTE: I visited a lot of threads with people having this problem. Their solution was replacing INVALID_PLAYER_ID with IsPlayerConnected. Still says the same. I also upgraded sscanf's version to the newest one.
I was working on CMD:makeadmin for a few days and still got nothing, third character isnt working. I would like someone to help me fix the commands and explain me how to make third character "i" work.
I also attempted copying commands from other ZCMD Gamemodes I found, but I got the same error.
And the last thing I did was replacing places to functions "if".
Reply
#2

Sorry for my missunderstanding sentences. I ment only 2 parameters, second and third slot ( "u" and "i" ). Second aka first parameter is working fine, but when I type third one aka second parameter it shows me "Server Unknown command" or if I returned command with "if(giveplayerid == INVALID_PLAYER_ID)" or "if(IsPlayerConnected(playerid))". It just doesnt work. I even tried removing return option and it promoted me to Level 0 administrator whenever I type /makeadmin ( without using parameters ). I just dont know what I misstaken. I red a lot your threads about SSCANF on forums last a few days, but still I cant get it.
Reply
#3

After I replaced some parameters:

Quote:

if(sscanf(params, "ui", giveplayerid, amount))

to this:

Quote:

if(sscanf(params, "is", giveplayerid, amount)) return SendClientMessage(playerid, -1, "USAGE: /makeadmin [playerid] [rank[1 - 6]]");

It works fine exept the fact that my nativechecker found an warning about sscanf:

Quote:

sscanf warning: Strings without a length are deprecated, please add a destination size.

So, I came to the final fact that my "i" param isnt working. As I said above, Whenever I put "i" instead of "s"(or smthing else) it gives me warning like Player Isnt Connected and stuff. I need help how to solve this.
Reply
#4

Probably cause the player isn't connected. the "s" is a string, the "i" is an integer. Your amount variable is not a string, so why use "s"?
Reply
#5

I know that, I just wanted to check if it will work, and it actually did work. The point is "i" isnt working to set admins level to specific integer.
Reply
#6

You really need to learn proper indentation. Also keep in mind that the structure of the command is definitely something you should focus more on. From what I was able to see, you're giving the person the admin level and sending the message. Then at the very last part you check to see if the level was < 0 or > 6 and also if the ID was invalid. That's just illogical. Try this one:

pawn Code:
CMD:makeadmin(playerid, params[])
{
    if(PlayerInfo[playerid][AdminLevel] < 6 && !IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command!");
       
    new giveplayerid, amount, string[128], sendername[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
    if(!sscanf(params, "ui", giveplayerid, amount))
    {
        if(giveplayerid != INVALID_PLAYER_ID)
        {
            if(amount > 6)
                return SendClientMessage(playerid, COLOR_WHITE,"There are only 6 administrator levels!");
            if(amount < 0)
                return SendClientMessage(playerid, COLOR_WHITE, "Invalid administrator level!");
       
            PlayerInfo[giveplayerid][AdminLevel] = amount;
       
            GetPlayerName(playerid,sendername,sizeof(sendername));
            GetPlayerName(giveplayerid,name,sizeof(name));
            format(string, sizeof(string), "AdmCmd: %s was made a level %d administrator by %s.", name, amount, sendername);
            //ABroadCast(COLOR_LIGHTRED,string,1);
           
            format(string, sizeof(string), "MAKE-ADMIN: %s has made %s a level %i adminstrator.",playerid,giveplayerid, PlayerInfo[giveplayerid][AdminLevel]);
            //Log("logs/administration.log", string);
        }
    }
    else SendClientMessage(playerid, -1, "USAGE: /makeadmin [playerid] [rank[1 - 6]]");
    return 1;
}
Reply
#7

I said I am begginer with sscanf, just started using it, I was so desperate so I started changing "if" statement places... I was fixing this command for 3-4 days atleast 3 hours per day. Anyways thanks for reply. . Still the second parameter is not working.
Reply
#8

Show me how you're using the command.
Reply
#9

If you ment screenshots, here:



You can see I am logged in as a rcon admin and sscanf returns 1 parameter.



After I pressed full command with both parameters, it doesnt show anything (blank).
I also have nativechecker which shows me there is no warnings.
Reply
#10

It still isnt working, some help would be good.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)