Jump to content

Recommended Posts

executeSQLQuery("CREATE TABLE IF NOT EXISTS `player_stats` (`username` TEXT, `Thirst` INT, `Hunger` INT)")

addEventHandler("onPlayerQuit",
function (Player)
  local atsh = getElementData(source, "Thirst")
  local hungry = getElementData(source, "Hunger")
  local username = getAccountName(getPlayerAccount(thePlayer))

  local result = executeSQLQuery("SELECT * FROM player_stats WHERE `username` = ?", username)
  if (#result > 1) then
    executeSQLQuery("UPDATE `player_stats` SET `Hunger` = ?, `Thirst` = ? WHERE `username` = ?", hungry, atsh, username)
  else
    executeSQLQuery("INSERT INTO health (username, Thirst, Hunger) VALUES (?, ?, ?)", username, atsh, hungry)
  end
end)

addEventHandler("onPlayerLogin", root, function(_, account)
  local accountName = getAccountName(account)
  local result = executeSQLQuery("SELECT * FROM player_stats WHERE username = ?", accountName)
  if (#result > 1) then
    setElementData(source, "Thirst", result[1].Thirst)
    setElementData(source, "Hunger", result[1].Hunger)
  end
end)

it isn't working please help

 

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