SA-MP Forums Archive
[Help]Dcmd & sscanf errors - 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: [Help]Dcmd & sscanf errors (/showthread.php?tid=305436)



[Help]Dcmd & sscanf errors - Jagofr - 22.12.2011

Can Someone fix this please?
I get these errors

pawn Код:
TestLogin.pwn(155) : warning 211: possibly unintended assignment
TestLogin.pwn(155) : error 022: must be lvalue (non-constant)
TestLogin.pwn(155) : error 029: invalid expression, assumed zero
TestLogin.pwn(155) : warning 215: expression has no effect
TestLogin.pwn(155) : error 029: invalid expression, assumed zero
TestLogin.pwn(155) : fatal error 107: too many error messages on one line
pawn Код:
dcmd_makeadmin(playerid, params[])
{
    if (strlen(params))
    {
        if(pAdmin =< 2)
        {
            new
                pID,
                level;
            if (!sscanf(params, "ii", pID, level)
            {
                if (pID != INVALID_PLAYER_ID)
                {
                    new msg;
                    INI_WriteInt(File,"Admin",level);
                    SendClientMessage(playerid, COLOR_WHITE, "You have been promoted");
                }
                else SendClientMessage(playerid, COLOR_WHITE, "Player not connected");
            }
            else SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /makeadmin <playerid> <level>");
        }
        else SendClientMessage(playerid, COLOR_WHITE, "You need to be at least level 2 for this command")
    }
    return 1;
}



Re: [Help]Dcmd & sscanf errors - Ash. - 22.12.2011

You're missing a bracket on the 'sscanf' if line. Put a bracket at the end.


Re: [Help]Dcmd & sscanf errors - SomebodyAndMe - 22.12.2011

Try this.

pawn Код:
dcmd_makeadmin(playerid, params[])
{
    if (strlen(params))
    {
        if(pAdmin =< 2)
        {
            new
                pID,
                level;
            if (!sscanf(params, "ii", pID, level)) // Add a ")" at the end.
            {
                if (pID != INVALID_PLAYER_ID)
                {
                    new msg;
                    INI_WriteInt(File,"Admin",level);
                    SendClientMessage(playerid, COLOR_WHITE, "You have been promoted");
                }
                else SendClientMessage(playerid, COLOR_WHITE, "Player not connected");
            }
            else SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /makeadmin <playerid> <level>");
        }
        else SendClientMessage(playerid, COLOR_WHITE, "You need to be at least level 2 for this command")
    }
    return 1;
}



Re: [Help]Dcmd & sscanf errors - Jagofr - 22.12.2011

Thanks.. I cant believe I missed that but I still get some problems

pawn Код:
TestLogin.pwn(155) : warning 213: tag mismatch
TestLogin.pwn(155) : warning 206: redundant test: constant expression is non-zero

pawn Код:
dcmd_makeadmin(playerid, params[])
{
    if (strlen(params))
    {
        if(pAdmin <= 2) //Line 155
        {
            new
            pID,
            level;
            if (!sscanf(params, "ii", pID, level)) // Line 160            
            {
                    if (pID != INVALID_PLAYER_ID)
                    {
                        new INI:File = INI_Open(UserPath(pID));
                        INI_WriteInt(File,"Admin",level);
                        SendClientMessage(playerid, COLOR_WHITE, "You have been promoted");
                    }
                    else SendClientMessage(playerid, COLOR_WHITE, "Player not connected");
            }
            else SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /makeadmin <playerid> <level>");
        }
        else SendClientMessage(playerid, COLOR_WHITE, "You need to be at least level 2 for this command");
    }
    return 1;
}



Re: [Help]Dcmd & sscanf errors - Ash. - 22.12.2011

Can you show us where you declare 'pAdmin'?

Also, you haven't included the sscanf include. Assuming you have the necessary files, you need:
pawn Код:
#include <sscanf>
at the top of your script (but under the inclusion of a_samp).


Re: [Help]Dcmd & sscanf errors - Jagofr - 22.12.2011

Quote:
Originally Posted by funky1234
Посмотреть сообщение
Can you show us where you declare 'pAdmin'?

Also, you haven't included the sscanf include. Assuming you have the necessary files, you need:
pawn Код:
#include <sscanf>
at the top of your script (but under the inclusion of a_samp).
pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths
}
I hope thats what you mean


Re: [Help]Dcmd & sscanf errors - Jagofr - 22.12.2011

Quote:
Originally Posted by Jagofr
Посмотреть сообщение
pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths
}
I hope thats what you mean
Dont worry I got it.. Just needed to change
pawn Код:
if(pAdmin <= 2)
to
pawn Код:
if(PlayerInfo[playerid][pAdmin] <= 2)
I hope thiis was nt mch of a bother


Re: [Help]Dcmd & sscanf errors - Jagofr - 22.12.2011

New problem
I get no errors; or so I thought but I get this in my server_log:

"sscanf warning: Format specifier does not match parameter count."

And in-game if I do
/makeadmin 0
It does
pawn Код:
else if (PlayerInfo[playerid][pAdmin] <= 3)
    {
        new INI:File = INI_Open(UserPath(pID));
        INI_WriteInt(File,"Admin",level);
        SendClientMessage(pID, COLOR_WHITE, "Level changed!");
        SendClientMessage(playerid, COLOR_WHITE, "Player level changed!");
    }
or if I do
/makeadmin 0 5
it does
pawn Код:
else if (PlayerInfo[playerid][pAdmin] <= 3)
    {
        new INI:File = INI_Open(UserPath(pID));
        INI_WriteInt(File,"Admin",level);
        SendClientMessage(pID, COLOR_WHITE, "Level changed!");
        SendClientMessage(playerid, COLOR_WHITE, "Player level changed!");
    }
but no change in the .ini file
Help!!
Here is the dcmd code


pawn Код:
dcmd_makeadmin(playerid, params[])
{
    new pID,
        level;
    if (sscanf(params, "u", pID, level)) SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: \"/makeadmin <playerid> <level>\"");
    else if (pID == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_WHITE, "No such player!");
    else if (PlayerInfo[playerid][pAdmin] <= 3)
    {
        new INI:File = INI_Open(UserPath(pID));
        INI_WriteInt(File,"Admin",level);
        SendClientMessage(pID, COLOR_WHITE, "Level changed!");
        SendClientMessage(playerid, COLOR_WHITE, "Player level changed!");
    }
    else SendClientMessage(playerid, COLOR_WHITE, "Need to be at least Admin Level 3 to use this command");
    return 1;
}



Re: [Help]Dcmd & sscanf errors - Ash. - 22.12.2011

You're only giving sscanf on specifier in your last example, though are telling sscanf you're expecting two variables (pID, level). Add another specifier for "level" (probably 'i' if it's an integer).


Re: [Help]Dcmd & sscanf errors - Jagofr - 22.12.2011

Can I ask you one more question?

I fixed the integer problem but it still doesnt change anything in the .ini file and completley ignores the level setting when I use the command in-game

Anything else im doing wrong?