AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Message's bugged! (https://forums.alliedmods.net/showthread.php?t=184690)

Bilal Pro 05-07-2012 17:23

Message's bugged!
 
Hello there,

i hooked say, but for example im saying 'You know i love you' i still unlock the phrase, it has to be only: 'i love you' for example. What am i doing wrong here?

PHP Code:

public CmdSay(id)
{
    new 
message[192], name[32]
    
read_args(messagecharsmax(message))
    
get_user_name(idname31)
    
remove_quotes(message)
    
    if (
contain(message"i love you") >= 0)
    {
        
client_cmd(0"spk misc/trophy.wav")
        
ColorChat(idGREY"%s ^4%s^1 has unlocked the achievement: ^4Secret Phrase #1"Prefixname)
        return 
PLUGIN_HANDLED
    
}
    if (
contain(message"i hate you") >= 0)
    {
        
        
client_cmd(0"spk misc/trophy.wav")
        
ColorChat(idGREY"%s ^4%s^1 has unlocked the achievement: ^4Secret Phrase #2"Prefixname)
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE



Liverwiz 05-07-2012 21:52

Re: Message's bugged!
 
Code:

if(containi(message, "i love you") != -1)
use containi as to make sure its is NOT case sensitive.
containi returns -1 on failure, so just make sure that it DOES NOT EQUAL -1, rather than >= 0 -a more direct way of doing it.

fysiks 05-08-2012 01:49

Re: Message's bugged!
 
Are you sure you hooked it correctly? Everything looks correct to me.

Quote:

Originally Posted by Liverwiz (Post 1704592)
Code:

if(containi(message, "i love you") != -1)
use containi as to make sure its is NOT case sensitive.
containi returns -1 on failure, so just make sure that it DOES NOT EQUAL -1, rather than >= 0 -a more direct way of doing it.

>=0 and !=-1 are the same thing (regarding contain and containi). That's twice now. Also, he doesn't have to use case insensitive functions if he doesn't want to do so.

<VeCo> 05-08-2012 08:34

Re: Message's bugged!
 
Use equal, it checks if 2 strings are the same, which you need in this case.
Contain only checks if one string contains the other, but that doesn't mean they are the same.

Bilal Pro 05-08-2012 08:46

Re: Message's bugged!
 
@fysiks, Im pretty sure that i hooked it correctly

@Veco, What do you mean with use equal?

<VeCo> 05-08-2012 08:52

Re: Message's bugged!
 
Ok, you are saying "You know I love you". The string that you need is "I love you".
Then contain cheks if the message contains the needed string, so that's: "You know I love you". It just checks if the needed string is somewhere in the message, not if the message is the same as the string you want.
So you need equal - it will check if the message is exactly the same as the string: "You know I love you" won't pass this time, because there is also "You know ", which you don't want, so the funtion will be called only if you type "I love you" (nothing more, nothing less) - that's what you need.

Bilal Pro 05-08-2012 09:03

Re: Message's bugged!
 
But i can unlock it either in another sentec, for example: owkadoawjlad i love you.

It will still unlock :s

<VeCo> 05-08-2012 09:20

Re: Message's bugged!
 
Use equal and you won't have such problem.

Bilal Pro 05-08-2012 09:25

Re: Message's bugged!
 
Thank you sir, worked really well :)

fysiks 05-08-2012 12:59

Re: Message's bugged!
 
Using equal is not a solution to finding a string within a string like he was originally trying to do. I don't know how he got it to work with equal because it's not possible to say "You know I love you" and use equal() to know if the string "i love you" is in it.


All times are GMT -4. The time now is 00:29.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.