Invalid command entered!
#1

Fixed!
Reply
#2

Always return 1 at the end of commands.
Reply
#3

Today, I will teach you the importance of indenting the code properly:

Which code is better or more readable? Yours or mine?

Код:
 
if(strcmp(cmd, "/armourevent", true) == 0)
{
        if(AccInfo[playerid][LoggedIn] == 1 && AccInfo[playerid][Level] >=2)
        {
	        if(Event == 0) return SendClientMessage(playerid,red, "[ ERROR: There is no event hosted at the moment to armour event participants. ]");
	        else
	        {
		        new PlayerName[MAX_PLAYER_NAME], string[256];
		        GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
		           SendClientMessage(playerid, BlueMsg, "[ NOTIFICATION: You have refilled armour of event participants. ]");
		        SendCommandToAdmins(playerid,"AmourEvent");
		        format(string,sizeof(string),"[ ADMIN: %s (Id: %d) has refilled the armour of every the event participants. ]",PlayerName,playerid);
		        SendClientMessageToAll(COLOR_PINK,string);
		        for(new i = 0; i < MAX_PLAYERS; i++)
		        {
			        if(GetPlayerVirtualWorld(i) == 9999)
			        {
			         SetPlayerArmour(i, 100.0);
			        }
		        }
	        }
        }
        else return SendClientMessage(playerid,red, "[ ERROR: You have entered an invalid command, please type /cmds to know the server's commands. ]");
}
Do you notice that "SendClientMessage(playerid,red, "[ ERROR: You have entered an invalid command, please type /cmds to know the server's commands. ]");" is inside your command?

Also remember that you need to return 1 to avoid the Unknown Command Message.

Please switch to iZCMD or y_commands.
Reply
#4

Fixed!
Reply
#5

Quote:
Originally Posted by Sc0pion
Посмотреть сообщение
Yes, your one is more readable, and the following line is used when the player is not an admin, and not logged in, but I still receive this even I'm an admin, and logged in.

Код:
else return SendClientMessage(playerid,red, "[ ERROR: You have entered an invalid command, please type /cmds to know the server's commands. ]");

I returned 1 below SetPlayerAmour(i,100.0); but still the same.
It's an if/else statement, it'll only be met if the conditions of the if statement are not met. In this case, "if(AccInfo[playerid][LoggedIn] == 1 && AccInfo[playerid][Level] >=2)". You should add one at either the last line of the very end of the command before the closing bracket in NO if/else statement, or at the end of the if statement before the else is started. How you're structuring your command doesn't make sense IMO. I generally prefer to just check if the player is admin/logged in at the beginning, and if they're not, just return a message then, and at the end just returning 1.

I would replace 'else return SendClientMessage(playerid,red, "[ ERROR: You have entered an invalid command, please type /cmds to know the server's commands. ]");' with removing the if/else and checking at the beginning if they're admin at the beginning, and returning a permission denied, or returning 0 if you want it to return the unknown command error. Then, at the end, simply return 1. The logged in check isn't really needed, since I'd assume admin levels can only be set to those players which are logged in.


Example:
Код:
	
	if(strcmp(cmd, "/armourevent", true) == 0)
	{
			if(AccInfo[playerid][Level] >=2)
				return SendClientMessage(playerid, -1, "You do not have the permissions needed for this command!");
			if(Event == 0) 
				return SendClientMessage(playerid,red, "[ ERROR: There is no event hosted at the moment to armour event participants. ]");
			new PlayerName[MAX_PLAYER_NAME], string[256];
			GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
			   SendClientMessage(playerid, BlueMsg, "[ NOTIFICATION: You have refilled armour of event participants. ]");
			SendCommandToAdmins(playerid,"AmourEvent");
			format(string,sizeof(string),"[ ADMIN: %s (Id: %d) has refilled the armour of every the event participants. ]",PlayerName,playerid);
			SendClientMessageToAll(COLOR_PINK,string);
			for(new i = 0; i < MAX_PLAYERS; i++)
			{
				if(GetPlayerVirtualWorld(i) == 9999)
				{
					SetPlayerArmour(i, 100.0);
				}
			}
		   return 1;
	}
As a side note, as said above, I'd look into an alternate command processor. I'd also look into foreach.
Reply
#6

Fixed!
Reply
#7

Quote:
Originally Posted by Sc0pion
Посмотреть сообщение
Nice explanation, understood, worked, and you earned a rep from you, but;

Код:
if(AccInfo[playerid][Level] < 2)
Whoops, yeah, didn't catch that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)