Post Processing problems

OK, so in short, I’m trying to make it so that when I press a specific key, it toggles between a certain postprocessing set of values.

This is code outside of a gamemode.

Here it is:



local vats = true --for toggle bind?

local function effectss()
	
	DrawMotionBlur( 0.2, 0.99, 0.01 )
	local tab = {}
	tab[ "$pp_colour_addr" ] = 0
	tab[ "$pp_colour_addg" ] = 0
	tab[ "$pp_colour_addb" ] = 0
	tab[ "$pp_colour_brightness" ] = 0
	tab[ "$pp_colour_contrast" ] = 1
	tab[ "$pp_colour_colour" ] = 1
	tab[ "$pp_colour_mulr" ] = 0
	tab[ "$pp_colour_mulg" ] = 1
	tab[ "$pp_colour_mulb" ] = 1 
	DrawColorModify( tab )
	DrawToyTown( 3, 0.4 )

end
hook.Add("RenderScreenspaceEffects", "vatshook", effectss)

local function govats( ply )

	if vats then
		ply:ConCommand("host_timescale 0.1")
		
		effectss()
		
		vats = false
	else
--		ply:ChatPrint(HUD_PRINTTALK, "Nope.")
		vats = true
	end
	
end
concommand.Add("vats", govats)


(I called it VATS for the lulz).

Can anyone tell me what’s wrong? I’m getting this error:


[lua\autorun\vats.lua:5] attempt to call global 'DrawMotionBlur' (a nil value)

But I swear I’ve followed everything said on the wiki page

Any help is much appreciated.

DrawMotionBlur is clientside.

And how do I get it to be clientside? I tried wrapping a “if (CLIENT) then” tag around it…

This is my new code:



if (SERVER) then
	print("Y U PUT ON SERVERSIDE???")
end

local vats = true --for toggle bind?

local function govats( ply )

	if vats then
		ply:ConCommand("host_timescale 0.1")
	if (CLIENT) then
		DrawMotionBlur( 0.2, 0.99, 0.01 )
		local tab = {}
		tab[ "$pp_colour_addr" ] = 0
		tab[ "$pp_colour_addg" ] = 0
		tab[ "$pp_colour_addb" ] = 0
		tab[ "$pp_colour_brightness" ] = 0
		tab[ "$pp_colour_contrast" ] = 1
		tab[ "$pp_colour_colour" ] = 1
		tab[ "$pp_colour_mulr" ] = 0
		tab[ "$pp_colour_mulg" ] = 1
		tab[ "$pp_colour_mulb" ] = 1 
		DrawColorModify( tab )
		DrawToyTown( 3, 0.4 )
	end
		vats = false
	else
		ply:ConCommand("host_timescale 1")
		vats = true
	end
	
end
concommand.Add("vats", govats)
hook.Add("RenderScreenspaceEffects", "vatshook", govats)


I’ve even put it all in the autorun/client folder. No joy.

But the “host_timescale” toggle part works fine. I know that’s serverside.

No errors either, apart from the one I made at the top.

Firstly, I think you have the casing wrong for the hook (I have absolutely no idea if it matters, but it very well might). Secondly, that hook is only client side. So you need to also wrap it around an if ( CLIENT ) then statement.

[lua]
// This needs to be changed
hook.Add(“RenderScreenspaceEffects”, “vatshook”, govats)
// To this
if ( CLIENT ) then
hook.Add(“RenderScreenSpaceEffects”, “vatshook”, govats)
end
[/lua]

[lua]
if (SERVER) then
print(“Y U PUT ON SERVERSIDE???”)
end

local vats = true

/*local function vatsvision()

if (CLIENT) then
	DrawMotionBlur( 0.2, 0.99, 0.01 )
	local tab = {}
	tab[ "$pp_colour_addr" ] = 0
	tab[ "$pp_colour_addg" ] = 0
	tab[ "$pp_colour_addb" ] = 0
	tab[ "$pp_colour_brightness" ] = 0
	tab[ "$pp_colour_contrast" ] = 1
	tab[ "$pp_colour_colour" ] = 1
	tab[ "$pp_colour_mulr" ] = 0
	tab[ "$pp_colour_mulg" ] = 0
	tab[ "$pp_colour_mulb" ] = 0
	DrawColorModify( tab )
	DrawToyTown( 3, 0.4 )
end

end*/
–hook.Add(“RenderScreenspaceEffects”, “vatshook”, vatsvision)

