(I don't know much about coding at all)
I am trying to make a money system for a Garry's Mod map and I need to know how to see for certain commands in a LUA file that counts money like:
[code]local STARTMONEY = 15 -- This is the amount of cash that players start with
local PAYDAYS = false -- Should there be paydays? true = yes, false = no
local PAYDAY_AMOUNT = 5 -- If there are paydays, what should the salary be?
local PAYDAY_INTERVAL = 8 -- If there are paydays, what should the payday interval be? (Seconds)
local PAYDAY_SOUND = true -- If there are paydays, should a sound play when there's a payday? true = yes, false = no
local MONEY_HUD = true -- Should the money be displayed on the screen? true = yes, false = no
if SERVER then -- If this file is on a server do: (SERVER)
local pm = FindMetaTable("Player") -- We state that entities under the meta table "player" is called pm, just to make it easier!
function PlayerMoneySpawn( ply )
ply:Money_Create()
end
hook.Add("PlayerInitialSpawn", "MoneySystemStart", PlayerMoneySpawn)
function pm:Money_Create() -- DONT TOUCH! THIS FUNCTION SAVES THE SHIT
print("Creating money account for: "..self:Nick())
if self:GetPData( "cash" ) == nil then -- if there is no data under "cash", create some!
self:SetPData( "cash", STARTMONEY ) -- if there is no "cash" data, give them 15 cash to begin with!
end
end
function pm:Money_Set( cash ) -- player:Money_Set = SET THE MONEY OF A PLAYER
self:SetPData( "cash", tonumber(cash) ) -- Saves the cash to the server
self:SetNWInt( "cash", tonumber(cash) ) -- Sends the amount to the players' screens
end
function pm:Money_Add( cash ) -- player:Money_Add = ADD MONEY FOR A PLAYER
if cash > 0 then -- If the cash to give is over 0...
local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money
self:Money_Set( current + cash ) -- Set the money to: The old amount of money + the money wished to be added
end
end
function pm:Money_Has( cash ) -- player:Money_Add = GET THE MONEY FOR A PLAYER
local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money
if current >= tonumber(cash) then -- if the old amount si over the amount checked...
return true -- say it's true!
else
return false -- if not, say it's false!
end
end
function pm:Money_Get() -- player:Money_Add = GET THE MONEY FOR A PLAYER
local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money
return current
end
function pm:Money_Take( cash ) -- player:Money_Add = TAKE MONEY FOR A PLAYER
if self:Money_Has( cash ) then -- if you got the amount of money...
local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money
self:Money_Set( current - cash ) -- Take the old amount of money and take away the amount given!
end
end
if PAYDAYS then
timer.Create( "payday_timer", PAYDAY_INTERVAL, 0, function()
for k, ply in pairs(player.GetAll()) do
ply:Money_Add( PAYDAY_AMOUNT )
if PAYDAY_SOUND then
ply:EmitSound("items/ammo_pickup.wav")
end
end
end )
end
else -- IF THIS FILE IS ON A PLAYER PC DO... (CLIENT)
local function Money_Draw()
/////////////////////////////////////////////////////////////////
///////// FOR ADVANCED USERS: MAKE A HUD HERE ///////////////
/////////////////////////////////////////////////////////////////
if not MONEY_HUD then return end
local mulleh = LocalPlayer():GetNWInt( "cash" ) -- The amount of money you got
draw.DrawText("Money: "..mulleh, "Trebuchet18", 60, 60, Color(255,255,255,255))
end
hook.Add("HUDPaint", "MoneyPainting", Money_Draw)[/code]
I just need to know how to find a console command in a LUA file to put in a point_clientcommand's Output function to make this give, take, or set money.
- Is there a way to make commands with some sort of other file so I may use with console?
So basically, you want to create console commands? This is probably what you're looking for: [url]http://wiki.garrysmod.com/page/concommand/Add[/url]
Why would you need console commands for this though? Console commands are supposed to be used by players to interact with the server, like buying items. But players should not be allowed to give themselves money at any time, that's something only the server should decide.
And why use point_clientcommand entities?
If you still really want to make a console command for giving yourself money, here's a quick example:
[lua]concommand.Add("give_money", function(ply, cmd, args)
local amount = tonumber(args[1]) -- get first argument
if amount then -- if it's a valid number
ply:Money_Add(amount) -- add money
end
end)[/lua]
It should be serverside, of course.
[QUOTE=_Kilburn;41080385]So basically, you want to create console commands? This is probably what you're looking for: [url]http://wiki.garrysmod.com/page/concommand/Add[/url]
Why would you need console commands for this though? Console commands are supposed to be used by players to interact with the server, like buying items. But players should not be allowed to give themselves money at any time, that's something only the server should decide.
And why use point_clientcommand entities?
If you still really want to make a console command for giving yourself money, here's a quick example:
[lua]concommand.Add("give_money", function(ply, cmd, args)
local amount = tonumber(args[1]) -- get first argument
if amount then -- if it's a valid number
ply:Money_Add(amount) -- add money
end
end)[/lua]
It should be serverside, of course.[/QUOTE]
Well I basically found out away to make a simple money system for a map, it goes something like this: first you make a button that simply spawns an item like lets say a weapon, second you make a point_client or server command then you set a math_counter, third you make the button take away lets say $50 so you make the math counter subtract 50 at the same time in the point_client or server command set a Output parameter of take_money 50 or something like that of a console command, forth you make the math couter lock the switch when you can't afford it because you would have $0 or so left in the math_counter.
I am trying to make a map money system for me and my brother to use so I want this fairly simple, we don't have to have different money it just gotta to be for one player mainly.
btw thank you for the help, your time was much appreciated.
Sorry, you need to Log In to post a reply to this thread.