Raised This Month: $32 Target: $400
 8% 

Cvars


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
spiider
AlliedModders Donor
Join Date: Jan 2010
Old 01-30-2010 , 12:00   Cvars
Reply With Quote #1

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.

Last edited by spiider; 01-30-2010 at 12:48. Reason: adding some comment's
spiider is offline
spiider
AlliedModders Donor
Join Date: Jan 2010
Old 01-30-2010 , 13:08   Re: Cvars
Reply With Quote #2

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)) 

Last edited by spiider; 01-30-2010 at 14:13.
spiider 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 07:22.


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