Making a drop money command.

I’m trying to make a dropmoney command, but it fails because it doesn’t want to read what value you drop,



local function DropMoney(ply, args)
      local NewCash = math.floor(tonumber(args))
end
AddChatCommand("dropmoney", DropMoney)
AddChatCommand("moneydrop", DropMoney)


Shouldn’t that read the amount you write?
“dropmoney 10”

args is a table, so you need to do: args[1]

Tested and it gives this error:

[@garrysmod\gamemodes\rp\gamemode\sv_items.lua:265] bad argument #1 to ‘floor’ (number expected, got nil)

local function DropMoney(ply, command, args)

What do you even want the function to do? Right now, from what code you provided, all it’s doing is generating a local variable…
Show the AddChatCommand function too.

Now I’m getting this error instead lol :stuck_out_tongue:

[garrysmod\gamemodes\rp\gamemode\sv_items.lua:265] attempt to index local ‘args’ (a boolean value)

I know it’s just checking the variable, not done so far xD

[editline]19th June 2011[/editline]

Looks like this ATM.


local function DropMoney(ply, command, args)

	local NewCash = math.floor(tonumber(args[1]))

	ply:AddCash(-NewCash)
	
	timer.Simple(1, function(ply) 
		if ValidEntity(ply) then
			local trace = {}
			trace.start = ply:EyePos()
			trace.endpos = trace.start + ply:GetAimVector() * 85
			trace.filter = ply

			local tr = util.TraceLine(trace)
			RPCreateMoneyBag(tr.HitPos, NewCash)
		end
	end, ply)

end
AddChatCommand("dropmoney", DropMoney)
AddChatCommand("moneydrop", DropMoney)

Looks fine for a simple concommand, however, no idea what that AddchatCommand is doing. Post that function, and perhaps try to run your code as a concommand.
concommand.Add(“dropmoney”, DropMoney)

dropmoney <amount> in console

Works perfect with console command ty :slight_smile:

Though I need to have it in the chat D:

[lua]
function ChatStuffs(ply, text, team)
if (string.sub(text, 1, 10) == “/dropmoney”) then
local message = string.sub(text, 12, string.len(text))
ply:ConCommand("dropmoney "…message)
return “”
end
end
hook.Add(“PlayerSay”, “ChatStuffs”, ChatStuffs)
[/lua]
/dropmoney <amount> in chat

AddChatCommand is a function that exists in DarkRP. Dunno about other gamemodes, but it doesn’t exist in base or sandbox.

Still doesn’t work, nothing happens when you write that.

I fixed it, nvm, thanks for help though :smiley: