SA-MP Forums Archive
/setolevel - 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: /setolevel (/showthread.php?tid=625056)



/setolevel - Loinal - 27.12.2016

Hey guys, When ever i use that command it doesn't work Why

PHP код:
CMD:setolevel(playeridparams[])
{
    new 
lookupid,level,name[MAX_PLAYER_NAME],string[143];
    if(
pData[playerid][Admin] >= 9)
    {
        if(
sscanf(params,"ud",lookupid,level)) return SendClientMessage(playeridCOLOR_YELLOW"Usage: /setolevel (Name on database) (level)");
        if(
level ||level 10) return SendClientMessage(playerid, -1"1 to 10 levels"); //  you can change this to any level you want
        
mysql_format(mysql,stringsizeof(string), "UPDATE `players` SET level = %d WHERE username = '%s'",level,name);
        
mysql_tquery(mysqlstring"""");
    }
    else return 
SendClientMessage(playeridCOLOR_YELLOW"Only +level 9 can use this command");
    return 
1;




Re: /setolevel - Misiur - 27.12.2016

Code looks ok. 2 possible reasons:
1. some query error, check mysql_log
2. You're expecting user level to automatically changed when he's ingame. Check if player is online and set his level accordingly


Re: /setolevel - Lordzy - 27.12.2016

There are few reasons why your command could fail :
- 'name' array is left to be empty or null.
- You're not supposed to use "u" specifier to set offline names because the player is supposed to be offline and "u" specifier will return the ID as an invalid one.
- Not really the reason why your command isn't working but it's safe to escape your input string.

pawn Код:
CMD:setolevel(playerid, params[]) {

    if(pData[playerid][Admin] < 9)
        return SendClientMessage(//only 9+ can stuff...

    new
        accName[MAX_PLAYER_NAME],
        level,
        string[100]
    ;
    if(sscanf(params, "s["#MAX_PLAYER_NAME"]d", accName, level))
        return SendClientMessage(playerid, COLOR_YELLOW, "USAGE : /setolevel [account name] [level]");

    if(level < 1 || level > 10)
        return SendClientMessage(//message);

    //You should check if the account exists or not or just see if the query returns any error while update.
 
    mysql_format(mysql, string, sizeof(string), "UPDATE `players` SET `level`=%d WHERE `username`='%e'",
        level, accName);
    mysql_tquery(mysql, string, "", "");
    return 1;
}