Making money

Im making an rp gamemode and I have no idea how to code the money…

Can someone help me doing it please??

I have made a Money System, since im making an RP, would you like me to lend you the base of it?

Yeah it would be very nice thanks

Here is the money system, it is really simple and useful.

here is: lua/autorun/money.lua
[lua]//---------------------------------//
// Money System by Sylph //
//---------------------------------//

local pmeta = FindMetaTable(“Player”) – lets start our metatable (player in this case)
local MoneyIdentity = “PlayerMoney” – name of the money
local Moneyfunctions = {} – functions follow

function pmeta:GetMoney() – This is used to get the players amount of money
return tonumber(self:GetPData(MoneyIdentity))
end

function pmeta:SetMoney(amount) – This is used to set money on a player
self:SetPData(MoneyIdentity, tonumber(amount))
self:SetNWInt(MoneyIdentity, tonumber(amount))
end

function pmeta:SetPrice(amount, entity) – This is experimental, it hasen’t been tested yet
entity:SetPData(MoneyIdentity, tonumber(amount))
entity:SetNWInt(MoneyIdentity, tonumber(amount))
end

function pmeta:AddMoney(amount) – This is used to add money to a player (in other words, give)
self:SetPData(MoneyIdentity, tonumber(self:GetPData(MoneyIdentity)) + tonumber(amount))
self:SetNWInt(MoneyIdentity, tonumber(self:GetPData(MoneyIdentity)))
end

function pmeta:HasMoney(amount) – Used to see if the player has enough money (used to buy and such)
if tonumber(self:GetPData(MoneyIdentity)) >= tonumber(amount) then
return true
else
return false
end
end

function pmeta:TakeMoney(amount) – This is used to lets say when you buy something, it takes money from you
if self:HasMoney(tonumber(amount)) then
self:SetPData(MoneyIdentity, tonumber(self:GetPData(MoneyIdentity)) - tonumber(amount))
self:SetNWInt(MoneyIdentity, tonumber(self:GetPData(MoneyIdentity)))
end
end

//This is the Base of my Money System, so you can build on top of it.
//Here are the functions available in this script:

– Player:GetMoney()
– Player:SetMoney( number or string )
– Entity:SetPrice( number or string ) – Experimental
– Player:AddMoney( number or string )
– Player:HasMoney( number or string ) – best to use a string IMO
– Player:TakeMoney( number or string )

//Salary system must be made by you if you wish to have one, I have one but I decided to not
//Include it in.
//If you need help contact me.[/lua]

So include this script in another script to make it work, and use the functions as you wish.
if you don’t know how to include, it is done like this:
[lua]include(“autorun/money.lua”)[/lua]

Hope this helps, cya and good luck.

How does this works?? I mean how to put a salary?? I dont figure out with what you wrote…

Rated you dumb for truth.

You obviously don’t have any programming knowledge.

I dont give a shit that you rate me dumb… If you post this for telling I dont have knowledge so just fuck off and shut up, I am a new lua coder, and im trying to code a rp gamemode to learn more about the function etc. So shut up and I think you were like me when you start coding so…

If you don’t give a shit why are you raging? : /

Basically what it does is it creates a variable which is on the owner.
So it is not technically real money since it dosen’t exist in Gmod, we are calling it money since we can use and modify it. I will show you an example script of how to use it.
Example

[lua]include(“autorun/money.lua”) – we are including it, so we can use its functions

function Citizen(ply) – ply stands for the player (you)
ply:SetMoney( 500 ) – so the player will have 500$
end – Now we are closing the function, no big deal

concommand.Add(“money_test”, Citizen) – we make a concommand, this way we can test it out in Gmod[/lua]

So basically, now, if you run money_test in your console, you will have 500$ on you. It will not be displayed and you will not see it unless you place this element on your HUD, basically, you would use the function ply:GetMoney() in your HUD script (if you have one of course).
This is an example of one function, the other ones should be quite easy to get, for the salary system, try making it out first, don’t give up, and you will probably have it working.
Good Luck.

PS: If you really really aren’t able to make a Salary System, then PM me, but try before.

Oh and bilbasio, if you are pissed at other users, express yourself but calmly, I once went a bit hardcore, and I learned afterwards that I was flamming, which is not good, like we say, we learn from our mistakes ^^.

Thank you sylph you were more useful than Matt

No problem, good luck with your RP, if you need help, contact me, send me a PM, I will help you ;).

Ok, I will probably be rated dumb twice but can you give me an example of an Hud script that you put the money please??

[editline]01:14AM[/editline]

Oh, didnt saw you other post XD

Anyway, to get on topic here’s a salary thing I made for my gamemode.

[Lua] function pmeta:Check()

return self:GetNetworkedInt( "Salary" )

end

function pmeta:SetCheck()

for k, v in pairs( player.GetAll( ) ) do

if v:Team() == 1 then
	self:SetNetworkedInt( "Salary", 25 )
elseif v:Team() == 2 then
	self:SetNetworkedInt( "Salary", 105 )
elseif v:Team() == 3 then
	self:SetNetworkedInt( "Salary", 125 )
end

end

end

function pmeta:Paycheck()

self:SetCheck()

self:AddMoney( self:Check() )

self:PrintMessage( HUD_PRINTTALK, "Paycheck Received" )

end
end [/LUA]

The function Paycheck is run after 420 seconds with

[Lua] if (CurTime() >= NextPayDay) then

		ply:Paycheck()
	
		NextPayDay = CurTime() + 420
	
	end [/Lua]

What do I put this?? Probably in init.lua?

Nah its ok :P, I will give you an example script for your HUD.
this is: lua/autorun/client/money_hud.lua

[lua]include(“autorun/money.lua”) – Once again

function hudINT() – Starting the function

local person = LocalPlayer() – Us
local numMoney = person:GetNWInt( “PlayerMoney” ) – We are getting how much the person has (you)
draw.SimpleText("Money: "… numMoney … “$”, “hudtxt”, ScrW() / 2 - 95, ScrH()-17, Color(255, 255,255, 255), 0, 0)
end – Im not sure if I really need an end here, oh well, if I don’t, just take it off.

hook.Add(“HUDPaint”, “hudINT”, hudINT) – Hooking our function[/lua]

This is very ridiculus, I made it live in the reply box, it will display Money: “Amount” at the bottom of your screen.

If its a gamemode, it goes in cl_init??

If im not wrong, client = cl_init ??

Yes, cl_init is for client stuff

This will probably not save the money when we re-connect??

No the money won’t be saved, you need to make a script for that, I haven’t made it so I cannot help you on this part :/.
Maybe GUNHOG made one.

Sylph, Could you add me on steam at Nefertia1122. I have a few questions :slight_smile: