Curious on how to make two things. A simple timer that shows up in the middle of your screen when dead that states something around the lines of: “You will respawn in (#) seconds”, and also wondering how to make your screen have a certain effect for a certain amount of time when taking any damage.
Use the Wiki
It is your friend!
timer.Create to create the timer.
math.ceil to round your seconds up so that you won’t see “You will respawn in 3.2523463623 seconds”. and you will see “You will respawn in 4 seconds.” (not necessary to round down if you think about how we count down irl with numbers)
GM:PlayerDeathThink to prevent the player from respawning until their timer is up.
As for the second portion of your question. I challenge you to find out how to do it yourself using the wiki (link at top of my post). You can do it!
You can always just use
GM:PlayerDeathThink to track the time since that manages when the player can respawn.
I was thinking in the hudpaint just retrieve the amount of time left on the timer till respawn, but the hook code_gs provided needs to be used to prevent people from respawning.
Thanks, I’ll give it a try right now.
[editline]22nd September 2017[/editline]
Yeah, nevermind. I’m a mess. Came up with this, but it’s most likely completely incorrect.
function GM:PlayerDeath( player ply) if Entity:Health(0) then hook.Add( "HUDPaint", "Respawning in 5 seconds.", function() draw.DrawText( "Respawning in 5 seconds.", "TargetID", ScrW() * 0.5, ScrH() * 0.25, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER ) end )
(1) GM:PlayerDeath(), like all the other spawn and death hooks, is only called serverside. You are trying to add a HUDPaint hook, which is only called clientside. Try sending a net message to the client, with his time of death, and do the math clientside to figure out how long until he respawns.
(2) “player ply”, shown in the function signature at the top of the page on the wiki, is not valid Lua syntax and it is not what you should be copying. Lua does not have type specifiers; you can see that any Lua tutorial, or in any GLua script.
(3) When you see “Entity:Health()” on the wiki or the forums, it means “the entity metafunction called ‘Health’” not “I can literally type ‘Entity:Health()’ in my code”. ‘Entity’ is a function, not an entity (and even if it were, how would Lua know which entity it should be?). You’re given “ply” in the hook arguments, so use it.
(4) Entity:Health() returns the entity’s health (an integer), not “is the entity’s health equal to something” (a boolean). That would be basically useless. Use an actual comparison instead.
I don’t know how new you are to Lua, but it probably wouldn’t hurt to check out the links at the top of the board.
First of all, you should not be over-writing functions in this case. You should be using hooks. Also instead of attempting to checking their health, you should be checking if they are dead by using Player:Alive( ). In addition, as stated in the post above me, there are numerous things wrong with your code. You also need to learn to scope properly and add end statements where needed. You are missing two end statements.
Side note: A player’s health can be negative when they are dead. A good way to test this if you want to is to use the draw or surface library to draw your health on your screen somewhere and get someone to shoot you to death. You will most likely end up with negative health.
STOP TELLING PEOPLE TO NETWORK DEATHS
hook.Add(“entity_killed”, “PlayerDeathClient”, function(dat)
local ent = Entity(dat.entindex_killed)
if (IsValid(ent) and ent:IsPlayer()) then
hook.Run(“PlayerDeathClient”, ent, Entity(dat.entindex_inflictor), Entity(dat.entindex_attacker))
You spelled “Death” in your hook wrong.
Please use the link button on the wiki rather than saying ‘this’ over and over again:
Just because if one day any of those links go down, then at least it’s clear what you’re talking about.
Also, it looks nicer.
Will edit my post
it’s a feature