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

How to client save data


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lodar
Junior Member
Join Date: Sep 2016
Old 12-25-2018 , 20:34   How to client save data
Reply With Quote #1

Hi. i have problem with save data on change map.

This is not work:
Code:
public void OnMapEnd()
{
	for (int i = 1; i <= MaxClients; i++)
	{
		if(IsValidClient(i)) SaveData(i);
	}
}
stock bool IsValidClient(int client)
{		
    if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || IsFakeClient(client) || IsClientSourceTV(client) || IsClientReplay(client))
    {
        return false;
    }
    return true;
}
This work fine, so save function is good:
Code:
public Action Event_Disconnect(Handle event, const char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(GetEventInt(event, "userid"));
	SaveData(client);
}
IsValidClient just copy from https://forums.alliedmods.net/showthread.php?p=2530794

What i must do? I need to save data all client to database on end map.
Now i use on round end event, but this make high server loads.
To save i use mysql on external sever (not localhost).

Last edited by Lodar; 12-25-2018 at 20:41.
Lodar is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 12-26-2018 , 02:38   Re: How to client save data
Reply With Quote #2

use OnClientDisconnect since player disconnects when map ends as well
__________________
8guawong is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 12-26-2018 , 02:49   Re: How to client save data
Reply With Quote #3

Consider saving only when the data changes, and just never save on disconnect.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
XiLuo
Member
Join Date: Mar 2018
Old 12-26-2018 , 03:12   Re: How to client save data
Reply With Quote #4

eyal282 is right ,disconnect is not best idea
XiLuo is offline
Lodar
Junior Member
Join Date: Sep 2016
Old 12-26-2018 , 16:47   Re: How to client save data
Reply With Quote #5

Quote:
Originally Posted by eyal282 View Post
Consider saving only when the data changes, and just never save on disconnect.

The plugin works so that for each kill you get a gift that you can open.
So data change very often (each kill and each gift open).
Lodar is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 12-26-2018 , 17:30   Re: How to client save data
Reply With Quote #6

Quote:
Originally Posted by Lodar View Post
The plugin works so that for each kill you get a gift that you can open.
So data change very often (each kill and each gift open).
That's perfectly fine as long as the plugin is using threaded queries, a roleplay plugin I helped develop performs multiple queries every time a player is killed (updating deathmatch table, updating money/drugs lost and inserting a log about the event) which has no impact on the server whatsoever.
CliptonHeist is offline
Lodar
Junior Member
Join Date: Sep 2016
Old 12-27-2018 , 07:55   Re: How to client save data
Reply With Quote #7

I never use threaded queries But i read about it and looks fine. But as i say, never use this before so please help me with that
How use it?
So far i use this (fragment of code):
HTML Code:
DB = SQL_Connect("prezent", true, Error, sizeof(Error));
	if(DB == INVALID_HANDLE)
	{
		PrintToServer("MySQL: %s", Error);
		CloseHandle(DB);
	}
	else
	{
		PrintToServer("Connected to MySQL");
	}

Format(query, 500, "SELECT prezenty FROM PrezentyDB WHERE steamid = '%s'", steamid); 
DBResultSet querys = SQL_Query(DB, query);
if (SQL_FetchRow(querys))
{	

}

Format(query, 500, "UPDATE PrezentyDB SET prezenty = prezenty - 1 WHERE steamid = '%s'", steamid); 
SQL_Query(DB, query);
Lodar is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 12-27-2018 , 07:59   Re: How to client save data
Reply With Quote #8

Quote:
Originally Posted by Lodar View Post
I never use threaded queries But i read about it and looks fine. But as i say, never use this before so please help me with that
How use it?
So far i use this (fragment of code):
HTML Code:
DB = SQL_Connect("prezent", true, Error, sizeof(Error));
	if(DB == INVALID_HANDLE)
	{
		PrintToServer("MySQL: %s", Error);
		CloseHandle(DB);
	}
	else
	{
		PrintToServer("Connected to MySQL");
	}

Format(query, 500, "SELECT prezenty FROM PrezentyDB WHERE steamid = '%s'", steamid); 
DBResultSet querys = SQL_Query(DB, query);
if (SQL_FetchRow(querys))
{	

}

Format(query, 500, "UPDATE PrezentyDB SET prezenty = prezenty - 1 WHERE steamid = '%s'", steamid); 
SQL_Query(DB, query);
https://wiki.alliedmods.net/SQL_(SourceMod_Scripting)

Found this on google.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 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:45.


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