It says no command exists, but it still works!
#1

Okay, whenever I do a command, it works, like if i were to do /me waves, it would say **Memoryz waves

But it also says No Command exists, even though it does and it works.

Heres are my current commands:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  new cmd[256];
  new sendername[MAX_PLAYER_NAME];
  new idx;
  new string[256];
  cmd = strtok(cmdtext, idx);
  dcmd(login,5,cmdtext); // because login has 5 characters
 	dcmd(register,8,cmdtext); // because register has 8 characters


  if (strcmp("/help", cmdtext, true, 10) == 0)
	 {
	   SendClientMessage(playerid,COLOR_YELLOW,"Account: /register /login /stats");
	   SendClientMessage(playerid,COLOR_YELLOW,"Roleplay: /me /do /attempt /(s)hout /(w)hisper /rap /freestyle /sing");
    }
 	if(strcmp(cmd, "/low", true) == 0 || strcmp(cmd, "/l", true) == 0)
	{
			GetPlayerName(playerid, sendername, sizeof(sendername));
			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(!strlen(result))
			{
				SendClientMessage(playerid, red, "USAGE: /low [chat text]");
				return 1;
			}
			else
			{
		  		format(string, sizeof(string), "%s Says: [LOW] %s", sendername, result);
			}
			ProxDetector(3.0, playerid, string,red,red,red,red,red);
			printf("%s", string);
		}
	if(strcmp(cmd, "/shout", true) == 0 || strcmp(cmd, "/s", true) == 0)
	{
			GetPlayerName(playerid, sendername, sizeof(sendername));
			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(!strlen(result))
			{
				SendClientMessage(playerid, red, "USAGE: /shout [chat text]");
				return 1;
			}
			else
			{
		  		format(string, sizeof(string), "%s Says: [shout] %s", sendername, result);
			}
			ProxDetector(30.0, playerid, string,red,red,red,red,red);
			printf("%s", string);
		}
	if(strcmp(cmd, "/me", true) == 0)
	{
		GetPlayerName(playerid, sendername, sizeof(sendername));
		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(!strlen(result))
			{
				SendClientMessage(playerid, red, "USAGE: /me [action]");
				return 1;
			}
			else
			{
				format(string, sizeof(string), "* %s %s", sendername, result);
			}
		ProxDetector(30.0, playerid, string, red,red,red,red,red);
		printf("%s", string);
		}
	if(strcmp(cmd, "/b", true) == 0)//local ooc
	{
			GetPlayerName(playerid, sendername, sizeof(sendername));
			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(!strlen(result))
			{
				SendClientMessage(playerid, grey, "USAGE: /b [local ooc chat]");
				return 1;
			}
			else
			{
				format(string, sizeof(string), "(( [%i] %s Says: %s ))", playerid, sendername, result);
			}
			ProxDetector(20.0, playerid, string,grey,grey,grey,grey,grey);
			printf("%s", string);
		}
	if(strcmp(cmd, "/freestyle", true) == 0 || strcmp(cmd, "/f", true) == 0)
	{
			GetPlayerName(playerid, sendername, sizeof(sendername));
			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(!strlen(result))
			{
				SendClientMessage(playerid, grey, "USAGE: /freestyle [Your FreeStyle]");
				return 1;
			}
			else
			{
				format(string, sizeof(string), " [%i] %s FreeStyles: %s ", playerid, sendername, result);
			}
			ProxDetector(20.0, playerid, string,green,green,green,green,green);
			printf("%s", string);
		}
	if(strcmp(cmd, "/rap", true) == 0 || strcmp(cmd, "/r", true) == 0)
	{
			GetPlayerName(playerid, sendername, sizeof(sendername));
			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(!strlen(result))
			{
				SendClientMessage(playerid, grey, "USAGE: /rap [Your Rap]");
				return 1;
			}
			else
			{
				format(string, sizeof(string), " [%i] %s Raps: %s ", playerid, sendername, result);
			}
			ProxDetector(20.0, playerid, string,orange,orange,orange,orange,orange);
			printf("%s", string);
		}
	if(strcmp(cmd, "/sing", true) == 0)
	{
			GetPlayerName(playerid, sendername, sizeof(sendername));
			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(!strlen(result))
			{
				SendClientMessage(playerid, grey, "USAGE: /sing [Your sing]");
				return 1;
			}
			else
			{
				format(string, sizeof(string), " [%i] %s Sings: %s ", playerid, sendername, result);
			}
			ProxDetector(30.0, playerid, string,orange,orange,orange,orange,orange);
			printf("%s", string);
		}
	return 0;
}

Reply
#2

You need to return 1 at the end of each command.
Reply
#3

So like:
Код:
if (strcmp("/help", cmdtext, true, 10) == 0)
	 {
	   SendClientMessage(playerid,COLOR_YELLOW,"Account: /register /login /stats");
	   SendClientMessage(playerid,COLOR_YELLOW,"Roleplay: /me /do /attempt /(s)hout /(w)hisper /rap /freestyle /sing");
    }
return 1;

if(strcmp(cmd, "/low", true) == 0 || strcmp(cmd, "/l", true) == 0)
	{
			GetPlayerName(playerid, sendername, sizeof(sendername));
			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(!strlen(result))
			{
				SendClientMessage(playerid, red, "USAGE: /low [chat text]");
				return 1;
			}
			else
			{
		  		format(string, sizeof(string), "%s Says: [LOW] %s", sendername, result);
			}
			ProxDetector(3.0, playerid, string,red,red,red,red,red);
			printf("%s", string);
		}
