Garry's Mod Wiki

Revision Difference

GM:PostPlayerDraw#549676

<function name="PostPlayerDraw" parent="GM" type="hook"> <ishook>yes</ishook> <description> Called after the player was drawn. ⤶ <rendercontext hook="true" type="3D"></rendercontext> Called after a player in your [PVS (Potential Visibility Set)](https://developer.valvesoftware.com/wiki/PVS "PVS - Valve Developer Community") was drawn. <rendercontext hook="true" type="3D"></rendercontext> </description> <realm>Client</realm> <predicted>No</predicted> <args> <arg name="ply" type="Player">The player that was drawn.</arg> <arg name="flags" type="number">The <page text="STUDIO_">Enums/STUDIO</page> flags for this render operation.</arg> </args> </function> <example> <description>Show each player's name above their model.</description> <code> local function DrawName( ply ) if ( !IsValid( ply ) ) then return end if ( ply == LocalPlayer() ) then return end -- Don't draw a name when the player is you if ( !ply:Alive() ) then return end -- Check if the player is alive local Distance = LocalPlayer():GetPos():Distance( ply:GetPos() ) --Get the distance between you and the player if ( Distance < 1000 ) then --If the distance is less than 1000 units, it will draw the name local offset = Vector( 0, 0, 85 ) local ang = LocalPlayer():EyeAngles() local pos = ply:GetPos() + offset + ang:Up() ang:RotateAroundAxis( ang:Forward(), 90 ) ang:RotateAroundAxis( ang:Right(), 90 ) cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.25 ) draw.DrawText( ply:GetName(), "HudSelectionText", 2, 2, team.GetColor(ply:Team()), TEXT_ALIGN_CENTER ) cam.End3D2D() end end hook.Add( "PostPlayerDraw", "DrawName", DrawName ) </code> </example> <example> <description>Draw a headcrab hat on all players. </description> <code> local model = ClientsideModel( "models/headcrabclassic.mdl" ) model:SetNoDraw( true ) hook.Add( "PostPlayerDraw" , "manual_model_draw_example" , function( ply ) if not IsValid(ply) or not ply:Alive() then return end local attach_id = ply:LookupAttachment('eyes') if not attach_id then return end local attach = ply:GetAttachment(attach_id) if not attach then return end local pos = attach.Pos local ang = attach.Ang model:SetModelScale(1.1, 0) pos = pos + (ang:Forward() * 2.5) ang:RotateAroundAxis(ang:Right(), 20) model:SetPos(pos) model:SetAngles(ang) model:SetRenderOrigin(pos) model:SetRenderAngles(ang) model:SetupBones() model:DrawModel() model:SetRenderOrigin() model:SetRenderAngles() end ) </code> </example> <note> Result: <upload src="4996d/8d7f44659e598a9.jpg" size="126942" name="4000_screenshots_20200509142006_1.jpg" /> </note>