Reset Health on timer completion (HELP)

Alright, so thanks to you guys I’ve made it this far, but now I’m having trouble reseting the health of the player using the “drug” heh. Heres my code:



local function DrawBlur()
	DrawMotionBlur( 0.1, 0.79, 0.035);
	DrawSharpen(1.991, 5)
end

local function HealthReset()
	self.Owner:SetHealth(100)
end
	

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


When the timer completes, it doesn’t reset the players health. Any help?

You need to reset health or remove screen effect?

Both, I got the screen effect to go away, now I just need to get the players health to reset.

Try this
[LUA]
timer.Simple( 30, function()
self.Owner:SetHealth(100)
hook.Remove( “RenderScreenspaceEffects”, “MMotionBlur”, HealthReset )
end)
[/LUA]

Nope, didn’t work. (Relevant user name? heh.)

SetHealth is run serverside.
You might also want to record the player’s health before using, since someone could use this at perhaps 1 hp and regain 100 at the end.

You don’t need 3rd argument for hook.Remove.

That’s the point, to reset your health, and give you a 30 buff…

[editline]28th September 2013[/editline]

Alright, but when I call the HealthReset function, within the timer function, it just errors out. I honestly have no clue what I’m doing here :confused:

Maybe this will help you

[LUA]
if SERVER then

end
[/LUA]

[LUA]
if CLIENT then return end
[/LUA]

First of all, if it errors, post the code that errors AND the error itself. And you don’t need to create separate function to just call another function.

This is where I need help with:



local function HealthReset()
	if SERVER then
		ply:SetHealth(100)
	end
end

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


And it doesn’t error out, it just doesn’t set your health back to 100.



timer.Simple( 30, function()	
		hook.Remove( "RenderScreenspaceEffects", "MMotionBlur")
		self.Owner:SetHealth(100);
	end)


Alright, will try that now, I’ll get back to you if it errors and what the error is.

[editline]28th September 2013[/editline]

Alright, that didn’t work.
Console spat this out:

[ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_pcp/shared.lua:66: Trie
d to use a NULL entity!

  1. __index - [C]:-1
  2. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_pcp/shared.lua:
    66

and Like 66 is the self.Owner:SetHealth(100);

Add


if IsValid( self ) then return end

before the set health. And make sure you don’t die and make sure the weapon doesn’t disappear.