WASSIm. Posted November 14, 2013 Share Posted November 14, 2013 hi guys plis i need help. i have problem it not working plis help EDIT DEBUG: http://i.imgur.com/JFafHLR.png local connection = nil addEventHandler ( "onResourceStart", resourceRoot, function ( ) connection = dbConnect( "sqlite", "database/database.db" ) if ( connection )then outputDebugString ( "Successfully connected to database.db" ) else outputDebugString ( "Failed to connect to database.db", 3 ) end end ) function dbQueryZA( ... ) local handler = connection if ( not handler ) then return false, "Couldn't connect to SQLite database." end local query = dbQuery( connection, ... ) local result, numrows, errmsg = dbPoll ( query, -1 ) if ( type ( result ) == "table" and #result == 0 or not result ) then return false else return result end end function dbExecZA( ... ) local handler = connection if ( not handler ) then return false, "Couldn't connect to SQLite database." end return dbExec( connection, ... ) end this exmple i use function getAccountZkill ( account ) local result = exports["server"]:dbQueryZA( "SELECT * FROM zkills WHERE account = ?", tostring ( account ) ) return tostring ( result[ 1 ][ "Zkill" ] ) end Link to comment
K4stic Posted November 14, 2013 Share Posted November 14, 2013 Try This: local connection = nil addEventHandler ( "onResourceStart", resourceRoot, function ( ) connection = dbConnect( "sqlite", "database/database.db" ) if ( connection )then outputDebugString ( "Successfully connected to database.db" ) else outputDebugString ( "Failed to connect to database.db", 3 ) end end ) function dbQueryZA( ... ) if (not connection ) then return false, "Couldn't connect to SQLite database." else local hadler = dbQuery( connection, ... ) return dbPoll( hadler, -1 ) end end function dbExecZA( monkey, ... ) if ( not connection ) then return false, "Couldn't connect to SQLite database." else return dbExec( connection, monkey, ... ) end end Link to comment
WASSIm. Posted November 14, 2013 Author Share Posted November 14, 2013 now result dbQuery nil Link to comment
TAPL Posted November 14, 2013 Share Posted November 14, 2013 Try local connection = nil addEventHandler("onResourceStart", resourceRoot, function() connection = dbConnect("sqlite", "database/database.db") if (connection)then outputDebugString("Successfully connected to database.db") else outputDebugString("Failed to connect to database.db", 3) end end ) function dbQueryZA(Query, ...) if (not connection) then return false, "Couldn't connect to SQLite database." end local query = dbQuery(connection, Query, table.concat({...}, ", ")) local result, numrows, errmsg = dbPoll(query, -1) if (type(result) == "table" and #result == 0 or not result) then return false else return result end end function dbExecZA(Query, ...) if (not connection) then return false, "Couldn't connect to SQLite database." end return dbExec(connection, Query, table.concat({...}, ", ")) end Link to comment
K4stic Posted November 14, 2013 Share Posted November 14, 2013 Try This: local connection = nil addEventHandler ( "onResourceStart", resourceRoot, function ( ) connection = dbConnect( "sqlite", "database/database.db" ) if ( connection )then outputDebugString ( "Successfully connected to database.db" ) else outputDebugString ( "Failed to connect to database.db", 3 ) end end ) function dbQueryZA( ... ) if (not connection ) then return false, "Couldn't connect to SQLite database." else local hadler = dbQuery( connection, ... ) return dbPoll( hadler, -1 ) end end function dbExecZA( monkey, ... ) if ( not connection ) then return false, "Couldn't connect to SQLite database." else return dbExec( connection, monkey, ... ) end end To work that i make it's easy do the next (it's the same example that you give with little edit) function getAccountZkill ( account ) local result = exports["server"]:dbQueryZA( "SELECT * FROM zkills WHERE account = ?", tostring ( account ) ) return tostring ( result ) end Link to comment
WASSIm. Posted November 14, 2013 Author Share Posted November 14, 2013 Post the code you use. that have getAccountZkill ? Link to comment
WASSIm. Posted November 14, 2013 Author Share Posted November 14, 2013 problem its in dbQueryZA local connection = nil addEventHandler ( "onResourceStart", resourceRoot, function ( ) exports["scoreboard"]:addScoreboardColumn( "Zombie kills", root, 80, "Z kills", 6) exports["server"]:dbExecZA("CREATE TABLE IF NOT EXISTS zkills (ID INTEGER PRIMARY KEY NOT NULL, account TEXT, Zkill INT)" ) end ) addEventHandler("onResourceStart", resourceRoot, function () for index, player in ipairs(getElementsByType("player")) do local account = getPlayerAccount(player) if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) local zkill = getAccountZkill ( accountName ) if (account) then if not ( zkill ) then addZkillToDatabase ( accountName ) setElementData(player, "Zombie kills", 0) else setElementData(player, "Zombie kills", tonumber(zkill)) end end end end ) addEventHandler("onResourceStop", resourceRoot, function () for index, player in ipairs(getElementsByType("player")) do local zkill = tonumber(getElementData(player,"Zombie kills")) or 0 local account = getPlayerAccount(player) if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) if (zkill) and (account) then setAccountZkill(accountName, tonumber(zkill)) removeElementData(player, "Zombie kills") end end end) addEventHandler("onPlayerLogout", getRootElement(), function (_,account) local zkill = tonumber(getElementData(source,"Zombie kills")) or 0 local accountName = getAccountName(account) setAccountZkill(accountName, zkill) removeElementData(source, "Zombie kills") end ) addEventHandler("onPlayerQuit", getRootElement(), function ( ) local zkill = tonumber(getElementData(source,"Zombie kills")) or 0 local account = getPlayerAccount(source) if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) if (zkill) and (account) then setAccountZkill(accountName, zkill) end end ) addEventHandler("onPlayerLogin", getRootElement(), function (_,account) local accountName = getAccountName(account) local zkill = getAccountZkill ( accountName ) if not ( zkill ) then addZkillToDatabase ( accountName ) setElementData(source, "Zombie kills", 0) else setElementData(source, "Zombie kills", zkill) end end ) function addZkillToDatabase ( account ) return exports["server"]:dbExecZA("INSERT INTO zkills (ID, account, Zkill) VALUES (NULL, '".. tostring ( account ) .."', '0')" ) end function getAccountZkill ( account ) local result = exports["server"]:dbQueryZA( "SELECT * FROM zkills WHERE account = ?", tostring ( account ) ) return tostring ( result[ 1 ][ "Zkill" ] ) end function setAccountZkill ( account, theZkille ) return exports["server"]:dbExecZA("UPDATE zkills SET Zkill = '".. tostring ( theZkille ) .."' WHERE account = '" .. tostring ( account ) .."'" ) end Link to comment
TAPL Posted November 14, 2013 Share Posted November 14, 2013 local connection = nil addEventHandler("onResourceStart", resourceRoot, function() connection = dbConnect("sqlite", "database/database.db") if (connection)then outputDebugString("Successfully connected to database.db") else outputDebugString("Failed to connect to database.db", 3) end end ) function dbQueryZA(Query) if (not connection) then return false, "Couldn't connect to SQLite database." end local query = dbQuery(connection, Query) local result, numrows, errmsg = dbPoll(query, -1) if (type(result) == "table" and #result == 0 or not result) then return false else return result end end function dbExecZA(Query) if (not connection) then return false, "Couldn't connect to SQLite database." end return dbExec(connection, Query) end addEventHandler("onResourceStart", resourceRoot, function() exports["scoreboard"]:addScoreboardColumn( "Zombie kills", root, 80, "Z kills", 6) exports["server"]:dbExecZA("CREATE TABLE IF NOT EXISTS zkills (ID INTEGER PRIMARY KEY NOT NULL, account TEXT, Zkill INT)") end ) addEventHandler("onResourceStart", resourceRoot, function() for index, player in ipairs(getElementsByType("player")) do local account = getPlayerAccount(player) if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) local zkill = getAccountZkill(accountName) if (account) then if not (zkill) then addZkillToDatabase ( accountName ) setElementData(player, "Zombie kills", 0) else setElementData(player, "Zombie kills", zkill) end end end end) addEventHandler("onResourceStop", resourceRoot, function () for index, player in ipairs(getElementsByType("player")) do local zkill = getElementData(player,"Zombie kills") or 0 local account = getPlayerAccount(player) if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) if (zkill) and (account) then setAccountZkill(accountName, zkill) removeElementData(player, "Zombie kills") end end end) addEventHandler("onPlayerLogout", getRootElement(), function (account) local zkill = getElementData(source,"Zombie kills") or 0 local accountName = getAccountName(account) setAccountZkill(accountName, zkill) removeElementData(source, "Zombie kills") end) addEventHandler("onPlayerQuit", getRootElement(), function ( ) local zkill = getElementData(source,"Zombie kills") or 0 local account = getPlayerAccount(source) if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) if (zkill) and (account) then setAccountZkill(accountName, zkill) end end) addEventHandler("onPlayerLogin", getRootElement(), function (_,account) local accountName = getAccountName(account) local zkill = getAccountZkill(accountName) if not ( zkill ) then addZkillToDatabase ( accountName ) setElementData(source, "Zombie kills", 0) else setElementData(source, "Zombie kills", zkill) end end) function addZkillToDatabase(account) return exports["server"]:dbExecZA("INSERT INTO zkills (ID, account, Zkill) VALUES (NULL, '"..account.."', '0')") end function getAccountZkill(account) local result = exports["server"]:dbQueryZA( "SELECT * FROM zkills WHERE account = '"..account.."'") if (type(result) == "table" and #result == 0 or not result) then return false else return tostring(result[1]["Zkill"]) end end function setAccountZkill(account, theZkille) return exports["server"]:dbExecZA("UPDATE zkills SET Zkill = '"..theZkille.."' WHERE account = '"..account.."'") end Link to comment
WASSIm. Posted November 14, 2013 Author Share Posted November 14, 2013 i can't make ( if (type(result) == "table" and #result == 0 or not result) then ) only in script have database ? Link to comment
TAPL Posted November 14, 2013 Share Posted November 14, 2013 function getAccountZkill(account) local result = exports["server"]:dbQueryZA( "SELECT * FROM zkills WHERE account = '"..account.."'") if (type(result) == "table" and #result == 0 or not result) then return false else return tostring(result[1]["Zkill"]) end end You can change it to: function getAccountZkill(account) local result = exports["server"]:dbQueryZA( "SELECT * FROM zkills WHERE account = '"..account.."'") if (result) then return tostring(result[1]["Zkill"]) end end Link to comment
WASSIm. Posted November 14, 2013 Author Share Posted November 14, 2013 thank you a lot Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now