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

Need help to fix this sql bank plugin (asap please)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
vikasvishwakarma
Member
Join Date: Mar 2013
Old 01-09-2017 , 20:36   Need help to fix this sql bank plugin (asap please)
Reply With Quote #1

i got this code from doni which works great but it has a small problem is any one can fix it please
as i have found this is the only best working plugin code till now.

the problem it gives is that when player is in the server it records the ammo and stores in the bank fine but if the player is been away for more then 1 to 2 hours it resets their ammo to 0.
if anyone can fix this and make it store for at least for 2 month will be really helpful.

Code:
/*********************USE EXTRA MIRROR Protection SYSTEM*********************/

/*********************mmoru.com/board/showthread.php?t=594787*********************/

/*********************Developed by Zombie-Arena.ru*********************/

/*********************Developed by Zombie-Arena.ru*********************/

#include <amxmodx>

#include <amxmisc>

#include <hamsandwich>

#include <fakemeta_util>

#include <dhudmessage>

#include <zombieplague>

#include <sqlx>



new g_PlayerMoney[33];



new const Host[]= "db2.myarena.ru",User[]= "",Pass[]= "",Db[]= "",Table[] = "zp_data",AuthRow[] = "steam",MoneyRow[]= "user_money",LevelRow[] = "user_level",ExpRow[] = "user_exp";

new Handle:SQL_Tuple,g_szSteam[33][35];



public plugin_cfg(){

	register_plugin("SimpleAmmoSave", "1.0nb", "Predat0r/Shel[Zombie-Arena.ru]")

	set_task(15.0, "Load_Debug")

}



public Load_Debug(){

	new g_Error[512]

	SQL_Tuple = SQL_MakeDbTuple(Host, User, Pass, Db);

	new ErrorCode,Handle:SqlConnection = SQL_Connect(SQL_Tuple,ErrorCode,g_Error,charsmax(g_Error))

	if(SqlConnection == Empty_Handle) 

		set_fail_state(g_Error)

	if(!SQL_TableExists(SqlConnection, Table)){

		new Handle:Queries;

		new Query[1024]

		format( Query, 1023, "CREATE TABLE `%s`.`%s` (`%s` VARCHAR(40) CHARACTER SET cp1250 COLLATE cp1250_general_ci NOT NULL, `%s` INT NOT NULL, `%s` INT NOT NULL, `%s` INT NOT NULL, PRIMARY KEY (`%s`))", Db, Table, AuthRow, MoneyRow, LevelRow, ExpRow, AuthRow);

		Queries = SQL_PrepareQuery( SqlConnection, Query )

		if(!SQL_Execute(Queries)){

			SQL_QueryError(Queries,g_Error,charsmax(g_Error))

			set_fail_state(g_Error);

		}

		SQL_FreeHandle(Queries)	

	}

	SQL_FreeHandle(SqlConnection)

}



public QueryHandler(FailState, Handle:Query, Error[], ErrCode, data[], size, Float:querytime){

	if(!CheckQuery(FailState, ErrCode, Error)) {

		SQL_FreeHandle(Query);

		return PLUGIN_HANDLED;

	}

	static id; id = data[0];

	

	if(SQL_NumResults(Query) < 1) {

		new Query[270]

		format( Query, 255, "INSERT INTO `%s` ( `%s` , `%s`, `%s`, `%s`) VALUES ('%s', '0', '0', '0');", Table, AuthRow, MoneyRow, LevelRow, ExpRow, g_szSteam[id] );

		SQL_ThreadQueryFormatNoData(SQL_Tuple, "IgnoreHandle", Query )

	}

	else {

		zp_set_user_ammo_packs(id,zp_get_user_ammo_packs(id) + SQL_ReadResult(Query, 0))

		if(get_user_money(id)==0 || equal(g_szSteam[id], "STEAM_ID_LAN") || equal(g_szSteam[id], "VALVE_ID_LAN"))

			set_user_money(id, 0)

	}

	SQL_FreeHandle(Query);

	return PLUGIN_CONTINUE;

}

