Make someone stay dead on death

I’ve tried to make it when a player dies they stay dead. Using DoPlayerDeath, it’s got ply:Spectate and I’ve tried things from PlayerDeathThink making a respawn counter and returning false from the wiki. Can’t get players to stay dead.

What’s the easiest method to use to keep a player as a spectator?


function GM:PlayerSpawn( ply )
         
        GAMEMODE:PlayerSpawnAsSpectator( ply )
 end


Maybe this im not sure?

I got it to work with some crazy code workaround, not bothered really no ones gonna be looking at the code of my server. But now how do you respawn alive characters back to the spawn point? So I can put everyone back on round start.

Also try this? Its neater


function GM:PlayerDeath( victim, inflictor, attacker )
 GAMEMODE:PlayerSpawnAsSpectator( ply )
end


Im not really good with lua but I guess you should be able to figure out what to do from that.

Also Explain better? So you want players to re-spawn from spectators? Or players that are alive to respawn?

[editline]30th June 2014[/editline]

Not to sure about re-spawning from spectator. Im not that useful when it comes to lua but thats all i could think of XD im an idiot :suicide:

I know Skate has posted the answer, but if you figure out another way to do it (or his way doesn’t work), it’s helpful to put the code here to help other people who search and find this thread.

Well it’s by no means helpful as it only works to my gamemode. I make it so under PlayerDeathThink it sets their team to Dead and does KillSilent this keeps them dead. If I do that under PlayerDeath they don’t stay dead they come straight back. But for my gamemode I need PlayerDeathThink for my end of round stuff.

I might try that though since I’d rather use spectator than a team.

Idiot code. 2 Stupid :v:
Removed.

Why on earth are you doing it like that Skate? You’re overthinking it.

[lua]function GM:PlayerDeathThink(ply)
return false
end[/lua]

What I have a feeling you’re doing Fylly is you’re spawning them before they should be, and that is causing them to essentially “continue to respawn”

forgot to add the return false part, why I didnt think of that way I dont know… But he now wants the player to be able to respawn once the round finishes?

Also he wants them to be on the team “Spectators”

If he wants them to respawn once the round finishes then he just needs to call

[lua]ply:Spawn();[/lua]

For example I have a spectator file and in that I have this function

[lua]function GM:SetSpectator(ply)
ply:SetTeam(TEAM_SPECTATOR)
ply:KillSilent()
ply:Spectate( OBS_MODE_ROAMING )
end[/lua]

I set their team, kill them, and then let them spectate.

Then when you want to spawn them at the end, just manually spawn them (after setting their team to the alive one and unspectate()

EDIT:

Also note, it should be a plyMeta, not a gamemode for SetSpectator, but this was awhile back and I probably did it with little sleep.

Yeah my codes a big mess, I’m super new to Lua (With my only languages I know being HTML5, PHP, CSS3 and BASIC) but I know that it’s spawning them too soon but the thing is in my code I can’t find where.

This is the code that runs when the round begins (this is only called when there are 0 left alive in one of the team.)


function round.Begin()
	for _, v in pairs(player.GetAll()) do
		if not v:Alive() then
			v:Spawn()
		end
	end
	
	-- Your code
	-- (Anything that may need to happen when the round begins)
	round.Going = true
	round.Broadcast("Round starting!")
end

And this is my code for when a player dies. Since I’m new I’m doing things very basic and messy but it’s getting the job somewhat done for now.


function GM:PlayerDeath( ply )
	ply:SetTeam( 3 )
	if team.NumPlayers( 1 ) == 0 then
		round.End()
	elseif team.NumPlayers( 2 ) == 0 then
		round.End()
	else return end
end

function GM:PlayerDeathThink( ply )
	ply:KillSilent()
end

The thing that I can’t do is I tried using ply:Spawn() to respawn but it didn’t work and just gave an error as if it couldn’t call the function. Since I’m not using ply:Spectate (it refused to work, all players who died and all I had under my PlayerDeath was ply:Spectate() and ply:KillSilent() they still respawned instantly. I have a round.Begin section which is called when one team wins (ie one team is all dead.) is there anything other than ply:Spawn() I can run to spawn all players?

I’m looking at your PlayerDeathThink, why are you killing them every time? Just return false…

Look at CanRespawn: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/spectating_players_system.lua.html

Basic concept of a round-system: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/round_system/basic_concept_of_round_systems.lua.html

Hope these help.

Or download Defibrillator addon and set the respawn timer to 999999999999999999999999999 or something? Not sure but it can be easy configged and its cheap Check it out on coderhire its made by KUNIT I believe