How would i make this take an argument? examble
cash_add in console it would add what i typed after etc, cash_add 5000 i would get 5000? how would i make that?
[editline]30th September 2014[/editline]
i already have money system ( customg amemode)
Read the [url=http://wiki.garrysmod.com/page/concommand/Add]wiki page[/url]
It tells you the callback function is passed these args:
[quote]Args: ( Player ply , string cmd , table args , string fullstring )[/quote]
[lua]concommand.Add( "cash_add", function( ply, _, args )
local cash = args[1] -- First argument would be cash
-- Run code
end )[/lua]
Try this.
[lua]concommand.Add("cash_add", function(player, command, arguments)
if (!player:IsSuperAdmin()) then return end
local cash = tonumber(arguments[1])
if (cash) then
-- Use the player and cash variables to give the player the money.
end
end)[/lua]
Make sure you're adding the command serverside and not clientside.
I am putting in init.lua which is server side right?
[editline]30th September 2014[/editline]
[QUOTE=rotor2;46115646]Try this.
[lua]concommand.Add("cash_add", function(player, command, arguments)
if (!player:IsSuperAdmin()) then return end
local cash = tonumber(arguments[1])
if (cash) then
-- Use the player and cash variables to give the player the money.
end
end)[/lua]
Make sure you're adding the command serverside and not clientside.[/QUOTE]
I did this:
[LUA]
function DebugGiveMoney( ply, arguments )
local giveamount = tonumber(arguments[1])
if (giveamount) then
ply:AddMoney(giveamount)
end
end
concommand.Add("cash_add", DebugGiveMoney)
[/LUA]
No errors when i do cash_add 500 but i dont get any money at all?
[QUOTE=xAl3xTh3K1nG;46116056]I am putting in init.lua which is server side right?
[editline]30th September 2014[/editline]
I did this:
function DebugGiveMoney( ply, arguments ) local giveamount = tonumber(arguments[1]) if (giveamount) then ply:AddMoney(giveamount) end end concommand.Add("cash_add", DebugGiveMoney)
No errors when i do cash_add 500 but i dont get any money at all?[/QUOTE]
You can't just ignore some arguments. You removed 'commands' it needs to be there.
I recommend reading [url=http://www.lua.org/pil/5.html] this[/url]
[QUOTE=mcd1992;46116239]You can't just ignore some arguments. You removed 'commands' it needs to be there.
I recommend reading [url=http://www.lua.org/pil/5.html] this[/url][/QUOTE]
Thanks so much! I love facepunch already and i nearly just started using it alot! People will help alot usually :) THanks for the link ill look at it tomorrow gotta go now though.
You really should check if they're superadmin, though. This could easily be abused.
Sorry, you need to Log In to post a reply to this thread.