Jump to content

sqlite problem


Recommended Posts

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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).."'")

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
executeSQLQuery returns table of rows (tables inside a table) not just row. So, row[ 1 ].deaths should work.

yea it worked, thanks!

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

oh.. im used to code in PHP, where you are getting only one row, and you have to put it in while loop..

it working the same for MySQL for MTA.

I havent used SQLite much, as i dont like it (missing features)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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