commands works but also returns "unknown command"
#1

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;
}
Reply
#2

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"
Reply
#3

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 :/
Reply
#4

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

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

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

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
Reply
#8

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

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

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)