Jump to content

DxScoreboard Add Money Collum?


Admigo

Recommended Posts

-- server side

addEventHandler("onResourceStart",resourceRoot, 
    function() 
        call(getResourceFromName("scoreboard"),"addScoreboardColumn","Money") 
    end 
) 

-- client side

local starttick, currenttick 
local player = getLocalPlayer() 
  
addEventHandler("onClientResourceStart",resourceRoot, 
function () 
    setTimer(updateMoney, 1000000, 0) 
    addEventHandler("onClientRender",root,moneyRender) 
end) 
  
function moneyRender() 
        if not starttick then 
            starttick = getTickCount() 
        end 
        currenttick = getTickCount() 
        if currenttick - starttick >= 1000 then 
            setElementData(player,"Money",getPlayerMoney( player )) 
            starttick =  getTickCount() 
        end 
end 
  
function updateMoney() 
    for k, v in ipairs(getElementsByType('player')) do 
        local money = getPlayerMoney(v) 
        setElementData(v,"Money", money) 
    end 
end 

Link to comment

Make a new resource? don't you know how resource system works?

If your scoreboard is called "dxscoreboard" then you need to change

call(getResourceFromName("scoreboard"),"addScoreboardColumn","Money") 

to

call(getResourceFromName("dxscoreboard"),"addScoreboardColumn","Money") 

Link to comment

One thing: Is that timer that loops all players really needed? setElementData is synced between server and client, so whenever the client updates it, the others will receive that info too, so making the loop kinda pointless imo.

Also, you're updating the players money even when it hasn't been changed. This can really create a big traffic load, which you surely not want. I'd suggest a variable that holds the current player money, and if the money has been changed, update it.

  
local pMoney = 0 
  
addEventHandler("onClientResourceStart",resourceRoot, 
function () 
    setTimer(updateMoney, 1000, 0) 
end) 
  
function updateMoney() 
    local newMoney = getPlayerMoney ( localPlayer )  
    if pMoney ~= newMoney then 
        pMoney = newMoney 
        setElementData ( localPlayer, "Money", newMoney ) 
    end 
end 

And after a map change your money is zero? Probably because theres somewhere 'resetMapInfo' called. This resets everything in your map, including money. You should script a custom system if you want to prevent the money reset.

Link to comment

ServerSide :

  
exports.scoreboard:addScoreboardColumn('Money') 
  
function addMoneyScore () 
local money = getPlayerMoney ( source ) 
setElementData ( source, "Money", "$" .. money ) 
    end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), addMoneyScore ) 

Edit . . . Test Now :mrgreen:

Link to comment

hi ,

-- Client Side

  
function moneyTab() 
    exports.scoreboard:scoreboardAddColumn("Money") 
    setElementData(getLocalPlayer(),"Money",tostring (getPlayerMoney(getLocalPlayer))) 
    setTimer( function () setElementData(getLocalPlayer(),"Money",tonumber(getPlayerMoney(getLocalPlayer))) end ,5000,0) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), moneyTab) 
  

Money Updates each 5 sec ..

Link to comment

1.Rename the directory or .zip dxscoreboard to scoreboard

2.Add this in race_server or made new resource. Type server.

ServerSide :

  
exports.scoreboard:addScoreboardColumn('Money') 
  
function addMoneyScore () 
local money = getPlayerMoney ( source ) 
setElementData ( source, "Money", "$" .. money ) 
    end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), addMoneyScore ) 

Start this script and wait next map.

Link to comment

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...