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

I need ideas to solve this


Post New Thread Reply   
 
Thread Tools Display Modes
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 04-19-2021 , 03:46   Re: I need ideas to solve this
Reply With Quote #21

Code:
new g_PlayerLevel[MAX_PLAYERS+1];
new Handle: g_SQLTuple;

new const g_szFile[] = "addons/amxmodx/configs/sql_dump.txt";

public client_disconnect(id)
{
	if(is_user_bot(id) || is_user_hltv(id))
		return;

	if(!g_SQLTuple)
	{
		new g_Query[256], g_szName[32];
		get_user_name(id, g_szName, charsmax(g_szName));
		formatex(g_Query, charsmax(g_Query), "INSERT INTO `table_name` ( player_name, player_level ) VALUES ('%s', '%s')", g_szName, g_PlayerLevel[id]);
		write_file(g_szFile, g_Query, -1);
	}
}

public plugin_init()	set_task(25.0, "recheck_sql", .flags="b");

public recheck_sql()
{
	if(!g_SQLTuple)
	{
		g_SQLTuple = SQL_MakeDBTuple("host", "user", "pass", 5");

		if(!g_SQLTuple && file_exists(g_szFile))
		{
			new g_szQuery[4096], SQL_Dump = fopen(g_szFile, "r");

			if(SQL_Dump)
			{
				fgets(SQL_Dump, g_szQuery, charsmax(g_szQuery));
				trim(g_szQuery);

				SQL_ThreadQuery(g_SQLTuple, "SQL_Resend_Data", g_szQuery);
			}
		}
	}
}

public SQL_Resend_Data(FailState, Handle: Query, szError[], iErrorCode, szData[], iDataSize)
{
	if(!FailState && !iErrorCode)
	{
		server_print("Data updated succefully.");

		if(file_exists(g_szFile))
			delete_file(g_szFile);
	}

	else
	{
		server_print("SQL Connection did not get any response.");
		
	}

	SQL_FreeHandle(Query);
}
didn't know how good i coded this but it's a way however ) you can adjust my code to a better one.
__________________
LondoN is offline
loiraolhosazul
Member
Join Date: May 2020
Old 04-25-2021 , 18:13   Re: I need ideas to solve this
Reply With Quote #22

Quote:
Originally Posted by LondoN View Post
Code:
new g_PlayerLevel[MAX_PLAYERS+1];
new Handle: g_SQLTuple;

new const g_szFile[] = "addons/amxmodx/configs/sql_dump.txt";

public client_disconnect(id)
{
	if(is_user_bot(id) || is_user_hltv(id))
		return;

	if(!g_SQLTuple)
	{
		new g_Query[256], g_szName[32];
		get_user_name(id, g_szName, charsmax(g_szName));
		formatex(g_Query, charsmax(g_Query), "INSERT INTO `table_name` ( player_name, player_level ) VALUES ('%s', '%s')", g_szName, g_PlayerLevel[id]);
		write_file(g_szFile, g_Query, -1);
	}
}

public plugin_init()	set_task(25.0, "recheck_sql", .flags="b");

public recheck_sql()
{
	if(!g_SQLTuple)
	{
		g_SQLTuple = SQL_MakeDBTuple("host", "user", "pass", 5");

		if(!g_SQLTuple && file_exists(g_szFile))
		{
			new g_szQuery[4096], SQL_Dump = fopen(g_szFile, "r");

			if(SQL_Dump)
			{
				fgets(SQL_Dump, g_szQuery, charsmax(g_szQuery));
				trim(g_szQuery);

				SQL_ThreadQuery(g_SQLTuple, "SQL_Resend_Data", g_szQuery);
			}
		}
	}
}

public SQL_Resend_Data(FailState, Handle: Query, szError[], iErrorCode, szData[], iDataSize)
{
	if(!FailState && !iErrorCode)
	{
		server_print("Data updated succefully.");

		if(file_exists(g_szFile))
			delete_file(g_szFile);
	}

	else
	{
		server_print("SQL Connection did not get any response.");
		
	}

	SQL_FreeHandle(Query);
}
didn't know how good i coded this but it's a way however ) you can adjust my code to a better one.
I understood the idea, you can do something better. it cost
loiraolhosazul 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 13:07.


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