How to check the words in inputtext? (dialog)
#1

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

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

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

if(inputtext(words))
{
//
}
Reply
#4

you mean if inputtext is a specific word you set?
Reply
#5

Yes.
Reply
#6

then use strfind
Reply
#7

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

An example of code pls?
Reply
#9

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'
   }
}
...
Reply
#10

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


Forum Jump:


Users browsing this thread: 2 Guest(s)