Cadu12 Posted December 6, 2011 Share Posted December 6, 2011 Solidsnake14, as onPlayerPickUpRacePickup it needs fix multi or it'll bugs/spam (i mean multi-pickup for hunter). huntersplayers = {} 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 huntersplayers = {} 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) and (not huntersplayers[source] or huntersplayers[source] == false) then local serial = getPlayerSerial(source) local Cash = executeSQLSelect ( "playerData", "Cash","serial = '" .. serial .. "'") local Cash = tonumber(Cash[1]["Cash"]) + 1000 huntersplayers[source] = true 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
Castillo Posted December 6, 2011 Share Posted December 6, 2011 I never had such problem Cadu12. @on-topic: You can put that code to see player money in the same script or in a different resource, wouldn't make difference. Link to comment
Carlossg Posted December 6, 2011 Author Share Posted December 6, 2011 Now I have a question, can I save the DB? Or every time when I restart the Server DB is restarted? Link to comment
Carlossg Posted December 6, 2011 Author Share Posted December 6, 2011 Yes, you can. How? Link to comment
Cadu12 Posted December 6, 2011 Share Posted December 6, 2011 When you use executeSQLUpdate will be saved. Or you doesnt need to make, DB every time will be saved. Link to comment
Carlossg Posted December 8, 2011 Author Share Posted December 8, 2011 Now it works but when a player join don't see money until player get hunter Link to comment
Castillo Posted December 8, 2011 Share Posted December 8, 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) local CheckPlayer = executeSQLSelect ( "playerData", "*", "serial = '" .. serial .. "'" ) if ( type( CheckPlayer ) == "table" and #CheckPlayer == 0 ) or not CheckPlayer then executeSQLInsert ( "playerData", "'"..serial.."','0','0','0'" ) else local Cash = tonumber(CheckPlayer [1]["Cash"]) setElementData(source,"Cash", Cash) setElementData(source,"data.money",Cash,true) 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 8, 2011 Author Share Posted December 8, 2011 Ok.Works fine.What's commands do you use to do this? Link to comment
Castillo Posted December 8, 2011 Share Posted December 8, 2011 What do you mean? how did I make it? well, you can check what I'd. 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