SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 31/10/2018, 09:26 AM   #11
TheToretto
Gangsta
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 600
Reputation: 66
Default Re: Saving players stats on changes or in timer? [MySQL]

Well your server isn't going to crash the whole day, just add a command for the server owner to save all players' stats. Without kicking them or calling OnPlayerDisconnect, then... Shutdown your server;

If your server is really really unstable, just put a global timer, not per player, which saves players data every 20 minutes, or less. Who give a fuck if you lose 10$ because you bought a condom in the 24/7, I mean, you won't lose much data, you can't get $2.000.000 in 10/20 minutes...
__________________






Toretto#9902

Rest in peace grandpa, 03 November 2018
TheToretto is offline   Reply With Quote
Old 02/11/2018, 10:47 AM   #12
Ermanhaut
Gangsta
 
Ermanhaut's Avatar
 
Join Date: Apr 2016
Location: Curitiba
Posts: 635
Reputation: 47
Default Re: Saving players stats on changes or in timer? [MySQL]

Quote:
Originally Posted by TheToretto View Post
Well your server isn't going to crash the whole day, just add a command for the server owner to save all players' stats. Without kicking them or calling OnPlayerDisconnect, then... Shutdown your server;

If your server is really really unstable, just put a global timer, not per player, which saves players data every 20 minutes, or less. Who give a fuck if you lose 10$ because you bought a condom in the 24/7, I mean, you won't lose much data, you can't get $2.000.000 in 10/20 minutes...
Lottery.


Regarding the topic:
I would create a ten minute timer after the player logs in and also update the database whenever it's necessary.
i.e. The player unlocked an achievement. Or he got into a new job. Or he wins the lottery.
__________________
try, try and try again
Ermanhaut is offline   Reply With Quote
Old 02/11/2018, 10:55 AM   #13
TheToretto
Gangsta
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 600
Reputation: 66
Default Re: Saving players stats on changes or in timer? [MySQL]

Quote:
Originally Posted by Ermanhaut View Post
Lottery.


Regarding the topic:
I would create a ten minute timer after the player logs in and also update the database whenever it's necessary.
i.e. The player unlocked an achievement. Or he got into a new job. Or he wins the lottery.
The lottery isn't ran every minute, at a maximum it'll be twice a day, regarding the script you're using, plus, for the lottery, it's something obvious, so if you connect, it'll be the first thing that you notice, then ask for a refund. Concrete things may need queries.
__________________






Toretto#9902

Rest in peace grandpa, 03 November 2018
TheToretto is offline   Reply With Quote
Old 02/11/2018, 11:32 AM   #14
AmigaBlizzard
Huge Clucker
 
Join Date: Jul 2012
Posts: 320
Reputation: 60
Default Re: Saving players stats on changes or in timer? [MySQL]

Quote:
Originally Posted by TheToretto View Post
Well your server isn't going to crash the whole day, just add a command for the server owner to save all players' stats. Without kicking them or calling OnPlayerDisconnect, then... Shutdown your server;

If your server is really really unstable, just put a global timer, not per player, which saves players data every 20 minutes, or less. Who give a fuck if you lose 10$ because you bought a condom in the 24/7, I mean, you won't lose much data, you can't get $2.000.000 in 10/20 minutes...
I would, and alot of other players.
Because in 10 minutes, you could buy a house, apply a different interior, buy some furniture and place it, buy a house-vehicle, repaint it and apply tuning components.
Whenever that's done and something happens before your timer saves the data, all that is lost.
By the time you relog, someone else might have bought that house.
I would never come back to your server because I know playing there doesn't guarantee proper data-saving.
Players don't know if you save every 10 minutes, only on disconnect or if you save whenever data changes.
They DO care if they lose data and some will be furious and never come back, even if you reimburse them.
They just see that some data hasn't been saved properly and will distrust your server because of unreliable saving functions.


In every MMORPG I've played, data is saved whenever something changes.
I've never lost alot of progress, even when timing out, server crashes, lagging followed by a disconnect, whatever reason, simply because they save whenever data changes.
You could gain a level or 2, do some quests or turn them in, go to another map, all that in less than 10 minutes.
I've never respawned in the previous map, having to turn in quests for the second time or regain my 2 levels I gained right before the crash/timeout/whatever.


Also, only saving when the player disconnects will also guarantee you'll lose players.

Some players play for hours at a time and if something unexpected happens, his entire progress hasn't been saved.
A stupid hacker can mess up your server, making it crash and you'll have no data saved for hours on end for multiple players.

Even a timer which saves everything at once is usually not done.
This timer would save EVERYTHING, even sex, class, skin, name (if you allow name-changes), email, ... (things that very rarely change, if they ever do).
Would you really generate a huge query with hundreds of values that must be saved, even when the possibility exists that some players afk for hours? Then you would send a huge query to MySQL which in the end does absolutely nothing, because there is nothing to be updated/changed.

