Player Ring

How would I go about creating a ring at the base of a player the same way fretta does it?

check the player position, then draw it at the vetor 0, 0 ,0 or something maybe?

[lua]
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]
garrysmod/garrysmod/gamemodes/fretta/gamemode/cl_init.lua

hey, that took less then a minute.

Well, I have this code that I found from another posting, but I dont know how actually make the player have the ring. It doesnt output any errors, but I dont see the “DrawPlayerRing” message either. I know that PrePlayerDraw is fired right before the player is drawn, but when exactly is the player drawn?

[lua]
hook.Add( “PrePlayerDraw”, “DrawPlayerRing”, DrawPlayerRing)

local function DrawPlayerRing(ply)
Msg(“DrawPlayerRing”)
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(Material( “SGM/playercircle” ))
render.DrawQuadEasy( tr.HitPos + tr.HitNormal, tr.HitNormal, 32, 32, color )

end
[/lua]

I was going to say “Look it up in Fretta” but… I can’t find the files myself. :S

Alright, I tried what you gave me Zephilinox, and it gave me this message:
[lua\ring.lua:1] attempt to index global ‘GM’ (a nil value)

First day on the forums, and I have to admit, I am amazed at the quick responses.

What I posted would not work, for 3 reasons:

  1. GM: needs to be removed.

  2. its clientside

  3. this line

[lua]if ( !pPlayer:GetNWBool( “DrawRing”, false ) ) then return end[/lua]

is ending the function, because you don’t have the NWBool “DrawRing” set, you could delete the line, but there’s still the other 2 problems, and it’ll likely spew out errors if you removed it.

I can’t help you with this, you’l have to wait for someone who a. can do it and b. has patience.

^ That and CircleMat isnt defined anywhere in that function, so that will error as well.
And all the gamemode player variables need to be substituted out

Thanks for the responses, but I would still like to know at least when PrePlayerDraw is fired and ouput a message at least. I fixed made those few changes and I set a material for render.SetMaterial and added a Msg output above all of the code. I opened it up in gmod and it gives me no errors but still doesnt output my message.

Could someone give me a working example of PrePlayerDraw outputting a single Msg

hook.Add( “PrePlayerDraw”, “DrawPlayerRing”, function( ply ) GAMEMODE:DrawPlayerRing( ply ) end )

get rid of “GAMEMODE:”

Try hooking it with this:
[lua]
hook.Add(“PrePlayerDraw”, “MyHook”, function()
print(“PrePlayerDraw hooked!”)
end)
[/lua]
Then run this on the server in the gamemode’s init or whatever.
However, I don’t know if you can hook every function, or only ones on the Wiki.

If you use that then the Player Ring wouldn’t draw, since the function for it is whats being hooked.

Im sorry, Im really having trouble with this.
I added what you said Lord Ned into garrysmod/garrysmod/gamemodes/mygamemode/gamemode/cl_init.lua
and I added a Msg output after that
[lua]
hook.Add(“PostPlayerDraw”, “MyHook”, function()
Msg(“PrePlayerDraw hooked!”)
print(“PrePlayerDraw hooked!”)
end)

Msg(“After PrePlayerDraw hook”)
[/lua]

It shows the “After PrePlayerDraw hook” message, but I dont see an output from the PrePlayerDraw hook itself.

When is it suppose to be fired?

According to the wiki its fired when the player is drawn, I suppose that means when it connects, or when a player enters your view?

http://img28.imageshack.us/img28/3972/rpevocityv2d0002l.jpg

Something like that?

More glowy and translucent :3

He means like this I think:

Ah fair enough, that is using a texture.

[editline]5th December 2010[/editline]

So you want it like this:

http://img220.imageshack.us/img220/3240/rpevocityv2d0003.jpg

[editline]5th December 2010[/editline]

http://img208.imageshack.us/img208/6281/rpevocityv2d0004.jpg

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

hook.Add( “PrePlayerDraw”, “PlayerRings”, function( ply )

------------------------------------
local colour = Color(255,0,255,75)-- Only change these
local radius = 70                 --
------------------------------------

local trace = {}
trace.start = ply:GetPos() + Vector(0,0,50)
trace.endpos = trace.start + Vector(0,0,-300)
trace.filter = ply
local tr = util.TraceLine( trace )
if !tr.HitWorld then
    tr.HitPos = ply:GetPos()
end
render.SetMaterial( CircleMat )
render.DrawQuadEasy( tr.HitPos + tr.HitNormal, tr.HitNormal, radius, radius, colour )

end )
[/lua]

[lua]

function DrawCircle( ply )
if !ply:Alive() then return end
local offset = Vector( 0, 0, 0 )
local pos = ply:GetPos() + offset
cam.Start3D2D( pos, Angle( 0, 0, 0 ), 0.25 )
draw.RoundedBox( 90, -90,-90, 200, 200, Color( 0, 0, 0, 150 ) )
draw.RoundedBox( 80, -75,-75, 170,170, Color( 255,0,255,75 ) )
cam.End3D2D()
end
hook.Add( “PostPlayerDraw”, “DrawCircle”, DrawCircle )

[/lua]

little less pretty, but not requiring a texture,

basically the code from:

produces this:

http://content.screencast.com/users/antid2/folders/Jing/media/3e5de56c-1a2f-41e1-a239-c3fdb93c5dc3/2010-12-06_0043.png

this makes it stay underneath you, but if you want it to stick to the ground, just copy that guy’s trace code and put it in like this

[lua]
function DrawCircle( ply )
if !ply:Alive() then return end

local trace = {}
trace.start = ply:GetPos() + Vector(0,0,50)
trace.endpos = trace.start + Vector(0,0,-300)
trace.filter = ply
local tr = util.TraceLine( trace )
if !tr.HitWorld then
    tr.HitPos = ply:GetPos()
end
cam.Start3D2D( tr.HitPos + tr.HitNormal, Angle( 0, 0, 0 ), 0.25 )
	draw.RoundedBox( 90, -90,-90, 200, 200, Color( 0, 0, 0, 150 ) )
	draw.RoundedBox( 80, -75,-75, 170,170, Color( 255,0,255,75 ) )
cam.End3D2D()

end
hook.Add( “PostPlayerDraw”, “DrawCircle”, DrawCircle )
[/lua]

The texture is automatically included in gmod, its a base texture you could say.