How can i add console command there set players money .. ?
like i want bobs money to be 80000 then i would type in console
/money STEAM_0:0:98651 80000
the cash thing is PData( "cash" )
[lua]
concommand.Add("money", function(sender, command, arguments)
if not sender:IsAdmin() then return end --this prevents players from using this command, only admins
local steamid = arguments[1] -- first argument you entered is the steamid
local amount = arguments[2] -- second argument you entered is the money to add
for _, pl in pairs(player.GetAll()) do
if pl:SteamID() == steamid then
local money = pl:GetPData("cash")
pl:SetPData("cash", money+amount)
break
end
end
end)
[/lua]
Not tested, just to give you an idea.
yea thank you :)
[editline]12:31PM[/editline]
how to check if there is a ohter symbols than numbers in the money i want to add?
[lua]if not tonumber(arguments[2]) then
sender:PrintMessage(HUD_PRINTCONSOLE, "Invalid amount type!\n")
return
end[/lua]
[QUOTE=grunewald;23249547]How can i add console command there set players money .. ?
like i want bobs money to be 80000 then i would type in console
/money STEAM_0:0:98651 80000
the cash thing is PData( "cash" )[/QUOTE]
If this is for darkrp, there is already a command to do so called rp_setmoney.
it's not for darkrp, i am making my own gamemode.. UnderGroundRP also i have a server for it, but only test server ;)
...Is it based of DarkRP?
[lua]local function GiveMoneyToSomeone(ply, cmd, args)
for k, v in pairs (player.GetAll()) do
local intstring = "cash"
local guy = v
local ID = tostring(args[1])
if not ID then return end
local amount = tonumber(args[2])
if not amount then return end
if guy:SteamID() == ID then
if guy:GetNWInt(intstring) != nil then
guy:SetPData(intstring, guy:GetPData(intstring) + amount)
else
guy:SetPData(intstring, amount)
end
ply:EmitSound("buttons/button15.wav")
ply:PrintMessage( HUD_PRINTCENTER,"You gave money to "..ID)
end
end
end
concommand.Add("give_money", GiveMoneyToSomeone)[/lua]
read this like it is a song..
IIIIIIITTTTTSSSSSS NOOOOOOOOOOOOT WOOOOOOORKIIIIIING
ITS should be light and then turn the sound to be deeper when you reach working :D
^ Yea, you dont know anything about this, and you dont speak very well english, so, uh... yea.
well i know that, my english is not very well, and no, i don't know alot abot this, but still you understand me, and i try to code, and yea some annoying people says to me that me english is not very good, and i don't know very much of that i am doing .. :)
[editline]10:00PM[/editline]
But any way, can some one help me with this?
Saying it is not working is not all that helpful. Describe what you did and what happens. Any errors?
Also, what code did you use?
i did try both codes, no error's only thing i know is that its not working :(
insert this into any of the codes, in the beginning of the console command function
[lua]PrintTable(arguments)[/lua]
(replace arguments with args for second code)
Then paste the result (what was printed to the console) here.
I have a feeling that the SteamID is not treated as a single argument.
This works for both:
[lua]
local function GiveMoneyToSomeone(ply, cmd, args)
local intstring = "cash"
local guy = nil
local id = ""
local amount = nil
if #args > 2 then
for i=1,(#args-1) do
id = id .. args[i]
end
amount = tonumber(args[6])
else
id = args[1]
amount = tonumber(args[2])
end
if not (id and amount) then return end
for k, v in pairs (player.GetAll()) do
if v:SteamID() == id then
guy = v
break
end
end
if not guy then return end
local currentMoney = guy:GetNWInt(intstring) or 0
guy:SetPData(intstring, guy:GetPData(intstring) + amount)
ply:EmitSound("buttons/button15.wav")
ply:PrintMessage( HUD_PRINTCENTER,"You gave money to "..ID)
end
concommand.Add("give_money", GiveMoneyToSomeone)[/lua]
ok thanks
[lua]local function Money(ply, cmd, args)
if not ply:IsAdmin() or #args < 2 then return end
if not tonumber(args[#args]) then
ply:PrintMessage(HUD_PRINTCONSOLE, "Invalid amount type!")
return
end
local steamid, plys = table.concat(args, "", 1, #args - 1), player.GetAll()
for k = 1, #plys do
if plys[k]:SteamID() == steamid then
plys[k]:SetPData("money", (plys[k]:GetPData("money") or 0) + args[#args])
ply:EmitSound("buttons/button15.wav")
ply:PrintMessage(HUD_PRINTCONSOLE, "You gave money to " .. plys[k]:Nick())
return
end
end
ply:PrintMessage(HUD_PRINTCONSOLE, "Player not found!")
end
concommand.Add("give_money", Money)[/lua]
Sorry, you need to Log In to post a reply to this thread.