proracer Posted January 15, 2011 Share Posted January 15, 2011 Hello all.I have tried to make simple cash system but I got a weird error. addEvent("onMapStarting") function creatingTables() executeSQLCreateTable("Money", "Cash INT") executeSQLCreateTable("DDDM", "serial STRING,DDAttempts INT") outputChatBox("Cash System by Pr0RaC3R started.") end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), creatingTables) function ClientReady(g_player) local serial = getPlayerSerial(g_player) local playername = getPlayerName(g_player) CheckPlayer = executeSQLSelect ( "Money", "serial", "serial = '" .. serial .. "'" ) CheckPlayer2= executeSQLSelect ( "DDDM", "serial", "serial = '" .. serial .. "'" ) if ( type( CheckPlayer ) == "table" and #CheckPlayer == 0 ) or not CheckPlayer then executeSQLInsert ( "Money", "'"..serial.."','0','0','0','0'" ) end if ( type( CheckPlayer2 ) == "table" and #CheckPlayer2 == 0 ) or not CheckPlayer2 then executeSQLInsert ( "DDDM", "'"..serial.."','0','0'" ) end end addEvent("onClientReady",true) addEventHandler("onClientReady",getRootElement(),ClientReady) function DestructionMoney(mapInfo,mapOptions,gameOptions) info = mapInfo.modename if mapInfo.modename == "Destruction derby" then local players = getElementsByType("player") for k,v in ipairs(players) do local serial = getPlayerSerial(v) local DDAttempts = executeSQLSelect ( "DDDM", "DDAttempts","serial = '" .. serial .. "'") DDAttempts = tonumber(DDAttempts[1]["DDAttempts"]) + 1 executeSQLUpdate ( "DDDM", "DDAttempts = '"..DDAttempts.."'","serial = '" .. serial .. "'") setElementData(v,"data.DDAttempts",DDAttempts,true) end end end function DestructionMoney2(thePlayer) local playername = getPlayerName(thePlayer) local serial = getPlayerSerial(thePlayer) local Cash = executeSQLSelect ( "Money", "Cash","serial = '" .. serial .. "'") outputChatBox("*Wins: "..playername.." took $"..get('MoneyForDD').." for winning the map!",getRootElement(),255,255,0) Cash = tonumber(Cash[1]["Cash"]) + get('MoneyForDD') setElementData(thePlayer ,"Cash", Cash) setElementData(thePlayer ,"data.money",Cash,true) setElementData(thePlayer ,"data.playername",playername,true) executeSQLUpdate ( "Money", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") end function hunterBonus(pickupID, pickupType, vehicleModel) if info == "Destruction derby" then if pickupType == "vehiclechange" then if vehicleModel == 425 then local serial = getPlayerSerial(source) local Cash = executeSQLSelect ( "Money", "Cash","serial = '" .. serial .. "'") Cash = tonumber(Cash[1]["Cash"]) + 1000 outputChatBox("*Hunter: "..getPlayerName(source).." gets a $1000 hunter bonus!",source,25,125,225) setElementData(source ,"Cash", Cash) setElementData(source ,"data.money",Cash,true) executeSQLUpdate ( "Money", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") end end end end addEventHandler("onPlayerPickUpRacePickup",getRootElement(),hunterBonus) addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() exports.scoreboard:addScoreboardColumn("Cash") end) addEventHandler("onMapStarting", getRootElement() , DestructionMoney) Error: Line33 (attempt to index field '?' (a nil value) ) Link to comment
SDK Posted January 15, 2011 Share Posted January 15, 2011 It means DDAttemps[1] = nil. I guess your SQL select returns an empty table, try checking your select + results. Link to comment
proracer Posted January 15, 2011 Author Share Posted January 15, 2011 I accidently forgot to add serial category to Money table.Now it returns no errors but it simply doesn't work. EDIT: Console said some functions were deprecated so I edit it.Now it shows the error still but I don't know how to fix it. I have looked over the script many times and I can't find the error. Link to comment
SDK Posted January 15, 2011 Share Posted January 15, 2011 Post the new script and if you can add some example from your table using this: https://community.multitheftauto.com/index.php?p= ... ils&id=495 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