MySQL Helper level does not save.
#1

Код:
CMD:role(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pHelper] >= 3 || PlayerInfo[playerid][pDeveloper] >= 3)
    {
        new subcmd[30], scmd_params[30];

        if(sscanf(params, "s[30]S()[30]",subcmd, scmd_params))
            return SendClientMessage(playerid, COLOR_INFO, "/role [(o)helper/(o)developer/(o)admin]");



        // role helper subcmd
        if(strmatch(subcmd, "helper"))
        {
            if(PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pHelper] >= 3)
            {
                new targetid, value, str[128];

                if(sscanf(params, "s[30]ui",subcmd, targetid, value))
                    return SCM(playerid, COLOR_INFO, "/role helper [name/id] [value]");

                if(targetid == playerid)
                    return SCM(playerid, COLOR_ERROR, "You can not use this command on yourself.");

                if(!IsPlayerConnected(targetid))
                    return SCM(playerid, COLOR_ERROR, "That account is not connected.") && SCM(playerid, COLOR_INFO, "Use /role ohelper instead.");

                if(FirstSpawn[targetid])
                    return SCM(playerid, COLOR_ERROR, "That player has not logged in or spawned yet.");

                if(value < 0 || value > 4)
                    return SCM(playerid, COLOR_ERROR, "You can only use a level value between 0 and 4.");

                if(!IsAdmin(playerid))
                {
                    if(value > PlayerInfo[playerid][pHelper])
                        return SCM(playerid, COLOR_ERROR, "You can only use a level value that does not surpass your own.");
                }

                if(PlayerInfo[targetid][pAdmin] > PlayerInfo[playerid][pAdmin])
                    return SCM(playerid, COLOR_ERROR, "That player has a higher helper level than you.");

                PlayerInfo[targetid][pHelper] = value;

                format(str,sizeof(str),"You have set %s(%i) their helper level to %i.",ReturnICName(targetid), targetid, value);
                SCM(playerid, COLOR_COOLBLUE, str);

                format(str,sizeof(str),"Your helper level was set to %i by %s(%i).",value, ReturnICName(playerid), playerid);
                SCM(targetid, COLOR_COOLBLUE,str);

                new action[128];
                format(action, sizeof(action), "role helper to %i", value);

                new query[250];

                mysql_format(g_SQL, query, sizeof(query), "INSERT INTO logs_roles(acc_dbid, acc_name, target_dbid, target_name, time, action) VALUES('%i', '%e', '%i', '%e', UTC_TIMESTAMP(), '%e')", PlayerInfo[playerid][pDBID], ReturnName(playerid), PlayerInfo[targetid][pDBID], ReturnName(targetid), action);
                mysql_tquery(g_SQL, query);

                mysql_format(g_SQL, query, sizeof(query),"UPDATE `accounts` SET `helper` = %i WHERE `acc_dbid` = '%i' LIMIT 1",value, PlayerInfo[targetid][pHelper]);
                mysql_tquery(g_SQL, query);

            }

            else return SCM(playerid,COLOR_ERROR,"You do not have the required access to execute this subcommand.");
        }

        // if no strmatch
        else return SCM(playerid, COLOR_ERROR, "That subcommand does not exist.");
    }

    else return SCM(playerid,COLOR_ERROR,"You do not have the required access to execute this command.");

    return 1;
}
The helper level does not update in MySQL. I've marked the relevant code in red. Any idea why it won't?
Reply
#2

nvm solved, i used PlayerInfo[targetid][pHelper] instead of PlayerInfo[targetid][pDBID]
Reply
#3

why are you using LIMIT 1? and it's not really necessary to use ' in a int
Reply
#4

Quote:
Originally Posted by ConnorW
Посмотреть сообщение
why are you using LIMIT 1? and it's not really necessary to use ' in a int
Why should I not use LIMIT 1 there? Could you please explain?
Reply
#5

Quote:
Originally Posted by Stefhan
Посмотреть сообщение
Why should I not use LIMIT 1 there? Could you please explain?
Because in your mysql line, you specifically are only updating 1 account row in MySQL at a time anyway
Why add extra mysql commands when youve already basically made it update 1 anyway,

Limiting it to 1 in another area such as saving player information before they quit the server, could possibly miss saving other players data if I am not wrong, but anyone else feel free to correct me if I am wrong...

BUT I do know that limit is used for specific mysql queries such as the following, read it, youll get an understanding
http://www.mysqltutorial.org/mysql-limit.aspx
Dont just read the top, read right through, you might actually find some use for it later on
pawn Код:
mysql_format(g_SQL, query, sizeof(query),"UPDATE `accounts` SET `helper` = %i WHERE `acc_dbid` = '%i' LIMIT 1",value, PlayerInfo[targetid][pHelper]);
pawn Код:
WHERE `acc_dbid` = '%i'
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)