Trying to draw an icon on a players HUD where an entity is. I put this in a HUD paint hook:
[lua]
local pos = v:GetPos():ToScreen()
render.DrawSprite(pos, 12, 12, COLOR_WHITE)
[/lua]
output:
[lua]
bad argument #1 to 'DrawSprite' (Vector expected, got table)
[/lua]
Can someone please explain to me how to fix this, because ply:GetPos() returns a vector and the error states that it is a table. Thanks
Toscreen() returns a table with three elements; "x", "y" and "visible".
You need to change the
[lua]render.DrawSprite(pos, 12, 12, COLOR_WHITE)[/lua]
to
[lua]render.DrawSprite(pos.x,pos.y, 12, 12, COLOR_WHITE)[/lua]
or
[lua]render.DrawSprite(Vector(pos.x,pos.y,0), 12, 12, COLOR_WHITE)[/lua](Don't know if works)
Draw sprite renders in 3D, not 2D. Remove :ToScreen().
If you're drawing to the HUD you shouldn't be using render.DrawSprite in the first place.
You might want to have a look at the [url=http://wiki.garrysmod.com/page/Category:surface]surface[/url] library, notably [url=http://wiki.garrysmod.com/page/surface/SetMaterial]surface.SetMaterial[/url] and [url=http://wiki.garrysmod.com/page/surface/DrawTexturedRect]surface.DrawTexturedRect[/url].
Sorry, you need to Log In to post a reply to this thread.