[HELP] Targetid is egnored ?
#1

Hello guys, so I was making an admin command, and while doing so I found this really annoying problem,
in which a whole line of code gets egnored of something like that,
in other words, I'm making a /setlevel cmd to promote/demote players(admin status), but whatever the ID I enter is, the command works on me, not on the targetid, and when I do like /setlevel 5006454 3 It doesn't execute the ClientMessage that says "INVALID ID",
here is the code

Код:
CMD:setlevel(playerid, params[]) {
	new
		string[MAX_PLAYER_NAME+64],
		pname[MAX_PLAYER_NAME],
		tname[MAX_PLAYER_NAME],
		targetid,
		level;
	if((IsPlayerAdmin(playerid)) || PlayerInfo[playerid][AdminLevel] >= 3) {
 		if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, -1, "USAGE: /makeadmin (playerid) (level)");
 		for(new i; i <= MAX_PLAYERS; i++) {
 		    if((!IsPlayerConnected(targetid)) || (targetid == INVALID_PLAYER_ID)) SendClientMessage(playerid, 0xFF0000, "Player Is Not Connected!");
 		    else {
 		        if(level < 1 || level > 4) return SendClientMessage( playerid, 0xFF0000, "available levels (1-4)");
				GetPlayerName(playerid, pname, sizeof(pname));
				GetPlayerName(targetid, tname, sizeof(tname));
				format(string, sizeof(string), "Administrator %s has promoted %s to level %i admin", pname, tname, level);
				SendClientMessageToAll(-1, string);
				PlayerInfo[targetid][AdminLevel] = level;
				new INI:File = INI_Open(AdminPath(targetid));
				INI_SetTag(File, "AdminData");
				INI_WriteInt(File, "AdminLevel", PlayerInfo[targetid][AdminLevel]);
				INI_Close(File);
				return 1;
			}
 		}
	}
	else {
 		SendClientMessage( playerid, 0xFF0000, "you can't use this command!");
	    return 1;
	}
	return 1;
}
Reply
#2

Wtf, why you are using loop here?

