• SWEP.DrawHUD() for Entity?
    9 replies, posted
I'm trying to draw a texture on screen, using an entity. But this does not seem as easy as it does with sweps ( SWEP:DrawHUD() ) How would I go about doing this? Here's the texture code. [lua] local entpos = self.Entity:GetPos():ToScreen() local xm8 = Material("vgui/xm8_icon") surface.SetMaterial(xm8) surface.SetDrawColor(255,255,255,255) surface.DrawTexturedRect( entpos.x, entpos.y, 20, 20 ) [/lua]
You would have to use a hook and loop through all the entities and draw what you need to, or loop through them all and call a custom DrawHUD function. [lua]hook.Add("HUDPaint", "HUDPaintentityrtgsdk", function() for _, ent in ipairs(ents.FindByClass("your_entity_class")) do if ValidEntity(ent) and ent.DrawHUD then ent:DrawHUD() end end end)[/lua] [editline]01:44PM[/editline] Using this code, you can use DrawHUD like with SWEPS.
Is that the only way? I already have that running with a custom hud (Since it's part of a gamemode), but I thought finding my entity class every frame wouldn't be too efficient.
Well yes, because entities don't have HUDPaint functions.
[QUOTE=MakeR;20894449] [lua]hook.Add("HUDPaint", "HUDPaintentityrtgsdk", function() for _, ent in ipairs(ents.FindByClass("your_entity_class")) do if ValidEntity(ent) and ent.DrawHUD then ent:DrawHUD() end end end)[/lua] [/QUOTE] Couldn't you just use something like this in the ENT:Init(): [lua]hook.Add("HUDPaint", "HUDPaintentity" .. self.Entity:EntIndex(), function() --special hook for each ent self.Entity:DrawHUD() --draw the hud for this instance of the entity end)[/lua]? Or am I sadly mistaken? (I dont use hooks much)
[QUOTE=jakegadget;20924136]Couldn't you just use something like this in the ENT:Init(): [lua]hook.Add("HUDPaint", "HUDPaintentity" .. self.Entity:EntIndex(), function() --special hook for each ent self.Entity:DrawHUD() --draw the hud for this instance of the entity end)[/lua]? Or am I sadly mistaken? (I dont use hooks much)[/QUOTE] You are mistaken, the drawing code should be in a HUDPaint hook, so calling the entities DrawHUD in the HUDPaint hook is correct.
[QUOTE=MakeR;20894449]You would have to use a hook and loop through all the entities and draw what you need to, or loop through them all and call a custom DrawHUD function. [lua]hook.Add("HUDPaint", "HUDPaintentityrtgsdk", function() for _, ent in ipairs(ents.FindByClass("your_entity_class")) do if ValidEntity(ent) and ent.DrawHUD then ent:DrawHUD() end end end)[/lua] [editline]01:44PM[/editline] Using this code, you can use DrawHUD like with SWEPS.[/QUOTE] Which lua doc should I put this in shared, init, or cl_init? I want to make it so that the lockpicking screen comes up but I will change the wording so that when using the entity, You will see a loading bar thats says like "Working..."
[code] function ENT:Initialize() if CLIENT then hook.Add( "HUDPaint", self, self.DrawHUD ) end end function ENT:DrawHUD() -- :) end [/code]
Anyone mind helping me out with this ik im late as fuck would appreciate it
What do you need help with
Sorry, you need to Log In to post a reply to this thread.