Where is the bug
#1

Why is this code not good?

Quote:

if(strcmp(cmd, "/ban", true) == 0)
{
if ((!IsPlayerAdmin(playerid)) || adminlevel[playerid] < 3)
{
SendClientMessage(playerid, COLOR_RED, "You have not enough rights to use this command!");
return 1;
}
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD, "USAGE: /ban [playerid] [reason]");
return 1;
}
if(!IsPlayerConnected(playerid))
{
SendClientMessage(playerid, COLOR_RED, "That player is not connected!");
return 1;
}

giveplayerid = strval(tmp);

new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if ((IsPlayerAdmin(giveplayerid)))
{
SendClientMessage(playerid, COLOR_RED, "You can not ban the server owner!");
return 1;
}
if ((IsPlayerAdmin(playerid)) || adminlevel[playerid] >= 3)
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string,sizeof(string),"*** Admin %s has banned %s (reason: %s) ***",sendername,giveplayer, result);
SendClientMessageToAll(COLOR_RED,string);
printf("*** Admin %s has banned %s with reason: %s ***",sendername,giveplayer, result);
Ban(giveplayerid);
return 1;
}
else
{
SendClientMessage(playerid,COLOR_RED,"You have not enough rights to use this command!");
return 1;
}
}

I want that if a player is not rconlogged or if a player has not admin level 3 is that the command can not use

Can anybody see the bug?

(srry for bad bad english)
Reply
#2

Give this a try, this should work.

Код:
if(strcmp(cmd, "/ban", true) == 0)
	{
		if (!IsPlayerAdmin(playerid) && adminlevel[playerid] < 3)
		{
 			SendClientMessage(playerid, COLOR_RED, "You have not enough rights to use this command!");
			return 1;
 		}
 		if(IsPlayerAdmin(playerid) || adminlevel[playerid] > 2)
 		{
  			tmp = strtok(cmdtext, idx);
  		if(!strlen(tmp))
  		{
  			SendClientMessage(playerid, COLOR_GRAD, "USAGE: /ban [playerid] [reason]");
  	 		return 1;
  		}
  		if(!IsPlayerConnected(playerid))
  		{
  	 		SendClientMessage(playerid, COLOR_RED, "That player is not connected!");
  	    return 1;
  	  	}
  	  	giveplayerid = strval(tmp);
  	  new length = strlen(cmdtext);
  	  while ((idx < length) && (cmdtext[idx] <= ' '))
  	  {
  	    idx++;
  	  }
  	  new offset = idx;
  	  new result[64];
  	  while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
  	  {
  	    result[idx - offset] = cmdtext[idx];
  	    idx++;
  	  }
  	  result[idx - offset] = EOS;
  	  if ((IsPlayerAdmin(giveplayerid)))
  	  {
  	    SendClientMessage(playerid, COLOR_RED, "You can not ban the server owner!");
  	    return 1;
  	  }
  	  if ((IsPlayerAdmin(playerid)) || adminlevel[playerid] >= 3)
  	  {
  	  	  GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
   	 	 	GetPlayerName(playerid, sendername, sizeof(sendername));
   	    format(string,sizeof(string),"*** Admin %s has banned %s (reason: %s) ***",sendername,giveplayer, result);
    	  SendClientMessageToAll(COLOR_RED,string);
      	printf("*** Admin %s has banned %s with reason: %s ***",sendername,giveplayer, result);
      	Ban(giveplayerid);
      	return 1;
    	}
  		 	else
    	{
    	 	  SendClientMessage(playerid,COLOR_RED,"You have not enough rights to use this command!");
   		 	return 1;
    	}
   	}
   	return 1;
	}
Reply
#3

Ty i try it
Reply
#4

The code is using wasted arrays and also will be slow.
What's that btw?
pawn Код:
if(!IsPlayerConnected(playerid))
        {
            SendClientMessage(playerid, COLOR_RED, "That player is not connected!");
        return 1;
        }
Reply
#5

Yea, I see what you're saying. I only just fixed the bit for admin, like he requested. There is some wrong stuff he already has there
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)