• How do I add an "Icon" on the screen?
    8 replies, posted
I want to add something like this: [IMG]http://i1143.photobucket.com/albums/n627/santiago540/Nuevaimagendemapadebits_zps1fbc1787.jpg[/IMG] (Paint level 9000) How do I do that? I mean, I have the "triggers" but how do I make it so an transparent image appears in the middle-bottom part of the screen saying "Press Alt to do something" or how do I put some text saying that? Thanks!
If you want to add text on the screen, try looking into the [URL="http://wiki.garrysmod.com/page/Category:surface"]surface library[/URL].
[code] function PaintCustomHUD() draw.DrawText("Press ALT to do something", "Default", 40,40,Color(255,255,255,255),0) end hook.Add("HUDPaint", "Whatever", PaintCustomHUD) [/code] Put that in a lua file and send it to the client.
[QUOTE=Mors Quaedam;44001652][code] function PaintCustomHUD() draw.DrawText("Press ALT to do something", "Default", 40,40,Color(255,255,255,255),0) end hook.Add("HUDPaint", "Whatever", PaintCustomHUD) [/code] Put that in a lua file and send it to the client.[/QUOTE] Yeah, the thing is that I want to do that when a trace hits something, how do I do that? [code] function Thing() for id,ply in pairs ( player.GetAll( ) ) do tracedata={} tracedata.start = ply:EyePos() tracedata.endpos = ply:EyePos()+(ply:GetAimVector()*64) tracedata.filter = ply local trace = util.TraceLine(tracedata) if trace.Hit then ---here should be the press alt to do something thing-- [/code]
You'd have to hook the entire function into a HUDPaint hook like so: [lua] ply = LocalPlayer() hook.Add( "HUDPaint", "DrawMessage", function() tracedata={} tracedata.start = ply:EyePos() tracedata.endpos = ply:EyePos()+(ply:GetAimVector()*64) tracedata.filter = ply local trace = util.TraceLine(tracedata) if trace.Hit then draw.DrawText( "Press ALT to peek", "Default", 40, 40, Color( 255, 255, 255 ) ) end end ) [/lua] This would only be needed clientside, since the surface library and the HUDPaint hook only work clientside.
To draw an icon use this: Where _mat is a Material( ) defined outside of the HUDPaint, and _x, _y are the location, and _w, _h are the width and height of the material. [lua]surface.SetMaterial( _mat ); surface.SetDrawColor( Color( 255, 255, 255, 255 ) ); surface.DrawTexturedRect( _x, _y, _w, _h );[/lua]
[QUOTE=Internet1001;44005338]You'd have to hook the entire function into a HUDPaint hook like so: [lua] ply = LocalPlayer() hook.Add( "HUDPaint", "DrawMessage", function() tracedata={} tracedata.start = ply:EyePos() tracedata.endpos = ply:EyePos()+(ply:GetAimVector()*64) tracedata.filter = ply local trace = util.TraceLine(tracedata) if trace.Hit then draw.DrawText( "Press ALT to peek", "Default", 40, 40, Color( 255, 255, 255 ) ) end end ) [/lua] This would only be needed clientside, since the surface library and the HUDPaint hook only work clientside.[/QUOTE] Thank you! Is there any way to change the size?
[QUOTE=shadowsaints;44023880]Thank you! Is there any way to change the size?[/QUOTE] You'd have to make your own font using [url=http://wiki.garrysmod.com/page/surface/CreateFont]surface.CreateFont[/url]
[QUOTE=HumbleTH;44024142]You'd have to make your own font using [url=http://wiki.garrysmod.com/page/surface/CreateFont]surface.CreateFont[/url][/QUOTE] Thank you!
Sorry, you need to Log In to post a reply to this thread.