Creating DrawCircle on a player position?

Not sure why this doesn’t work. It’s suppose to record the position of LocalPlayer and draw a circle on the screen. Anyone know what’s wrong?



function Set()

c = LocalPlayer():GetPos():ToScreen()

end


function setpos()

surface.SetDrawColor( 255, 40, 80, 255 )
surface.DrawCircle( math.floor(c.x), math.floor(c.y) + 50, 50, Color(255,100,100,255) )

end

concommand.Add("set", Set)
hook.Add("HUDPaint", "SetPos" ,setpos)

You are taking a World Vector, and drawing onto the screen with those values.

Use the ToScreen function and you should be good to go.

gonna guess you want a circle under he player, if not ignore me:

[lua]local CircleMat = Material( “SGM/playercircle” );

function GM:DrawPlayerRing( pPlayer )

    if ( !IsValid( pPlayer ) ) then return end
    if ( !pPlayer:GetNWBool( "DrawRing", false ) ) then return end
    if ( !pPlayer:Alive() ) then return end
    
    local trace = {}
    trace.start         = pPlayer:GetPos() + Vector(0,0,50)
    trace.endpos         = trace.start + Vector(0,0,-300)
    trace.filter         = pPlayer
    
    local tr = util.TraceLine( trace )
    
    if not tr.HitWorld then
            tr.HitPos = pPlayer:GetPos()
    end

    local color = table.Copy( team.GetColor( pPlayer:Team() ) )
    color.a = 40;

    render.SetMaterial( CircleMat )
    render.DrawQuadEasy( tr.HitPos + tr.HitNormal, tr.HitNormal, GAMEMODE.PlayerRingSize, GAMEMODE.PlayerRingSize, color )        

end

hook.Add( “PrePlayerDraw”, “DrawPlayerRing”, function( ply ) GAMEMODE:DrawPlayerRing( ply ) end ) [/lua]

Well, among other things c is going to be nil before you run the console command “set” and the HUDPaint hook is going to just go whether c is available or not. I’m assuming you’re getting an error that says something along the lines of attempting to index a nil value

I’m not 100% sure why you need the console command but if you want it for some reason, put an if statement before drawing things, like this

[lua]if ( c ) then
surface.SetDrawColor( 255, 40, 80, 255 )
surface.DrawCircle( math.floor(c.x), math.floor(c.y) + 50, 50, Color(255,100,100,255) )
end[/lua]

It isn’t nil I tested it. It sets the value of the location but doesn’t paint it on the screen.