Money System (Basic)

I know many people asked for money systems, but they just don’t work.
I would like to know if someone would be ready to make one or help me make one.
I am not asking alot for the system, it would be pretty basic, but I just don’t know where to start and how to develop.
So here is basically what I need for the system.

Money System (Basic)

  • Money of the bank is displayed in a Derma Panel that is ready.
  • Money can be stored from the players storage (pocket) into a bank for which the menu is ready as well.
  • Money can be taken from the bank and placed in the players storage (pocket) and the total amount on the player is displayed on the HUD.
  • Money can be used later on. eg: It can be dropped.

So this sums it up.
It might be dumb, but if someone could help me produce it I would be thankful.
If you wish to take on the request or want to communicate through steam to help me make one, then send me a pm.

I hope someone will help, Thank you.

This is all quite simple but why do you need a bank?
Does it do anything else then keep money out of your pockets? Anyway it’s something you should build on top of your money system once it’s done.
I might help more tomorrow, if I can. We’ll see.

Alright thank you.

But no, the money can be used on afterwards but I think I can handle that part, I would need someone to help me making the base of it. Like;

  • The money from the pocket is displayed on the HUD
  • The money of the Bank displayed in the Bank (Derma Panel)
  • Money can be added to the bank by a derma button.
  • Money can be taken out of the bank from another Derma Button
  • If the player tries to put more money in the bank than he has in his pocket, then return false.
  • If the player tries to take more money than he has in the bank, then return false.

I need help on getting started or if someone can do it, basically, those points above.

And I assume you want money to be saved inbetween sessions? Should both the bank and pocket money be saved?

If you can do it, then it would be nice, but if you dont feel like it, then don’t its not the biggest problem, but still is a good point.
If you feel like doing it, then please go ahead :).

Well I feel like being educative today so I’ll keep it to the bare minimum of what you need. This is a base you will be able to build on top of easilly.

lua/autorun/money.lua
[lua]AddCSLuaFile(“autorun/client/cl_money.lua”)

///////////////////////////////////
/////////Gamemode Hooks///////////
///////////////////////////////////

local Starting_Amount = 100

hook.Add(“PlayerInitialSpawn”,“StartingMoney”, function(ply) – This is called the first time a player spawns
timer.Simple(1,function()–Waiting for the player’s object to initialize
ply:SetMoney(Starting_Amounr)
end)
end)

///////////////////////////////////
///////////Meta Methods////////////
///////////////////////////////////

local meta = FindMetaTable(“Player”) – meta is now the template with which all player objects are made, so you can add functions to use on players with this.

function meta:SetMoney(amount) – Immediately sets the player’s money to the given amount.
if amount < 0 then amount = 0 end – This is so you can’t have negative money
self.Money = amount --Updates the Money variable linked to this player object.
umsg.Start(“ClientMoneyUpdate”, self) --Starts to send a message to send to the player so he knows how much money he has
umsg.Long( amount )
umsg.End()
end

– The following are convenience functions and are only included to make your life easier

function meta:Money()
return self.Money --Returns the money value assossiated with the player. That means doing ply:Money() is the same as doing ply.Money
end

function meta:GiveMoney(amount) – use this to give the player some money
self:SetMoney(self.Money + amount)
end

function meta:TakeMoney(amount) --Use this to take money from the player
self:SetMoney(self.Money - amount)
end

function meta:CanAfford(cost) --Use this to check if the player has enough money for something.
return (self.Money - cost) >= 0
end[/lua]

lua/autorun/client/cl_money.lua
[lua]-- Setting the player’s money clientside so it can be used in clientside scripts.

local function ClientMoneyUpdate( um )
LocalPlayer().Money = um:ReadLong() --Update our money with the value the server has sent us.
end
usermessage.Hook(“ClientMoneyUpdate”, ClientMoneyUpdate)

//////////////////////////
////////Money HUD////////
//////////////////////////

– This draws a simple money display

hook.Add(“HUDPaint”,“DrawMoney”,function()
local amount = LocalPlayer().Money
if LocalPlayer():Alive() and amount then
draw.RoundedBox( 8, 25, ScrH() - 100, 130, 23, Color( 128, 255, 128, 255 ) )
draw.DrawText("Money: "…amount, “ScoreboardText”, 30, ScrH() - 97, Color(255,255,255,255),0)
end
end)[/lua]

As you can see there’s only 2 small functions you need to make it all work as the only thing you need is to be able to set a value serverside and have it updated for a player clientside. Ask any question you want about it.

Note : This does not save the money.

Alright thank you, I will give it a try and work from this base.
If I ever need help may I PM you?

Anyway, thanks alot.