Raised This Month: $51 Target: $400
 12% 

Can anybody help me? (Sqlx Host/exp system)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SkumTomteN
Veteran Member
Join Date: Oct 2013
Location: Asgard
Old 06-04-2014 , 19:37   Can anybody help me? (Sqlx Host/exp system)
Reply With Quote #1

i have 0 experience with mysql, and i got some questions and requests.

do you need to configure the sqlx server first, then write the plugin?.

could you say if its possible to make a sql server from looking at this source code?.

This is the sourcecode for the xp system:
PHP Code:
#include <amxmodx> 
#include <fakemeta> 
#include <fun> 
#include <hamsandwich>
#include <zombieplague>
#include <money>
#include < sqlx >

#define PLUGIN "Level system on XP for zombie plague" 
#define VERSION "1.0" 
#define AUTHOR "Leksa" 

new players_menuplayers[32], numi,accessmenuiName[64], callback,g_system[4][32],g_maxplayers
new cvar_host[4]
 
new 
Handle:g_SqlTuple
new g_Error[512
 
public 
plugin_init( )
{
    
register_plugin PLUGINVERSIONAUTHOR );
    
RegisterHam(Ham_Killed"player""ham_PlayerKilled")
    
g_maxplayers=get_maxplayers()
    
register_dictionary("zp_cs_buymenu.txt")
    
register_clcmd("set_user_exp""transfer_menu")        
    
register_clcmd("transfer""transfer_money")
    
register_clcmd("amx_setexp","clcmd_setexp")
    
set_task(1.0"MySql_Init")
    
cvar_host[0] = register_cvar("zp_exp_host","Skumek:port")
    
cvar_host[1] = register_cvar("zp_exp_user","Skumek")
    
cvar_host[2] = register_cvar("zp_exp_pass","Something")
    
cvar_host[3] = register_cvar("zp_exp_base","Skumek")
}
public 
plugin_natives()
{
register_native("get_max_exp""native_get_max_exp"1)
register_native("get_old_exp""native_get_old_exp"1)
register_native("get_exp""native_get_exp"1)
register_native("get_level""native_get_level"1)
register_native("set_exp""native_set_exp"1)
}
public 
ham_PlayerKilled(victimattackershouldgib)
{
    if ( !
is_user_connected(attacker)) return HAM_IGNORED
    
if((attacker<1)||(attacker>g_maxplayers)||(attacker==victim)) return HAM_IGNORED
    g_system
[0][attacker] ++
    while(
g_system[0][attacker]>=g_system[1][attacker] && g_system[2][attacker] <= 30)
    {
    
g_system[3][attacker] = g_system[1][attacker]
    
g_system[1][attacker] *= 2
    g_system
[1][attacker] += 2    
    g_system
[2][attacker]++
    }
    
message_begin(MSG_ONEget_user_msgid("ScreenFade"), {0,0,0}, attacker)
    
write_short(1<<10)
    
write_short(1<<10)
    
write_short(0x0000)
    
write_byte(0)
    
write_byte(0)
    
write_byte(200)
    
write_byte(75)
    
message_end()
    return 
HAM_IGNORED;
}
public 
native_set_exp(id,value)
{
g_system[0][id]=value    
}
public 
native_get_old_exp(id)
{
return 
g_system[3][id]    
}
public 
native_get_max_exp(id)
{
return 
g_system[1][id]
}
public 
native_get_exp(id)
{
return 
g_system[0][id]    
}
public 
native_get_level(id)
{
return 
g_system[2][id]
}
///
public clcmd_setexp(attacker)
{
g_system[0][attacker]+=500
while(g_system[0][attacker]>=g_system[1][attacker] && g_system[2][attacker] <= 30)
    {
    
g_system[3][attacker] = g_system[1][attacker]
    
g_system[1][attacker] *= 2
    g_system
[1][attacker] += 2    
    g_system
[2][attacker]++
    }    
}
public 
client_putinserver(id)
{
g_system[2][id] = 1
g_system
[0][id] = 0
g_system
[1][id] = 4
g_system
[3][id] = 0
Load_MySql
(id)    
}
public 
transfer_menu(id)
{
        
get_players(playersnum"c")
       
        if (
num <= 1)
        {
                return 
PLUGIN_HANDLED
        
}
       
        new 
tempname[32], info[10]
       
        
players_menu menu_create("Players""players_menu_handler")
       
        for(
0numi++)
        {
                if(
players[i] == id)
                        continue
               
                
get_user_name(players[i], tempname31)
                
num_to_str(players[i], info9)
                
menu_additem(players_menutempnameinfo0)
        }
       
        
menu_setprop(players_menuMPROP_EXITMEXIT_ALL)
       
        
menu_display(idplayers_menu0)
        return 
PLUGIN_CONTINUE
}
 
