Jump to content

Sql my first script


Recommended Posts

so, i start read sql and i am try make one save system, but no work. can help me?

-- by manawydan, sqlsavesystem 
  
addEventHandler("onResourceStart",resourceRoot, 
function() 
executeSQLQuery("CREATE TABLE IF NOT EXISTS SistemaDeDados (atual TEXT, x INT, y INT, z INT, skin INT, arma0 INT, arma1 INT, arma2 INT, arma3 INT, arma4 INT, arma5 INT, arma6 INT, arma7 INT, arma8 INT, arma9 INT, arma10 INT, arma11 INT, arma12 INT, marma0 INT, marma1 INT, marma2 INT, marma3 INT, marma4 INT, marma5 INT, marma6 INT, marma7 INT, marma8 INT, marma9 INT, marma10 INT, marma11 INT, marma12 INT, vida INT, colete INT, interior INT, dimension INT, dinheiro INT, time TEXT)") 
local valores = executeSQLQuery("SELECT * FROM SistemaDeDados") 
if #valores == 0 then 
outputDebugString("Sistema de salvamento sendo iniciado.") 
outputDebugString("Valores atuais da tabela sendo criados.") 
end 
end) 
  
addEventHandler("onPlayerQuit",root, 
function() 
local conta = getPlayerAccount(source) 
if not isGuestAccount(conta) then 
setAccountData(conta,"JajogouAki",true) 
local x,y,z = getElementPosition(source) 
local health = getElementHealth(source) 
local colete = getPedArmor(source) 
local skin = getElementModel(source) 
local interior = getElementInterior(source) or 0 
local dimension = getElementDimension(source) 
local dinheiro = getPlayerMoney(source) or 0 
local time = getPlayerTeam(source)  
local arma0 = getPedWeapon(source,0)  
local arma1 = getPedWeapon(source,1)  
local arma2 = getPedWeapon(source,2)  
local arma3 = getPedWeapon(source,3)  
local arma4 = getPedWeapon(source,4) 
local arma5 = getPedWeapon(source,5)   
local arma6 = getPedWeapon(source,6) 
local arma7 = getPedWeapon(source,7)   
local arma8 = getPedWeapon(source,8)  
local arma9 = getPedWeapon(source,9)  
local arma10 = getPedWeapon(source,10) 
local arma11 = getPedWeapon(source,11)   
local arma12 = getPedWeapon(source,12)  
local marma0 = getPedTotalAmmo(source,0)  
local marma1 = getPedTotalAmmo(source,1)  
local marma2 = getPedTotalAmmo(source,2)  
local marma3 = getPedTotalAmmo(source,3)  
local marma4 = getPedTotalAmmo(source,4) 
local marma5 = getPedTotalAmmo(source,5)   
local marma6 = getPedTotalAmmo(source,6) 
local marma7 = getPedTotalAmmo(source,7)   
local marma8 = getPedTotalAmmo(source,8)  
local marma9 = getPedTotalAmmo(source,9)  
local marma10 = getPedTotalAmmo(source,10) 
local marma11 = getPedTotalAmmo(source,11)   
local marma12 = getPedTotalAmmo(source,12)  
executeSQLQuery("INSERT INTO SistemaDeDados(atual,x,y,z,skin,arma0,arma1,arma2,arma3,arma4,arma5,arma6,arma7,arma8,arma9,arma10,arma11,arma12,marma0,marma1,marma2,marma3,marma4,marma5,marma6,marma7,marma8,marma9,marma10,marma11,marma12,vida,colete,interior,dimension,dinheiro,time) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",conta,x,y,z,skin,arma0,arma1,arma2,arma3,arma4,arma5,arma6,arma7,arma8,arma9,arma10,arma11,arma12,marma0,marma1,marma2,marma3,marma4,marma5,marma6,marma7,marma8,marma9,marma10,marma11,marma12,health,colete,interior,dimension,dinheiro,time) 
end 
end) 
  
addEventHandler("onPlayerLogin",root, 
function(antes,atual) 
if atual and not isGuestAccount(atual) then 
if getAccountData(atual,"JajogouAki") then 
local Data = executeSQLQuery("SELECT * FROM SistemaDeDados WHERE atual=?",atual)  
setElementHealth(source,Data[1]) 
setElementPosition(source,Data[2],Data[3],Data[4]) 
end 
end 
end) 
  

Link to comment
  • Moderators
so just use getAccountName and work?

Almost yeah. You need to use getAccountName to then use that name in the saving query (onPlayerQuit) and in the loading query too (onPlayerLogin).

But there is another problem in your onPlayerLogin:

- Data[1] will be the 1st row in the returned table (so the row with all players datas).

- Data[1].vida will be the health.

local Data = executeSQLQuery("SELECT * FROM SistemaDeDados WHERE atual=?", atualName) 
setElementHealth(source, Data[1].vida) 
setElementPosition(source, Data[1].x, Data[1].y, Data[1].z) 

You can also do this:

local Data = executeSQLQuery("SELECT * FROM SistemaDeDados WHERE atual=?",atual) 
local datas = Data[1] 
setElementHealth(source, data.vida) 
setElementPosition(source, datas.x, datas.y, datas.z) 