return 1;
Above..?

EDIT: Ya, but now I get

C:\Users\Matthew\samp02Xserver.win32\RPSERVER\game modes\SCRATCHIE.pwn(349) : warning 225: unreachable code

And the rest of the cmds dont work.
Reply
#4

try this
Код:
if (strcmp("/help", cmdtext, true, 5) == 0)
	 {
	   SendClientMessage(playerid,COLOR_YELLOW,"Account: /register /login /stats");
	   SendClientMessage(playerid,COLOR_YELLOW,"Roleplay: /me /do /attempt /(s)hout /(w)hisper /rap /freestyle /sing");
return 1;
    }
Reply
#5

Oh I see how to do it now!

Thanks Gappy & Pliva!
Reply
#6

also intend you code good and try to optimize like this(it's rly about the if(blabla)...easily optimized with returns :P):
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[]){
  new cmd[256],sendername[MAX_PLAYER_NAME],idx,string[256];
  cmd = strtok(cmdtext, idx);
  dcmd(login,5,cmdtext); // because login has 5 characters
    dcmd(register,8,cmdtext); // because register has 8 characters
  if (strcmp("/help", cmdtext, true, 10) == 0){
    SendClientMessage(playerid,COLOR_YELLOW,"Account: /register /login /stats");
        SendClientMessage(playerid,COLOR_YELLOW,"Roleplay: /me /do /attempt /(s)hout /(w)hisper /rap /freestyle /sing");
        return 1;
    }
    if(strcmp(cmd, "/low", true) == 0 || strcmp(cmd, "/l", true) == 0){
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' ')){idx++;}
        new offset = idx,result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))){result[idx - offset] = cmdtext[idx];idx++;}
        result[idx - offset] = EOS;
        if(!strlen(result))return SendClientMessage(playerid, red, "USAGE: /low [chat text]");
        format(string, sizeof(string), "%s Says: [LOW] %s", sendername, result);
        ProxDetector(3.0, playerid, string,red,red,red,red,red);
        printf("%s", string);
        return 1;
    }
    if(strcmp(cmd, "/shout", true) == 0 || strcmp(cmd, "/s", true) == 0){
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' ')){idx++;}
        new offset = idx,result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))){result[idx - offset] = cmdtext[idx];idx++;}
        result[idx - offset] = EOS;
        if(!strlen(result))return SendClientMessage(playerid, red, "USAGE: /shout [chat text]");
        format(string, sizeof(string), "%s Says: [shout] %s", sendername, result);
        ProxDetector(30.0, playerid, string,red,red,red,red,red);
        printf("%s", string);
        return 1;
    }
    if(strcmp(cmd, "/me", true) == 0){
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' ')){idx++;}
        new offset = idx,result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))){result[idx - offset] = cmdtext[idx];idx++;}
        result[idx - offset] = EOS;
        if(!strlen(result))return SendClientMessage(playerid, red, "USAGE: /me [action]");
        format(string, sizeof(string), "* %s %s", sendername, result);
        ProxDetector(30.0, playerid, string, red,red,red,red,red);
        printf("%s", string);
        return 1;
    }
    if(strcmp(cmd, "/b", true) == 0){// local ooc
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' ')){idx++;}
        new offset = idx,result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))){result[idx - offset] = cmdtext[idx];idx++;}
        result[idx - offset] = EOS;
        if(!strlen(result))return SendClientMessage(playerid, grey, "USAGE: /b [local ooc chat]");
        format(string, sizeof(string), "(( [%i] %s Says: %s ))", playerid, sendername, result);
        ProxDetector(20.0, playerid, string,grey,grey,grey,grey,grey);
        printf("%s", string);
        return 1;
    }
    if(strcmp(cmd, "/freestyle", true) == 0 || strcmp(cmd, "/f", true) == 0){
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' ')){idx++;}
        new offset = idx,result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))){result[idx - offset] = cmdtext[idx];idx++;}
        result[idx - offset] = EOS;
        if(!strlen(result))return SendClientMessage(playerid, grey, "USAGE: /freestyle [Your FreeStyle]");
        ProxDetector(20.0, playerid, string,green,green,green,green,green);
        printf("%s", string);
        return 1;
    }
    if(strcmp(cmd, "/rap", true) == 0 || strcmp(cmd, "/r", true) == 0){
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' ')){idx++;}
        new offset = idx,result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))){result[idx - offset] = cmdtext[idx];idx++;}
        result[idx - offset] = EOS;
        if(!strlen(result))return SendClientMessage(playerid, grey, "USAGE: /rap [Your Rap]");
        format(string, sizeof(string), " [%i] %s Raps: %s ", playerid, sendername, result);
        ProxDetector(20.0, playerid, string,orange,orange,orange,orange,orange);
        printf("%s", string);
        return 1;
    }
    if(strcmp(cmd, "/sing", true) == 0){
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' ')){idx++;}
        new offset = idx,result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))){result[idx - offset] = cmdtext[idx];idx++;}
        result[idx - offset] = EOS;
        if(!strlen(result))return SendClientMessage(playerid, grey, "USAGE: /sing [Your sing]");
        format(string, sizeof(string), " [%i] %s Sings: %s ", playerid, sendername, result);
        ProxDetector(30.0, playerid, string,orange,orange,orange,orange,orange);
        printf("%s", string);
        return 1;
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)