How do I say this in lua?

“if the player dies, remove all HUD paint”

How would I put this in lua?

You need to hook it to player death. HudPaint.Remove ? Not exactly sure…

Hahahahahahaha. No.

[lua]
function GM:HUDPaint()
if(!LocalPlayer():Alive()) then return end

*Rest of your code here*

end[/lua]

Then why are you posting?

Why are you posting?

[editline]03:00PM[/editline]

atleast his was a little helpful.

Server
[lua]
hook.Add(“PlayerDeath”, “RemoveHUD”, function(vicitm, inflictor, killer)
SendUserMessage(“RemoveHUD”, victim)
end)

hook.Add(“PlayerSpawn”, “EnableHUD”, function(ply)
SendUserMessage(“EnableHUD”, ply)
end)
[/lua]

Client

[lua]
usermessage.Hook(“RemoveHUD”, function()
hook.Add(“HUDShouldDraw”, “RemoveHUD”, function()
return false
end)
end)

usermessage.Hook(“EnableHUD”, function()
hook.Remove(“HUDShouldDraw”, “RemoveHUD”)
end)
[/lua]

Or if you are making your own HUD, do as Dave Parker said.

Your hook names have irregular capitalisation there. Otherwise that would probably work, but wouldn’t it be easier to slap this in some clientside file:

[lua]
hook.Add(“HUDShouldDraw”, “NoHUDDeath”, function ()
return LocalPlayer():Alive()
end)
[/lua]

As for HUD stuff drawn in Lua, I can’t think of a way to make them disappear without editing its code directly.

[lua]local removedhooks = {}
hook.Add(“Think”, “NoHUDDeath”, function()
if LocalPlayer():Alive() then
for n, h in pairs(removedhooks) do
hook.Add(“HUDPaint”, n, h);
end
else
local ht = hook.GetTable();
local hudtable = ht.HUDPaint;
for n, h in pairs(hudtable) do
removedhooks[n] = h;
hook.Remove(“HUDPaint”, h);
end
end
end)[/lua]

Or

[lua]local oldHookCall = hook.Call;
function hook.Call(n, …)
if n == “HUDPaint” and not LocalPlayer():Alive() then
return;
end
oldHookCall(n, …)
end[/lua]

That would be a lot easier :smiley:

:eng101:
[LUA]local client = LocalPlayer()
if !client:Alive() then return end
if(client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == “Camera”) then return end[/LUA]

Already been answered, did you read the thread?

Just an easier way, and a reference.

The exact same thing was posted.

Okay then, just a reference added.

Ideally you should not return anything if you don’t change anything. This would block all other hooks to that event even when the player is alive.

Oh yeah. Didn’t think about that.

Sweet, I didn’t expect this many people to respond.

But now I have another question. How would I make it so that when a hook is called, it emits a sound?

Clientsided?

[lua]hook.Add(YOUR_HOOK_NAME, “RandomSoundHook”, function()
surface.PlaySound(YOUR_SOUND_FILE_PATH_HERE)
end)[/lua]

I think it’s better to set an Entity, and use Ent.EmitSound.

Probbably not, that would mean you have to create a entity then remove it when the sound is completed(i think)

if you wanna do this serverside you can use <player here>:EmitSound(<soundpath>)

if clientside use what Dave said