How to detect a string/text in a command?
#1

I'm trying to make a simple /engine command which works something like: /engine [on/off/hotwire]

However I haven't got a clue how I can detect if they've said "on", "off" or "hotwire".

How would I go about doing this?

Thanks
Reply
#2

pawn Код:
if(!strcmp, "on", /*Your string*/, true)
{
// What it should make here..
}
pawn Код:
dcmd_engine(playerid,params[]) {
  if(!strlen(params)) return SendClientMessage(playerid,red,"USAGE: /engine [on/off]");
  new tmp[256], Index; tmp = strtok(params,Index);
  if(!strcmp(tmp,"on",true))
    {
    SendClientMessage(playerid, yellow, "Engine is ON.");
    }
  if(!strcmp(tmp,"off",true))
    {
    SendClientMessage(playerid, yellow, "Engine is OFF.");
    }
  return 1;
}
Cheers.
Reply
#3

pawn Код:
COMMAND:engine(playerid,params[])
{
  if(isnull(params)) //usage
  else if(!strcmp(params,"on",true,2)) //on
  else if(!strcmp(params,"off",true,3)) //off
  else if(!strcmp(params,"hotwire",true,7)) //on
  else //invalid option
  return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)