WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 How are saved drift points? I mean getElementData in this case. Also, show me your meta file and print screen of folder where "Drift_DB.db" is. Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 here is the meta "LagParty" version="1.0.4" type="script"/> here is the picture Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 U didn't add 'drft_db.lua' to meta. Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 do i need to ? it have exact same code as .db Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 What's the content of drft_db.lua? Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 What's the content of drft_db.lua? current it have addEventHandler ("onPlayerLogin",root, function (thePreviousAccount, theCurrentAccount, autoLogin) local anterior = getAccountData (theCurrentAccount,"Last_Drift") local total = getAccountData (theCurrentAccount,"Total_Drift") local mejor = getAccountData (theCurrentAccount,"Best_Drift") setElementData(source, "Last Drift", anterior) setElementData(source, "Total Drift", total) setElementData(source, "Best Drift", mejor) end) addEventHandler ("onPlayerLogout", root, function() if not kickPlayer (source, nil, "Logging out is disallowed.") then -- if the player doesn't get kicked(no admin rights) setElementData(source, "Last Drift", false) setElementData(source, "Total Drift", false) setElementData(source, "Best Drift", false) end end) addEventHandler ("onPlayerQuit", root, function (quitType, reason, responsibleElement) local account = getPlayerAccount (source) if not isGuestAccount (account) then local anterior = getElementData(source, "Last Drift") local total = getElementData(source, "Total Drift") local mejor = getElementData(source, "Best Drift") setAccountData (account,"Last_Drift",anterior) setAccountData (account,"Total_Drift",total) setAccountData (account,"Best_Drift",mejor) end end) but it wont calculate old point to the new points its just recount after rejoin Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 Replace this whole code with mine and add it to meta. Drift_DB.db can't have content. It has to be clear. Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 i ave cleared up the Drift_DB.db and i have changed the drft_db.lua to your code i tryed to let it work in meta as server side but dind work 0 error's and also same for client side and id dind save / load Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 and i have downloaded the script from vps and it also dind putted anything into Drift_DB.db Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 addEventHandler ( "onResourceStart", root, function ( ) -- creating connection and if true creates column if not exist connection = dbConnect ( "sqlite" , "Drift_DB.db" ) if ( connection ) then dbQuery ( connection , "CREATE TABLE IF NOT EXISTS `drift` ( `data` TEXT, `account` TEXT )" ); outputDebugString ( "connected" ); else outputDebugString ( "not connected" ); end -- creating connection and if true creates column if not exist end ); When you start resource check what debug says ("connected" or "not connected"). Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 Did something bad, replace whole code with that -- CHANGE IF NECCESSARY dataName = { ["last"] = "Last Drift", ["total"] = "Total Drift", ["best"] = "Best Drift" } -- type here what the elementData's names addEventHandler ( "onResourceStart", root, function ( ) -- creating connection and if true creates column if not exist connection = dbConnect ( "sqlite", "Drift_DB.db" ) if ( connection ) then dbQuery ( connection, "CREATE TABLE IF NOT EXISTS `drift` ( `data` TEXT, `account` TEXT )" ); outputDebugString ( "connected" ); else outputDebugString ( "not connected" ); end -- creating connection and if true creates column if not exist end ); function saveDriftPoints ( ) local account = getPlayerAccount ( source ); -- getting account if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local t = { } -- creating table for drift's data for k, v in pairs ( dataName ) do local data = getElementData ( source, v ); if ( data ) then t[v] = data; -- inserting values to table from ElementData end end local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if exist row if ( #check > 0 ) then for k, v in pairs ( fromJSON ( check[1]["data"] ) ) do t[k] = ( tonumber ( t[k] ) + tonumber ( v ) ); end dbQuery ( connection, "UPDATE `drift` SET `data`=? WHERE `account`=?", toJSON ( t ), accName ); -- if yes updating elseif ( #check == 0 ) then dbQuery ( connection, "INSERT INTO `drift` ( `data`, `account` ) VALUES ( ?, ? )", toJSON ( t ), accName ); -- if not creating end end addEventHandler ( "onPlayerQuit", root, saveDriftPoints ); function loadDriftPoints ( _, account ) if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if row exist if ( #check > 0 ) then -- if yes local d = check[1]; local t = fromJSON ( d["data"] ); if ( type ( t ) == "table" ) then for k, v in pairs ( t ) do setElementData ( source, k, v ); -- setting ElementData from saved drift's table in table end end end end addEventHandler ( "onPlayerLogin", root, loadDriftPoints ); Again updated. Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 its working but it still not working fully its saving and loading but when there coming new points its recounting example i quit the game when i have 2564 best drift, 231 last drift, 5684322 total drift and when i join the game and make 1 drift from 6 points then it shows on scoreboard 6 best drift, 6 last drift, 6 total drift Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 -- CHANGE IF NECCESSARY dataName = { ["last"] = "Last Drift", ["total"] = "Total Drift", ["best"] = "Best Drift" } -- type here what the elementData's names addEventHandler ( "onResourceStart", root, function ( ) -- creating connection and if true creates column if not exist connection = dbConnect ( "sqlite", "Drift_DB.db" ) if ( connection ) then dbQuery ( connection, "CREATE TABLE IF NOT EXISTS `drift` ( `data` TEXT, `account` TEXT )" ); outputDebugString ( "connected" ); else outputDebugString ( "not connected" ); end -- creating connection and if true creates column if not exist end ); function saveDriftPoints ( ) local account = getPlayerAccount ( source ); -- getting account if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local t = { } -- creating table for drift's data for k, v in pairs ( dataName ) do local data = getElementData ( source, v ); if ( data ) then t[v] = data; -- inserting values to table from ElementData end end local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if exist row if ( #check > 0 ) then for k, v in pairs ( fromJSON ( check[1]["data"] ) ) do t[k] = ( tonumber ( t[k] ) + tonumber ( v ) ); end dbQuery ( connection, "UPDATE `drift` SET `data`=? WHERE `account`=?", toJSON ( t ), accName ); -- if yes updating elseif ( #check == 0 ) then dbQuery ( connection, "INSERT INTO `drift` ( `data`, `account` ) VALUES ( ?, ? )", toJSON ( t ), accName ); -- if not creating end end addEventHandler ( "onPlayerQuit", root, saveDriftPoints ); function loadDriftPoints ( _, account ) if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if row exist if ( #check > 0 ) then -- if yes local d = check[1]; local t = fromJSON ( d["data"] ); if ( type ( t ) == "table" ) then for k, v in pairs ( t ) do setElementData ( source, k, v ); -- setting ElementData from saved drift's table in table end end end end addEventHandler ( "onPlayerLogin", root, loadDriftPoints ); Well, it should work imo. Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 -- CHANGE IF NECCESSARY dataName = { ["last"] = "Last Drift", ["total"] = "Total Drift", ["best"] = "Best Drift" } -- type here what the elementData's names addEventHandler ( "onResourceStart", root, function ( ) -- creating connection and if true creates column if not exist connection = dbConnect ( "sqlite", "Drift_DB.db" ) if ( connection ) then dbQuery ( connection, "CREATE TABLE IF NOT EXISTS `drift` ( `data` TEXT, `account` TEXT )" ); outputDebugString ( "connected" ); else outputDebugString ( "not connected" ); end -- creating connection and if true creates column if not exist end ); function saveDriftPoints ( ) local account = getPlayerAccount ( source ); -- getting account if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local t = { } -- creating table for drift's data for k, v in pairs ( dataName ) do local data = getElementData ( source, v ); if ( data ) then t[v] = data; -- inserting values to table from ElementData end end local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if exist row if ( #check > 0 ) then for k, v in pairs ( fromJSON ( check[1]["data"] ) ) do t[k] = ( tonumber ( t[k] ) + tonumber ( v ) ); end dbQuery ( connection, "UPDATE `drift` SET `data`=? WHERE `account`=?", toJSON ( t ), accName ); -- if yes updating elseif ( #check == 0 ) then dbQuery ( connection, "INSERT INTO `drift` ( `data`, `account` ) VALUES ( ?, ? )", toJSON ( t ), accName ); -- if not creating end end addEventHandler ( "onPlayerQuit", root, saveDriftPoints ); function loadDriftPoints ( _, account ) if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if row exist if ( #check > 0 ) then -- if yes local d = check[1]; local t = fromJSON ( d["data"] ); if ( type ( t ) == "table" ) then for k, v in pairs ( t ) do setElementData ( source, k, v ); -- setting ElementData from saved drift's table in table end end end end addEventHandler ( "onPlayerLogin", root, loadDriftPoints ); Well, it should work imo. no its still the same this are the score when i quit this are the score when i join and did 1 drift Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 Are you sure? Any errors? Make sure that you restarted resource. I made a simulation with tables and adding values and it should work. Made it other way: -- CHANGE IF NECCESSARY dataName = { ["last"] = "Last Drift", ["total"] = "Total Drift", ["best"] = "Best Drift" } -- type here what the elementData's names addEventHandler ( "onResourceStart", root, function ( ) -- creating connection and if true creates column if not exist connection = dbConnect ( "sqlite", "Drift_DB.db" ) if ( connection ) then dbQuery ( connection, "CREATE TABLE IF NOT EXISTS `drift` ( `data` TEXT, `account` TEXT )" ); outputDebugString ( "connected" ); else outputDebugString ( "not connected" ); end -- creating connection and if true creates column if not exist end ); function saveDriftPoints ( ) local account = getPlayerAccount ( source ); -- getting account if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local t = { } -- creating table for drift's data for k, v in pairs ( dataName ) do local data = getElementData ( source, v ); if ( data ) then t[v] = data; -- inserting values to table from ElementData end end local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if exist row if ( #check > 0 ) then local data = fromJSON ( check[1]["data"] ); if ( data ) then for n, v in pairs ( t ) do data[n] = tonumber ( data[n] ) + tonumber ( v ); end end dbQuery ( connection, "UPDATE `drift` SET `data`=? WHERE `account`=?", toJSON ( data ), accName ); -- if yes updating elseif ( #check == 0 ) then dbQuery ( connection, "INSERT INTO `drift` ( `data`, `account` ) VALUES ( ?, ? )", toJSON ( t ), accName ); -- if not creating end end addEventHandler ( "onPlayerQuit", root, saveDriftPoints ); function loadDriftPoints ( _, account ) if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if row exist if ( #check > 0 ) then -- if yes local d = check[1]; local t = fromJSON ( d["data"] ); if ( type ( t ) == "table" ) then for k, v in pairs ( t ) do setElementData ( source, k, v ); -- setting ElementData from saved drift's table in table end end end end addEventHandler ( "onPlayerLogin", root, loadDriftPoints ); Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 ye i have restarted i have added the resource to admin acl and i dont see any error idk whats wrong Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 Copy my code which I gave you. Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 its still the same problem Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 Send here your drift script and I will test it. Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 Send here your drift script and I will test it. here is it Link to comment
WhoAmI Posted April 24, 2015 Share Posted April 24, 2015 Saving works fine, but your resource is reseting score by itself. I don't have that much time to edit it. Link to comment
spoty Posted April 24, 2015 Author Share Posted April 24, 2015 Saving works fine, but your resource is reseting score by itself. I don't have that much time to edit it. hmm ok can you mayby fix it later or explain me how to do Link to comment
spoty Posted April 25, 2015 Author Share Posted April 25, 2015 now i get a error when i have edited my resource 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