DakiLLa

Giving money to players

Recommended Posts

Hi! I need script of giving money to players, but in Lua i'm full noob :cry: . Can you write this script for me please?

Something of this: /givemoney [Player name] [the sum]

Share this post


Link to post

Sure! there u go If you take a look at the wiki of mtasa You will learn alot :)

http://development.mtasa.com/index.php? ... layerMoney

Here is how u wanted it(try to learn something from it)

  
function GiveCash ( thePlayer, command, targetmoney, amount ) 
local nick = getPlayerFromNick(targetmoney) 
        givePlayerMoney ( nick, amount ) 
end 
addCommandHandler("givemoney",GiveCash) 
  

Share this post


Link to post

i dont want to create a new topic and i ask here:

how can i save my money when i log-out and return money when i log-in ? can you help me with script ?

Share this post


Link to post

setAccountData and getAccountData

Share this post


Link to post

in example what is "piraterpg.money" in setaccountdata and getaccountdata ? it's current file in which saves information of players or not ?

Share this post


Link to post
in example what is "piraterpg.money" in setaccountdata and getaccountdata ? it's current file in which saves information of players or not ?
Example

For a pirate roleplaying gametype, the amount of money a player has is made persistent by storing it in his account. Note the code uses "piraterpg.money" as key instead of just "money", as the player may be participating in other gametypes that also save his money amount to his account. If both gametypes would use "money" as the account key, they'd overwrite each other's data.

Share this post


Link to post

Function setAccountData doesn't work as it should. Some people say it does work but I've never managed to make it work (even the way they said).

setAccountData removes all the accounts from accounts.xml file when server stops.

Share this post


Link to post

huh..nice..but i need to save progress in gamemode :? . Any ways to solve this problem?

Share this post


Link to post

setAccountData is fixed in DP3. Not that that helps you now...

Share this post


Link to post
setAccountData is fixed in DP3. Not that that helps you now...

haha owned ^^

Share this post


Link to post
setAccountData is fixed in DP3. Not that that helps you now...

haha owned ^^

haha spam ^^

But to stick on topic, i kinda wonder how this bug wasn't discovered during testing.. :wink:

Share this post


Link to post

Just in case you didn't already notice - the script provided above will make that command available on the server - and unless you restrict it in the ACL, it'll be available to all players. So anybody could give themselves money, thus defeating the purpose of having money on most servers. We could all be chairmen of the Federal Reserve.

Share this post


Link to post
function onJoin(thePlayer) 
        local account = getClientAccount(thePlayer) 
        local money = getAccountData(account, "players/Player.money") 
        setPlayerMoney(thePlayer, money) 
end 
  
function giveCash(thePlayer, commandName, amount) 
        local account = getClientAccount(source) 
        local admin = getAccountData(account, "players/Player.admin") 
        if(admin >= 1) 
            local name1 = getClientName(source) 
            local name2 = getClientName(thePlayer) 
            givePlayerMoney(thePlayer, amount) 
            outputChatBox("Admin "..name1.." has given you $"..amount, thePlayer,0,255,255) 
            outputChatBox("You have given "..name2.." $"..amount, thePlayer,0,255,255) 
end 
  
addCommandHandler("givecash", giveCash) 

Of course you still need to use setAccountData when the player joins. So, that script doesn't entirely work yet.

Share this post


Link to post

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.