SA-MP Forums Archive
How to detect a string/text in a 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: How to detect a string/text in a command? (/showthread.php?tid=150893)



How to detect a string/text in a command? - DX7 - 28.05.2010

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


Re: How to detect a string/text in a command? - Jeffry - 28.05.2010

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.


Re: How to detect a string/text in a command? - Sergei - 28.05.2010

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;
}