AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   solved String print help (https://forums.alliedmods.net/showthread.php?t=95974)

TheRadiance 06-29-2009 08:36

solved String print help
 
Hello all.
I have a "stupid" problem with string printing and i don't know how to solve it.

I have a global constant variable named g_table(the only variable named g_table in the script) that contains string "banned_ids".
PHP Code:

//...
new const g_table[] = "banned_ids";
//... 

I added test-print in plugin_init().
PHP Code:

//...
new const g_table[] = "banned_ids";

public 
plugin_init()
{
    
register_plugin("amx_banid""1.0""Radiance");
    
register_concmd("amx_banid""cmd_banid"ADMIN_BAN"<name or #userid> <minutes>");
    
server_print("test-print: %s"g_table);
//... 

And also i added test-print into admin command function.
PHP Code:

//...
public cmd_banid(idlevelcid)
{
    if (!
cmd_access(idlevelcid3))
    {
        return 
1;
    }

    
client_print(idprint_console"test-print: %s"g_table);
//... 

From plugin_init() print i got: test-print: banned_ids
From cmd_banid() print i got: test-print:

g_table is empy in the second case. Why?
And there is no errors/debug in the server's/client's console.
Need help ^^

Thanks in advance.
Sorry for bad English.

Bugsy 06-29-2009 08:45

Re: String print help
 
There is no problem with your string usage. It isn't even possible for the string to get emptied since it is a constant.

See if this works:

console_print( id , "test-print: %s", g_table);

TheRadiance 06-29-2009 09:07

Re: String print help
 
Quote:

Originally Posted by Bugsy (Post 860012)
There is no problem with your string usage. It isn't even possible for the string to get emptied since it is a constant.

See if this works:

console_print( id , "test-print: %s", g_table);

Thanks for quick reply.
At first, i used g_table for SQL Request - SQL_PrepareQuery(g_mysql, "SELECT `id` FROM `%s` ...", g_table)
It worked fine, but after 3 or 4 server-restarts it started return me an empty result.
I've started print all argumentes of this request. Only g_table is empty ^^

Sql connection is ok(localhost). Another plugins works as usual.

Quote:

console_print( id , "test-print: %s", g_table);
Still doesn't work.

P.S. - server platform - STEAM

bug?

Bugsy 06-29-2009 09:17

Re: String print help
 
Are you sure it isn't being defined twice? (local and global)

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "bugsy"

new const g_table[] = "banned_ids"

public 
plugin_init() 
{
    
console_print(0"test-print: %s"g_table); 
    
server_print("test-print: %s"g_table); 
    
TheFunc();
}

public 
TheFunc()
{
    new 
g_table[] = "hi";
    
    
console_print(0"test-print: %s"g_table); 
    
server_print("test-print: %s"g_table); 



TheRadiance 06-29-2009 09:26

Re: String print help
 
Quote:

Are you sure it isn't being defined twice? (local and global)
Yes.
see cmd_current

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <sqlx>

#pragma semicolon 1
#pragma ctrlchar '\'

new Handle:g_mysql;

new 
g_loaded_admins[][32];
new 
g_count;

new const 
g_table[] = "banned_ids";

public 
plugin_init()
{
    
register_plugin("amx_banid""1.0""Radiance");
    
register_concmd("amx_current""cmd_current"ADMIN_BAN"[shows info about banned players]");
    
//register_concmd("amx_unbanid", "cmd_unbanid", ADMIN_BAN, "<name or #steamid>");
    
server_print("test-print: %s"g_table); // here i got: test-print: banned_ids
}

public 
plugin_cfg()
{
    
_sql_init();
    
_load_admins();
}

_sql_init()
{
    new 
cvars[4][16];
    new 
error[64];
    new 
errcode;

    
get_cvar_string("amx_sql_host"cvars[0], 16);
    
get_cvar_string("amx_sql_user"cvars[1], 16);
    
get_cvar_string("amx_sql_pass"cvars[2], 16);
    
get_cvar_string("amx_sql_db"cvars[3], 16);

    new 
Handle:cn_tuple SQL_MakeDbTuple(cvars[0], cvars[1], cvars[2], cvars[3]);
    if ((
g_mysql SQL_Connect(cn_tupleerrcodeerrorsizeof (error))) == Empty_Handle)
    {
        
server_print("[amx_banid.amxx] %s(#%i)"errorerrcode);
        
pause("a");
    }
}

_load_admins()
{
    new 
file[64];

    
get_configsdir(filesizeof (file));
    
format(filesizeof (file), "%s/admins.ini"file);

    if (!
file_exists(file))
    {
        return;
    }

    for (new 
ifile_size(file1); i++)
    {
        new 
nick[32];
        new 
ln;

        
read_file(fileinicksizeof (nick), ln);

        if ((
nick[0] != ';') && ln)
        {
            
g_loaded_admins[g_count++] = nick;
        }
    }
}

bool:_is_priority_admin(id)
{
    new 
nick[32];
    
get_user_name(idnicksizeof (nick));

    for (new 
ig_counti++)
    {
        if (
equal(nickg_loaded_admins[i]))
        {
            return 
true;
        }
    }

    return 
false;
}

public 
cmd_current(idlevelcid)
{
    if (!
cmd_access(idlevelcid1))
    {
        return 
1;
    }

    new 
Handle:q[2];
    

    
q[0] = SQL_PrepareQuery(g_mysql"SELECT `id` FROM `%s`"g_table);
    
q[1] = SQL_PrepareQuery(g_mysql"SELECT `id` FROM `%s` WHERE `unban` = '0'"g_table);

    if (!
SQL_Execute(q[0]) || !SQL_Execute(q[1])) // as i said after 3 or 4 successfull calls of this function plugin started passing through this condition everytime and i started print for test arguments..
    
{
        
//set_fail_state("SQL_Execute() failed.");
        
client_print(idprint_console"test-print: %s"g_table); // here i got: test-print: 
    
}

    new 
i[2];

    
i[0] = SQL_NumResults(q[0]);
    
i[1] = SQL_NumResults(q[1]);

    
SQL_FreeHandle(q[0]);
    
SQL_FreeHandle(q[1]);

    new 
fmt[128];

    if (!
i[0])
    {
        
formatex(fmtsizeof (fmt), "[AMXX] There are no banned players.");
    }
    else
    {
        if (
i[0] == 1)
        {
            if (
i[1])
            {
                
formatex(fmtsizeof (fmt), "[AMXX] There is a player banned permanently.");
            }
            else
            {
                
formatex(fmtsizeof (fmt), "[AMXX] There is a player banned.");
            }
        }
        else
        {
            if (
i[1])
            {
                
formatex(fmtsizeof (fmt), "[AMXX] There are %i players banned. %i of them banned permanently."i[0], i[1]);
            }
            else
            {
                
formatex(fmtsizeof (fmt), "[AMXX] There are %i players banned."i[0]);
            }
        }
    }

    
client_print(idprint_consolefmt);
    return 
1;



Bugsy 06-29-2009 09:41

Re: String print help
 
It has to be some type of bug because there is no way a constant value can be changed during run-time.

Try

#define g_table "banned_ids"

TheRadiance 06-29-2009 10:13

Re: String print help
 
Quote:

Try

#define g_table "banned_ids"
Thx, this works.
But it is still riddle for me.

solved.

Thx, Bugsy


All times are GMT -4. The time now is 15:33.

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