Near Death Effect

Ok basically im trying to make this “near death” effect and im not sure if this would work

[lua]
if(CLIENT)then

// Get Players Health
local PlyHealth = ply:Health()

// Test Players Health
function Test()
if PlyHealth <= 15 then DeathEffect(ply)
end

// Draw Effects
function DeathEffect(ply)
pl:ConCommand(“pp_motionblur 1”)
pl:ConCommand(“pp_motionblur_addalpha 0.05”)
pl:ConCommand(“pp_motionblur_delay 0.035”)
pl:ConCommand(“pp_motionblur_drawalpha 1.00”)
pl:ConCommand(“pp_dof 1”)
pl:ConCommand(“pp_dof_initlength 9”)
pl:ConCommand(“pp_dof_spacing 8”)
pl:ConCommand(“pp_dof_spacing 8”)
pl:ConCommand(“pp_color_saturation 1”)
end
end
[/lua]

The idea is it checks to see if the players health is less than 15 then is should run the con commands that turns on the post processing effects to make its blurry and black and white.

I put this in lua/autorun and tried to get it to work with no luck im not sure if this is the correct way to get a players health so thats why this might not work :S

You are missing an end and never call the function Test. Try this instead, it is untested and therefore not garunteed to work. You would still need to set the pp effects back to default when the player dies.

[lua]hook.Add(“EntityTakeDamage”, “NearDeath”, function(ent)
if ent:IsPlayer() then
ent:ConCommand(“pp_motionblur 1”)
ent:ConCommand(“pp_motionblur_addalpha 0.05”)
ent:ConCommand(“pp_motionblur_delay 0.035”)
ent:ConCommand(“pp_motionblur_drawalpha 1.00”)
ent:ConCommand(“pp_dof 1”)
ent:ConCommand(“pp_dof_initlength 9”)
ent:ConCommand(“pp_dof_spacing 8”)
ent:ConCommand(“pp_dof_spacing 8”)
ent:ConCommand(“pp_color_saturation 1”)
end
end)[/lua]

Ok i will try it for changing it back should i just do the same but when the players health is equal to 0?

what?

Do it in a PlayerDeath hook.

will be better if you will use something like
[lua]
function RenderEffects( )

DrawMotionBlur( addalpha, drawalpha, framedelay );

end
hook.Add( “RenderScreenspaceEffects”, “RenderMahScreenspaceEffects”, RenderEffects )
[/lua]

Ok i dont quite understand how the hooks work im guessing it goes like this

hook.Add( “HookName”, “Description?”, Function )

But say how does the hook know the players health becuse at the moment i have this

[lua]
if(CLIENT)then

// Get Players Health
local PlyHealth = ply:Health()

// Test Players Health
function Test()
if PlyHealth <= 15 then DeathEffect(ply)
end

// Draw Effects
if(CLIENT)then

// Get Players Health
local PlyHealth = ply:Health()

// Test Players Health
function Health()
if PlyHealth <= 15 then RenderEffects()
end

function RenderEffects()
if ent:IsPlayer() then
ent:ConCommand(“pp_motionblur 1”)
ent:ConCommand(“pp_motionblur_addalpha 0.2”)
ent:ConCommand(“pp_motionblur_delay 0.0”)
ent:ConCommand(“pp_motionblur_drawalpha 0.99”)
ent:ConCommand(“pp_dof 1”)
ent:ConCommand(“pp_dof_initlength 512”)
ent:ConCommand(“pp_dof_spacing 38”)
ent:ConCommand(“pp_colormod 1”)
ent:ConCommand(“pp_colormod_contrast 1.5”)
ent:ConCommand(“pp_colormod_brightness 0”)
end
end
hook.Add( “RenderScreenspaceEffects”, “NearDeath”, RenderEffects )

function RemoveEffect()
if ent:IsPlayer() then
ent:ConCommand(“pp_motionblur 0”)
ent:ConCommand(“pp_dof 0”)
ent:ConCommand(“pp_colormod 0”)
end
end
hook.Add( “PlayerDeath”, “playerDeathTest”, RemoveEffects )
end
[/lua]

EDIT:- Still not working im pretty sure its something to do with how i am trying to get the effects to actually enable is there another way of doing it? i will try “DrawMotionBlur” but is that the same for the DOF and ColorMod?

eg would i do
DrawDOF( 512, 38 );

Ok i tried this and it dosent work i am still lost as to how to do this

[lua]
if(CLIENT)then

// Get Players Health
local PlyHealth = ply:Health()

// Test Players Health
function Test()
if PlyHealth <= 15 then DeathEffect(ply)
end

// Draw Effects
if(CLIENT)then

// Get Players Health
local PlyHealth = ply:Health()

// Test Players Health
function Health()
if PlyHealth <= 15 then RenderEffects()
end

function RenderEffects()
DrawMotionBlur( 0.2, 0.99, 0.0 );
DrawDOF( 38, 150 );
DrawColorMod( 0, 1.5, 0 )
end
hook.Add( “RenderScreenspaceEffects”, “NearDeath”, RenderEffects )

function RemoveEffect()
if ent:IsPlayer() then
ent:ConCommand(“pp_motionblur 0”)
ent:ConCommand(“pp_dof 0”)
ent:ConCommand(“pp_colormod 0”)
end
end
hook.Add( “PlayerDeath”, “playerDeathTest”, RemoveEffects )
end
[/lua]

To simplify you could just do…
[lua]function DrawNearDeath( pl )
if pl:IsAlive() and pl:Health() <= 15 then
–Draw Stuff
end
end[/lua]
Don’t think you need a Removing effect as it should not draw them when the health is above and not equal to, never used PP though.

Also see: http://wiki.garrysmod.com/?title=Gamemode.RenderScreenspaceEffects
Mind the lack of examples, is it required to draw Post Processing effects?

Hmm i tried this

[lua]
if(CLIENT)then
function DrawNearDeath( pl )
if pl:IsAlive() and pl:Health() <= 15 then
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.5
tab[ “$pp_colour_colour” ] = 0
tab[ “$pp_colour_mulr” ] = 0
tab[ “$pp_colour_mulg” ] = 1
tab[ “$pp_colour_mulb” ] = 1
DrawColorModify( tab )
end
DrawMotionBlur( 0.1, 0.79, 0.05)
DrawDOF( 38, 512 )

			hook.Add( "RenderScreenspaceEffects", "RenderBLUR", DrawNearDeath )
	else
	end  
end  

end
[/lua]

basically ins a copy and paste from the wiki but it still dosent work :S