local function govats()

if vats then
	LocalPlayer():ConCommand("host_timescale 0.1")
	DrawMotionBlur( 0.2, 0.99, 0.01 )
	local tab = {}
	tab[ "$pp_colour_addr" ] = 0
	tab[ "$pp_colour_addg" ] = 0
	tab[ "$pp_colour_addb" ] = 0
	tab[ "$pp_colour_brightness" ] = 0
	tab[ "$pp_colour_contrast" ] = 1
	tab[ "$pp_colour_colour" ] = 1
	tab[ "$pp_colour_mulr" ] = 0
	tab[ "$pp_colour_mulg" ] = 0
	tab[ "$pp_colour_mulb" ] = 0
	DrawColorModify( tab )
	DrawToyTown( 3, 0.4 )

– vatsvision()
vats = false
else
LocalPlayer():ConCommand(“host_timescale 1”)
vats = true
end

end
concommand.Add(“vats”, govats)
if (CLIENT) then
hook.Add(“RenderScreenspaceEffects”, “vatshook”, govats)
end
[/lua]

So far, no luck. :<

My screen really spazzes out too.

Ahhh wait, your screen spazzes out? That could mean it’s apply the effect. Do you get any code errors still?

Also, since I am sure there are a few code changes you’ve made, what file is this located in and which folder did you put it in?

Just fixed it all. Decided to rewrite the code and here’s what I got:

[lua]
if (SERVER) then
print(“Y U PUT ON SERVERSIDE???”)
end

local eff = false

local function effect()

if eff then
	DrawMotionBlur( 0.2, 0.99, 0.01 )
	local tab = {}
	tab[ "$pp_colour_addr" ] = 0
	tab[ "$pp_colour_addg" ] = 0
	tab[ "$pp_colour_addb" ] = 0
	tab[ "$pp_colour_brightness" ] = 0
	tab[ "$pp_colour_contrast" ] = 1
	tab[ "$pp_colour_colour" ] = 1
	tab[ "$pp_colour_mulr" ] = 0
	tab[ "$pp_colour_mulg" ] = 0
	tab[ "$pp_colour_mulb" ] = 0
	DrawColorModify( tab )
	DrawToyTown( 3, 0.4 )
end

end
hook.Add(“RenderScreenspaceEffects”, “vatshook”, effect)

local vats = true

local function togglevats( ply )

if vats then
	ply:PrintMessage(HUD_PRINTTALK, "VATS ON!")
	ply:ConCommand("host_timescale 0.1")
	vats = false
	eff = true
else
	ply:PrintMessage(HUD_PRINTTALK, "VATS OFF!")
	ply:ConCommand("host_timescale 1")
	vats = true
	eff = false
end

end
concommand.Add(“vatstog”, togglevats)
[/lua]

It all works. :smiley:

It’s times like these where you feel like you’re the best at Lua… But you’re not really. Well, for the moment you are. :wink:

Thanks for the help guys. I’ll probably fuck it up fairly soon though. :stuck_out_tongue:

Bump (apologies).

Yeah. Not quite relating to the topic but it’s the same script. I tried adding a timer to it so that when you turn it on, 5 seconds later it would automatically turn off. It turns on perfectly fine, but doesn’t turn off.

[lua]
local vats = true

local function vatsoff( ply )

if vats then
	ply:PrintMessage(HUD_PRINTTALK, "VATS OFF!")
	ply:ConCommand("host_timescale 1")
	vats = true
	eff = false
end

end

local function vatson( ply )

if vats then
	ply:PrintMessage(HUD_PRINTTALK, "VATS ON!")
	ply:ConCommand("host_timescale 0.1")
	vats = false
	eff = true
end
timer.Simple(5, vatsoff, ply)

end
concommand.Add(“vats”, vatson)
[/lua]

The wiki page is unclear (to me, anywho) about it. Can anyone help me here? :frowning:

I think its because you’re looping it to turn true over, and over again.