Jump to content

sqlite problem


Recommended Posts

hey guys, i got a problem with a sqlite script,

local playerstbl = "deaths"
local playerstbl2 = "kills"
 
function start ()
executeSQLCreateTable("playerstbl", "accountname TEXT, deaths INT")
executeSQLCreateTable("playerstbl2", "accountname TEXT, kills INT")
outputDebugString ( "Resource loaded.", 3 )
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start)
 
function login1(prev, account, autologin)
local result = executeSQLSelect("playerstbl", "deaths", "accountname = '"..getAccountName(account).."'")
local result2 = executeSQLSelect("playerstbl2", "kills", "accountname = '"..getAccountName(account).."'")
if result and #result > 0 then
setElementData(source, "deaths", tonumber(result[1]["deaths"]) or 0)
--		setElementData(source, "kills", tonumber(result2[1]["kills"]) or 0)
else
executeSQLInsert("playerstbl", "'0', '"..getAccountName(account).."'", "deaths, accountname")
executeSQLInsert("playerstbl2", "'0', '"..getAccountName(account).."'", "kills, accountname")
end		
end
addEventHandler("onPlayerLogin", getRootElement(), login1)
 
function rewardOnWasted ( ammo, killer, killerweapon, bodypart )
local acc = getPlayerAccount(source)
if not isGuestAccount(acc) then
local deaths = executeSQLQuery("SELECT deaths FROM playerstbl WHERE accountname = '"..getAccountName(acc).."'")["deaths"]	
if not deaths then
deaths = 1
else
deaths = deaths +1
end
executeSQLUpdate("playerstbl", "deaths = '"..deaths.."'", "accountname = '"..getAccountName(acc).."'")
end
end
addEventHandler ( "onPlayerWasted", getRootElement(), rewardOnWasted )
 
function rewardOnWasted2 ( ammo, killer, killerweapon, bodypart )
if (killer ) and (killer ~=source ) then
local acc2 = getPlayerAccount(killer)
if not isGuestAccount(acc2) then
local kills = executeSQLQuery("SELECT kills FROM playerstbl2 WHERE accountname = '"..getAccountName(acc2).."'")["kills"]	
if not kills then
kills = 1
else
kills = kills + 1
end
executeSQLUpdate("playerstbl2", "kills = '"..kills.."'", "accountname = '"..getAccountName(acc2).."'")
end
end
end
addEventHandler ( "onPlayerWasted", getRootElement(), rewardOnWasted2 )

the problem is that when i suicide the "deaths" dosnt set to +1 it just set to 1.

Link to comment
local row = executeSQLQuery("SELECT deaths FROM playerstbl WHERE accountname = '"..getAccountName(acc).."'")["deaths"]	
if not row then
 deaths = 1
else
 deaths = row['deaths'] +1
end
executeSQLUpdate("playerstbl", "deaths = '"..deaths.."'", "accountname = '"..getAccountName(acc).."'")

Link to comment
local row = executeSQLQuery("SELECT deaths FROM playerstbl WHERE accountname = '"..getAccountName(acc).."'")["deaths"]	
if not row then
 deaths = 1
else
 deaths = row['deaths'] +1
end
executeSQLUpdate("playerstbl", "deaths = '"..deaths.."'", "accountname = '"..getAccountName(acc).."'")

Still dosnt work.

Link to comment

debug, debug, debug ;)

local row = executeSQLQuery("SELECT deaths FROM playerstbl WHERE accountname = '"..getAccountName(acc).."'") -- WTF is that? i didnt see its here -> ["deaths"]	
if not row then
outputDebugString("there was no row")
 deaths = 1
else
outputDebugString("there was one row with deaths "..row['deaths'].." now its "..row['deaths']+1)
 deaths = row['deaths'] +1
end
executeSQLUpdate("playerstbl", "deaths = '"..deaths.."'", "accountname = '"..getAccountName(acc).."'")

and btw, your script is unsafe, read about SQL Injections

Link to comment
debug, debug, debug ;)
local row = executeSQLQuery("SELECT deaths FROM playerstbl WHERE accountname = '"..getAccountName(acc).."'") -- WTF is that? i didnt see its here -> ["deaths"]	
if not row then
outputDebugString("there was no row")
 deaths = 1
else
outputDebugString("there was one row with deaths "..row['deaths'].." now its "..row['deaths']+1)
 deaths = row['deaths'] +1
end
executeSQLUpdate("playerstbl", "deaths = '"..deaths.."'", "accountname = '"..getAccountName(acc).."'")

and btw, your script is unsafe, read about SQL Injections

I ever use DEBUG, the error is this now "attempt to perform arithmetic on field "deaths" (a nil value)"

in this line: outputDebugString("there was one row with deaths "..row['deaths'].." now its "..row['deaths']+1)

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