Right now i am currently making a custom HUD for darkRP gmod, however i want an image to be placed in my HUD. I am able to see the image on my Garry's mod because i have it installed into my materials folder, however i can't seem to figure out how to get the client to download the images from my server. Would this code be the correct approach from getting images onto your hud?
Also i have notice that i can't use this code more then once or the image will be replace.
local mat = Material( "vgui/Armor.png" )
hook.Add( "HUDPaint", "DrawTexturedRectUV_example1", function()
surface.SetDrawColor( color_white )
surface.SetMaterial( mat )
surface.DrawTexturedRect( 23, 1009, 29, 29 )
end )
Please help me get the multiple images onto my HUD and give me advice on how the server can give the client the image files.
rename mat to a custom name for the armor material, and create more variables for each material you want.
for the client to download each material, you need to use resource.AddFile serverside on each material you are wanting the client to download.
[url]http://wiki.garrysmod.com/page/resource/AddFile[/url]
If I'm understanding the "more than once" thing right, just create another material under a different variable name and draw it somewhere else.
[CODE]
local mat = Material( "vgui/Armor.png" )
local bingbong = Material( "something/else.png" )
hook.Add( "HUDPaint", "DrawTexturedRectUV_example1", function()
surface.SetDrawColor( color_white )
surface.SetMaterial( mat )
surface.DrawTexturedRect( 23, 1009, 29, 29 )
surface.SetMaterial( bingbong )
surface.DrawTexturedRect( --[[ somewhere else ]] )
end )
[/CODE]
If you want people to download your images, use resource.AddFile in conjunction with a FastDL repository.
[CODE]
-- run serverside
resource.AddFile( "materials/vgui/Armor.png" )[/CODE]
Also, screen sizes change, i.e. huds have to act responsively towards changing screen resolutions. This isn't hard to do. Say you have a 29x29 png and want it do draw on the bottom right corner of the screen, regardless of the screen's size. You could do something like:
[CODE]
local sh = ScrH() -- ScrH() gets the height of the screen in pixels
local sw = ScrW() -- ScrW() gets the width of the screen in pixels
hook.Add( "HUDPaint", "aaaaaaaaaaaaaaaaaaaaa", function()
surface.SetDrawColor( color_white )
surface.SetMaterial( mat )
-- subtract 29 from the width and 29 from the height to represent the top left of the 29x29 image;
-- then, draw it at that spot and it'll show at the bottom right of every screen.
surface.DrawTexturedRect( sw - 29, sh - 29, 29, 29 )
end )
[/CODE]
[editline]30th December 2016[/editline]
when you get ninja'd okay
Please use the tags.
[.code][./code]
Without the dot.
Sorry, you need to Log In to post a reply to this thread.