Carlossg Posted December 5, 2011 Share Posted December 5, 2011 Hi I'm new on this forum. I found this script on Web and I try to edit to unbug but don't work It's for cash to DD/DM addEvent("onMapStarting") function creatingTables() executeSQLCreateTable("Money", "Cash INT") executeSQLCreateTable("DDDM", "serial STRING,DDAttempts INT") executeSQLCreateTable("DDAttempts", "serial STRING,DDAttempts INT") outputChatBox("Cash System by KHD 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 .. "'" ) CheckPlayer3= executeSQLSelect ( "DDAttemps", "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 if ( type( CheckPlayer3 ) == "table" and #CheckPlayer3 == 1 ) or not CheckPlayer3 then executeSQLInsert ( "DDAttempts", "'"..serial.."','1','1'" ) 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["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: cashddDMKHD\cashdddm.lua:38: attempt to index field '?' (a nil value) Why is this so? Link to comment
tropez Posted December 5, 2011 Share Posted December 5, 2011 (edited) Try this: DDAttempts = ( tonumber(DDAttempts["DDAttempts"]) + 1 ) or 0 If you want to fix that then synch. your script with sql lite. Probably tables did not create. Edited December 5, 2011 by Guest Link to comment
Castillo Posted December 5, 2011 Share Posted December 5, 2011 This script is not complete, you are triggering this event: "onClientReady", but from where? Because, "ERROR: cashddDMKHD\cashdddm.lua:38: attempt to index field '?' (a nil value)", means that the user is not in the SQL table. Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 Now other error WARNING: cashddDMKHD\cashdddm.lua:11: Bad argument @ 'getPlayerSerial' WARNING: cashddDMKHD\cashdddm.lua:12: Bad argument @ 'getPlayerName' [Expected element at argument 1, got nil] ERROR: cashddDMKHD\cashdddm.lua:13: attempt to concatenate local 'serial' (a boolean value) And: ERROR: cashddDMKHD\cashdddm.lua:38: attempt to perform arithmetic on a nil value Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 This script is not complete, you are triggering this event: "onClientReady", but from where?Because, "ERROR: cashddDMKHD\cashdddm.lua:38: attempt to index field '?' (a nil value)", means that the user is not in the SQL table. Sorry but I don't know how to fix it I have not enough knowledge Link to comment
tropez Posted December 5, 2011 Share Posted December 5, 2011 (edited) To be honest, give yourself the peace of mind with that... There are a lot of structures. Edited December 5, 2011 by Guest Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 To be honest, leave that... There are a lot of structures. Today I just put this on my goal and I will not stop until I get Link to comment
tropez Posted December 5, 2011 Share Posted December 5, 2011 Okey, then start it reading - https://wiki.multitheftauto.com/wiki/Ser ... _functions Link to comment
Castillo Posted December 5, 2011 Share Posted December 5, 2011 If you are new to Lua scripting, then you shouldn't start with hard things. Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 I've read and reread but I don't find that fails here: WARNING: cashddDMKHD\cashdddm.lua:11: Bad argument @ 'getPlayerSerial' WARNING: cashddDMKHD\cashdddm.lua:12: Bad argument @ 'getPlayerName' [Expected element at argument 1, got nil] ERROR: cashddDMKHD\cashdddm.lua:13: attempt to concatenate local 'serial' (a boolean value) I'm not new on Lua I'm new on Lua whit MTA commands PD:Whats mean boolean value.Empty value? Link to comment
Castillo Posted December 5, 2011 Share Posted December 5, 2011 Show us your COMPLETE code. Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 Show us your COMPLETE code. Sorry addEvent("onMapStarting") function creatingTables() executeSQLCreateTable("Money", "Cash INT") executeSQLCreateTable("DDDM", "serial STRING,DDAttempts INT") executeSQLCreateTable("DDAttempts", "serial STRING,DDAttempts INT") outputChatBox("Cash System by KHD started.") end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), creatingTables) function ClientReady(source) local serial = getPlayerSerial(source) local playername = getPlayerName(source) CheckPlayer = executeSQLSelect ( "Money", "serial", "serial = '" .. serial .. "'" ) CheckPlayer2= executeSQLSelect ( "DDDM", "serial", "serial = '" .. serial .. "'" ) CheckPlayer3= executeSQLSelect ( "DDAttemps", "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 if ( type( CheckPlayer3 ) == "table" and #CheckPlayer3 == 1 ) or not CheckPlayer3 then executeSQLInsert ( "DDAttempts", "'"..serial.."','1','1'" ) 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["DDAttempts"]) + 1 ) or 0 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) Link to comment
Castillo Posted December 5, 2011 Share Posted December 5, 2011 (edited) function creatingTables() exports.scoreboard:addScoreboardColumn("Cash") executeSQLCreateTable("playerData", "serial STRING, Cash INT, DMAttempts INT, DDAttempts INT") outputChatBox("Cash System by KHD started.") for index, player in ipairs(getElementsByType("player")) do addAccountIfNotExists(player) end end addEventHandler("onResourceStart", resourceRoot, creatingTables) function addAccountIfNotExists(player) local serial = getPlayerSerial(player) CheckPlayer = executeSQLSelect ( "playerData", "serial", "serial = '" .. serial .. "'" ) if ( type( CheckPlayer ) == "table" and #CheckPlayer == 0 ) or not CheckPlayer then executeSQLInsert ( "playerData", "'"..serial.."','0','0','0'" ) end end addEventHandler("onPlayerJoin",root,function () addAccountIfNotExists(source) end) function DestructionMoney(mapInfo,mapOptions,gameOptions) info = mapInfo.modename if mapInfo.modename == "Destruction derby" then for k,v in ipairs(getElementsByType("player")) do local serial = getPlayerSerial(v) local DDAttempts = executeSQLSelect ( "playerData", "DDAttempts","serial = '" .. serial .. "'") local DDAttempts = tonumber(DDAttempts[1]["DDAttempts"]) + 1 executeSQLUpdate ( "playerData", "DDAttempts = '"..DDAttempts.."'","serial = '" .. serial .. "'") setElementData(v,"data.DDAttempts",DDAttempts,true) end end end addEvent("onMapStarting") addEventHandler("onMapStarting", getRootElement(), DestructionMoney) function DestructionMoney2(thePlayer) local playername = getPlayerName(thePlayer) local serial = getPlayerSerial(thePlayer) local Cash = executeSQLSelect ( "playerData", "Cash","serial = '" .. serial .. "'") outputChatBox("*Wins: "..playername.." took $"..get('MoneyForDD').." for winning the map!",getRootElement(),255,255,0) local Cash = tonumber(Cash[1]["Cash"]) + get('MoneyForDD') setElementData(thePlayer ,"Cash", Cash) setElementData(thePlayer ,"data.money",Cash,true) setElementData(thePlayer ,"data.playername",playername,true) executeSQLUpdate ( "playerData", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") end function hunterBonus(pickupID, pickupType, vehicleModel) if (info == "Destruction derby" and pickupType == "vehiclechange" and vehicleModel == 425) then local serial = getPlayerSerial(source) local Cash = executeSQLSelect ( "playerData", "Cash","serial = '" .. serial .. "'") local 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 ( "playerData", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") end end addEventHandler("onPlayerPickUpRacePickup",getRootElement(),hunterBonus) Edited December 5, 2011 by Guest Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 still fail ERROR: cashddDMKHD\cashdddm.lua:15: Database query failed: no such column: serial ERROR: cashddDMKHD\cashdddm.lua:17: Database query failed: no such column: serial ERROR: cashddDMKHD\cashdddm.lua:20: Database query failed: table Money has 1 columns but 5 values were supplied ERROR: cashddDMKHD\cashdddm.lua:23: Database query failed: table DDDM has 2 columns but 3 values were supplied ERROR: cashddDMKHD\cashdddm.lua:26: Database query failed: table DDAttempts has 2 columns but 3 values were supplied ERROR: cashddDMKHD\cashdddm.lua:38: attempt to perform arithmetic on a nil value The code is same as you post Link to comment
Castillo Posted December 5, 2011 Share Posted December 5, 2011 Copy my last code again and see if it works, I changed it to just ONE table, as one table for each is just ridiculous. Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 Copy my last code again and see if it works, I changed it to just ONE table, as one table for each is just ridiculous. OK. Right only 1 error ERROR: cashddDMKHD\cashdddm.lua:28: attempt to perform arithmetic on a nil value Link to comment
Castillo Posted December 5, 2011 Share Posted December 5, 2011 Ok, I fixed the error you mentioned, copy it again. Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 Ok, I fixed the error you mentioned, copy it again. I copy it and same error Link to comment
Castillo Posted December 5, 2011 Share Posted December 5, 2011 function creatingTables() exports.scoreboard:addScoreboardColumn("Cash") executeSQLCreateTable("playerData", "serial STRING, Cash INT, DMAttempts INT, DDAttempts INT") outputChatBox("Cash System by KHD started.") for index, player in ipairs(getElementsByType("player")) do addAccountIfNotExists(player) end end addEventHandler("onResourceStart", resourceRoot, creatingTables) function addAccountIfNotExists(player) local serial = getPlayerSerial(player) CheckPlayer = executeSQLSelect ( "playerData", "serial", "serial = '" .. serial .. "'" ) if ( type( CheckPlayer ) == "table" and #CheckPlayer == 0 ) or not CheckPlayer then executeSQLInsert ( "playerData", "'"..serial.."','0','0','0'" ) end end addEventHandler("onPlayerJoin",root,function () addAccountIfNotExists(source) end) function DestructionMoney(mapInfo,mapOptions,gameOptions) info = mapInfo.modename if mapInfo.modename == "Destruction derby" then for k,v in ipairs(getElementsByType("player")) do local serial = getPlayerSerial(v) local DDAttempts = executeSQLSelect ( "playerData", "DDAttempts","serial = '" .. serial .. "'") local DDAttempts = tonumber(DDAttempts[1]["DDAttempts"]) + 1 executeSQLUpdate ( "playerData", "DDAttempts = '"..DDAttempts.."'","serial = '" .. serial .. "'") setElementData(v,"data.DDAttempts",DDAttempts,true) end end end addEvent("onMapStarting") addEventHandler("onMapStarting", getRootElement(), DestructionMoney) function DestructionMoney2(thePlayer) local playername = getPlayerName(thePlayer) local serial = getPlayerSerial(thePlayer) local Cash = executeSQLSelect ( "playerData", "Cash","serial = '" .. serial .. "'") outputChatBox("*Wins: "..playername.." took $"..get('MoneyForDD').." for winning the map!",getRootElement(),255,255,0) local Cash = tonumber(Cash[1]["Cash"]) + get('MoneyForDD') setElementData(thePlayer ,"Cash", Cash) setElementData(thePlayer ,"data.money",Cash,true) setElementData(thePlayer ,"data.playername",playername,true) executeSQLUpdate ( "playerData", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") end function hunterBonus(pickupID, pickupType, vehicleModel) if (info == "Destruction derby" and pickupType == "vehiclechange" and vehicleModel == 425) then local serial = getPlayerSerial(source) local Cash = executeSQLSelect ( "playerData", "Cash","serial = '" .. serial .. "'") local 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 ( "playerData", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") end end addEventHandler("onPlayerPickUpRacePickup",getRootElement(),hunterBonus) Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 function creatingTables() exports.scoreboard:addScoreboardColumn("Cash") executeSQLCreateTable("playerData", "serial STRING, Cash INT, DMAttempts INT, DDAttempts INT") outputChatBox("Cash System by KHD started.") for index, player in ipairs(getElementsByType("player")) do addAccountIfNotExists(player) end end addEventHandler("onResourceStart", resourceRoot, creatingTables) function addAccountIfNotExists(player) local serial = getPlayerSerial(player) CheckPlayer = executeSQLSelect ( "playerData", "serial", "serial = '" .. serial .. "'" ) if ( type( CheckPlayer ) == "table" and #CheckPlayer == 0 ) or not CheckPlayer then executeSQLInsert ( "playerData", "'"..serial.."','0','0','0'" ) end end addEventHandler("onPlayerJoin",root,function () addAccountIfNotExists(source) end) function DestructionMoney(mapInfo,mapOptions,gameOptions) info = mapInfo.modename if mapInfo.modename == "Destruction derby" then for k,v in ipairs(getElementsByType("player")) do local serial = getPlayerSerial(v) local DDAttempts = executeSQLSelect ( "playerData", "DDAttempts","serial = '" .. serial .. "'") local DDAttempts = tonumber(DDAttempts[1]["DDAttempts"]) + 1 executeSQLUpdate ( "playerData", "DDAttempts = '"..DDAttempts.."'","serial = '" .. serial .. "'") setElementData(v,"data.DDAttempts",DDAttempts,true) end end end addEvent("onMapStarting") addEventHandler("onMapStarting", getRootElement(), DestructionMoney) function DestructionMoney2(thePlayer) local playername = getPlayerName(thePlayer) local serial = getPlayerSerial(thePlayer) local Cash = executeSQLSelect ( "playerData", "Cash","serial = '" .. serial .. "'") outputChatBox("*Wins: "..playername.." took $"..get('MoneyForDD').." for winning the map!",getRootElement(),255,255,0) local Cash = tonumber(Cash[1]["Cash"]) + get('MoneyForDD') setElementData(thePlayer ,"Cash", Cash) setElementData(thePlayer ,"data.money",Cash,true) setElementData(thePlayer ,"data.playername",playername,true) executeSQLUpdate ( "playerData", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") end function hunterBonus(pickupID, pickupType, vehicleModel) if (info == "Destruction derby" and pickupType == "vehiclechange" and vehicleModel == 425) then local serial = getPlayerSerial(source) local Cash = executeSQLSelect ( "playerData", "Cash","serial = '" .. serial .. "'") local 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 ( "playerData", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") end end addEventHandler("onPlayerPickUpRacePickup",getRootElement(),hunterBonus) right script no bugged but no money when win a DD Link to comment
Castillo Posted December 5, 2011 Share Posted December 5, 2011 Do you know how this script works? this sets a ELEMENT DATA of money, it doesn't use the DEFAULT MTA money system. Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 Do you know how this script works? this sets a ELEMENT DATA of money, it doesn't use the DEFAULT MTA money system. I know it,but I can save de DB or when I restart server it restart? Other If I want to do a shop whit this money what comands I need to use? Link to comment
Castillo Posted December 5, 2011 Share Posted December 5, 2011 addCommandHandler("cash", function (thePlayer) local money = tonumber(getElementData(thePlayer,"data.money")) if (money) then outputChatBox("Your money is $".. tostring(money) .."!",thePlayer,0,255,0) end end) Link to comment
Carlossg Posted December 5, 2011 Author Share Posted December 5, 2011 addCommandHandler("cash", function (thePlayer) local money = tonumber(getElementData(thePlayer,"data.money")) if (money) then outputChatBox("Your money is $".. tostring(money) .."!",thePlayer,0,255,0) end end) Whit this when i type /cash I see money? I add this on other script or in same? 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