How to get RId of this - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to get RId of this (
/showthread.php?tid=253766)
How to get RId of this -
Artix - 07.05.2011
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;
}
Re: How to get RId of this -
BizzyD - 07.05.2011
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
Re: How to get RId of this -
Artix - 07.05.2011
i mean every time i use an unknown command?
Re: How to get RId of this -
BizzyD - 07.05.2011
Yea, That is what happends then :P
Re: How to get RId of this -
Artix - 07.05.2011
Thanks mate
Re: How to get RId of this -
Seven_of_Nine - 08.05.2011
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
Re: How to get RId of this -
Joe Staff - 08.05.2011
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.