Raised This Month: $51 Target: $400
 12% 

StrEquals not working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ninncore
Member
Join Date: Sep 2015
Old 11-05-2015 , 15:29   StrEquals not working
Reply With Quote #1

Quick description: StrEquals dont work. SteamId is the same (compared by me). Can print out the SteamId after StrContains but not after StrEquals. Hope you can help out.

Code:
    // Admin Clantag SQL
    if (g_bAdminClantag)
    {
        new String:SteamId[64];
        new String:Error[70];
        new DB = SQL_Connect("sourcebans", true, Error, sizeof(Error));
        new Handle:query = SQL_Query(DB, "SELECT `authid` FROM `sb_admins` WHERE srv_group='Admin'")
        
        if (query == INVALID_HANDLE)
        {
            new String:error[255]
            SQL_GetError(DB, error, sizeof(error))
            PrintToServer("Failed to query (error: %s)", error)
        }
        
        else {
            while (SQL_FetchRow(query))
            {
                if (SQL_FetchString(query, 0, SteamId, 64))
                {
                    if ((StrContains(SteamId,"STEAM",true)) && (StrEqual(SteamId,g_szSteamID[client])))
                    {
                        Format(g_pr_chat_coloredrank[client], 32, "%s %cADMIN%c",g_pr_chat_coloredrank[client],LIMEGREEN,WHITE);
                        Format(g_pr_rankname[client], 32, "ADMIN");
                    }
                }
            }
        }
    }
ninncore is offline
SoulSharD
Member
Join Date: Oct 2013
Location: United Kingdom
Old 11-05-2015 , 15:34   Re: StrEquals not working
Reply With Quote #2

StrEqual is case sensitive by default, is it possible that SteamId and g_szSteamID are different in terms of upper and lower case letters?
__________________

SoulSharD is offline
ninncore
Member
Join Date: Sep 2015
Old 11-05-2015 , 15:39   Re: StrEquals not working
Reply With Quote #3

Quote:
StrEqual is case sensitive by default, is it possible that SteamId and g_szSteamID are different in terms of upper and lower case letters?
g_szSteamId is case sensitive, it's from the cksurf plugin, I also tested it with (StrEqual(SteamId,g_szSteamID[client],false) yet still the same result, it even refuses to print the SteamId to the console after the StrEqual invoke.
ninncore is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 11-05-2015 , 15:57   Re: StrEquals not working
Reply With Quote #4

the if is failing because StrContains is returning 0
Miu is offline
Godis
Senior Member
Join Date: Jan 2014
Old 11-05-2015 , 16:07   Re: StrEquals not working
Reply With Quote #5

StrContains is not a boolean, it returns the position in the string of the first match, so, instead you should be checking that StrContains does not return -1
Godis is offline
ninncore
Member
Join Date: Sep 2015
Old 11-05-2015 , 16:14   Re: StrEquals not working
Reply With Quote #6

Thx for helping c: I'm now just removed the StrContains since I'm kinda retarded not to check that it returned not an boolean value... case closed.

Last edited by ninncore; 11-05-2015 at 16:23.
ninncore is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-05-2015 , 16:20   Re: StrEquals not working
Reply With Quote #7

Quote:
Originally Posted by ninncore View Post
Thx for helping c: I'm now just removed the StrContains since I'm kinda retarded not to check that it returned an boolean value... case closed.
We've all made that mistake before.

It might be because the name implies it returns a boolean. That's why the function's name is strpos or something similar in other languages, which implies that it returns the position number instead of a boolean.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 11-06-2015 , 05:00   Re: StrEquals not working
Reply With Quote #8

Yup I definitly already smashed my head on this function.
h3bus is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 11-06-2015 , 11:57   Re: StrEquals not working
Reply With Quote #9

Always read the function documentation of a native you are using. Don't assume it does exactly what the name says on the tin. I believe everybody was bitten in the ass by this function one way or another.
Potato Uno is offline
ninncore
Member
Join Date: Sep 2015
Old 11-14-2015 , 23:15   Re: StrEquals not working
Reply With Quote #10

Sorry to bring up this thread again up, but having another problem, memory leaks...
I tried to fix it for 2 days now, without success, idk really know what is wrong with the handles... since to me it looks normal.

Code:
    if (g_bAdminClantag)
    {
        new String:SteamId[32], String:Error[70];
        new DB = SQL_Connect("sourcebans", true, Error, sizeof(Error));
        new Handle:query = SQL_Query(DB, "SELECT `authid` FROM `sb_admins` WHERE srv_group='ADMIN'")
        
        if (query == INVALID_HANDLE)
        {
            new String:error[255]
            SQL_GetError(DB, error, sizeof(error))
            PrintToServer("Failed to query (error: %s)", error)
        }
        
        else
        {
            if (SQL_FetchRow(query))
            {
                if (SQL_FetchString(query, 0, SteamId, 32))
                {
                    if (StrEqual(SteamId,g_szSteamID[client]))
                    {
                        Format(g_pr_chat_coloredrank[client], 32, "%s %cADMIN%c",g_pr_chat_coloredrank[client],LIMEGREEN,WHITE);
                        Format(g_pr_rankname[client], 32, "ADMIN");
                    }
                }
            }
        } CloseHandle(query);
    }
ninncore 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 06:47.


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