Screen Effects within a function

So for my server, I have a thing where you take drugs, doubles your Hp, and plays some music, but I also want the motion blur effect, and the blur effect to happen, right now, this is what I have, and it doesn’t work. Am I missing something? When I try the bloom and blur in a separate function, it happens globally. Any help?
[lua]
function SWEP:PrimaryAttack()
self.Owner:SetHealth(200);
self:EmitSound (ShootSound);
self:TakePrimaryAmmo(1);
DrawBloom( 0, 0.75, 3, 3, 2, 3, 255, 255, 255 );
DrawMotionBlur( 0.1, 0.79, 0.05 );
end
[/lua]



local function DrawBlur()
	DrawBloom( 0, 0.75, 3, 3, 2, 3, 255, 255, 255 );
	DrawMotionBlur( 0.1, 0.79, 0.05 );
end

function SWEP:PrimaryAttack()
	self.Owner:SetHealth(200);
	self:EmitSound (ShootSound);
	self:TakePrimaryAmmo(1);
	hook.Add( "RenderScreenspaceEffects", "MMotionBlur", DrawBlur )
end


Wrote it in chat here, let me know if calling that hook in the PrimaryAttack doesn’t work.

Also thank you, you just answered my question :slight_smile:

Hey thanks! Also, would you know how to disable the blur and stuff after 30 seconds? And what question did I answer? :dance:

Make a timer in PrimaryAttack that removes the hook after 30 seconds?

hook.Remove( “RenderScreenspaceEffects”, “MMotionBlur” ) to remove the hook.

Did I do something wrong here? This errors out when I run it.
[lua]
local function DrawBlur()
DrawMotionBlur( 0.1, 0.79, 0.05);
end

local function EndBlur()
hook.Remove( “RenderScreenspaceEffects”, “MMotionBlur” )
end

function SWEP:PrimaryAttack()
self.Owner:SetHealth(200);
self:EmitSound (ShootSound);
self:TakePrimaryAmmo(1);
hook.Add( “RenderScreenspaceEffects”, “MMotionBlur”, DrawBlur )
timer.Simple( 30, Endblur )
end
[/lua]

I was just about to make a thread asking how to do screen effects because I had never done anything with them. And you answered my second question how to remove them!

Thanks bud :stuck_out_tongue:

You wouldn’t happen to know about timers would you? :tinfoil:

not tested done in browser:



local function DrawBlur()
	DrawBloom( 0, 0.75, 3, 3, 2, 3, 255, 255, 255 );
	DrawMotionBlur( 0.1, 0.79, 0.05 );
end

function SWEP:PrimaryAttack()
	self.Owner:SetHealth(200);
	self:EmitSound (ShootSound);
	self:TakePrimaryAmmo(1);
	hook.Add( "RenderScreenspaceEffects", "MMotionBlur", DrawBlur )
	
	timer.Simple( 20, function()
		hook.Remove( "RenderScreenspaceEffects", "MMotionBlur" )
	end)
	
end


Thanks man, worked perfect.