This is a pure waste of processing power, both for your server which must construct the entire query, but mostly for MySQL, which must break down the entire query, find every value in the database, check if the provided value is valid (you can't store an int in a float column so MySQL checks that), and eventually overwrite the value one by one (it won't overwrite the value if it hasn't changed).

Surely pc's nowadays have fast processors, but that's no excuse to be a lazy programmer.
Creating a huge query that covers all values and put it in a timer seems a smart thing to do (it's at least convenient), but it's just being lazy.

Having alot of smaller queries which are executed whenever something changes save you alot of trouble.

One bug in your huge query and NOTHING gets saved.
One bug in one small query only messes up that single query while keeping everything else intact.

One huge query is also alot more difficult to bug-fix and find the problem.

Also, saving only when something changes prevents queries to be sent when they're not even needed, saving alot of processing power.

A game's render engine also only renders whatever is being displayed on the screen.
What if that engine would render the entire game world at once, from which only 5% would be shown on your screen? It would also be convenient for the programmer and it would guarantee the required models would be rendered, but it's not the proper way to create a game.
Your game would lag immensely and is impossible to play.

Only do whatever needs to be done at the time it needs to be done.
Don't do unneccessary stuff.
This applies for everything you do, not only programming.



Do you paint your living room every month just in case there "might" be a spot, crack, some dirt, whatever on your wall, wasting expensive paint and alot of time in the process?
Or do you just repaint your living room when it's really time to paint it (you don't like it anymore, or there are too many spots/cracks/whatever), which would be every 10 years or so?

Do you dismantle your car's engine every month to prevent wear and tear, applying new grease to every moving part to prevent anything happening soon, even when nothing's wrong?
Or do you only do the required maintenance as told by the manufacturer (change oil every year) and go to the garage whenever something's broken?

If your teacher requires you to read page 55 (in a 200-page book), do you read the entire book, including page 55, just to be sure you've read it, even when the class for that day only handles page 55?
Or do you simply do whatever she wants you to do, and read only page 55?

Do you go to the toilet every 10 minutes and sit down, waiting for 2 minutes just in case you would need to build a huge pile of brown stuff, making you sit on the toilet over 100 times a day without even the need to do poopoo?
Or do you only go to the toilet when nature calls?

In all cases, I'm pretty sure you do the second option.
Why would you do the first option in programming?

Last edited by AmigaBlizzard; 02/11/2018 at 12:07 PM.
AmigaBlizzard is offline   Reply With Quote
Old 07/11/2018, 11:48 AM   #15
IdonTmiss
Big Clucker
 
Join Date: Dec 2016
Posts: 145
Reputation: 0
Default Re: Saving players stats on changes or in timer? [MySQL]

Damn, he said it all, don't use Timers, I mean they're bad atleast for me and he said everything ( the post above )
IdonTmiss is offline   Reply With Quote
Old 12/11/2018, 10:56 PM   #16
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,761
Reputation: 840
Default Re: Saving players stats on changes or in timer? [MySQL]

Now, instead of saving player data only when player disconnects, why not save it whenever the player DIES.

I mean, in most servers, player's data is significantly changed when they die (maybe not for RP servers). So when the player dies, save their data.

pawn Code:
public OnPlayerDeath(playerid, killerid, reason) {
    // add kills and change variables' data

    // save data in the end
    mysql_tquery(...);

    return 1;
}

Moreover, for security reasons its better to have a interval check between two deaths, so if a Cheater spams your OnPlayerDeath for fake kills/deaths, your server won't crash from MySQL query overload!

gettime() would do it for you. Before saving data, check if last save was not very recently and then forward.

pawn Code:
new lastSaveTimestamp[MAX_PLAYERS];

public OnPlayerDeath(playerid, killerid, reason) {

    new currentTimestamp = gettime();
    if (currentTimestamp - lastSaveTimestamp[playerid] >= 600) { // 10 minutes interval

        // save data if last update was 10 minutes atleast
        mysql_tquery(...);

        lastSaveTimestamp[playerid] = currentTimestamp; // update player's last save time to current timestamp
    }

    return 1;
}


But the above case is only for data which is significantly changed, other data like "AdminLevel" doesn't require to be updated in OnPlayerDeath. You should update AdminLevel whenever its changed in script, i.e. Update query for AdminLevel in your /setadmin command.

The whole idea about using Timer to save stats is nonsense.
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix is offline   Reply With Quote
Old 13/11/2018, 07:01 PM   #17
Alteh
Big Clucker
 
Alteh's Avatar
 
Join Date: Aug 2018
Location: Narnia
Posts: 67
Reputation: 10
Default Re: Saving players stats on changes or in timer? [MySQL]

my opinion it better to save data when value is modified
Alteh is offline   Reply With Quote
Old 16/11/2018, 01:21 AM   #18
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,071
Reputation: 184
Default Re: Saving players stats on changes or in timer? [MySQL]

Usually you want to save on each change, even money. But some things like online time, i would save on timer basis and call single query (well a few queries are not problem as long they are not for each player at same time).
__________________
Looking for someone to start drifting server, drop me a pm if you are interested.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[MySQL] All players saving the same stats. ounce Scripting Help 7 30/07/2015 05:54 PM
Saving players' stats in OnGameModeExit. Denying Scripting Help 6 24/05/2014 01:26 PM
Timer Help, saving stats LiamM Scripting Help 5 01/11/2011 06:43 PM
saving players stats on server restart. Face9000 Help Archive 8 13/12/2010 05:04 PM
saving all player stats timer. iggy1 Help Archive 2 24/11/2010 04:32 AM


All times are GMT. The time now is 01:17 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.