I figured that I cant draw it withing the swep.lua but how would I proceed on drawing vgui on lets say PrimaryAttack() ?
I don’t think vgui is what you’re after because it doesn’t get removed after the next frame, it stays on screen forever, meaning whenever you shoot, a new panel will appear and never disappear until you remove it.
I think what you’re after is
Not quite, I am making a swep to turn the player invisible and visible with primary fire,
but I want the player to have some sort of effects overlaying the screen whenever he is invisible
the only thing I could think of is using a derma panel that covers the screen with a material over it
It’d be much easier to just use SWEP:DrawHUD. Using a panel for this is just stupid.
Pretty sure that can be achieved using stencils. There’s a couple of tutorials here on Facepunch if you aren’t familiar with it.
[editline]30th August 2017[/editline]
But why cant I DrawMaterialOverlay on the SWEP:DrawHUD function?
Can anyone explain?
I think it may be because it has to be ran on the hook
GM:RenderScreenspaceEffects or because you’re not putting a valid material/refract amount on the code.
Can we see the code? Because, you know, saying “It doesn’t work” or “why cant i use it” doesn’t help much you know.
If you really want to use derma then only create your panel once and set it to be painted manually. Then SWEP:DrawHud tell the panel to paint.
The problem with using SWEP:DrawHud is that it only runs when the weapon Active. By what you’ve described, you’re more interested in just using the weapon to toggle a player’s “invisible” state.
To that end, whenever you set the player to invisible, you can create a hook on their client, and remove the hook whent hey go back to being visible.
I would use
Rough untested example:
function SWEP:PrimaryAttack() self.Owner.Invisible = not self.Owner.Invisible -- Just make sure to network the Player's invisible state because Primary Attack only runs clientside on the owner. if CLIENT then if not self.Owner.Invisible then hook.Add("HUDPaintBackground", "InvisibleEffect", function() -- add the hook, you might want to put some checks in here for it to remove itself if the player is dead or no longer ivnisible or whatever. DrawMaterialOverlay("material", refraction) end) else hook.Remove("HUDPaintBackground", "InvisibleEffect") -- remove the hook end end end
Since When? I’ve been able to use DrawMaterialOverlay perfectly fine in SWEP:DrawHUD().
Oh, he wanted it to run when others we’re looking at him. Okay, i missunderstood the question.
And well, just because that’s the hook in which that function is usually ran on. I know both are 2D rendering hooks, and that HUDPaint runs after RenderScreenspaceEffects
function SWEP:PrimaryAttack() if ( !self.phase ) then self.Owner:SetNoDraw(true) self.Owner:PrintMessage( HUD_PRINTCENTER, "PRESS PRIMARY-ATTACK TO DEACTIVATE" ) self.Owner:SetNoTarget(true) self.Owner:SetCollisionGroup(COLLISION_GROUP_WORLD) self.Owner:SetRunSpeed(self.Owner:GetRunSpeed() + 200) self.Owner:SetFOV(self.Owner:GetFOV() + 40 , 3 ) self.phase = true self:SetNextPrimaryFire(CurTime() + 4) else self.Owner:SetNoDraw(false) self.Owner:PrintMessage( HUD_PRINTCENTER, "PRESS PRIMARY-ATTACK TO ACTIVATE" ) self.Owner:SetNoTarget(false) self.Owner:SetCollisionGroup(COLLISION_GROUP_NONE) self.Owner:SetRunSpeed(400) self.Owner:SetFOV(self.Owner:GetFOV() - 40 , 3 ) self.phase = false self:SetNextPrimaryFire(CurTime() + 25) end end
this is my primary attack function,
are you saying that I should put the hook in the first IF statement?
Do not use SetRunSpeed in a weapon: modify the speed in a Move hook
What is wrong with doing it in the weapon may I ask ?
function SWEP:DrawHUD() if self.Owner:IsInvisible() then -- change this to whatever you use to check if they're invisible DrawMaterialOverlay( "models/props_c17/fisheyelens", -0.06 ) -- change this to whatever effect end end
[editline]31st August 2017[/editline]
I do not recommend this. If you must use a hook, then don’t create and remove it every single time, just do this kind of thing:
-- CLIENTSIDE hook.Add( "HUDPaint", "InvisibleEffect", function() if self.Owner:IsInvisible() then -- change this to whatever you use to check if they're invisible DrawMaterialOverlay( "models/props_c17/fisheyelens", -0.06 ) -- change this to whatever effect end end ) -- SERVERSIDE function SWEP:PrimaryAttack() self.Owner:SetInvisible( true ) -- change this to whatever you do to set if they're invisible end
Of course, it depends what method you’re using to set whether or not the player is invisible.
It overrides the gamemode calls to it, and does not scale with custom speeds.
I have a single shared.lua file for my swep, how do I differentiate between server and client?
By using the CLIENT and SERVER globals.