Some help with my money giving command.

I got this money command i’m making.
I got these tips from Spacetech:
Spacetech: for k,v in pairs(player.GetAll()) do if(v:UserID() == tonumber(args[1])) then target = v end end
Spacetech: if(IsValid(target)) then givemoneyhere end

My current money giving code:[lua]concommand.Add(“givedollars”, function(ply, cmd, args)
if not ply:IsAdmin() then return end

local playerid = player.GetByID(args[1])
local num = tonumber(args[2])
   
    playerid:AddMoney(num, "has given " .. ply:Nick() .. "!")

end)[/lua]

How would I implent this? I have no idea, I want to type like “givedollars [a players userid] [amount of money]”.

givedollars staneh 1000 would mean that givedollars is cmd, staneh is args[1] and 1000 is args[2]

playerid:AddMoney doesn’t exist

printmessage (HUD_PRINTCHAT, ply…“has given “…args[1]:Nick()…” “…args[2]…” dollars.”)

Staneh has given Zephilinox 1000 dollars.

of course, you would need someplace to save the money, I believe the gmod wiki has a sqlite tutorial based on a money saving system, I’ll see if I can find it later.

I got my whole money system done, you know, it’s just this command.
My AddMoney function is: [lua]function meta:AddMoney(amount)
local current_cash = self:GetMoney()
self:SetMoney( current_cash + amount )
end[/lua]

[lua]concommand.Add(“givedollars”, function(ply, cmd, args)
if not ply:IsAdmin() then return end

local playerid = player.GetByID(args[1])
local num = tonumber(args[2])
    
    printmessage (HUD_PRINTCHAT, ply..."has given "...playerid:Nick().." "..num.." dollars.")
	playerid:AddMoney (num)

end)[/lua]

Got to go, sorry I couldn’t help more.

Thank you so so much, it worked.
Though theres something wrong with: PrintMessage(HUD_PRINTCHAT, ply:Nick()…“has given “…playerid:Nick()…” “…num…” dollars.”)
The error: [gamemodes\basicdm\gamemode\shared.lua:22] ‘)’ expected near ‘…’

My bad, I was in a rush so I didn’t double check it, I see you got the help you needed from the WAYWO thread, is everything working now?

Well, not really, I still don’t have the PrintMessage text, but the command itself works.

Why don’t you have it?

[lua] printmessage (HUD_PRINTCHAT, ply…“has given “…playerid:Nick()…” “…num…” dollars.”) [/lua]

[lua]ply:PrintMessage( HUD_PRINTCHAT, ply:Nick()…" has given “…playerid:Nick()…” “…num…” dollars." )[/lua]

[gamemodes\basicdm\gamemode\shared.lua:25] attempt to call method ‘Nick’ (a nil value)

That error pops up now.

May I ask what you typed into the console? Try typing ‘givedollars 1 2000’ (In single player)

I did that, “givedollars [my userid] [moneyamount]”

[lua]

concommand.Add(“givedollars”, function(ply, cmd, args)
if not ply:IsAdmin() then return end

local player = tonumber(args[1])
local num = tonumber(args[2])
if player == nil then PrintMessage ( HUD_PRINTCONSOLE, "You did not enter a number for the player id" ) return end
if num == nil then PrintMessage ( HUD_PRINTCONSOLE, "You did not enter a number for the dollar value" ) return end
local playerid = player.GetByID(player)

if ply:Nick() == playerid:Nick() then PrintMessage ( HUD_PRINTCHAT, ply:Nick().." has given himself "..num.." dollars.")
	else
		PrintMessage (HUD_PRINTCHAT, ply:Nick().." has given "..playerid:Nick().." "..num.." dollars.")
end

playerid:AddMoney (num)
end)

[/lua]

I’ll check if it works.

Now the command isnt even here, it says: “Unknown Command”

Uh, I don’t see why it wouldn’t exist, any errors on startup? and is this in a shared file?

EDIT: I don’t think this would fix anything, but worth a try I guess.

[lua]

concommand.Add(“givedollars”, function(ply, cmd, args)
local playernum = type(tonumber(args[1]))
local isnum = type(tonumber(args[2]))
local playerid = player.GetByID(args[1])
local num = args[2]

if not ply:IsAdmin() then return end
if playernum != number then PrintMessage ( HUD_PRINTCONSOLE, "You did not enter a number for the player id" ) return end
if isnum != number then PrintMessage ( HUD_PRINTCONSOLE, "You did not enter a number for the dollar value" ) return end

if ply:Nick() == playerid:Nick() then PrintMessage ( HUD_PRINTCHAT, ply:Nick().." has given himself "..num.." dollars.")
    else PrintMessage (HUD_PRINTCHAT, ply:Nick().." has given "..playerid:Nick().." "..num.." dollars.")
end

playerid:AddMoney (num)
end)

[/lua]

No errors, only the Nick one, and i’m sure it is in Shared.lua

You should just do a simpler method that you’d understand and use 3 or 4 times, for other thing.

Zephilinox stop trying to help you obviously don’t know what you’re doing.

You shouldn’t be using PrintMessage since that prints to all players, trying using player:PrintMessage instead.

You should also check to see if playerid is a valid player (plus everything else is just a mess and won’t work), try this code:

[lua]
concommand.Add(“givedollars”, function(ply, cmd, args)
local playerid = player.GetByID(tonumber(args[1]))
local amount = tonumber(args[2]) or 0

if !ply:IsAdmin() then 
	ply:PrintMessage(HUD_PRINTCONSOLE, "You are not an admin!")
	return
end
if !playerid or !playerid:IsPlayer() then
	ply:PrintMessage(HUD_PRINTCONSOLE, "Invalid player!")
	return
end
if amount == 0 then
	ply:PrintMessage(HUD_PRINTCONSOLE, "Invalid amount to give!")
	return
end

if ply == playerid then
	PrintMessage(HUD_PRINTCHAT, ply:Nick().." has given himself $"..amount.." (what a cheater)")
    else
	PrintMessage(HUD_PRINTCHAT, ply:Nick().." has given "..playerid:Nick().." "..num.." dollars.")
end

playerid:AddMoney(amount)
--ply:RemoveMoney(amount) -- if you want them to 'give'

end)
[/lua]

This is why garry should add a fucking modular function that looks up a player for you, if it is a int check the player ids if it is something else check the player names if it looks like a steam id check those etc… seriously everytime I need something like that I have to write my own functions.