SetMaterial Issue

Right now I’m trying to use a custom icon for a darkrp HUD, but I can’t seem to get the directory right or somthing.
I’m completely stumped, I’ve tried to change the directory to a bunch of things.

Here is my code:
This is a shortened version of the code. Obviously I have other things for the hud, such as health, armor, etc.



if CLIENT then
resource.AddFile("material/hud/health.png")

local function drawIcon()
    surface.SetMaterial(Material("material/hud/health.png"))
    surface.SetDrawColor(255,255,255,255)
    surface.DrawTexturedRect(370 + 10,ScrH() - 160,25,25)
end

local function DrawHUD()
    drawIcon()
end
hook.Add("HUDPaint","DrawHUD",DrawHUD)


The file is located in:

garrysmod\addons\MatteHUD\material\hud

That is the location on my computer / Dedicated Server

First, it’s material**s**, not material. Second, you do not need to specify materials/ part of the path in the call to Material().

Do i need to specify materials in the resource.AddFile?

You do.

It still is that pink gmod checker board

Updated code:




if CLIENT then
resource.AddFile("materials/hud/health.png")

local function drawIcon()
    surface.SetMaterial(Material("hud/health.png"))
    surface.SetDrawColor(255,255,255,255)
    surface.DrawTexturedRect(370 + 10,ScrH() - 160,25,25)
end

local function DrawHUD()
    drawIcon()
end
hook.Add("HUDPaint","DrawHUD",DrawHUD)


resource.AddFile isn’t clientside

[editline]16th January 2017[/editline]



if SERVER then
    resource.AddFile("materials/hud/health.png")
end

if CLIENT then
    local health = Material("hud/health.png") -- cache before use for better performance

    local function drawIcon()
        surface.SetMaterial( health )
        surface.SetDrawColor(255,255,255,255)
        surface.DrawTexturedRect(370 + 10,ScrH() - 160,25,25)
    end

    local function DrawHUD()
        drawIcon()
    end

    hook.Add("HUDPaint","DrawHUD",DrawHUD)
end


[editline]16th January 2017[/editline]

^ If that doesn’t work then make sure the folder is called materials rather than material

That still, did not work, I tried to make it server side before, but that did not work, so I thought I was just stupid and it was client side.

And yes, the folder says materials not material

Could you post a screenshot or something of the file path of the image?

I honestly can’t think of what else it could be

Sorry, this is probably a stupid question, but what is the GMOD folder? For me the folder is called GarrysMod. I guess it’s just a shortcut or something but I just wanted to check

Its my server folder. where start.bat and all that is

bumb

Snippity :snip:

If you do not see anything at all:

  1. Make sure your code is ran clientside AND serverside ( Put the file into autorun/ folder or something )
  2. Make sure your hook identifier is more unique ( read hook.Add wiki page )
  3. Make sure your file name is unique and not init.lua or shared.lua or hud.lua or something like that

If you see black/purple checker board:

  1. Make sure your file is being downloaded to the clients. Open your gmod folder in steam and make sure the file exists there in the download/ folder.

Work great thanks so much!