Raised This Month: $32 Target: $400
 8% 

StrContains does not work fully


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 05-11-2014 , 19:01   StrContains does not work fully
Reply With Quote #1

Function StrContains does not work fully

Code

PHP Code:
while(ReadDirEntry(dirbuffersizeof(buffer), type)) 

    if(
StrEqual(buffer"1.wav"false))
    {
        
PrintToServer("Dir %s - %i"buffertype);
    }

Result:

PHP Code:
Dir .
Dir .. - 1
Dir 1.wav 

Code

PHP Code:
while(ReadDirEntry(dirbuffersizeof(buffer), type)) 

    if(
StrContains(buffer".wav"false))
    {
        
PrintToServer("Dir %s - %i"buffertype);
    }

Result:

PHP Code:
Dir .
Dir .. - 1
Dir 1.wav 
2
Dir 10.wav 
2
Dir 2.wav 
2
Dir 3.wav 
2
Dir 4.wav 
2
Dir 5.wav 
2
Dir 6.wav 
2
Dir 7.wav 
2
Dir 8.wav 
2
Dir 9.wav 
2
Dir czsbrasil_facadazm
.mp3 2
Dir round_start
.wav 
How make it work fully?

Regards.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM

Last edited by rodrigo286; 05-11-2014 at 19:04.
rodrigo286 is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 05-11-2014 , 19:06   Re: StrContains does not work fully
Reply With Quote #2

PHP Code:
if(StrContains(buffer".wav"false) != -1
arthurdead is offline
Internet Bully
Member
Join Date: Apr 2014
Old 05-11-2014 , 19:11   Re: StrContains does not work fully
Reply With Quote #3

PHP Code:
StrContains

Syntax
:
native StrContains(const String:str[], const String:substr[], bool:caseSensitive=true);

Usage:
 
str            String to search in.
 
substr        Substring to find inside the original string.
 
caseSensitive    If true (default), search is case sensitive. If falsesearch is case insensitive.
Notes:
Tests whether a string is found inside another string.

Return:
-
1 on failure (no match found). Any other value indicates a position in the string where the match starts
Internet Bully is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 05-11-2014 , 19:12   Re: StrContains does not work fully
Reply With Quote #4

StrContains works nicely, read doc.
KissLick is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 05-11-2014 , 20:47   Re: StrContains does not work fully
Reply With Quote #5

I can understand why this is happening. The name StrContains is misleading, because it doesn't return whether the string exists, but the position of the sub string.

It should perhaps be renamed to StringPosition or something like that. The StringContains function should return true or false, nothing else. Though, we're probalby stuck with StringContains this way, since changing it would break compatibility.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)

Last edited by rhelgeby; 05-11-2014 at 20:49.
rhelgeby is offline
Send a message via MSN to rhelgeby
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 05-11-2014 , 22:23   Re: StrContains does not work fully
Reply With Quote #6

Thanks, this work.

Regards.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM

Last edited by rodrigo286; 05-11-2014 at 22:37.
rodrigo286 is offline
canadianjeff
BANNED
Join Date: Sep 2016
Old 07-02-2021 , 00:50   Re: StrContains does not work fully
Reply With Quote #7

how do I deal with StrContains OR StrContains??? this example does not work

Code:
				if (StrContains(modelName, "survivor_gambler.mdl") || StrContains(modelName, "survivor_manager.mdl") == true){
					SOUND_CLIP = ZOMB_TANK_GROWL;
					PrintToChat(client, "#1");
				}
				else if (StrContains(modelName, "survivor_producer.mdl") || StrContains(modelName, "survivor_biker.mdl") == true){
					SOUND_CLIP = ZOMB_HUNTER_GROWL;
					PrintToChat(client, "#2");
				}
				else if (StrContains(modelName, "survivor_coach.mdl") || StrContains(modelName, "survivor_namvet.mdl") == true){
					SOUND_CLIP = ZOMB_SPITTER_GROWL;
					PrintToChat(client, "#3");
				}
				else if (StrContains(modelName, "survivor_mechanic.mdl") || StrContains(modelName, "survivor_teenangst.mdl") == true){
					SOUND_CLIP = ZOMB_JOCKEY_GROWL;
					PrintToChat(client, "#4");
				}
				else
				{
					PrintToChat(client, "NO MATCH");
				}
canadianjeff is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 07-02-2021 , 01:22   Re: StrContains does not work fully
Reply With Quote #8

StrContains is really bad for multiple string checks like this because it goes through every character. Avoid doing that.

Instead, if you're definitely retrieving a client/survivors model use this:
PHP Code:
// Get survivor model
GetEntPropString(clientProp_Data"m_ModelName"modelsizeof(model));

switch( 
model[29] )
{
    case 
'c': {} // Coach
    
case 'b': {} // Nick
    
case 'h': {} // Ellis
    
case 'd': {} // Rochelle
    
case 'v': {} // Bill
    
case 'e': {} // Francis
    
case 'a': {} // Louis
    
case 'n': {} // Zoey

P.S nice necro.
P.P.S read the API on what StrContains returns, the way you're using is incorrect because you're expecting a bool like the OP of this thread.
__________________

Last edited by Silvers; 07-02-2021 at 01:23.
Silvers is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 07-15-2021 , 07:10   Re: StrContains does not work fully
Reply With Quote #9

canadianjeff, read docs.
Code:
if( StrContains(modelName, "survivor_gambler.mdl", false) != -1 )
...
if you like going that way.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:10.


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