Jump to content

Giving money to players


DakiLLa

Recommended Posts

Posted

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]

Posted

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) 
  

Posted

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 ?

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

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

  • 1 month later...
Posted
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:

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

Posted

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.

Build a man a fire - he shall be warm for a night.

Light a man on fire - he shall be warm for the rest of his life.

--Cho Mo

  • 2 weeks later...
Posted
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.

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