Help with command GiveMoney

Hi guys , i need an command for my gamemode Flood , what i need?:

Command only for SuperAdmins/admins “/setmoney” to give money for any player or admin , and where i need to put the lines of .lua .

I searched “setmoney” in this forum , and in GMOD wiki but i doesn’t find any tutorial or source .

PD: Sorry for my english , i’m from Spain :slight_smile: .

Thanks.

Well I don’t know the meta tables for it but uh I would guess it goes a lil’ something like:
[lua]
function GiveMoney(pl,cmd,args)
if args[1] then
pl:GiveMoney(args[1])
end
end
concommand.Add(“Flood_Admin_AddMoney”,AddMoney)
[/lua]

Thanks , but where are the amount of money , and the command? " ex: /Givemoney " .

Its a console command

Assuming your givemoney function is player:GiveMoney(num) then:
[lua]
function FindPlayer(info)
local pls = player.GetAll()
for k, v in pairs(pls) do
if string.find(string.lower(v:Name()), string.lower(tostring(info)), 1, true) ~= nil then
return v
end
end
return nil
end
function ChatStuffs(ply, text, team)
if (string.sub(text, 1, 5) == “/give”) then
local message = string.sub(text, 7, string.len(text))
ply:ConCommand("givecash "…message)
return “”
end
end
hook.Add(“PlayerSay”, “ChatStuffs”, ChatStuffs)

function GiveMoney(ply, command, args)
local player = FindPlayer(args[1])
local money = tonumber(args[2])
if player and money then
player:GiveMoney(money)
end
end
concommand.Add(“givecash”, GiveMoney)
[/lua]
Untested, but should work. /give name amount in chat, or givecash name amount in console. You may want to add some checks for admin(ply:IsAdmin()).

You aren’t checking if the player is an admin, and givecash -5000

Like I said, some admin checks may need to be added. And I’d assume the error checking would happen in the GiveMoney function… that’d be the most logical place anyways. Here you go anyways, some very simple error checking.
[lua]function FindPlayer(info)
local pls = player.GetAll()
for k, v in pairs(pls) do
if string.find(string.lower(v:Name()), string.lower(tostring(info)), 1, true) ~= nil then
return v
end
end
return nil
end
function ChatStuffs(ply, text, team)
if ply:IsAdmin()
if (string.sub(text, 1, 5) == “/give”) then
local message = string.sub(text, 7, string.len(text))
ply:ConCommand("givecash "…message)
return “”
end
end
end
hook.Add(“PlayerSay”, “ChatStuffs”, ChatStuffs)

function GiveMoney(ply, command, args)
if ply:IsAdmin() then
local player = FindPlayer(args[1])
local money = tonumber(args[2])
if money <=0 then return end
if player and money then
player:GiveMoney(money)
end
end
end
concommand.Add(“givecash”, GiveMoney)[/lua] Place it in a server side file, for example, lua/autorun/server/givemoney.lua

Thanks all for the answer’s , but i get an error: [lua\autorun\server\givemoney.lua:12] ‘then’ expected near ‘if’

Dumb mistake on my part.
Change
[lua]
if ply:IsAdmin()[/lua]
to:
[lua]
if ply:IsAdmin() then[/lua]

Thanks , now work , but…

Why when I write: /give Nemessis 3 , say that:

[lua\autorun\server\givemoney.lua:25] attempt to compare nil with number
[lua\autorun\server\givemoney.lua:25] attempt to compare nil with number
[lua\autorun\server\givemoney.lua:25] attempt to compare nil with number
[lua\autorun\server\givemoney.lua:25] attempt to compare nil with number
[lua\autorun\server\givemoney.lua:27] attempt to call method ‘GiveMoney’ (a
value)
[lua\autorun\server\givemoney.lua:25] attempt to compare nil with number

Well, GiveMoney() is nil, because I do not know what your money functions are. I was simply pointing you in the right direction. The other error is very odd. Try “givecash nemessis 3” in console.

Same:

[lua\autorun\server\givemoney.lua:27] attempt to call method ‘GiveMoney’ (a nil
value)

I have an Flood gamemode “3” , only i want to set the money .

I do not know how Flood works. You’ll have to fill in the Flood Give Money functions in the correct places.

Ok , thanks , other way to set the money in Flood gamemode ? .
I have ULX admin , but not have these option.

Flood will have some function to give money. You’ll have to input that function into the code I gave you.

that version of flood mod uses
[lua]player:SetNWInt(“Cash”, math.floor(player:GetNWInt(“Cash”) + money))[/lua]
to set the money.

Here’s the full script, if you’re not sure where to place that, valy.
[lua]
function FindPlayer(info)
local pls = player.GetAll()
for k, v in pairs(pls) do
if string.find(string.lower(v:Name()), string.lower(tostring(info)), 1, true) ~= nil then
return v
end
end
return nil
end
function ChatStuffs(ply, text, team)
if ply:IsAdmin() then
if (string.sub(text, 1, 5) == “/give”) then
local message = string.sub(text, 7, string.len(text))
ply:ConCommand("givecash "…message)
return “”
end
end
end
hook.Add(“PlayerSay”, “ChatStuffs”, ChatStuffs)

function GiveMoney(ply, command, args)
if ply:IsAdmin() then
local player = FindPlayer(args[1])
local money = tonumber(args[2])
if money <=0 then return end
if player and money then
player:SetNWInt(“Cash”, math.floor(player:GetNWInt(“Cash”) + money))
end
end
end
concommand.Add(“givecash”, GiveMoney)
[/lua]

Networked Variables, how convenient.

How was this relevant to the OP?