Setlevel command problem
#1

Hey, I have got a problem in my /setlevel command. I have got errors, lines where are they are marked with [ b ]

Errors:

...Gamemode.pwn(42 : error 033: array must be indexed (variable "level")
...Gamemode.pwn(429) : error 033: array must be indexed (variable "level")
...Gamemode.pwn(430) : error 006: must be assigned to an array
...Gamemode.pwn(431) : error 035: argument type mismatch (argument 3)

Here's the code:

Код:
dcmd_setlevel(playerid,params[])
{
    if(level[playerid] >= 5)
    {
		new playerid2, string[128];
    	if(!sscanf(params, "ud", playerid2, level))
    	{
         	if(IsPlayerConnected(playerid2))
       		{
    			new playerfile[128];
				new tmp[128], tmp2[128], Index;
				tmp = strtok(params,Index), tmp2 = strtok(params,Index),playerid2 = strval(tmp),level = strval(tmp2);
				if(level >= 6) return SendClientMessage(playerid,red,"ERROR: Incorrect level! Please choose beetween 0 and 5!");
				level[playerid] = level;
				dini_IntSet(playerfile,"Level",level);
				format(string,sizeof(string),"You have set %s's Administrator Level to %d!",GetName(playerid2),level);
				SendClientMessage(playerid,red,string);
				format(string,sizeof(string),"Administrator %s has set your Administrator Level to %d!",GetName(playerid),level);
				SendClientMessage(playerid2,red,string);
        	}
        	else return SendClientMessage(playerid,red,"ERROR: Player is not connected!");
    	}
    	else return SendClientMessage(playerid,red,"USAGE: /setlevel [playerid] [level]");
    }
	else return SendClientMessage(playerid,red,"ERROR: Only Admins with level 5 can use this command!");
	return 1;
}
Anyway, thanks for the help.
Reply
#2

pawn Код:
dcmd_setlevel(playerid,params[])
{
    if(level[playerid] >= 5) return SendClientMessage(playerid,red,"ERROR: Only Admins with level 5 can use this command!");
    new playerid2, string[128];
    if(sscanf(params, "ud", playerid2, level)) return SendClientMessage(playerid,red,"USAGE: /setlevel [playerid] [level]");
    if(!IsPlayerConnected(playerid2)) return SendClientMessage(playerid,red,"ERROR: Player is not connected!");
    new playerfile[128];
    if(level >= 6) return SendClientMessage(playerid,red,"ERROR: Incorrect level! Please choose beetween 0 and 5!");
    level[playerid] = level;
    dini_IntSet(playerfile,"Level",level);
    format(string,sizeof(string),"You have set %s's Administrator Level to %d!",GetName(playerid2),level);
    SendClientMessage(playerid,red,string);
    format(string,sizeof(string),"Administrator %s has set your Administrator Level to %d!",GetName(playerid),level);
    SendClientMessage(playerid2,red,string);
    return 1;
}
Un Tested

Should work, my question is why you were using strtok w/ sscanf?
Reply
#3

Thanks for anwser, but I still have the problem...

...Gamemode.pwn(426) : error 033: array must be indexed (variable "level")
...Gamemode.pwn(429) : error 006: must be assigned to an array
...Gamemode.pwn(430) : error 035: argument type mismatch (argument 3)

Код:
dcmd_setlevel(playerid,params[])
{
    if(level[playerid] >= 5)
    {
		new playerid2, string[128];
    	if(sscanf(params, "ud", playerid2, level))
    	{
         	if(IsPlayerConnected(playerid2))
       		{
				if(level >= 6)
				{
    			new playerfile[128];
    			level[playerid] = level;
    			dini_IntSet(playerfile,"Level",level);
    			format(string,sizeof(string),"You have set %s's Administrator Level to %d!",GetName(playerid2),level);
    			SendClientMessage(playerid,red,string);
    			format(string,sizeof(string),"Administrator %s has set your Administrator Level to %d!",GetName(playerid),level);
    			SendClientMessage(playerid2,red,string);
    			}
    			else return SendClientMessage(playerid,red,"ERROR: You cannot set higher Administrator Level than 5!");
        	}
        	else return SendClientMessage(playerid,red,"ERROR: Player is not connected!");
    	}
    	else return SendClientMessage(playerid,red,"USAGE: /setlevel [playerid] [level]");
    }
	else return SendClientMessage(playerid,red,"ERROR: Only Admins with level 5 can use this command!");
	return 1;
}
Reply
#4

pawn Код:
dcmd_setlevel(playerid,params[])
{
    new alevel;
    if(level[playerid] >= 5)
    {
        new playerid2, string[128];
        if(sscanf(params, "ud", playerid2, alevel))
        {
            if(IsPlayerConnected(playerid2))
            {
                if(level >= 6)
                {
                new playerfile[128];
                level[playerid2] = alevel;
                dini_IntSet(playerfile,"Level",alevel);
                format(string,sizeof(string),"You have set %s's Administrator Level to %d!",GetName(playerid2),level);
                SendClientMessage(playerid,red,string);
                format(string,sizeof(string),"Administrator %s has set your Administrator Level to %d!",GetName(playerid),level);
                SendClientMessage(playerid2,red,string);
                }
                else return SendClientMessage(playerid,red,"ERROR: You cannot set higher Administrator Level than 5!");
            }
            else return SendClientMessage(playerid,red,"ERROR: Player is not connected!");
        }
        else return SendClientMessage(playerid,red,"USAGE: /setlevel [playerid] [level]");
    }
    else return SendClientMessage(playerid,red,"ERROR: Only Admins with level 5 can use this command!");
    return 1;
}
Reply
#5

Thanks, works without errors now... But this is a little bugged. In "if(alevel >= 6)" (I fixed this, there should be alevel, not level ) works bugged. I've typed /setlevel and it said I can't set higher administrator level than 5 (I've typed ONLY /setlevel). With level <= (not >=) in /setlevel sets my administrator level to 0, in /setlevel 0 5, it says "USAGE...". Could anyone help?
Reply
#6

Quote:
Originally Posted by Libra_PL
Посмотреть сообщение
Thanks, works without errors now... But this is a little bugged. In "if(alevel >= 6)" (I fixed this, there should be alevel, not level ) works bugged. I've typed /setlevel and it said I can't set higher administrator level than 5 (I've typed ONLY /setlevel). With level <= (not >=) in /setlevel sets my administrator level to 0, in /setlevel 0 5, it says "USAGE...". Could anyone help?
Post your fixed code
Reply
#7

The same like up (only one letter added):

Код:
dcmd_setlevel(playerid,params[])
{
    new alevel;
    if(level[playerid] >= 5)
    {
        new playerid2, string[128];
        if(sscanf(params, "ud", playerid2, alevel))
        {
            if(IsPlayerConnected(playerid2))
            {
                if(alevel <= 6)
                {
                new playerfile[128];
                level[playerid2] = alevel;
                dini_IntSet(playerfile,"Level",alevel);
                format(string,sizeof(string),"You have set %s's Administrator Level to %d!",GetName(playerid2),level);
                SendClientMessage(playerid,red,string);
                format(string,sizeof(string),"Administrator %s has set your Administrator Level to %d!",GetName(playerid),level);
                SendClientMessage(playerid2,red,string);
                }
                else return SendClientMessage(playerid,red,"ERROR: You cannot set higher Administrator Level than 5!");
            }
            else return SendClientMessage(playerid,red,"ERROR: Player is not connected!");
        }
        else return SendClientMessage(playerid,red,"USAGE: /setlevel [playerid] [level]");
    }
    else return SendClientMessage(playerid,red,"ERROR: Only Admins with level 5 can use this command!");
    return 1;
}
Reply
#8

pawn Код:
dcmd_setlevel(playerid,params[])
{
    new alevel;
    if(level[playerid] >= 5)
    {
        new playerid2, string[128];
        if(sscanf(params, "ud", playerid2, alevel))
        {
            if(IsPlayerConnected(playerid2))
            {
                if(alevel <= 6)
                {
                new playerfile[128];
                level[playerid2] = alevel;
                dini_IntSet(playerfile,"Level",alevel);
                format(string,sizeof(string),"You have set %s's Administrator Level to %d!",GetName(playerid2),alevel);
                SendClientMessage(playerid,red,string);
                format(string,sizeof(string),"Administrator %s has set your Administrator Level to %d!",GetName(playerid),alevel);
                SendClientMessage(playerid2,red,string);
                }
                else return SendClientMessage(playerid,red,"ERROR: You cannot set higher Administrator Level than 5!");
            }
            else return SendClientMessage(playerid,red,"ERROR: Player is not connected!");
        }
        else return SendClientMessage(playerid,red,"USAGE: /setlevel [playerid] [level]");
    }
    else return SendClientMessage(playerid,red,"ERROR: Only Admins with level 5 can use this command!");
    return 1;
}
Reply
#9

Still doesn't work. Command "/setlevel" sets my level to 0 and "/setlevel 0 5" gives me usage message.
Reply
#10

pawn Код:
dcmd_setlevel(playerid,params[])
{
    new alevel;
    if(level[playerid] >= 5)
    {
        new playerid2, string[128];
        if(!sscanf(params, "ud", playerid2, alevel))
        {
            if(IsPlayerConnected(playerid2))
            {
                if(alevel <= 6)
                {
                new playerfile[128];
                level[playerid2] = alevel;
                dini_IntSet(playerfile,"Level",alevel);
                format(string,sizeof(string),"You have set %s's Administrator Level to %d!",GetName(playerid2),alevel);
                SendClientMessage(playerid,red,string);
                format(string,sizeof(string),"Administrator %s has set your Administrator Level to %d!",GetName(playerid),alevel);
                SendClientMessage(playerid2,red,string);
                }
                else return SendClientMessage(playerid,red,"ERROR: You cannot set higher Administrator Level than 5!");
            }
            else return SendClientMessage(playerid,red,"ERROR: Player is not connected!");
        }
        else return SendClientMessage(playerid,red,"USAGE: /setlevel [playerid] [level]");
    }
    else return SendClientMessage(playerid,red,"ERROR: Only Admins with level 5 can use this command!");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)