public LoadData(task){

	new id=task-73718

	if(!is_user_connected(id)) 

		return;

	g_szSteam[id][0] = '^0'

	set_user_money(id, 0)

	get_user_authid(id, g_szSteam[id] ,charsmax(g_szSteam))

	new Query[1024]

	static data[1]; data[0]=id

	format( Query, 1023, "SELECT `%s`,`%s`,`%s` FROM `%s` WHERE `%s` = '%s'", MoneyRow, LevelRow, ExpRow, Table, AuthRow, g_szSteam[id] );

	SQL_ThreadQueryFormat(SQL_Tuple,"QueryHandler", Query, data, 1 )	

}

public Save_Data(id){

	static iValue;

	iValue = zp_get_user_ammo_packs(id)

	SQL_ThreadQueryFormatNoData(SQL_Tuple, "IgnoreHandle", "UPDATE `%s` SET `%s` = '%i', `%s` = '0', `%s` = '0' WHERE `%s`.`%s` = '%s'", Table, MoneyRow, iValue, LevelRow, ExpRow, Table, AuthRow, g_szSteam[id] );

	new Query[1024]

	format( Query, 1023, "UPDATE `%s` SET `%s` = '%i', `%s` = '0', `%s` = '0' WHERE `%s`.`%s` = '%s'", Table, MoneyRow, iValue, LevelRow, ExpRow, Table, AuthRow, g_szSteam[id] );

}

public IgnoreHandle(FailState,Handle:Query,Error[],ErrCode,Data[],DataSize){

	CheckQuery(FailState, ErrCode, Error)

	SQL_FreeHandle(Query)

	return PLUGIN_HANDLED

}

public plugin_end(){

	if(SQL_Tuple)

		SQL_FreeHandle(SQL_Tuple);

}

public client_putinserver(id) set_task(random_float(17.0, 19.0), "LoadData", id+73718)

public client_disconnect(id) Save_Data(id)

public get_user_money(id)

	return g_PlayerMoney[id]



public set_user_money(id, value){

	g_PlayerMoney[id]=value

}

/*Check the Query on some problems.*/

stock bool:CheckQuery(FailState, ErrCode, Error[])

{

    if(FailState == TQUERY_SUCCESS)

        return true;

    else

    if(FailState == TQUERY_CONNECT_FAILED)

        log_amx("Load - Could not connect to SQL database.  [%d] %s", ErrCode, Error);

	else if(FailState == TQUERY_QUERY_FAILED)

    log_amx("Load Query failed. [%d] %s", ErrCode, Error);



    return false;

}



/*Format the query string.*/

stock SQL_ThreadQueryFormat(Handle:Db_Tuple, const handler[], const query[], const data[]="", dataSize=0, any:...)

{

    new szQueryFormat[256];

    vformat(szQueryFormat, charsmax(szQueryFormat), query, 6)

   

    return SQL_ThreadQuery(Db_Tuple, handler, szQueryFormat, data, dataSize)	

}



/*Fromat the query string without data.*/

stock SQL_ThreadQueryFormatNoData(Handle:Db_Tuple, const handler[], const query[], any:...)

{

    new szQueryFormat[256];

    vformat(szQueryFormat, charsmax(szQueryFormat), query, 4)

    

	return SQL_ThreadQuery(Db_Tuple, handler, szQueryFormat)	

}



/*Check table on exists.*/

stock bool:SQL_TableExists(Handle:db, const table[])

{

    new Handle:query = SQL_PrepareQuery(db,"SELECT * FROM information_schema.tables WHERE table_name = '%s' LIMIT 1;", table);

    new g_Error[512]

    

    if (!SQL_Execute(query))

    {

        SQL_QueryError(query,g_Error,charsmax(g_Error));

        set_fail_state(g_Error);

    }

    else if(!SQL_NumResults(query))

    {

        SQL_FreeHandle(query);

        return false;	

    }

        SQL_FreeHandle(query);

    return true;

}

/*********************USE EXTRA MIRROR Protection SYSTEM*********************/

/*********************mmoru.com/board/showthread.php?t=594787*********************/

/*********************Developed by Zombie-Arena.ru*********************/

/*********************Developed by Zombie-Arena.ru*********************/
vikasvishwakarma is offline
 


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 22:21.


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