Raised This Month: $248 Target: $400
 62% 

Change nvault to sql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 09-14-2020 , 00:34   Change nvault to sql
Reply With Quote #1

Hi everybody, can someone change this code to sql pls? .... thx in advance

PHP Code:
#include <amxmodx>
#include <nvault>

//Uncomment 'IM_USING_ZP50' if your server is running ZP50 and above.
//#define IM_USING_ZP50
#if defined IM_USING_ZP50
native zp_ammopacks_get(id)
native zp_ammopacks_set(idamount)
#else
native zp_get_user_ammo_packs(id)
native zp_set_user_ammo_packs(idamount)
#endif

//Your vault name
#define VAULT_NAME "apstore"

//Max player's ammopack that can be save in vault.
#define MAX_AMMOPACK 9999

//Max day player's ammopack can be stay in vault, set 0 = permanent.
#define DAY_PRUNE 15
new hVaultHandlebool:bIsLoaded[33], szSteamid[33][35]

public 
plugin_init()
{
    
register_plugin("ZP AP Store""0.0.1""wbyokomo")
}

public 
plugin_cfg()
{
    
hVaultHandle nvault_open(VAULT_NAME)
    if(
hVaultHandle == INVALID_HANDLE)
    {
        new 
szText[128]
        
formatex(szText127"Error opening '%s' nVault."VAULT_NAME)
        
set_fail_state(szText)
    }
    
    new 
day DAY_PRUNE
    
if(day 0nvault_prune(hVaultHandle0get_systime() - (DAY_PRUNE 86400));
}

public 
plugin_end()
{
    
nvault_close(hVaultHandle)
}

public 
client_putinserver(id)
{
    if(
is_user_hltv(id)) return;
    if(
is_user_bot(id)) return;
    
    
get_user_authid(idszSteamid[id], 34)
    
LoadData(id)
}

public 
client_disconnect(id)
{
    
SaveData(id)
    
bIsLoaded[id] = false
}

LoadData(id)
{
    new 
szKey[40]
    
formatex(szKey39"%sZPAP"szSteamid[id])
    new 
iAmmo nvault_get(hVaultHandleszKey)
    
#if defined IM_USING_ZP50
    
zp_ammopacks_set(idiAmmo)
    
#else
    
zp_set_user_ammo_packs(idiAmmo)
    
#endif
    
bIsLoaded[id] = true
}

SaveData(id)
{
    if(!
bIsLoaded[id]) return;
    
    
#if defined IM_USING_ZP50
    
new ap zp_ammopacks_get(id)
    
#else
    
new ap zp_get_user_ammo_packs(id)
    
#endif
    
if(ap MAX_AMMOPACKap MAX_AMMOPACK;
    new 
szAmmo[12], szKey[40]
    
formatex(szKey39"%sZPAP"szSteamid[id])
    
formatex(szAmmo11"%d"ap)
    
nvault_set(hVaultHandleszKeyszAmmo)

wicho is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-17-2020 , 21:14   Re: Change nvault to sql
Reply With Quote #2

Untested
PHP Code:

#include <amxmodx>
#include <sqlx>

//Uncomment 'IM_USING_ZP50' if your server is running ZP50 and above.
//#define IM_USING_ZP50

#if defined IM_USING_ZP50
native zp_ammopacks_get(id)
native zp_ammopacks_set(idamount)
#else
native zp_get_user_ammo_packs(id)
native zp_set_user_ammo_packs(idamount)
#endif

#define MAX_PLAYERS 32

//Max player's ammopack that can be save in vault.
#define MAX_AMMOPACK 9999

//Max day player's ammopack can be stay in vault, set 0 = permanent.
#define DAY_PRUNE 15

new const szHost[] = "";
new const 
szUser[] = "";
new const 
szPass[] = "";

enum QueryTypes
{
    
qtCreateTable,
    
qtPruneDB,
    
qtLoadAmmo,
    
qtSaveAmmo
}

new const 
Query_CreateTable[] = "CREATE TABLE IF NOT EXISTS tblStore (ID INTEGER PRIMARY KEY AUTOINCREMENT, SteamID VARCHAR(34) UNIQUE, Time_Stamp INTEGER, Ammo INTEGER);";
new const 
Query_PruneDatabase[] = "DELETE FROM tblStore WHERE Time_Stamp < %d;";
new const 
Query_LoadAmmo[] = "SELECT Ammo FROM tblStore WHERE SteamID='%s';";
new const 
Query_SaveAmmo[] = "REPLACE INTO tblStore (SteamID, Time_Stamp, Ammo) VALUES ('%s',%d,%d);";

enum _:QueryInfo
{
    
QueryTypes:qiQueryType,
    
qiPlayerID
}

new 
bool:bIsLoadedMAX_PLAYERS ], szSteamidMAX_PLAYERS ][ 35 ];
new 
Handle:g_SQLTuple g_szBuffer256 ];

