SA-MP Forums Archive
How to check the words in inputtext? (dialog) - 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)
+--- Thread: How to check the words in inputtext? (dialog) (/showthread.php?tid=533435)



How to check the words in inputtext? (dialog) - Metharon - 24.08.2014

Please , explain me how can i do to check if the player inputtext is : ADM , HLP , VIP , SYMBOLS (!@#$@%)
?


Re: How to check the words in inputtext? (dialog) - MicroD - 24.08.2014

You can use https://sampwiki.blast.hk/wiki/Strcmp but I'm not really sure what you want to do entirely ther emight be a better way of doing that.


Re: How to check the words in inputtext? (dialog) - Metharon - 24.08.2014

i don't want to compare them , i know i can use strfind but i want to do something like:

if(inputtext(words))
{
//
}


Re: How to check the words in inputtext? (dialog) - Sawalha - 24.08.2014

you mean if inputtext is a specific word you set?


Re: How to check the words in inputtext? (dialog) - Metharon - 24.08.2014

Yes.


Re: How to check the words in inputtext? (dialog) - Sawalha - 24.08.2014

then use strfind


Re: How to check the words in inputtext? (dialog) - Virtual1ty - 24.08.2014

Strfind might be okay, but what I think it really does internally is looping through the string, now consider this everytime you need to check for something. A better way would be looping through the string only once checking for what you need.


Re: How to check the words in inputtext? (dialog) - Metharon - 25.08.2014

An example of code pls?


Re: How to check the words in inputtext? (dialog) - RajatPawar - 25.08.2014

pawn Код:
static const arrWords[][] =
{
      "FirstWord",
      "SecondWord"
};

......

for(new i = 0; i < sizeof(arrWords); i++)
{
   if(strfind(inputtext, arrWords[i], true) != -1)
   {
         // you found the word at index 'i'
   }
}
...



Re: How to check the words in inputtext? (dialog) - Virtual1ty - 25.08.2014

If you're only checking for "clan tags" with no more than 3 chars, you could loop through the whole string and check for each character, gets long when there are more chars to check, but does the trick:
pawn Код:
new i = 0, str[10]; // adjust to your needs
while (str[i] != '\0')
{
    if (str[i] == '!' || str[i] == '?' || str[i] == '@' || str[i] == '#' || str[i] == '&' || str[i] == '%' || str[i] == '$')
        // string contains invalid symbol
   
    // check for clan names
    if (str[i] == 'A' && str[i+1] == 'D' && str[i+2] == 'M')
        // 'ADM' tag
    // etc.

    i++;
}