Scope Question (DarkRP)

Maybe this isn’t a scope related question…

Ok so I have a GUI entity located at
gamemodes/DarkRP/entities/entities/somecustomentity/cl_init.lua

And I want it to call a function… for example meta:AddMoney(amount) function in
gamemodes/DarkRP/gamemode/player.lua

function meta:AddMoney(amount)
	if not amount then return false end
	DB.StoreMoney(self, self.DarkRPVars.money + math.floor(amount))
end

I’m trying to make a button that calls a function AddMoney and give money to a player, but i’m not sure how to call it correctly, or whether the SENT can even see it

	local bB = vgui.Create("DButton")
	bB:SetParent(pShop)
	bB:SetText("Free Money!!!")
	bB:SetPos(125,100)
	bB:SetSize(100,25)
	bB.DoClick = function ()
		ply:AddMoney(50)
	end

Is that even possible?

Yes

[editline]05:53PM[/editline]

Why didn’t you just go ingame and test?

It seems alot of people cant be assed testing their stuff, before posting about it on Facepunch.

Your code will not work. AddMoney is serverside, the DButton is clientside.

Make a console command serverside to add the money.

And you can use arguments to tell how much.
[lua]
function GimmeCash(Player,Command,Arguments)
local money = tonumber(Arguments[1])
if !money then return end
Player:AddMoney(money)
Player:SendLua(“GAMEMODE:AddNotify('You have earned $”…money…"!’,NOTIFY_GENERIC,5)")
end
concommand.Add(“gimmecash”,GimmeCash)
[/lua]
[lua]
local bB = vgui.Create(“DButton”)
bB:SetParent(pShop)
bB:SetText(“Free Money!!!”)
bB:SetPos(125,100)
bB:SetSize(100,25)
bB.DoClick = function ()
RunConsoleCommand(“gimmecash 50”)
end
[/lua]

However, if it’s a console command, anyone can use it at any time, not necessarily only in the vgui.

Then he’ll have to check if they’re close to the NPC.

Thanks for the replies, Drew, Clevin & Jamie that helps a lot.
I kept trying to call the AddMoney function from the gui.

If you need any more help just ask.

-snip-

figured it out