Jump to content

[help] Database update style


monday

Recommended Posts

Hi, my aim is to use SQLite to store+load the data for each player but i'm not sure about few things. The first one is:

1. Is it alright to save the data to .db file every time the value changes? Or it would be laggy and it's better to update the values in another table + save them to .db file only when the player is disconnecting? If the second option is better I have another question:

2. How can I convert SQLite table to a normal table with a custom name based on player's name? Something like:

function Login(_thePreviousAccount, _theCurrentAccount) 
      accountName = getAccountName(_theCurrentAccount) 
      local connection = dbConnect ("sqlite" , "database.db") 
      local queryHandle = dbQuery (connection , "SELECT * FROM '??'", accountName) 
      playerData = dbPoll (queryHandle, -1) 
      (string.format("%s", accountName.."_data")) = {playerData} 
addEventHandler("onPlayerLogin", getRootElement(), Login) 
  

My plan is to reach the data for specific player at any stage of the script by something like:

AntonioBanderas_data.Attack + 1 

Please let me know if there's any more simple way to do it or if I made any mistake other than the (string.format) thing in the script above, I'm at early-learning stage so any advice would be appreciated. Thanks in advance

Link to comment
  
getPlayerName(source)_data = dbPoll (queryHandle, 10) 
  
  

Not realy sure.

Connecting a string into a variable name? auto ban yourself from this forums for god sake, you don't even know what the hell are you doing

Ontopic:

You can save the values when the value changes, it will keep your data safe in case of server crash or anything else, also you can make a timer and save the data every five minutes, but take in mind that there is more data to be updated since in those five minutes the values changed and didn't get saved when it changed, so I'd rather save it when the value changes.

You can make a table with the player account as index, for example:

  
local _playerstats = {} 
  
local query = dbQuery(your_database_connection, "SELECT * FROM player_stats WHERE account = '" ..the_player_account_name.. "'") 
local result = dbPoll(query, -1) 
if #result > 0 then 
    _playerstats[the_player_account_name] = {} 
    _playerstats[the_player_account_name].kills = 1 
    _playerstats[the_player_account_name].deaths = 89 
    _playerstats[the_player_account_name].name = "HeyYou" 
end 
  

Also, I see that you are creating tables for each player stats, what you have to is make a table named stats and then insert new values in that table.

Link to comment
  
getPlayerName(source)_data = dbPoll (queryHandle, 10) 
  
  

Not realy sure.

Connecting a string into a variable name? auto ban yourself from this forums for god sake, you don't even know what the hell are you doing

Ontopic:

You can save the values when the value changes, it will keep your data safe in case of server crash or anything else, also you can make a timer and save the data every five minutes, but take in mind that there is more data to be updated since in those five minutes the values changed and didn't get saved when it changed, so I'd rather save it when the value changes.

You can make a table with the player account as index, for example:

  
local _playerstats = {} 
  
local query = dbQuery(your_database_connection, "SELECT * FROM player_stats WHERE account = '" ..the_player_account_name.. "'") 
local result = dbPoll(query, -1) 
if #result > 0 then 
    _playerstats[the_player_account_name] = {} 
    _playerstats[the_player_account_name].kills = 1 
    _playerstats[the_player_account_name].deaths = 89 
    _playerstats[the_player_account_name].name = "HeyYou" 
end 
  

Also, I see that you are creating tables for each player stats, what you have to is make a table named stats and then insert new values in that table.

I told I'm not sure.

Link to comment
  
getPlayerName(source)_data = dbPoll (queryHandle, 10) 
  
  

Not realy sure.

Connecting a string into a variable name? auto ban yourself from this forums for god sake, you don't even know what the hell are you doing

Ontopic:

You can save the values when the value changes, it will keep your data safe in case of server crash or anything else, also you can make a timer and save the data every five minutes, but take in mind that there is more data to be updated since in those five minutes the values changed and didn't get saved when it changed, so I'd rather save it when the value changes.

You can make a table with the player account as index, for example:

  
local _playerstats = {} 
  
local query = dbQuery(your_database_connection, "SELECT * FROM player_stats WHERE account = '" ..the_player_account_name.. "'") 
local result = dbPoll(query, -1) 
if #result > 0 then 
    _playerstats[the_player_account_name] = {} 
    _playerstats[the_player_account_name].kills = 1 
    _playerstats[the_player_account_name].deaths = 89 
    _playerstats[the_player_account_name].name = "HeyYou" 
end 
  

Also, I see that you are creating tables for each player stats, what you have to is make a table named stats and then insert new values in that table.

I told I'm not sure.

If you know minimum Lua programming, you would know that you are f*king wrong.

Link to comment

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.
×
×
  • Create New...