for(new i; i <= MAX_PLAYERS; i++) {
Reply
#3

pawn Код:
CMD:setlevel(playerid, params[])
{
    if(!IsPlayerAdmin(playerid) || PlayerInfo[playerid][AdminLevel] < 3) SendClientMessage( playerid, 0xFF000000, "you can't use this command!");
    else
    {
        new targetid, level;
        if(sscanf(params, "ui", targetid, level)) SendClientMessage(playerid, -1, "USAGE: /makeadmin (playerid) (level)");
        else if(targetid == INVALID_PLAYER_ID || !IsPlayerConnected(targetid)) SendClientMessage(playerid, 0xFF000000, "Player Is Not Connected!");
        else if(level < 1 || level > 4) SendClientMessage(playerid, 0xFF000000, "available levels (1-4)");
        else
        {
            new
                string[MAX_PLAYER_NAME + 64],
                pname[MAX_PLAYER_NAME + 1],
                tname[MAX_PLAYER_NAME + 1]
            ;

            GetPlayerName(playerid, pname, sizeof(pname));
            GetPlayerName(targetid, tname, sizeof(tname));

            PlayerInfo[targetid][AdminLevel] = level;
            format(string, sizeof(string), "Administrator %s has promoted %s to level %i admin", pname, tname, level);
            SendClientMessageToAll(-1, string);
            new INI:File = INI_Open(AdminPath(targetid));
            INI_SetTag(File, "AdminData");
            INI_WriteInt(File, "AdminLevel", level);
            INI_Close(File);
        }
    }
    return 1;
}
Reply
#4

Hey Eoussama,

What Rdx means by the above is that line 10 you run the code to set their level (MAX_PLAYERS + 1) times - because you have a for loop <= MAX_PLAYERS there.

In terms of it only ever working for you - your sscanf looks fine to me, but there are an array of oddities that could be causing us to miss something further on in addition to the for loop. Could you try running the below and pasting the console output and what happens ingame?

Also string[MAX_PLAYER_NAME+64] is probably too small - I would put it as string[MAX_PLAYER_NAME*2 + 64] if you want to continue with two names!

PHP код:
CMD:setlevel(playeridparams[]) 
{
    new
        
string[MAX_PLAYER_NAME+64],
        
pname[MAX_PLAYER_NAME],
        
tname[MAX_PLAYER_NAME],
        
targetid,
        
level;
        
    if((
IsPlayerAdmin(playerid)) || PlayerInfo[playerid][AdminLevel] >= 3
    {
         if(
sscanf(params"ui"targetidlevel)) 
        {
            return 
SendClientMessage(playerid0xFF0000"USAGE: /makeadmin (playerid) (level)");
        }
        
        
printf("** %i, %i, '%s'"playeridtargetidparams);
        
        if((!
IsPlayerConnected(targetid)) || (targetid == INVALID_PLAYER_ID)) 
        {
            
SendClientMessage(playerid0xFF0000"Player Is Not Connected!");
        }
        else 
        {
            if(
level || level 4
            {
                return 
SendClientMessageplayerid0xFF0000"available levels (1-4)");
            }
            
            
GetPlayerName(playeridpnamesizeof(pname));
            
GetPlayerName(targetidtnamesizeof(tname));
            
format(stringsizeof(string), "Administrator %s has promoted %s to level %i admin"pnametnamelevel);
            
SendClientMessageToAll(-1string);
            
PlayerInfo[targetid][AdminLevel] = level;
            new 
INI:File INI_Open(AdminPath(targetid));
            
INI_SetTag(File"AdminData");
            
INI_WriteInt(File"AdminLevel"PlayerInfo[targetid][AdminLevel]);
            
INI_Close(File);
            return 
1;
        }
    }
    else 
    {
         
SendClientMessageplayerid0xFF0000"you can't use this command!");
        return 
1;
    }
    return 
1;

Reply
#5

Quote:
Originally Posted by Alcatrik
Посмотреть сообщение
Hey Eoussama,

What Rdx means by the above is that line 10 you run the code to set their level (MAX_PLAYERS + 1) times - because you have a for loop <= MAX_PLAYERS there.

In terms of it only ever working for you - your sscanf looks fine to me, but there are an array of oddities that could be causing us to miss something further on in addition to the for loop. Could you try running the below and pasting the console output and what happens ingame?

Also string[MAX_PLAYER_NAME+64] is probably too small - I would put it as string[MAX_PLAYER_NAME*2 + 64] if you want to continue with two names!

PHP код:
CMD:setlevel(playeridparams[]) 
{
    new
        
string[MAX_PLAYER_NAME+64],
        
pname[MAX_PLAYER_NAME],
        
tname[MAX_PLAYER_NAME],
        
targetid,
        
level;
        
    if((
IsPlayerAdmin(playerid)) || PlayerInfo[playerid][AdminLevel] >= 3
    {
         if(
sscanf(params"ui"targetidlevel)) 
        {
            return 
SendClientMessage(playerid0xFF0000"USAGE: /makeadmin (playerid) (level)");
        }
        
        
printf("** %i, %i, '%s'"playeridtargetidparams);
        
        if((!
IsPlayerConnected(targetid)) || (targetid == INVALID_PLAYER_ID)) 
        {
            
SendClientMessage(playerid0xFF0000"Player Is Not Connected!");
        }
        else 
        {
            if(
level || level 4
            {
                return 
SendClientMessageplayerid0xFF0000"available levels (1-4)");
            }
            
            
GetPlayerName(playeridpnamesizeof(pname));
            
GetPlayerName(targetidtnamesizeof(tname));
            
format(stringsizeof(string), "Administrator %s has promoted %s to level %i admin"pnametnamelevel);
            
SendClientMessageToAll(-1string);
            
PlayerInfo[targetid][AdminLevel] = level;
            new 
INI:File INI_Open(AdminPath(targetid));
            
INI_SetTag(File"AdminData");
            
INI_WriteInt(File"AdminLevel"PlayerInfo[targetid][AdminLevel]);
            
INI_Close(File);
            return 
1;
        }
    }
    else 
    {
         
SendClientMessageplayerid0xFF0000"you can't use this command!");
        return 
1;
    }
    return 
1;

tnx for responding,
unfortunately I still have the same problem, I typed /setlevel 5689498 3 and again it gave me the inputted level whereas I was expecting it to display an error "invalid id"
Reply
#6

In the server console it should have printed out ** with two numbers and a string - mind pasting that to me?
Reply
#7

Quote:
Originally Posted by Alcatrik
Посмотреть сообщение
In the server console it should have printed out ** with two numbers and a string - mind pasting that to me?
here, I typed this time /setlevel 456 4
and the consol displayed this ** 0, 0, '456 4'
Reply
#8

Thanks for the help guys, the problem is finally solved,
I changed this if(sscanf(params, "ui", targetid, level)) to this if(sscanf(params, "ii", targetid, level))

I didn't find any of this logical, but it worked,
any explanation guys?!
Reply
#9

Then is it really solved...? No.
Reply
#10

Probably faulty sscanf version.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)