SA-MP Forums Archive
commands works but also returns "unknown command" - 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: commands works but also returns "unknown command" (/showthread.php?tid=72868)



commands works but also returns "unknown command" - Coolman12 - 11.04.2009

I started coding for samp yesterday, and i can't seem to get my commands working completely, they all return "unknown command", but they still works as suspected.

(I have searched)

commands code:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/makemehappy", cmdtext, true, 10) == 0)
	{
	  SetPlayerHealth(playerid, 100);
	  GivePlayerMoney(playerid,1000000);
		return 1;
	}
	return 0;
}



Re: commands works but also returns "unknown command" - OmeRinG - 11.04.2009

This is weird as it seems you were doing the code alright, try this instead:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext,"/makemehappy",true))
    {
      SetPlayerHealth(playerid, 100);
      GivePlayerMoney(playerid,1000000);
      return 1;
    }
    return SendClientMessage(playerid,0xffffffff,"I don't know this command.");
}
And tell me if it says "I don't know this command" or it keeps saying "Unknown command"


Re: commands works but also returns "unknown command" - Coolman12 - 11.04.2009

Quote:
Originally Posted by OmeRinG
This is weird as it seems you were doing the code alright, try this instead:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext,"/makemehappy",true))
    {
     SetPlayerHealth(playerid, 100);
     GivePlayerMoney(playerid,1000000);
     return 1;
    }
    return SendClientMessage(playerid,0xffffffff,"I don't know this command.");
}
And tell me if it says "I don't know this command" or it keeps saying "Unknown command"
it works now! thanks

when i type an invalid command it returns "i don't know this command."

and when i type the valid command, it does as supposed to, without anything else

Edit:

While i'm on it, how do i make an if statement telling if the player is in a vehicle or not?

i tried with:
Код:
if(!IsPlayerInAnyVehicle(playerid);)return 1;
{
	//code
}
else
{
	//code
}
but it didn't work :/


Re: commands works but also returns "unknown command" - MenaceX^ - 11.04.2009

Also if you return it with false, it does the same thing.


Re: commands works but also returns "unknown command" - Coolman12 - 11.04.2009

Quote:
Originally Posted by MenaceX^
Also if you return it with false, it does the same thing.
what?


Re: commands works but also returns "unknown command" - Fire Dragon - 11.04.2009

pawn Код:
if(IsPlayerInAnyVehicle(playerid))
{
    //code if player is in any veh
}
else
{
    //code if player is on foot or smth diffrent
}



Re: commands works but also returns "unknown command" - Coolman12 - 11.04.2009

Quote:
Originally Posted by Fire Dragon
pawn Код:
if(IsPlayerInAnyVehicle(playerid))
{
    //code if player is in any veh
}
else
{
    //code if player is on foot or smth diffrent
}
when i tried this all commands executed at the same time.
code:
pawn Код:
if (strcmp (cmdtext,"/fix", true))
 {
  if(IsPlayerInAnyVehicle(playerid))
  {
    SendClientMessage(playerid,0xFFFFFFFF,"You are inside a vehicle.");
  }
  else
  {
    SendClientMessage(playerid,0xFFFFFFFF,"You are NOT inside a vehicle.");
  }
 }
what did i do wrong? lol


Re: commands works but also returns "unknown command" - ICECOLDKILLAK8 - 11.04.2009

pawn Код:
if (strcmp (cmdtext,"/fix", true))
// Change to
if (strcmp (cmdtext,"/fix", true) == 0)



Re: commands works but also returns "unknown command" - Coolman12 - 11.04.2009

Quote:
Originally Posted by JeNkStAX
pawn Код:
if (strcmp (cmdtext,"/fix", true))
// Change to
if (strcmp (cmdtext,"/fix", true) == 0)
still executes all the commands


Re: commands works but also returns "unknown command" - Pyrokid - 11.04.2009

This worked for me:
pawn Код:
if (strcmp (cmdtext,"/fix", true) ==0)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            SendClientMessage(playerid,0xFFFFFFFF,"You are inside a vehicle.");
      } else {
            SendClientMessage(playerid,0xFFFFFFFF,"You are NOT inside a vehicle.");
      }
      return 1;
    }
I tested it in-game.