function GetConnectedPlayerCount() -- return the number of all players connected playercount = 0 for _, player in pairs(ents.GetAllPlayers()) do if player:IsRealPlayer() and player:GetPlayerName() ~= "Demo-Bot" then playercount = playercount + 1 end end return playercount end function GetAlivePlayerCount() -- return the number of all players alive aliveplayercount = 0 for _, player in pairs(ents.GetAllPlayers()) do if player:IsRealPlayer() and player:GetPlayerName() ~= "Demo-Bot" and player:IsAlive() then aliveplayercount = aliveplayercount + 1 end end return aliveplayercount end function GetElevatorPlayerCount() -- return the number of players in the elevator (players with cond 12 are counted as "in the elevator") elevatorplayercount = 0 for _, player in pairs(ents.GetAllPlayers()) do if player:IsRealPlayer() and player:GetPlayerName() ~= "Demo-Bot" and player:InCond(12) then elevatorplayercount = elevatorplayercount + 1 end end return elevatorplayercount end ------------------------------------------------------------------------------------------------------------------------------------- function debugplayers() -- do this in console to check if nothing desyncs: sm_ent_fire popscript $debugplayers for _, player in pairs(ents.GetAllPlayers()) do player:DisplayTextChat("{blue}-------------------") end util.PrintToChatAll("connected: " .. GetConnectedPlayerCount()) util.PrintToChatAll("alive: " .. GetAlivePlayerCount()) end function CheckPlayersInElevator() --fire a $CheckPlayersInElevator to popscript, if everyone is in, triggers this_relay and triggers that_relay otherwise if GetElevatorPlayerCount() == GetAlivePlayerCount() then ents.FindByName("elevator_tranisition"):Trigger() else ents.FindByName("that_relay"):Trigger() end end