Jump to content

[Help]Money core system


ManeXi

Recommended Posts

Actually i'm using this to create the element "money"

This is on login

                local Money = getAccountData(acc,"Money" ) 
                if not Money then 
                    setAccountData(acc,"Money",0) 
                    Money = 0 
                end 
                setElementData(source,"Money",Money) 

This is on register

                        local accountAdded = addAccount(tostring(username),tostring(password)) 
                        if (accountAdded) then 
                            setAccountData(accountAdded,"Money",0) 

This is the unique way to get "money" (by killing)

function giveKill ( player ) 
    if getElementType(player) == "player" then 
        setElementData(player,"Kills",getElementData(player,"Kills") + 1) 
        local acc = getPlayerAccount(player) 
        if not isGuestAccount(acc) then 
            setAccountData(acc,"Kills",getElementData(player,"Kills") + 1) 
            local mo = getElementData(player,"Money") 
            setElementData(player,"Money",tonumber(mo) + 50) 
            setAccountData(acc,"Money",tonumber(mo) + 50) 
        end 
    end 
end 

The script is working perfectly but i've got a big problem, the money is not shown in HUD and is not compatible with other scripts who uses money (Ammunation system, car shop systems...)

Link to comment

Try to create an export function then use it everytime the player buy something.

Example function to take the player money.

function takeMoney(player, amount) 
    if (not isElement(player)) then return end 
    if not tonumber(amount) then return end 
    local account = getPlayerAccount(player) 
    if account and not isGuestAccount(account) then  
        local mo = getElementData(player,"Money") or 0 
        if mo then 
        local moneyToTake = math.floor(tonumber(mo) - tonumber(amount)) 
        takePlayerMoney(player, tonumber(amount)) 
        setElementData(player,"Money",moneyToTake) 
        setAccountData(account,"Money",moneyToTake) 
        end  
    end  
end 

About the HUD you need to use getElementData(localPlayer,"Money") .

Link to comment
  • 2 weeks later...

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