Setmoney Command?

Ok, I already have a money system setup and everything. I just need an example of a ‘setmoney’ command. Thanks!

/setmoney USER AMOUNT ??
Isn’t that good enough?

Show your money commands, such as AddMoney, SetMoney, TakeMoney, just show what you have and it shouldn’t be hard to make a concommand or chat command.

Current system



local meta = FindMetaTable("Player") 
 
function meta:AddMoney(amount)
	local current_cash = self:GetMoney()
	self:SetMoney(current_cash + amount)
end
 
function meta:SetMoney(amount)
	self:SetNetworkedInt("Money", amount)
	self:SaveMoney()
end
 
function meta:SaveMoney()
	local cash = self:GetMoney()
	self:SetPData("money", cash)
end
 
function meta:SaveMoneyTXT()
	file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(self:SteamID(), ":", "_") ..".txt", self:GetMoneyString())
end
 
function meta:TakeMoney(amount)
   --Add money function here
   self:AddMoney(-amount)
end
 
function meta:GetMoney()
	return self:GetNetworkedInt("Money")
end
 


Don’t use NW anything dude it’ll become quite laggy throughout times. Use something like this:
http://www.facepunch.com/showthread.php?t=1193966&p=38679427&viewfull=1#post38679427

Then it would just be:
[lua]
concommand.Add(“set_money”, function(ply,cmd,args)
local amt = tonumber(args[1])
if !IsValid(ply) or !amt then return end
ply:SetMoney(amt)
end)
[/lua]

This is why you shouldn’t use NW anything:
http://www.facepunch.com/showthread.php?t=1193966&p=38685990&viewfull=1#post38685990

No, dammit, why!

How do I contact Maruits to get some of my old tutorials stripped, some of them are pretty shite, old and outdated. Anybody have his steam id?

At least you contributed!

KillerLUA you helped through a couple things, thank you. And Brandon thank you!

Ok this command doesn’t work. It doesn’t say invalid command, it just doesn’t do anything.

Show your code.

What gamemode are you planning on needing this command for?

Leo why the fuck did you just post on every single forum for Garry’s mod?

Ok guys I want know how I could add the player argument to a command like this:



concommand.Add("bw_addmoney", function(ply, cmd, args)
	local amount = tonumber(args[1])
	ply:AddMoney(amount)
end)


I’m kinda new to commands to I’m clueless as of now. Also, how would I make this command “superadmin” or “admin” team only? Something like?:



if ply:Team() == 3


Thanks guys.

Question, if your not suppose to use NetworkVars would it be more efficent to use PData or Usermessages? Because I know Usermessages are used in NetworkVars

Use none.

Use the all new super easy net library.
So efficient and the amount of data you can pack it with easily.

You have to check it there is a first argument in the console command or else if you try and use it AddMoney will try and give the player a nil value of money that will spit them an error.


concommand.Add("bw_addmoney", function(ply, cmd, args)
	local amount = tonumber(args[1])
	if !amount then return end
	if !ply:IsSuperAdmin() then return end
	ply:AddMoney(amount)
end)