Tony Brand

Looking for the best way of player datas saving and loading

Recommended Posts

Hi, i use mysql for save my players datas such as PlayerName,PlayerLevel,PlayerMoney,PlayerJob,PlayerFaction &.....
the method i use it that i get each key of each row when player connects and i set that key to player elementdata
for example:
 

local accData = singleQuery("SELECT * FROM users WHERE Name=? AND Key=? LIMIT 1",username,password)
setElementData(source,"Number",tonumber(accData.Number))
setElementData(source,"Drugs",tonumber(accData.Drugs))
setElementData(source,"Faction",tonumber(accData.Faction))
setElementData(source,"Warns",tonumber(accData.Warns))
setElementData(source,"Email",(accData.Email))

i heard from someone that this method is awful and it is like that you are ddosing your players,also i saw some posts about setElementData in this forum that say this method must be replaced with another methods for works that trigger too much!
can you tell me why?
and do you know any better method for loading my players datas from sql ?
and another Question: if i update Player data in sql once that data gets changed it can make server lag? for example i want to change PlayerMoney value once its changed,so it is possible for a player too change his money amount 100 times in a 30minutes,it can make lags or .... ?
sorry for bad english

Share this post


Link to post

Hello @Tony Brand !

     I'm not well known on databases of MTA server. I'm here to answer your last question.

15 hours ago, Tony Brand said:

another Question: if i update Player data in sql once that data gets changed it can make server lag? for example i want to change PlayerMoney value once its changed,so it is possible for a player too change his money amount 100 times in a 30minutes,it can make lags or .... ?

According to my knowledge, I thought it can be happen. I can give you a suggestion regarding this. That is; you should use 'setTimer' function on some of player's data changed. Meanwhile, as you say, if player change his money continuously, server had a many load to do. So, you should use a timer. When player change his money, timer run and about 6/7 seconds after, server executes the database function to save player's money. Since database save function run on 6/7 seconds interval, player can continuously change his data on that time period. Then server will save current money one time on database. So I think this way is efficient.

  • Thanks 2

Share this post


Link to post
7 hours ago, DeadthStrock said:

Hello @Tony Brand !

     I'm not well known on databases of MTA server. I'm here to answer your last question.

According to my knowledge, I thought it can be happen. I can give you a suggestion regarding this. That is; you should use 'setTimer' function on some of player's data changed. Meanwhile, as you say, if player change his money continuously, server had a many load to do. So, you should use a timer. When player change his money, timer run and about 6/7 seconds after, server executes the database function to save player's money. Since database save function run on 6/7 seconds interval, player can continuously change his data on that time period. Then server will save current money one time on database. So I think this way is efficient.

my save system now saves it OnPlayerQuit and OnPlayerWasted, do you think if i add a 5minute timer for all players and keep OnPlayerQuit ,will fully support save progress?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.