Hope it helps.

Link to comment

Well, isn't it better to use db functions? And create your own database in file which you could look in.

I'm actually using SQLite Manager - an addon for my browser, where i can load my database and look into it. Also i'm working on .sqlite files, not .db, which is my opinion better.

If you want to use my sultion download SQLite Manage from there:

https://addons.mozilla.org/pl/firefox/a ... e-manager/

And to turn it by writing on the website bar following code:

chrome://sqlitemanager/content/sqlitemanager.xul

or in Windows's start

firefox -chrome chrome://sqlitemanager/content/sqlitemanager.xul

Link to comment

so i try it:

-- by manawydan, sqlsavesystem 
  
addEventHandler("onResourceStart",resourceRoot, 
function() 
executeSQLQuery("CREATE TABLE IF NOT EXISTS SistemaDeDados (atual TEXT, x INT, y INT, z INT, skin INT, arma0 INT, arma1 INT, arma2 INT, arma3 INT, arma4 INT, arma5 INT, arma6 INT, arma7 INT, arma8 INT, arma9 INT, arma10 INT, arma11 INT, arma12 INT, marma0 INT, marma1 INT, marma2 INT, marma3 INT, marma4 INT, marma5 INT, marma6 INT, marma7 INT, marma8 INT, marma9 INT, marma10 INT, marma11 INT, marma12 INT, vida INT, colete INT, interior INT, dimension INT, dinheiro INT, time TEXT)") 
local valores = executeSQLQuery("SELECT * FROM SistemaDeDados") 
if #valores == 0 then 
outputDebugString("Sistema de salvamento sendo iniciado.") 
outputDebugString("Valores atuais da tabela sendo criados.") 
end 
end) 
  
addEventHandler("onPlayerQuit",root, 
function() 
local conta = getPlayerAccount(source) 
if not isGuestAccount(conta) then 
setAccountData(conta,"JajogouAki",true) 
local c = getAccountName(conta) 
local x,y,z = getElementPosition(source) 
local health = getElementHealth(source) 
local colete = getPedArmor(source) 
local skin = getElementModel(source) 
local interior = getElementInterior(source) or 0 
local dimension = getElementDimension(source) 
local dinheiro = getPlayerMoney(source) or 0 
local time = getPlayerTeam(source)  
local arma0 = getPedWeapon(source,0)  
local arma1 = getPedWeapon(source,1)  
local arma2 = getPedWeapon(source,2)  
local arma3 = getPedWeapon(source,3)  
local arma4 = getPedWeapon(source,4) 
local arma5 = getPedWeapon(source,5)   
local arma6 = getPedWeapon(source,6) 
local arma7 = getPedWeapon(source,7)   
local arma8 = getPedWeapon(source,8)  
local arma9 = getPedWeapon(source,9)  
local arma10 = getPedWeapon(source,10) 
local arma11 = getPedWeapon(source,11)   
local arma12 = getPedWeapon(source,12)  
local marma0 = getPedTotalAmmo(source,0)  
local marma1 = getPedTotalAmmo(source,1)  
local marma2 = getPedTotalAmmo(source,2)  
local marma3 = getPedTotalAmmo(source,3)  
local marma4 = getPedTotalAmmo(source,4) 
local marma5 = getPedTotalAmmo(source,5)   
local marma6 = getPedTotalAmmo(source,6) 
local marma7 = getPedTotalAmmo(source,7)   
local marma8 = getPedTotalAmmo(source,8)  
local marma9 = getPedTotalAmmo(source,9)  
local marma10 = getPedTotalAmmo(source,10) 
local marma11 = getPedTotalAmmo(source,11)   
local marma12 = getPedTotalAmmo(source,12)  
executeSQLQuery("INSERT INTO SistemaDeDados('atual','x','y','z','skin','arma0','arma1','arma2','arma3','arma4','arma5','arma6','arma7','arma8','arma9','arma10','arma11','arma12','marma0','marma1','marma2','marma3','marma4','marma5','marma6','marma7','marma8','marma9','marma10','marma11','marma12','vida','colete','interior','dimension','dinheiro','time') VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",'c','x','y','z','skin','arma0','arma1','arma2','arma3','arma4','arma5','arma6','arma7','arma8','arma9','arma10','arma11','arma12','marma0','marma1','marma2','marma3','marma4','marma5','marma6','marma7','marma8','marma9','marma10','marma11','marma12','vida','colete','interior','dimension','dinheiro','time') 
end 
end) 
  
addEventHandler("onPlayerLogin",root, 
function(antes,atual) 
if atual and not isGuestAccount(atual) then 
if getAccountData(atual,"JajogouAki") then 
local c = getAccountName(atual) 
local Data = executeSQLQuery("SELECT * FROM SistemaDeDados WHERE atual=?", c) 
setElementHealth(source, Data[1].vida) 
setElementPosition(source, Data[1].x, Data[1].y, Data[1].z) 
end 
end 
end) 
  

debug say: line 63 attemp to index field '?'

no errors in quit.

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