Make player screen pitch black on function like prop hunt

What would i need to write to make a players screen black when the function is called, like prop hunt?

Paint a big black fucking squre over ther screens:



surface.SetDrawColor( Color( 0,0,0))
draw.NoTexture()
surface.DrawRect( 0,0,ScrW(),ScrH())

Remember to put it into clienside hook HUDPaint.

Hahaha i like how you put it

[editline]11th September 2013[/editline]

And how do i revert back to normal?


hook.Remove( "HUDPaint", "Yourhookname" )

It’s not working, i added the hook,
Look:
[lua]
function BlackScreen()
surface.SetDrawColor( Color( 0,0,0))
draw.NoTexture()
surface.DrawRect( 0,0,ScrW(),ScrH())
end
hook.Add( “HUDPaint”, “BlackScreen”, BlackScreen() )
concommand.Add( “BlackScreen1”, BlackScreen )
[/lua]

[editline]11th September 2013[/editline]

The black screen itself isn’t working

[editline]11th September 2013[/editline]

Nvm it works now

[editline]11th September 2013[/editline]

How do i make the hook add/remove in a function
[lua]
function BlackScreen()
hook.Remove( “HUDPaint”, “PaintOutHud” )
surface.SetDrawColor( Color( 0,0,0))
draw.NoTexture()
surface.DrawRect( 0,0,ScrW(),ScrH())
end
hook.Add( “HUDPaint”, “BlackScreen”, BlackScreen )
concommand.Add( “BlackScreen1”, BlackScreen )

function NormalScreen()
hook.Remove( “HUDPaint”, “BlackScreen” )
hook.Add( “HUDPaint”, “PaintOurHud”, HUDPaint )
end
concommand.Add( “NormalScreen”, NormalScreen )
[/lua]

(Yes i am using the tutorial hud)

[editline]11th September 2013[/editline]

Another thing, When player press pause they can see, so can i make it so i force them to look down then ply:freeze() them?

[lua]local function BlackScreen()
hook.Remove( “HUDPaint”, “PaintOutHud” ) – idk what your using this for
surface.SetDrawColor(Color(0,0,0))
draw.NoTexture()
surface.DrawRect(0,0,ScrW(),ScrH())
LocalPlayer():SetAngles(Angle(-90,0,0)) – I think -90 is down, could be wrong
end

concommand.Add( “BlackScreen1”, function()
hook.Add( “HUDPaint”, “BlackScreen”, BlackScreen )
end)

local function NormalScreen()
hook.Remove( “HUDPaint”, “BlackScreen” )
hook.Add( “HUDPaint”, “PaintOurHud”, HUDPaint ) – idk what your using this for
end
concommand.Add( “NormalScreen”, NormalScreen )[/lua]

In my Init.lua i have
[lua]
AddCSLuaFile( “cl_init.lua” )
include( ‘cl_init.lua’ )
function NightTime( ply )
BlackScreen()
ply:SetAngles(Angle(90,0,0))
ply:Freeze()
end
concommand.Add( “NightTime”, NightTime )
[/lua]
and cl_init.lua
[lua]
local function BlackScreen()
surface.SetDrawColor(Color(0,0,0))
draw.NoTexture()
surface.DrawRect(0,0,ScrW(),ScrH())
LocalPlayer():SetAngles(Angle(-90,0,0)) – I think -90 is down, could be wrong
hook.Add( “HUDPaint”, “BlackScreen”, BlackScreen )
end
concommand.Add( “BlackScreen1”, BlackScreen )
[/lua]

Why won’t it work, I type BlackScreen1 in console, works fine (besides looking down)
I try NightTime, Nothing happens

ERROR:
[lua]

[ERROR] gamemodes/mvst/gamemode/cl_init.lua:4: attempt to index global ‘surface’ (a nil value)

  1. BlackScreen - gamemodes/mvst/gamemode/cl_init.lua:4
  2. unknown - gamemodes/mvst/gamemode/init.lua:35
    3. unknown - lua/includes/modules/concommand.lua:69

[/lua]

You can only draw the box on client ( cl_init.lua ), you can’t do it from server ( init.lua )

Yes, i have it on cl_init.lua, but i want to run the function that makes the screen black from the init.lua

look into the net library

http://wiki.garrysmod.com/page/Using_the_net_library

http://wiki.garrysmod.com/page/Category:net

Umm i don’t understand it very well, but i’ll look through it