• Keeping a player undrawed.
    5 replies, posted
My code, [lua]local function Observe( ply ) if not( ply:IsAdmin() or ply:IsSuperAdmin() ) then return end --No way is a non admin going into observe! if not ply.OldPos then if ply:GetActiveWeapon() and ply:GetActiveWeapon():IsValid() then ply:GetActiveWeapon():SetNoDraw( true ) end ply:SetMoveType( MOVETYPE_NOCLIP ) ply:SetNoDraw(true) ply.OldPos = ply:GetPos() ply:GodEnable() ply:PrintMessage(HUD_PRINTTALK, "Welcome to observe mode. You\'re now invisible and in noclip, just press noclip again to exit." ) else if ply:GetActiveWeapon() and ply:GetActiveWeapon():IsValid() then ply:GetActiveWeapon():SetNoDraw( false ) end timer.Simple(0.01,function() ply:SetPos( ply.OldPos ) ply.OldPos = nil ply:SetVelocity(ply:GetVelocity() * -1) -- This is to players don't keep their noclip speed. end) -- Delaying the SetPos fixes it. ply:SetMoveType( MOVETYPE_WALK ) ply:GodDisable() ply:SetNoDraw(false) ply:PrintMessage(HUD_PRINTTALK, "You\'re no longer in observe mode. You\'ve been returned to your original position." ) -- Escaped single quotes in the string, they were causing errors. end end hook.Add("PlayerNoClip", "ObserveMode", Observe)[/lua] works. However, the player becomes visible whenever they change their weapon, or weapon state.
A player should always be drawn by the engine. Try doing ply:SetColor(0,0,0,0), that should stay constant :smile:
Ahhh... So simple and I never thought of it. Thanks Gbps. [editline]11:38PM[/editline] +1 Tool. [editline]11:51PM[/editline] Ahh shit. It doesn't work. Same issue. [lua]local function Observe( ply ) if not( ply:IsAdmin() or ply:IsSuperAdmin() ) then return end --No way is a non admin going into observe! if not ply.OldPos then if ply:GetActiveWeapon() and ply:GetActiveWeapon():IsValid() then ply:GetActiveWeapon():SetNoDraw( true ) end ply:SetMoveType( MOVETYPE_NOCLIP ) ply:SetColor( 0, 0, 0, 0 ) ply:SetNoDraw(true) ply.OldPos = ply:GetPos() ply:GodEnable() ply:PrintMessage(HUD_PRINTTALK, "Welcome to observe mode. You\'re now invisible and in noclip, just press noclip again to exit." ) else if ply:GetActiveWeapon() and ply:GetActiveWeapon():IsValid() then ply:GetActiveWeapon():SetNoDraw( false ) end timer.Simple(0.01,function() ply:SetPos( ply.OldPos ) ply.OldPos = nil ply:SetVelocity(ply:GetVelocity() * -1) -- This is to players don't keep their noclip speed. end) -- Delaying the SetPos fixes it. ply:SetMoveType( MOVETYPE_WALK ) ply:GodDisable() ply:SetNoDraw(false) ply:SetColor( 255, 255, 255, 255 ) ply:PrintMessage(HUD_PRINTTALK, "You\'re no longer in observe mode. You\'ve been returned to your original position." ) -- Escaped single quotes in the string, they were causing errors. end end[/lua]
Any errors?
Here's how ULX does it : [url]http://ulyssesmod.net/ulib/trunk/lua/ULib/server/player.lua[/url] Scroll down to function ULib.invisible and start reading. :smile:
Thanks Crazy. That worked. Holy crap is that complicated just to make someone god damn invisible.
Sorry, you need to Log In to post a reply to this thread.