I was wondering how I would go about creating abbreviations in a hud. What I would personally like to do is in the darkrp hud I have created would be to make it so that when someone reaches $100,000 it would say instead 100k and then at $1,000,000 it would instead say 1m. Is that a possibility to do that? And if so, does anyone know a tutorial on how to do that or anyone here in general know?
I'm sure I've seen a function that does this, I can't remember if it was a gmod function or something in a gamemode though.
If I remember I'll let you know!
Yeah I could have sworn I have seen something like that before. I am just unsure of how I would do it.
hook.Add("HUDPaint","examplehookname", function()
local money = (LocalPlayer():getDarkRPVar("money"));
local moneytext = "";
if (money >= 10000) then
moneytext = string.format("Money: %dK", money * .001);
else
moneytext = string.format("Money: %d", money);
end
surface.SetDrawColor(Color(255,255,255,255));
surface.SetTextPos(ScrW()/2, ScrH()/2);
surface.DrawText(moneytext);
end)
Not exactly how I've seen it done (still can't remember where i saw it), but that should work
I just tried that out and it works! Thank you very much!
I don't really understand why would you do this because it'd confuse quite a few people and in general just isn't a convenient way to judge an amount outside of general transactions...
Anyways, here's a flexible function for what you need:
function amountToMonetaryUnit(amount)
local units = {
{symbol = "k", multiplier = 0.001},
{symbol = "m", multiplier = 0.000001},
{symbol = "b", multiplier = 0.000000001},
{symbol = "t", multiplier = 0.000000000001}
}
local conv = amount
for _, unit in pairs(units) do
local calc = amount * unit.multiplier
if calc >= 1 then conv = calc .. unit.symbol continue end
break
end
return conv
end
this is what you'd be getting with this...
132 = 132
1002 = 1.002k
5,423,142 = 5.423142m
2,240,000 = 5.24m
1,200,000,000 = 1.2b
etc...
Would this be outside of the hud function? Like in other words
function amountToMonetaryUnit(amount)local units = {
{symbol = "k", multiplier = 0.001},
{symbol = "m", multiplier = 0.000001},
{symbol = "b", multiplier = 0.000000001},
{symbol = "t", multiplier = 0.000000000001}
}
local conv = amount
for _, unit inpairs(units) dolocal calc = amount * unit.multiplier
if calc >= 1then conv = calc .. unit.symbol continue endbreakendreturn conv
end
local function CreateHUD()
Kinda like that? Sorry Im having such huge issues with the code thing for some reason.
like this
function amountToMonetaryUnit(amount)
local units = {
{symbol = "k", multiplier = 0.001},
{symbol = "m", multiplier = 0.000001},
{symbol = "b", multiplier = 0.000000001},
{symbol = "t", multiplier = 0.000000000001}
}
local conv = amount
for _, unit in pairs(units) do
local calc = amount * unit.multiplier
if calc >= 1 then conv = calc .. unit.symbol continue end
break
end
return conv
end
hook.Add("HUDPaint", "draw_money", function()
draw.SimpleText(amountToMonetaryUnit(1000, "ChatFont", 100, 100, Color(230, 230, 230))
end)
Its currently giving me this error [ERROR] addons/scg_hud/lua/autorun/scg_hud.lua:37: 'in' expected near 'inpairs'
1. unknown - addons/scg_hud/lua/autorun/scg_hud.lua:0
that error literally says that it should be in pairs insted of ur inpairs
You can use:
hook.Add("HUDPaint","hookname", function()
local moneyvaule = (LocalPlayer():getDarkRPVar("money"));
local moneyhud = "";
if (moneyvaule >= 1000000) then
moneyhud = string.format("You money: %dM", moneyvaule * .000001);
elseif (moneyvaule >= 100000) then
moneyhud = string.format("You money: %dK", moneyvaule * .001);
else
moneyhud = string.format("You money: %d", moneyvaule);
end
surface.SetDrawColor(Color(255,255,255,255));
surface.SetTextPos(0, 0);
surface.DrawText(moneyhud);
end)
Sorry, you need to Log In to post a reply to this thread.