Jump to content

Refresh for money in the scoreboard


papam77

Recommended Posts

Hello,

I've made this:

Client:

            dxDrawText("$"..getElementData(k,"MyMoney").."",820*(sw/1920),((middle+55)*(sh/1080))+((28*(sh/1080))*(i-1)),819*(sw/1920),448*(sh/1080),tocolor(255,255,255,255),1.8*(sh/1080),"default","left","top",false,false,false,true) 

Server:

addEventHandler("onPlayerJoin",root,function() 
    local MyCountry = exports.admin:getPlayerCountry(source) 
    if ( MyCountry ) then 
        setElementData(source,"MyCountryData",MyCountry) 
    else 
        setElementData(source,"MyCountryData","none") 
    end 
    setElementData(source,"MyMoney","?") 
end) 
  
addEvent("UpState",true) 
addEventHandler("UpState",root,function() 
    local Acc = getPlayerAccount(source) 
    if ( Acc ) then 
        if not (isGuestAccount(Acc)) then 
            local MoneyData = getAccountData(Acc,"cash") 
            if ( MoneyData ) then 
                setElementData(source,"MyMoney",MoneyData) 
            else 
                setElementData(source,"MyMoney","?") 
            end 
        end 
    end 
    local MyCountry = exports.admin:getPlayerCountry(source) 
    if ( MyCountry ) then 
        setElementData(source,"MyCountryData",MyCountry) 
    else 
        setElementData(source,"MyCountryData","none") 
    end 
end) 
  
addEventHandler("onPlayerLogin",root,function() 
    local Acc = getPlayerAccount(source) 
    if ( Acc ) then 
        if not (isGuestAccount(Acc)) then 
            local MoneyData = getAccountData(Acc,"cash") 
            if ( MoneyData ) then 
                setElementData(source,"MyMoney",MoneyData) 
            else 
                setElementData(source,"MyMoney","?") 
            end 
        end 
    end 
end) 

But i need to refresh it when player get new money by userpanel. How can do it? I must restart scoreboard to see current money. I need to make when userpanel give to player +Money it will refresh it and show the current money.

Link to comment

Try triggering an event from the userpanel and then add it handler to your script . e.g. :

-- Something like this on your userpanel 
givePlayerMoney( player, amount ) 
triggerEvent( "onPlayerGetMoney", player, amount ) 

And then, But in the other code :

addEvent( "onPlayerGetMoney", true ) 
addEventHandler( "onPlayerGetMoney", root, 
    function( amount ) 
        local current_money = getElementData( source, "MyMoney" ) 
        setElementData( source, "MyMoney",current_money + amount ) 
    end 
) 

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