DiGiTal Posted December 17, 2019 Share Posted December 17, 2019 hey i have created a systeme that will save deaths,kills,money on db all works fine but once i change the value of money it saves but it changing the kills and deaths equal to money value wtf is that local createTable = executeSQLQuery ("CREATE TABLE IF NOT EXISTS Players(accountName TEXT PRIMARY KEY,nickName TEXT,serial TEXT,IP TEXT,Money INT,kills INT,deaths INT)") addEventHandler ("onPlayerLogin",root, function(_,acName) ----------------------------------------------- local userAccountName = getAccountName ( acName ) local plr_serial = getPlayerSerial( source ) local plr_ip = getPlayerIP( source ) local plr_nick = getPlayerName( source ) local plr_money = getAccountData( acName,"money") local plr_kills = getAccountData( acName,"kills") local plr_deaths = getAccountData( acName,"deaths") ------------------------------------------------ local check = executeSQLQuery("SELECT accountName FROM Players WHERE accountName = ? ",userAccountName) ------------------------------------------------ if (#check==0) then local result1 = executeSQLQuery("INSERT INTO Players(accountName,serial,IP,Money,nickName,kills,deaths) VALUES(?,?,?,?,?,?,?)",userAccountName,plr_serial,plr_ip,0,plr_nick,0,0) print("hi1") else local result2 = executeSQLQuery( "UPDATE Players SET IP = ? ,Money = ?, kills =? ,deaths = ? ",plr_ip,tonumber(plr_money) ,tonumber(plr_kills),tonumber(plr_deaths)) local result3 = executeSQLQuery( "UPDATE Players SET nickName = ?", plr_nick) setPlayerMoney( source, tonumber(plr_money)) print("hi2") end end ) and this for the saving systeme -------------------------- addEventHandler("onPlayerQuit",root, function() ------------------------------------------------ local b_money = setAccountData( getPlayerAccount(source), "money", getPlayerMoney( source ) ) local result4 = executeSQLQuery( "UPDATE Players SET Money = ?",tonumber(getPlayerMoney( source ) ) ) ------------------------------------------------ updateStats(source) print("DATA SAVED") end ) -------------------------- function updateStats(thePlayer) if thePlayer then if not (isGuestAccount(getPlayerAccount(thePlayer)) ) then ------------------------------------------------ local kills1 = getAccountData(getPlayerAccount( thePlayer ),"kills") local deaths1 = getAccountData(getPlayerAccount( thePlayer ),"deaths") local result5 = executeSQLQuery( "UPDATE Players SET kills = ?,deaths = ?",tonumber(kills1) ,tonumber(deaths1)) print("hey2") ------------------------------------------------ end end end and this for the sync for kills and deaths function onWasted(totalAmmo,killer,killerWeapon) if not (isGuestAccount(getPlayerAccount(source)) ) then ------------------------------------------------ local deaths = getAccountData(getPlayerAccount(source),"deaths") ------------------------------------------------ setAccountData(getPlayerAccount(source),"deaths",tonumber(deaths)+1) updateStats(source) print("hey3") end if killer then if not checks and killer and (killer ~= source) then ------------------------------------------------ local kills = getAccountData( getPlayerAccount(killer), "kills") ------------------------------------------------ setAccountData(getPlayerAccount(killer),"kills",tonumber(kills)+1) updateStats(killer) print("hey4") end end end addEventHandler("onPlayerWasted",getRootElement(),onWasted) Link to comment
Motar2k Posted December 17, 2019 Share Posted December 17, 2019 I didn't see anything abnormal in the code, you probably got confused with the name of the data in some other resource. Traslated by google Link to comment
DiGiTal Posted December 17, 2019 Author Share Posted December 17, 2019 i restarted many time once changed the money value, it changes kills and deaths with same value @Avival Link to comment
Motar2k Posted December 17, 2019 Share Posted December 17, 2019 The bug occurs when logging in or disconnecting? @DiGiTal Link to comment
DiGiTal Posted December 17, 2019 Author Share Posted December 17, 2019 7 minutes ago, Avival said: The bug occurs when logging in or disconnecting? @DiGiTal Some persons says me it's the UPDATE must add the WHERE but doesn't work again Link to comment
DiGiTal Posted December 17, 2019 Author Share Posted December 17, 2019 fixed, the probleme was on ' must add WHERE + set account data for kills and deaths' 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