Jump to content

data base saving systeme (money,deaths)


DiGiTal

Recommended Posts

Posted

 

  • 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)

 

oKxg02t.png?width=300&height=300

 

Posted

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

My discord: Armisael_#1719

 Did my help work for you? Don't forget to thank 

¿Mi ayuda funcionó para ti? No olvides agradecer

How give thanks

 

 

 

 

Posted

The bug occurs when logging in or disconnecting? @DiGiTal

My discord: Armisael_#1719

 Did my help work for you? Don't forget to thank 

¿Mi ayuda funcionó para ti? No olvides agradecer

How give thanks

 

 

 

 

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...