How to get RId of this
#1

Hi everyone i have a problem

how to get rid of SERVER: Unknown Command.
when i enter a command.
that is Unknown to the server

Код:
if (strcmp("/God on", cmdtext, true, 10) == 0)
	{
		if(IsPlayerAdmin(i))
		{
		    SendClientMessage(i, SERVER," .Godmode Activated. ");
		    SetPlayerHealth(i, GOD_HEALTH);
			GivePlayerWeapon(i, GOD_WEAPON,GOD_AMMO);
		}
		else
		{
		    SendClientMessage(i, SERVER," Server Unknown Command use /help to see some information ");
		}
		return 1;
	}
Reply
#2

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return SendClientMessage(playerid, COLOUR, "INVAILD COMMAND! FAILLZOOR");
}
If you dont understand what to do, Delete the return 0 at the bottom of OnPlayerCommandText and replace it like i did in the code above
Reply
#3

i mean every time i use an unknown command?
Reply
#4

Yea, That is what happends then :P
Reply
#5

Thanks mate
Reply
#6

That is not the problem.
You have problems with the code..
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/god", cmdtext, true, 10) == 0) {
        new cmd[128],idx,tmp[128];
        cmd = strtok(cmdtext,idx);
        tmp = strtok(cmd,idx);
        if(IsPlayerAdmin(playerid)) {
            if(!strlen(tmp)) return SendClientMessage(playerid,white,"USAGE: /god [on | off]");
            if(strcmp(tmp,"on",true) == 0) {
                SendClientMessage(playerid, SERVER," .Godmode Activated. ");
                SetPlayerHealth(playerid, GOD_HEALTH);
                GivePlayerWeapon(playerid, GOD_WEAPON,GOD_AMMO);
            } else if(strcmp(tmp,"on",true) == 0) {
                SendClientMessage(playerid,SERVER,".Godmode Deactivated.");
            } else {
                return SendClientMessage(playerid,red,"USAGE: /god [on | off]");
            }
        } else {
            return SendClientMessage(playerid, SERVER,"ERROR: This command is only avaible for RCON Administrators.");
        }
        return 1;
    }
    return SendClientMessage(playerid,white,"Unknown Command. Please type /help to see avaible commands.");
}
EDIT: you need strtok:
pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
I don't know much about strtok() but it should work
Reply
#7

That's a horrible rendition of that command, strtok is completely unnecessary even if he does decide to have an on/off parameter (which too is unnecessary)
His command is fine as-is.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)