First of all, I would like to say that my Lua skills are shit, I know other programming languages, so I understand the base of it, but not the language specific syntax and such.
Second, this questions asks about DarkRP jobs and HUD scripts, which I recognize are not parts of the base game itself.
Now, the question itself is: Is it practical, or even possible, to make a script that would allow a different job to have a different HUD? For example, can I have a job have the default DarkRP HUD, and another job have a visor HUD?
To clarify, I am not looking for a complete script, I would prefer instructions so I can learn how to make one rather than a complete script.
It can definitely be done.
You'll want to use the HUDShouldDraw hook to disable specific hud aspects of DarkRP based on the LocalPlayer's job. You can find the DarkRP hud element names in the custom hud example on this page:
https://github.com/FPtje/darkrpmodification/blob/master/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua
You'll also want to use a HUDPaint hook that draws various things depending on the LocalPlayer's job.
As an example:
--Contains a table for each job we want to hide default elements for
--Each entry in the table specifies which elements we want to hide
local darkRPHideElements = {
["Citizen"] = {
--Hide the stuff in the bottom left corner for citizens, because why not?
["DarkRP_LocalPlayerHUD"] = true
}
}
--Create a custom font just for memes
surface.CreateFont(
"CitizenMemeFont",
{
font = "Tahoma",
--Stupidly large size at all resolutions thanks to ScreenScale
size = ScreenScale( 80 ),
--Make it bold because memes
weight = 600
}
);
--We could've made this more basic but messy by not creating functions for the draws per job
--But that'd turn into a mess over time
--So instead, we'll create a function for each job that needs to draw
--Here we define the table to hold these draw functions
local darkRPCustomJobHUDs = {};
--Now we define our citizen draw function
function darkRPCustomJobHUDs:Citizen()
--Get a flashy color-changing text color
local drawColor = HSVToColor( math.sin( CurTime() ) * 360, 1, 1 );
draw.SimpleText(
"You're a ~Citizen~",
"CitizenMemeFont",
ScrW() / 2,
ScrH() / 2,
drawColor,
TEXT_ALIGN_CENTER,
TEXT_ALIGN_CENTER
);
end;
--Just for shits and giggles let's make one for the civil protection too
--For this one we have to define it differently since the job name has a space in it
darkRPCustomJobHUDs["Civil Protection"] = function()
--Get a different flashy color-changing text color from citizen
local drawColor = Color(
255 / 2 * ( 1 + math.sin( CurTime() * 10 ) ),
0,
255 / 2 * ( 1 + math.cos( CurTime() * 10 ) )
);
draw.SimpleText(
"You're a ~CP~",
"CitizenMemeFont",
ScrW() / 2,
ScrH() / 2,
drawColor,
TEXT_ALIGN_CENTER,
TEXT_ALIGN_CENTER
);
end;
--Store the client outside of any hooks since it'll never need updating
local client = LocalPlayer();
--Add our hook to hide stuff based on job
hook.Add( "HUDShouldDraw", "HideDarkRPHUD_Jobs", function( element )
--Get the string name of the job we currently have
local job = client:getDarkRPVar( "job" );
--Make sure it's valid, not sure how DarkRP handles things before this is set
if( job ) then
--Check if we have an entry in the darkRPHideElements table for this job
if( darkRPHideElements[job] ) then
--Check if the specific element is true in the entry
--If it exists and is true, return false to prevent it from being drawn
if( darkRPHideElements[job][element] ) then return false end;
end;
end;
end );
--Add our hook to actually draw stuff now
hook.Add( "HUDPaint", "DrawDarkRPHUD_Jobs", function()
--Get the string name of the job we currently have
local job = client:getDarkRPVar( "job" );
--Get our custom hud function
local customHUDFunction = darkRPCustomJobHUDs[job];
--Make sure it's not nil
if( customHUDFunction ) then
--Call it
customHUDFunction();
end;
end );
Sorry, you need to Log In to post a reply to this thread.