Raised This Month: $ Target: $400
 0% 

Could someone correct this small plugin?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
OldWolf
Member
Join Date: Mar 2009
Old 04-05-2009 , 04:28   Could someone correct this small plugin?
Reply With Quote #1

Howdy,

I wrote this small plugin tonight (or maybe I should say modified it from a much larger one) as an intro for myself to Pawn. Unfortunately I seemed to have made at least one mistake (probably more).

It compiles with no errors, and shows up on my plugin list, but it doesn't seem to actually load up the cvars from my database (though it did correctly create the table).

I added the command so that I could test it while I was in the server, and whenever I run it it also fails to get my cvars from the database. In addition, it seems to freeze up the server for about 10 seconds, where I get a "Warning, connection problem" in the upper right hand corner... then it unfreezes and continues to work.

Here it is:
Code:
/* Plugin generated by AMXX-Studio */

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

#define PLUGIN "SQL CVARs"
#define VERSION "0.1"
#define AUTHOR "oldwolf"

#define TABLE "cvars"


public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    register_dictionary("sql_cvars.txt")
    
    register_concmd("amx_check_cvars","get_cvars",ADMIN_ADMIN,"Nothing special.") 

    get_cvars()
    
}


public get_cvars()
{
    new error[128], type[12], errno
    
    new Handle:info = SQL_MakeStdTuple()
    new Handle:sql = SQL_Connect(info, errno, error, 127)
    
    SQL_GetAffinity(type, 11)
    
    if (sql == Empty_Handle)
    {
        server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_CON", error)

        return PLUGIN_HANDLED
    }
    
    
    new Handle:query
    
    SQL_QueryAndIgnore(sql, "CREATE TABLE IF NOT EXISTS `%s` ( `cvar_key` VARCHAR( 32 ) NOT NULL, `cvar_value` VARCHAR( 32 ) NOT NULL, `status` TINYINT( 1 ) NOT NULL ) COMMENT = 'AMX Mod X CVARS'", TABLE)
    query = SQL_PrepareQuery(sql,"SELECT `cvar_key`,`cvar_value` FROM `%s` WHERE `status` = 1", TABLE)


    if (!SQL_Execute(query))
    {
        SQL_QueryError(query, error, 127)
        server_print("[AMXX] %L", LANG_SERVER, "CANT_LOAD_CVARS", error)
    } else if (!SQL_NumResults(query)) {
        server_print("[AMXX] %L", LANG_SERVER, "NO_CVARS")
    } else {
        
        new CVARS = 0

        /** do this incase people change the query order and forget to modify below */
        new k_cvar_key = SQL_FieldNameToNum(query, "cvar_key")
        new k_cvar_value = SQL_FieldNameToNum(query, "cvar_value")

        
        new cvar_key[44];
        new cvar_value[44];


        
        while (SQL_MoreResults(query))
        {
            SQL_ReadResult(query, k_cvar_key, cvar_key, sizeof(cvar_key)-1);
            SQL_ReadResult(query, k_cvar_value, cvar_value, sizeof(cvar_value)-1);

    
            register_cvar(cvar_key,cvar_value);
    
            ++CVARS;
            SQL_NextRow(query)
        }
    
        if (CVARS == 1)
        {
            server_print("[AMXX] %L", LANG_SERVER, "CVAR_LOADED")
        }
        else
        {
            server_print("[AMXX] %L", LANG_SERVER, "CVARS_LOADED", CVARS)
        }
        
        SQL_FreeHandle(query)
        SQL_FreeHandle(sql)
        SQL_FreeHandle(info)
    }
    
    return PLUGIN_HANDLED
}
If you could point out all of my mistakes, I'm sure it would help me learn... plus I'd actually like this plugin to work, lol. I plan to expand it with other features, such as the ability to add/change a cvar in the midst of a map.

Thanks!
OldWolf is offline
 



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 02:18.


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