AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   How to client save data (https://forums.alliedmods.net/showthread.php?t=313033)

Lodar 12-25-2018 20:34

How to client save data
 
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).

8guawong 12-26-2018 02:38

Re: How to client save data
 
use OnClientDisconnect since player disconnects when map ends as well

eyal282 12-26-2018 02:49

Re: How to client save data
 
Consider saving only when the data changes, and just never save on disconnect.

XiLuo 12-26-2018 03:12

Re: How to client save data
 
eyal282 is right ,disconnect is not best idea

Lodar 12-26-2018 16:47

Re: How to client save data
 
Quote:

Originally Posted by eyal282 (Post 2631019)
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).

CliptonHeist 12-26-2018 17:30

Re: How to client save data
 
Quote:

Originally Posted by Lodar (Post 2631139)
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.

Lodar 12-27-2018 07:55

Re: How to client save data
 
I never use threaded queries :D But i read about it and looks fine. But as i say, never use this before so please help me with that :D
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);


eyal282 12-27-2018 07:59

Re: How to client save data
 
Quote:

Originally Posted by Lodar (Post 2631254)
I never use threaded queries :D But i read about it and looks fine. But as i say, never use this before so please help me with that :D
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.


All times are GMT -4. The time now is 05:39.

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