Jump to content

Problem cash


Carlossg

Recommended Posts

Posted

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) 
  

Ingame nick: Cadu12

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

When you use executeSQLUpdate will be saved.

Or you doesnt need to make, DB every time will be saved.

Ingame nick: Cadu12

Posted
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) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

What do you mean? how did I make it? well, you can check what I'd.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...