AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can someone clarify why "containi" did this? (https://forums.alliedmods.net/showthread.php?t=46408)

TheNewt 10-26-2006 00:19

Can someone clarify why "containi" did this?
 
Code:
if(containi(szModel, "models/mymodel.mdl"))      client_print(id, print_chat, "True") if(!containi(szModel, "models/mymodel.mdl"))      client_print(id, print_chat, "False");

So this is what I have, lets say that the item that is supposed to trigger this event does not have mymodel.mdl, but has a different model, but it triggers as "True", and the item that does have mymodel.mdl triggers "False"...
O.o whats up with that??
doesn't !containi mean if it doesn't contain the model "mymodel"???

teame06 10-26-2006 00:20

Re: Can someone clarify why "containi" did this?
 
Code:
if(containi(szModel, "models/mymodel.mdl") != -1)     client_print(id, print_chat, "True") if(containi(szModel, "models/mymodel.mdl") == -1)     client_print(id, print_chat, "False");

contain or containi return -1 when it doesn't contain your argument. If it contain your argument I believe it will return the cell it start at.

TheNewt 10-26-2006 00:33

Re: Can someone clarify why "containi" did this?
 
Now everything comes out as true.
O.o
I'm gonna stick with
Code:
if(!containi(szModel, "models/mymodel.mdl"))      client_print(id, print_chat, "True");
since it works. :P

teame06 10-26-2006 00:47

Re: Can someone clarify why "containi" did this?
 
Code:
#include <amxmodx> new szModel[] = "models/mymodel.mdl"; public plugin_init() {     new IsTrue = containi(szModel, "models/mymodel.mdl"); // This will match     if(IsTrue != -1)         log_amx("[containi] is true %i", IsTrue);     new IsFalse = containi(szModel, "models/_mymodel.mdl"); // This won't match     if(IsFalse == -1)         log_amx("[containi] is false %i", IsFalse); }

Quote:

L 10/25/2006 - 21:55:40: [test.amxx] [containi] is true 0
L 10/25/2006 - 21:55:40: [test.amxx] [containi] is false -1
It seem from that code your going to match a string to another string and match it completely .. So I would just use equali

Since your doing if(!containi("What", "What")) So it kinda be the same thing as if(equal("What", "What")) if your checking if it return 0.

TheNewt 10-26-2006 09:54

Re: Can someone clarify why "containi" did this?
 
alright I'll try that when I come back from school today.

organizedKaoS 10-26-2006 15:09

Re: Can someone clarify why "containi" did this?
 
I could be wrong on some of this...so I'll admit it if I am. This was just thrown together of the top of my head.

Code:

equal - Checks if two strings are equal.
equal ( const a[], const b[], [ c ] )

Example: if(equal(string, mystring))
This checks if string and mystring are exactly the same, case for case.
string = Test, mystring = Test: Both strings are equal
string = Test, mystring = tEsT: Both strings are not equal

equali - Checks if two strings are equal, case insensitive.
equali ( const a[], const b[], [ c ] )
 
Example: if(equali(string, mystring))
This checks if string and mystring are the same, regardless of case.
string = test, mystring = TesT, equali will return that string and mystring are the same

contain - Returns position of string found inside of source, or -1 on failure.
contain ( const source[], const string[] )

Example: Using mapname...if(contain(map, "cs_"))
This checks if anywhere in the mapname contains the string "cs_" Exactly
if(contain(map, "Cs_"))
This checks if anywhere in the mapname contains the string "Cs_" Exactly.
Will return false if mapname is "cs_assualt", etc.

containi - Returns position of string found inside of source, or -1 on failure. Case insensitive.
containi ( const source[], const string[] )

Example: Using mapname...if(containi(map, "awp_"))
This checks if anywhere in the mapname contains the string "awp_", regardless of case.
So mapname of "Awp_" or "aWp_" will return true.

Then the extra values are your choice:

> -1
!= -1
== -1


TheNewt 10-26-2006 19:13

Re: Can someone clarify why "containi" did this?
 
well yeah, that SHOULD be correct
Except for that I have 2 models
Lets name em:
w_firstmodel.mdl, and w_secondmodel.mdl
I do "containi(model, "w_firstmodel.mdl"); but models with the w_secondmodel.mdl are triggering the containi true.
Why? O.o

edit:
I'm gonna use equali, it works (and makes more sense) :D

teame06 10-26-2006 19:29

Re: Can someone clarify why "containi" did this?
 
Code:
if(containi(model, "w_firstmodel.mdl")) { } if(containi(model, "w_secondmodel.mdl")) {      // Will be true even if it can't find it. }

Is this what your code look like?

If that is what it look like. Since it return -1 if it not found. Then if(-1) is still true. if(1) is still true. The only time it will return false is when it if(0) but for containi returning 0 mean it matches the string you want with the string your searching. When it return -1 it mean it couldn't find a match in your string. So you need to check it return value is greater than -1 or does not equal to -1 for contain or containi.

TheNewt 10-26-2006 20:33

Re: Can someone clarify why "containi" did this?
 
Gotcha. =P

k007 10-27-2006 01:01

Re: Can someone clarify why "containi" did this?
 
yeah mystic use equali or equal it's better :) the containi is usaly used to find letters, names.. etc


All times are GMT -4. The time now is 04:45.

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