• I want to add Armor to the DarkRP HUD, but I don't know how.
    21 replies, posted
I've made a Suit/Armor entity for DarkRP, and I need to make a bar for it on the hud, yet I could get a snippet for regular huds, but it's much different for DarkRP, could someone please show me how to do it? And what file? It's CL_Init.lua yeah? It's Regular DarkRP v2.4.1, this is for a server, so could I please get some help?
open cl_init.lua and search for "chud" and you will see "function GM:HUDShouldDraw(name)" i think you will see Suitpower or armor or whatever its called. then add this : [LUA]function DrawPlayerArmor() if (LocalPlayer():Armor() > 0) then draw.RoundedBox( 8, 32, 16, ScrW() - 64, 16, Color(200, 200, 200, 200)); draw.RoundedBox( 8, 34, 18, (ScrW() - 68)*(LocalPlayer():Armor() / 1000), 12, Color(0, 0, 200, 200)); end end hook.Add("HUDPaint","drawplayerarmor",DrawPlayerArmor); [/LUA] [b][url=http://wiki.garrysmod.com/?title=Player.Armor]Player.Armor [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] still not sure.
I tried that exact same code off of Gmod Wiki. Let me test. [editline]1st December 2010[/editline] Okay, it works as a bigass bar at the top, but how would I resize it/Add text? [editline]1st December 2010[/editline] Heres a picture of it ATM, I want it to max the bar at 100 suit. In the picture the suit is actually on 100. And the bar is only about 1/10th full. [U][media]http://img802.imageshack.us/img802/416/gmconstruct00000.jpg[/media][/U] I saw this bar before, I thought it was for somethin' else. Heres quick code. function DrawPlayerArmor() if (LocalPlayer():Armor() > 0) then draw.RoundedBox( 8, 32, 16, ScrW() - 64, 16, Color(200, 200, 200, 200)); draw.RoundedBox( 8, 34, 18, (ScrW() - 68)*(LocalPlayer():Armor() / 1000), 12, Color(0, 0, 200, 200)); end end hook.Add("HUDPaint","drawplayerarmor",DrawPlayerArmor); [editline]1st December 2010[/editline] It's base code, now how would I modify it? A little guide would be nice.
[url]http://wiki.garrysmod.com/?title=Creating_a_HUD[/url] you can draw it in anyway, but you must use the "LocalPlayer():Armor()" variable
I added the text part of the code Draw.SimpleText underneath the Draw.RoundedBox, and it messed up. [editline]2nd December 2010[/editline] OH don't worry, I accidently pressed C in Notepad++. [editline]2nd December 2010[/editline] Okay. How do I change the position of the bar?
Bump, I need this for a server.
Bump again, please respond.
Again, a little bump. Please answer guys.
Answer what? its already been answered.
[QUOTE=343N;26441069]I added the text part of the code Draw.SimpleText underneath the Draw.RoundedBox, and it messed up. [editline]2nd December 2010[/editline] OH don't worry, I accidently pressed C in Notepad++. [editline]2nd December 2010[/editline] Okay. How do I change the position of the bar?[/QUOTE] draw.RoundedBox( 8, 32 <- Here , 16 <- and here, ScrW() - 64, 16, Color(200, 200, 200, 200)); draw.RoundedBox( 8, 34 <- Here, 18 <- and here, (ScrW() - 68)*(LocalPlayer():Armor() / 1000), 12, Color(0, 0, 200, 200));
That 1000 number should be the max armor you can get, so if you want your bar to be full at 100 you would do [lua]draw.RoundedBox( 8, 34 <- Here, 18 <- and here, (ScrW() - 68)*(LocalPlayer():Armor() / 100), 12, Color(0, 0, 200, 200));[/lua]
How do I resize the bar, also? [editline]3rd December 2010[/editline] [media]http://img813.imageshack.us/img813/1263/gmconstruct0001.jpg[/media] To help explain. [editline]3rd December 2010[/editline] Bump.
Bumpy.
[code]draw.RoundedBox( round, x, y, w, h, color )[/code] [code]draw.RoundedBox( 2, ScrW( ) * .25, ScrH( ) * .9, ScrW( ) * .5, ScrH( ) * .02, color_black ) draw.RoundedBox( 2, ScrW( ) * .25, ScrH( ) * .9, ScrW( ) * .5 * math.Clamp( LocalPlayer( ):Armor( ) / 100, 0, 1 ), ScrH( ) * .02, color_white )[/code] Even looking at the wiki would reveal what each argument does.
But when I change the h, argument, it doesn't change the length of the bar. W argument changes thickness, which I've changed now. [editline]4th December 2010[/editline] Bump.
[QUOTE=343N;26469915]But when I change the h, argument, it doesn't change the length of the bar. W argument changes thickness, which I've changed now. [editline]4th December 2010[/editline] Bump.[/QUOTE] W is the width of the bar in pixels H is the height of the bar in pixels
[QUOTE=343N;26469915]But when I change the h, argument, it doesn't change the length of the bar. W argument changes thickness, which I've changed now. [editline]4th December 2010[/editline] Bump.[/QUOTE] .. [lua] function DrawPlayerArmor() local armor = LocalPlayer():Armor() // the players armor, omgawsh local maxarmor = 1000 // the maximum armor it will draw before it is "full" local bordersize1 = 8 // the rounded size of the corner local bordersize2 = 8 // the rounded size of the corner local x-axis1-position = 32 // the ROUNDED-CORNER-box's position on the x-axis local x-axis2-position = 34 // the ROUNDED-CORNER-box's position on the x-axis local y-axis1-position = 16 // the ROUNDED-CORNER-box's position on the y-axis local y-axis2-position = 18 // the ROUNDED-CORNER-box's position on the y-axis local width1 = ScrW() - 64 // the ROUNDED-CORNER-box's width local width2 = (ScrW() - 68)*(armor / maxarmor) // the ROUNDED-CORNER-box's width local height1 = 16 // the ROUNDED-CORNER-box's height local height2 = 12 // the ROUNDED-CORNER-box's height local color1 = Color(200, 200, 200, 200) // the ROUNDED-CORNER-box's color local color2 = Color(0, 0, 200, 200) // the ROUNDED-CORNER-box's color //WARNING: // * The bordersize value should be dividable by 2, otherwise a drawing bug will occur. // * The bordersize value should also be larger than 2, otherwise it will just draw a normal box with straight corners. if (armor > 0) then // IF ARMOR IS BIGGAAAAR THEN 0, ZERO, NOUGHT draw.RoundedBox( bordersize1, x-axis1-position, y-axis1-position, width1, height1, color1); // draw the ROUNDED-CORNER-box draw.RoundedBox( bordersize2, x-axis2-position, y-axis2-position, width2, height2, color2); // draw the ROUNDED-CORNER-box end // end "if" on line 4 end // end "function" on line 1 hook.Add("HUDPaint","drawplayerarmor",DrawPlayerArmor); // draw the ROUNDED-CORNER-box combined [/lua] If it feels like I'm patronizing you, then its because I am. Adj.1.patronizing - (used of behavior or attitude) characteristic of those who treat others with condescension
Sorry for bumping such an old thread... But where would i put this? (specifically)...
[QUOTE=Adam.;33660268]Sorry for bumping such an old thread... But where would i put this? (specifically)...[/QUOTE] It's client side.
[QUOTE=Adam.;33660268]Sorry for bumping such an old thread... But where would i put this? (specifically)...[/QUOTE] cl_hud.lua
Why don't I make this simple for you DarkRP diddles: [url]http://www.garrysmod.org/downloads/?a=view&id=126167[/url] Install my HUD instead.
1. why is my thread bumped. 2. the guy that linked to your hud has a internal server error. great job
Sorry, you need to Log In to post a reply to this thread.