Hey, i wanted to know how i would be able to get a servers prop limit and print it to a HUD. I know how to print it i just don’t know how to get the limit. sorry if it is simple I’m new to lua.
After searching for a bit I came across these functions:
local proplimit = GetConVar("sbox_maxprops") local varforhud = proplimit:GetInt() hook.Add( "HUDPaint", "HUDPaint_DrawABox", function() draw.SimpleText("Prop limit:"..varforhud, "DermaDefault", 100, ScrH()/2, Color(255, 0, 0, 255)) end )
I don’t know if this works but this would be my best bet.
If you use GetConVar then cache it outside of the HUDPaint hook. It’s expensive to call it every frame.
GetConVar is actually cached in the Lua state now, to which it calls GetConVar_Internal, but it’s still good practice to cache it so that you don’t have to do a table lookup every time.
I get this error
[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/simply_the_hud/cl_simpley_the_hud.lua:125: attempt to call local 'proplimit' (a userdata value) 1. fn - addons/darkrpmodification-master/lua/darkrp_modules/simply_the_hud/cl_simpley_the_hud.lua:125 2. unknown - addons/ulib_557962238/lua/ulib/shared/hook.lua:109
This is My code
local props = LocalPlayer():GetCount( "props" ) local proplimit = GetConVar("sbox_maxprops") local varforhud = proplimit():GetInt() draw.SimpleText(props.."/".. varforhud, "Font_British", 1250, ScrH() /2, Color(0,0,0), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
I just tested mine and it works, put the two variables outside the hud hook.
You’re calling a variable. You only need to do that for functions.
Yeah i think i made some placement mistakes,
Thank you for the Help