public 
plugin_init()
{
    
register_plugin"ZP AP Store SQL" "0.0.1" "wbyokomo/bugsy" );
}

public 
plugin_cfg()
{
    
SQL_SetAffinity"sqlite" );
    
g_SQLTuple SQL_MakeDbTupleszHost szUser szPass "ZPAPStore" );
    
    new 
Handle:SQLConnection ErrorCode;
    
SQLConnection SQL_Connectg_SQLTuple ErrorCode g_szBuffer charsmaxg_szBuffer ) );
    
    if( 
SQLConnection == Empty_Handle 
        
set_fail_stateg_szBuffer );
    
    
RunQuerySQLConnection Query_CreateTable );
    
    
#if DAY_PRUNE > 0  
    
formatexg_szBuffer charsmaxg_szBuffer ) , Query_PruneDatabase get_systime() - ( 86400 DAY_PRUNE ) );
    
RunQuerySQLConnection g_szBuffer );
    
#endif
}

public 
plugin_end()
{
    
SQL_FreeHandleg_SQLTuple );
}

public 
client_putinserver(id)
{
    if ( !
is_user_hltv(id) && !is_user_botid ) ) 
    {
        
get_user_authidid szSteamidid] , charsmaxszSteamid[] ) );
        
LoadDataid );
    }
}

#if AMXX_VERSION_NUM < 190
public client_disconnectid )
#else
public client_disconnectedid )
#endif
{
    
SaveDataid );
    
bIsLoadedid ] = false;
}

LoadDataid )
{
    new 
QueryDataQueryInfo ];
    
    
QueryDataqiQueryType ] = qtLoadAmmo;
    
QueryDataqiPlayerID ] = id;
    
    
formatexg_szBuffer charsmaxg_szBuffer ) , Query_LoadAmmo szSteamidid ] );
    
SQL_ThreadQueryg_SQLTuple "QueryHandle" g_szBuffer QueryData sizeofQueryData ) );
}

SaveDataid )
{
    if ( 
bIsLoadedid ] ) 
    {
        
#if defined IM_USING_ZP50
        
new ap minzp_ammopacks_getid ) , MAX_AMMOPACK );
        
#else
        
new ap minzp_get_user_ammo_packsid ), MAX_AMMOPACK );
        
#endif
        
        
formatexg_szBuffer charsmaxg_szBuffer ) , Query_SaveAmmo szSteamidid ]  , get_systime() , ap );
        
SQL_ThreadQueryg_SQLTuple "QueryHandle" g_szBuffer );
    }
}

RunQueryHandle:SQLConnection , const szQuery[] )
{
    new 
Handle:Query SQL_PrepareQuerySQLConnection szQuery );
    
    if( !
SQL_ExecuteQuery ) )
    {
        
SQL_QueryErrorQuery g_szBuffer charsmaxQuery_CreateTable ) );
        
set_fail_stateg_szBuffer );
    }
}

public 
QueryHandleFailState Handle:Query , const Error[] , Errcode , const DataQueryInfo ] , DataSize )
{
    if( 
FailState == TQUERY_CONNECT_FAILED )
    {
        
set_fail_state"Could not connect to SQL database." );
        return;
    }
    else if( 
FailState == TQUERY_QUERY_FAILED )
    {
        
log_amx"Query error: %s" Error );
        
set_fail_stateg_szBuffer );
        return;
    }
    
    new 
iAmmo id  =  DataqiPlayerID ];
    
    switch ( 
DataqiQueryType ] )
    {
        case 
qtLoadAmmo:
        {
            if ( 
SQL_NumResultsQuery ) )
            {
                
iAmmo SQL_ReadResultQuery );
                
                
#if defined IM_USING_ZP50
                
zp_ammopacks_setid iAmmo );
                
#else
                
zp_set_user_ammo_packsid iAmmo );
                
#endif    
                
                
bIsLoadedid ] = true;        
            }
        }
    }

__________________

Last edited by Bugsy; 09-17-2020 at 21:17.
Bugsy is offline
Reply


Thread Tools
Display Modes

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:49.


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