GanJaRuleZ Posted January 3, 2012 Share Posted January 3, 2012 Hai all , so after i tried the userpanel it gives me an error , and i can't solve it.. This is the ERROR ERROR: userpanel\server.lua:20: attempt to perform arithmetic on a nil value And after i type !stats 2 times It gives me the following error : ERROR: userpanel\server.lua:21: attempt to index fiel '?' (a nil value) So here is the script : function DestructionMoney2() local alivePlayers = getAlivePlayers() if info == "Destruction derby" then if #alivePlayers == 1 then local playername = getPlayerName(alivePlayers[1]) local serial = getPlayerSerial(alivePlayers[1]) local oldData = executeSQLSelect( "RaceStats", "RaceWins","serial = '" .. serial .. "'") newData = tonumber(oldData[1]["RaceWins"]) + 1 setElementData(alivePlayers[1], "RaceWins", tonumber(getElementData(alivePlayers[1], "RaceWins")) + 1) executeSQLUpdate("RaceStats", "RaceWins = '" .. newData .. "'","serial = '" .. serial .. "'") outputChatBox(getPlayerName(alivePlayers[1] ) .. " is the last player alive!", rootElement, 0, 255, 0) end end end addEventHandler("onPlayerWasted", getRootElement(), function() local serial = getPlayerSerial(source) local oldData = executeSQLSelect("RaceStats", "RaceLoses", "serial = '" .. serial .. "'") setElementData(source, "RaceLoses", tonumber(getElementData(source, "RaceLoses")) + 1) newData = tonumber(oldData[1]["RaceWins"]) + 1 executeSQLUpdate("RaceStats", "RaceLoses = '" .. newData.. "'","serial = '" .. serial .. "'") end) Thank you! Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 function DestructionMoney2() local alivePlayers = getAlivePlayers() if info == "Destruction derby" then if #alivePlayers == 1 then local playername = getPlayerName(alivePlayers[1]) local serial = getPlayerSerial(alivePlayers[1]) local oldData = executeSQLSelect( "RaceStats", "RaceWins","serial = '" .. serial .. "'") if #oldData == 0 then executeSQLInsert ( "RaceStats","'1','"..getPlayerSerial(alivePlayers[1]).."'","RaceWins,serial" ) else newData = tostring(tonumber(oldData[1]["RaceWins"]) + 1) executeSQLUpdate("RaceStats", "RaceWins = '" .. newData .. "'","serial = '" .. serial .. "'") end setElementData(alivePlayers[1], "RaceWins", tostring(tonumber(getElementData(alivePlayers[1], "RaceWins")) + 1) or "1") outputChatBox(getPlayerName(alivePlayers[1] ) .. " is the last player alive!", rootElement, 0, 255, 0) end end end addEventHandler("onPlayerWasted", getRootElement(), function() local serial = getPlayerSerial(source) local oldData = executeSQLSelect("RaceStats", "RaceLoses", "serial = '" .. serial .. "'") setElementData(source, "RaceLoses", tostring(tonumber(getElementData(source, "RaceLoses")) + 1) or "1" ) if #oldDate == 0 then executeSQLInsert ( "RaceStats","'1','"..getPlayerSerial(source).."'","RaceLoses,serial" ) else newData = tostring(tonumber(oldData[1]["RaceWins"]) + 1) executeSQLUpdate("RaceStats", "RaceLoses = '" .. newData.. "'","serial = '" .. serial .. "'") end end) Link to comment
GanJaRuleZ Posted January 3, 2012 Author Share Posted January 3, 2012 function DestructionMoney2() local alivePlayers = getAlivePlayers() if info == "Destruction derby" then if #alivePlayers == 1 then local playername = getPlayerName(alivePlayers[1]) local serial = getPlayerSerial(alivePlayers[1]) local oldData = executeSQLSelect( "RaceStats", "RaceWins","serial = '" .. serial .. "'") if #oldData == 0 then executeSQLInsert ( "RaceStats","'1','"..getPlayerSerial(alivePlayers[1]).."'","RaceWins,serial" ) else newData = tostring(tonumber(oldData[1]["RaceWins"]) + 1) executeSQLUpdate("RaceStats", "RaceWins = '" .. newData .. "'","serial = '" .. serial .. "'") end setElementData(alivePlayers[1], "RaceWins", tostring(tonumber(getElementData(alivePlayers[1], "RaceWins")) + 1) or "1") outputChatBox(getPlayerName(alivePlayers[1] ) .. " is the last player alive!", rootElement, 0, 255, 0) end end end addEventHandler("onPlayerWasted", getRootElement(), function() local serial = getPlayerSerial(source) local oldData = executeSQLSelect("RaceStats", "RaceLoses", "serial = '" .. serial .. "'") setElementData(source, "RaceLoses", tostring(tonumber(getElementData(source, "RaceLoses")) + 1) or "1" ) if #oldDate == 0 then executeSQLInsert ( "RaceStats","'1','"..getPlayerSerial(source).."'","RaceLoses,serial" ) else newData = tostring(tonumber(oldData[1]["RaceWins"]) + 1) executeSQLUpdate("RaceStats", "RaceLoses = '" .. newData.. "'","serial = '" .. serial .. "'") end end) Ye , but it returns the following error.. ERROR: userpanel\server.lua:25: attempt to get length of global 'oldDate' (a nil value) Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 function DestructionMoney2() local alivePlayers = getAlivePlayers() if info == "Destruction derby" then if #alivePlayers == 1 then local playername = getPlayerName(alivePlayers[1]) local serial = getPlayerSerial(alivePlayers[1]) local oldData = executeSQLSelect( "RaceStats", "RaceWins","serial = '" .. serial .. "'") if #oldData == 0 then executeSQLInsert ( "RaceStats","'1','"..getPlayerSerial(alivePlayers[1]).."'","RaceWins,serial" ) else newData = tostring(tonumber(oldData[1]["RaceWins"]) + 1) executeSQLUpdate("RaceStats", "RaceWins = '" .. newData .. "'","serial = '" .. serial .. "'") end setElementData(alivePlayers[1], "RaceWins", tostring(tonumber(getElementData(alivePlayers[1], "RaceWins")) + 1) or "1") outputChatBox(getPlayerName(alivePlayers[1] ) .. " is the last player alive!", rootElement, 0, 255, 0) end end end addEventHandler("onPlayerWasted", getRootElement(), function() local serial = getPlayerSerial(source) local oldData = executeSQLSelect("RaceStats", "RaceLoses", "serial = '" .. serial .. "'") setElementData(source, "RaceLoses", tostring(tonumber(getElementData(source, "RaceLoses")) + 1) or "1" ) if #oldData == 0 then executeSQLInsert ( "RaceStats","'1','"..getPlayerSerial(source).."'","RaceLoses,serial" ) else newData = tostring(tonumber(oldData[1]["RaceWins"]) + 1) executeSQLUpdate("RaceStats", "RaceLoses = '" .. newData.. "'","serial = '" .. serial .. "'") end end) My bad I misspelled it. Link to comment
GanJaRuleZ Posted January 3, 2012 Author Share Posted January 3, 2012 Ok no errors , but now the data doesen't saves... Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 I changed everything to the new db functions. addEventHandler ( "onResourceStart" , resourceRoot , function ( ) database = dbConnect ( "sqlite" , "database.db" ) dbExec ( database , "CREATE TABLE IF NOT EXISTS RaceStats (RaceWins,RaceLoses,serial)" ) end ) function DestructionMoney2() local alivePlayers = getAlivePlayers() if info == "Destruction derby" then if #alivePlayers == 1 then local playername = getPlayerName(alivePlayers[1]) local serial = getPlayerSerial(alivePlayers[1]) local raceWins local oldData = dbPoll ( dbQuery ( database , "SELECT * FROM RaceStats WHERE serial = ?" , getPlayerSerial ( alivePlayers [ 1 ] ) ) , -1 ) if #oldData == 0 then dbExec ( database , "INSERT INTO RaceStats VALUES (?,?,?)" , "1" , "0" , getPlayerSerial ( alivePlayers [ 1 ] ) ) raceWins = "1" else raceWins = tostring ( tonumber ( oldData [ 1 ] [ "RaceWins" ] ) + 1 ) dbExec ( database , "UPDATE RaceStats SET RaceWins = ? WHERE serial = ?" , raceWins , getPlayerSerial ( alivePlayers [ 1 ] ) ) end setElementData(alivePlayers[1], "RaceWins", raceWins ) outputChatBox(getPlayerName(alivePlayers[1] ) .. " is the last player alive!", root, 0, 255, 0) end end end addEventHandler("onPlayerWasted", getRootElement(), function() local serial = getPlayerSerial(source) local oldData = dbPoll ( dbQuery ( database , "SELECT * FROM RaceStats WHERE serial = ?" , serial ) , -1 ) local raceLoses if #oldData == 0 then dbExec ( database , "INSERT INTO RaceStats VALUES (?,?,?)" , "0" , "1" , serial ) raceLoses = "1" else raceLoses = tostring(tonumber(oldData[1]["RaceWins"]) + 1) dbExec ( database , "UPDATE RaceStats SET RaceLoses = ? WHERE serial = ?" , raceLoses , serial ) end setElementData(source, "RaceLoses", raceLoses) end) Link to comment
GanJaRuleZ Posted January 3, 2012 Author Share Posted January 3, 2012 It still doesen't saves ... Link to comment
Kenix Posted January 3, 2012 Share Posted January 3, 2012 Try: addEventHandler ( "onResourceStart" , resourceRoot , function ( ) database = dbConnect ( "sqlite" , "database.db" ) dbExec ( database , "CREATE TABLE IF NOT EXISTS RaceStats ( RaceWins INT,RaceLoses INT,serial TEXT )" ) end ) function DestructionMoney2() local alivePlayers = getAlivePlayers() if info == "Destruction derby" then if #alivePlayers == 1 then local playername = getPlayerName(alivePlayers[1]) local serial = getPlayerSerial(alivePlayers[1]) local raceWins local oldData = dbPoll ( dbQuery ( database , "SELECT * FROM RaceStats WHERE serial = ?" , getPlayerSerial ( alivePlayers [ 1 ] ) ) , -1 ) if #oldData == 0 then dbExec ( database , "INSERT INTO RaceStats VALUES (?,?,?)" , "1" , "0" , getPlayerSerial ( alivePlayers [ 1 ] ) ) raceWins = "1" else raceWins = tostring ( tonumber ( oldData [ 1 ] [ "RaceWins" ] ) + 1 ) dbExec ( database , "UPDATE RaceStats SET RaceWins = ? WHERE serial = ?" , raceWins , getPlayerSerial ( alivePlayers [ 1 ] ) ) end setElementData(alivePlayers[1], "RaceWins", raceWins ) outputChatBox(getPlayerName(alivePlayers[1] ) .. " is the last player alive!", root, 0, 255, 0) end end end addEventHandler("onPlayerWasted", getRootElement(), function() local serial = getPlayerSerial(source) local oldData = dbPoll ( dbQuery ( database , "SELECT * FROM RaceStats WHERE serial = ?" , serial ) , -1 ) local raceLoses if #oldData == 0 then dbExec ( database , "INSERT INTO RaceStats VALUES (?,?,?)" , "0" , "1" , serial ) raceLoses = "1" else raceLoses = tostring(tonumber(oldData[1]["RaceWins"]) + 1) dbExec ( database , "UPDATE RaceStats SET RaceLoses = ? WHERE serial = ?" , raceLoses , serial ) end setElementData(source, "RaceLoses", raceLoses) end) Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 That is because 'info' is not defined. addEventHandler ( "onResourceStart" , resourceRoot , function ( ) database = dbConnect ( "sqlite" , "database.db" ) dbExec ( database , "CREATE TABLE IF NOT EXISTS RaceStats ( RaceWins INT,RaceLoses INT,serial TEXT )" ) end ) function DestructionMoney2() local alivePlayers = getAlivePlayers() --if info == "Destruction derby" then if #alivePlayers == 1 then local playername = getPlayerName(alivePlayers[1]) local serial = getPlayerSerial(alivePlayers[1]) local raceWins local oldData = dbPoll ( dbQuery ( database , "SELECT * FROM RaceStats WHERE serial = ?" , getPlayerSerial ( alivePlayers [ 1 ] ) ) , -1 ) if #oldData == 0 then dbExec ( database , "INSERT INTO RaceStats VALUES (?,?,?)" , "1" , "0" , getPlayerSerial ( alivePlayers [ 1 ] ) ) raceWins = "1" else raceWins = tostring ( tonumber ( oldData [ 1 ] [ "RaceWins" ] ) + 1 ) dbExec ( database , "UPDATE RaceStats SET RaceWins = ? WHERE serial = ?" , raceWins , getPlayerSerial ( alivePlayers [ 1 ] ) ) end setElementData(alivePlayers[1], "RaceWins", raceWins ) outputChatBox(getPlayerName(alivePlayers[1] ) .. " is the last player alive!", root, 0, 255, 0) end end addEventHandler("onPlayerWasted", getRootElement(), function() local serial = getPlayerSerial(source) local oldData = dbPoll ( dbQuery ( database , "SELECT * FROM RaceStats WHERE serial = ?" , serial ) , -1 ) local raceLoses if #oldData == 0 then dbExec ( database , "INSERT INTO RaceStats VALUES (?,?,?)" , "0" , "1" , serial ) raceLoses = "1" else raceLoses = tostring(tonumber(oldData[1]["RaceWins"]) + 1) dbExec ( database , "UPDATE RaceStats SET RaceLoses = ? WHERE serial = ?" , raceLoses , serial ) end setElementData(source, "RaceLoses", raceLoses) end) 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