public 
players_menu_handler(idplayers_menuitem)
{
        if(
item == MENU_EXIT)
        {
                
menu_destroy(players_menu)
                return 
PLUGIN_HANDLED
        
}
       
        new 
data[6]
       
        
menu_item_getinfo(players_menuitemaccessmenudatacharsmax(data), iNamecharsmax(iName), callback)
       
        new 
player str_to_num(data)
       
        
client_cmd(id"messagemode ^"transfer %i^""player)
       
        return 
PLUGIN_CONTINUE
}
 
public 
transfer_money(id)
{
        new 
param[8]
        
read_argv(2paramcharsmax(param))
       
        for (new 
xstrlen(param); x++)
        {
                if(!
isdigit(param[x]))
                {
                        return 
PLUGIN_HANDLED
                
}
        }
       
        new 
amount str_to_num(param)
 
        if (!
amount )
        {
        return 
PLUGIN_HANDLED
        
}
       
        
read_argv(1paramcharsmax(param))
        new 
player str_to_num(param)
       
        
g_system[0][player] += amount
        
while(g_system[0][player]>=g_system[1][player] && g_system[2][player] <= 30)
    {
    
g_system[3][player] = g_system[1][player]
    
g_system[1][player] *= 2
    g_system
[1][player] += 2    
    g_system
[2][player]++
    }
       
        return 
PLUGIN_HANDLED
}
 
public 
client_disconnectiPlayer )
{
    
Save_MySqliPlayer )
}
public 
MySql_Init()
{
    new 
Host[50],User[50],Pass[50],Db[50]
    
get_pcvar_string(cvar_host[0], Host49)
    
get_pcvar_string(cvar_host[1], User49)
    
get_pcvar_string(cvar_host[2], Pass49)
    
get_pcvar_string(cvar_host[3], Db49)
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    new 
ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
       
    new 
Handle:Queries
    Queries 
SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS buymenu (steamid varchar(32),money INT(11),exp INT(11))")
 
    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
       
    }
    
SQL_FreeHandle(Queries)
    
SQL_FreeHandle(SqlConnection)  
}
 
public 
plugin_end()
{
    
SQL_FreeHandle(g_SqlTuple)
}
 
public 
Load_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
   
    new 
Data[1]
    
Data[0] = id
    format
(szTemp,charsmax(szTemp),"SELECT * FROM `buymenu` WHERE (`buymenu`.`steamid` = '%s')"szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}
 
public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }
 
    new 
id
    id 
Data[0]
   
    if(
SQL_NumResults(Query) < 1)
    {       
        new 
szSteamId[32]
        
get_user_authid(idszSteamIdcharsmax(szSteamId))
           
        new 
szTemp[512]
        
format(szTemp,charsmax(szTemp),"INSERT INTO `buymenu` ( `steamid` , `money` , `exp`)VALUES ('%s','%i','0');",szSteamId,get_cvar_num("zp_cs_money_start"))
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    }
    else
    {
        new 
money SQL_ReadResult(Query1)
        
zp_set_money(idmoney)
        
g_system[0][id]         = SQL_ReadResult(Query2)
    }
   
    return 
PLUGIN_HANDLED
}
 
public 
Save_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
format(szTemp,charsmax(szTemp),"UPDATE `buymenu` SET `money` = '%i' ,  `exp` = '%i'  WHERE `buymenu`.`steamid` = '%s';",zp_get_money(id),g_system[0][id], szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}
 
public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
   
    return 
PLUGIN_HANDLED
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
*/ 
__________________
Contact: Steam
Videos: Youtube
SkumTomteN is offline
Old 06-19-2014, 10:20
Ayoub.nasr
This message has been deleted by YamiKaitou. Reason: unrelated to thread
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 05:46.


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