Some back story, I'm heavily modding DarkRP and I'm currently working on a custom HUD. I'm drawn between two methods to show an Arrested HUD, the official method, and my custom method. Basically, the Official Method checks to see if the "Arrested" event has been called, then performs a few other checks and draws the HUD. Thing is, to actually get this method to work, it requires 16 lines of code, minimum.
My method involves just checking the players status to see if they're arrested or not, then just draws the HUD if they are, that requires 5 lines of code minimum.
The sum this all up, no matter what, a check has to be done to see if the player has been arrested, either a Hook check (Official) or an IF Statement (Custom) and these checks are being done every server tick. I'm new to coding for GMOD, so I cannot shake the feeling the Official method is there because of a certain reason, but I cannot figure out why, my method seems more efficient. Any opinions on the matter would be helpful.
OFFICIAL CODE
--local Arrested = function() end
--usermessage.Hook("GotArrested", function(msg)
-- local arrestTimestamp = CurTime()
-- local arrestTimelimit = msg:ReadFloat()
-- local arrestedHUDX, arrestedHUDY = 6, ScrH() - 175
-- Arrested = function()
-- if CurTime() - arrestTimestamp <= arrestTimelimit and LocalPlayer():getDarkRPVar("Arrested") then
-- draw.RoundedBox( 4, ScrW() / 2, ScrH() / 2, 100, 130, Color( 0, 0, 0, 150))
-- elseif not LocalPlayer():getDarkRPVar("Arrested") then
-- Arrested = function() end
-- end
-- end
--end )
--function intermittentHUDCheck()
-- Arrested()
--end
--hook.Add("HUDPaint", "nwsDisplaySystemIHUDC", intermittentHUDCheck)
CUSTOM CODE
function drawArrestedHUD()
if LocalPlayer():getDarkRPVar("Arrested") then
draw.RoundedBox( 4, ScrW() / 2, ScrH() / 2, 100, 130, Color( 0, 0, 0, 150))
end
end
hook.Add("HUDPaint", "nwsDisplaySystemArrested", drawArrestedHUD)
The default method is a micro optimisation, using either is fine.
The principle behind the default is simply that Arrested() will be an empty function if you aren't arrested, therefore it wont need to check if you actually are arrested when drawing the UI
I see, another thing I noticed while continuing to develop this is the Hook passes along data on the time that player has to serve. Thanks.
Sorry, you need to Log In to post a reply to this thread.