monday Posted November 2, 2014 Share Posted November 2, 2014 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
Anubhav Posted November 2, 2014 Share Posted November 2, 2014 2nd one would be better. And I don't suggest to use -1 on dbPoll as it make's server freeze dbPoll returns the converted table. So something like this: playerData[row].column Link to comment
monday Posted November 2, 2014 Author Share Posted November 2, 2014 Hmm, thanks. Btw is there any way to make it "_Data" instead of "playerData"? Something like: _data = dbPoll (queryHandle, 10) So later in the script I could add some stat for a specific player like: AntonioBanderas_data[1].Attack + 1 Link to comment
Anubhav Posted November 3, 2014 Share Posted November 3, 2014 getPlayerName(source)_data = dbPoll (queryHandle, 10) Not realy sure. Link to comment
monday Posted November 3, 2014 Author Share Posted November 3, 2014 Unfortunately it shows an error saying "unexpected symbol near '=' Link to comment
Feche1320 Posted November 3, 2014 Share Posted November 3, 2014 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
Anubhav Posted November 3, 2014 Share Posted November 3, 2014 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
Feche1320 Posted November 3, 2014 Share Posted November 3, 2014 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
monday Posted November 3, 2014 Author Share Posted November 3, 2014 Btw, would it be laggy if I loaded around 130 different values per each player? Link to comment
.:HyPeX:. Posted November 4, 2014 Share Posted November 4, 2014 Best option would be to save everything on resource stop and every 5min or a more realistic timer (one hour shouldnt make any issue, if you arent going to do a very unstable server). Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now