Jump to content

Money...


Mefisto_PL

Recommended Posts

Posted

I've made a Money System.. When I quit or logout my cash is saved.. But when I have for example $666 and when I use takePlayerMoney ( blah blah blah 500 for example ) then I have $166, when I quit I have $666.. WHY?!

Posted

setPlayerMoney/givePlayerMoney/takePlayerMoney:

Note: Using this function client side (not recommended) will not change a players money server side.
  • 2 weeks later...
Posted
Using
triggerServerEvent 

?

If you really have to keep your code client-side, then yes, use triggerServerEvent. If you can do the same code server-side, then do it server-side.

Posted

Using triggerServerEvent for setPlayerMoney/givePlayerMoney/takePlayerMoney

It is BAD idea, because hacker is able to set money.

Posted (edited)

We gave you 100 examples and you haven't understood a single one of them? Give us a break.

Test the money function by typing /ctest in-game. You should lose $100.00 and when you logout/quit the game, it will save your money. When you log in, it will return back your money.

This is just an example, you must understand the code and please take time to read and understand it.

Client-side

addCommandHandler("ctest", 
    function(cmd) 
        triggerServerEvent("onMoneyTaken", localPlayer) 
    end 
) 

Server-side

addEventHandler("onPlayerQuit", root, 
    function(quitType, reason, responsibleElement) 
        if isGuestAccount(getPlayerAccount(source)) then return end 
        setAccountData(getPlayerAccount(source), "player:money", getPlayerMoney(source)) 
    end 
) 
  
addEventHandler("onPlayerLogout", root, 
    function(previousAccount, currentAccount) 
        if isGuestAccount(getPlayerAccount(source)) then return end 
        setAccountData(getPlayerAccount(source), "player:money", getPlayerMoney(source)) 
    end 
) 
  
addEventHandler("onPlayerLogin", root, 
    function(previousAccount, currentAccount, autoLogin) 
        if getAccountData(currentAccount, "player:money") then 
            setPlayerMoney(source, tonumber(getAccountData(currentAccount, "player:money"))) 
        else 
            setPlayerMoney(source, 200) 
        end 
    end 
) 
  
addEvent("onMoneyTaken", true) 
addEventHandler("onMoneyTaken", root, 
    function() 
        takePlayerMoney(source, 100) 
    end 
) 

Edited by Guest
Posted

Cadu12 Wrote that is easy to hack for hackers.. but I forget about hacks isn't allowed in MTA ;x ( I know this way, and I want to use that, I understand it ;) )

///EDIT

In server-side isn't "addEvent" function and only that I don't understand.

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