Jump to content

DxScoreboard Add Money Collum?


Admigo

Recommended Posts

Posted

Heey all,

Can someone help me with dxscoreboard?

I want to add money collum with the getplayermoney function.

Pls i need this for shop.

Thnks admigo

Posted

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

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

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

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

I don't know, I didn't test it on race, I think I'd enough giving you the script, now you'll have to find out why it bugs.

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

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.

Posted

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:

Posted

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

ING : [xXx]~Al3grab

Posted

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.

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