AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Cvars (https://forums.alliedmods.net/showthread.php?t=117259)

spiider 01-30-2010 12:00

Cvars
 
hi, i'm new in amx i read in forums about cvars but i don't understand why my code don't work.
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <dbi>
#include <engine>
#include <csx>

#define PLUGIN "Change Name"
#define VERSION "1.0"
#define AUTHOR "spiider"


#define CVAR_CHHOST            "host"
#define CVAR_CHUSER            "user"
#define CVAR_CHPASS            "pass"
#define CVAR_CHDB            "db"
#define TABLE                "users"


new names[32// id->playername
new g_regged[33]
// vars going here
new gate_matchID
public pug_cvar_shield 1;

public 
plugin_modules() {
    
require_module("engine")
    
require_module("dbi")
}

// here goes check client and change name :)

public client_authorized(id) {
   
    
    
g_regged[id] = checkregister(authid)
    
    if (
g_regged[id]) {
        
    } else {
   
// here say your steamid is not registered for this game
        
server_cmd("kick #%d A tua SteamID %s nao esta registada para este jogo."get_user_userid(id), authid)
    }
    
    
    

    return 
true
}

// here goes check if is registered for this game
bool:checkregister(authid[]) {
    new 
Sql:sql
    
if (!connect(sql))
        return 
false
    
const LONGER 128
    
new query[LONGER 1]
    new 
test
// here is my problem i can't get value from matchID cvar :(

    
test get_pcvar_num(gate_matchID)
    
format(queryLONGER"SELECT `playerID` FROM players WHERE `steamID` = ^"%s^" AND `matchID` = ^"%s^" LIMIT 1"authid,test)
    new 
Result:result dbi_query(sqlquery)
    if (
result <= RESULT_FAILED) {
        new 
error[256]
        
dbi_error(sqlerror255)
        
log_amx("Error while quering SQL server for %s, can't check registration: %s"authiderror)
        
dbi_close(sql)
        return 
false
    
}
    else if (
result == RESULT_NONE) {
        
dbi_close(sql)
        return 
false
    
}

    if (!
dbi_nextrow(result)) {
        
dbi_close(sql)
        return 
false // not register for this game
    
}

    
dbi_close(sql)

    return 
true
}

// here goes the database connection
bool:connect(&Sql:sql) {
    const 
LEN 128
    
new host[LEN], user[LEN], pass[LEN], db[LEN], error_msg[LEN]

    
get_cvar_string(CVAR_CHHOSThostLEN 2)
    
get_cvar_string(CVAR_CHUSERuserLEN 2)
    
get_cvar_string(CVAR_CHPASSpassLEN 2)
    
get_cvar_string(CVAR_CHDBdbLEN 2)

    
sql dbi_connect(hostuserpassdberror_msgLEN 2)

    if (!
sql) {
        
log_amx("ERROR - Can't connect to SQL db: %s"error_msg)
        return 
false
    
}

    return 
true
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
    
register_cvar(CVAR_CHHOST"host")
    
register_cvar(CVAR_CHUSER"user")
    
register_cvar(CVAR_CHPASS"password")
    
register_cvar(CVAR_CHDB"db")
    
gate_matchID register_cvar("matchID""1")
    
//  get_cvar_pointer ("matchID")

    
new Sql:sql
    
if (!connect(sql)) {
        
log_amx("Couldn't connect to SQL database at plugin_init! Pausing plugin.")
        
pause("a")
        return
    }
    
    else
        
server_print("[%s] Connected successfully to SQL database."PLUGIN)
    
dbi_close(sql)
    
    


well, i want get the value from cvar and when a player join server, read value and check if steamid is reged in the database with the paremeters.

spiider 01-30-2010 13:08

Re: Cvars
 
well fixed :)

PHP Code:

gate_matchID get_cvar_pointer "matchID" )
    
format(queryLONGER"SELECT `playerID` FROM players WHERE `steamID` = ^"%s^" AND `matchID` = '%d' LIMIT 1"authid,get_pcvar_num(gate_matchID)) 



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

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