How would you check if everyone if dead?

How would you check if everyone is dead in a gamemode?

[lua]local function isEveryoneDead()
for _, pl in ipairs( player.GetAll() ) do
if pl:Alive() then return false end
end
return true
end[/lua]

Returns true if everyone is dead.

I swear that only would end up checking if the first player is alive.

Do a check on all players, if they are alive then add one to a number each time then Check if that number is equal to players on server.

[lua]function EveryoneAlive()
local check = false
for k, v in ipairs( player.GetAll() ) do
if v:Alive() then
check = true;
end
end
return !check;
end[/lua]
Anyone?

Why would you do that when it’s not needed at all?
Read raBBish code again, It goes though every player on the server, if a player is alive then return false; Meaning that every player isn’t dead.
Otherwise; Return true, everyone is dead.

Which is exactly what the OP asked for.

Yea, Re reading it makes sense.

sorry.

Dear god please stop thinking you can out smart people when you have no clue about anything

Ha, you’re the one who should be talking…

Let’s not start again.
The OP’s question is answeared.

Let the thread die.

Could I change that to:
[lua]
function IsEveryoneDead()
for _, pl in ipairs( player.GetAll() ) do
if pl:Alive() == false then RoundEnd()
end
end
[/lua]

[editline]22nd March 2011[/editline]

I thought that that code would run RoundEnd() for every player that was dead. So it is if every player is dead, then run RoundEnd().

[editline]22nd March 2011[/editline]

I was originally going to do RTM’s idea, where I had a variable which was the players that were alive, and compare it to the total amount of players, but this is an easier way.

No, you can’t.

[lua]for _, pl in ipairs( player.GetAll() ) do
if pl:Alive() then return; end
end
RoundEnd()[/lua]

Your code would run even if only the first player was dead.

Final version:
[lua]
function IsEveryoneDead()

for _, pl in ipairs( player.GetAll() ) do
	
	if pl:Alive() then return; end
	
end
	
RoundEnd()

end
[/lua]
If I used the original code could I do
[lua]
if IsEveryoneDead() == true then
[/lua]
Original code:
[lua]
function IsEveryoneDead()

for _, pl in ipairs( player.GetAll() ) do

	if pl:Alive() then return false end

end

return true

end
[/lua]

If I click your name and then click Find all started threads it instantly shows me you are as bad as him

[editline]22nd March 2011[/editline]

You could do that or you could do
[lua]if IsEveryoneDead() then[/lua]
instead

Oh yeah, I forgot about that shortcut…
Thanks to everyone who helped me in this thread!