AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   StrEquals not working (https://forums.alliedmods.net/showthread.php?t=274302)

ninncore 11-05-2015 15:29

StrEquals not working
 
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");
                    }
                }
            }
        }
    }


SoulSharD 11-05-2015 15:34

Re: StrEquals not working
 
StrEqual is case sensitive by default, is it possible that SteamId and g_szSteamID are different in terms of upper and lower case letters?

ninncore 11-05-2015 15:39

Re: StrEquals not working
 
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.

Miu 11-05-2015 15:57

Re: StrEquals not working
 
the if is failing because StrContains is returning 0

Godis 11-05-2015 16:07

Re: StrEquals not working
 
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

ninncore 11-05-2015 16:14

Re: StrEquals not working
 
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.

Powerlord 11-05-2015 16:20

Re: StrEquals not working
 
Quote:

Originally Posted by ninncore (Post 2360250)
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.

h3bus 11-06-2015 05:00

Re: StrEquals not working
 
Yup I definitly already smashed my head on this function.

Potato Uno 11-06-2015 11:57

Re: StrEquals not working
 
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.

ninncore 11-14-2015 23:15

Re: StrEquals not working
 
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);
    }



All times are GMT -4. The time now is 19:49.

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