public void onUpdate() { if (DateTime.Now.Subtract(LastSecond).TotalMilliseconds > 1000) { LastSecond = DateTime.Now; if (TimeLeft > 0) { TimeLeft--; if (TimeLeft == 0) { if (!IsVoteActive()) { StartVote(); } } else if (TimeLeft == 30) { API.sendChatMessageToAll("Vote for next map will start in 30 seconds!"); } else if (TimeLeft == 59) { API.sendChatMessageToAll("Vote for next map will start in 60 seconds!"); } } if (RaceStartCountdown > 0) { RaceStartCountdown--; if (RaceStartCountdown == 3) { API.triggerClientEventForAll("startRaceCountdown"); } else if (RaceStartCountdown == 0) { IsRaceOngoing = true; lock (Opponents) foreach (var opponent in Opponents) { API.setEntityPositionFrozen(opponent.Client, opponent.Vehicle, false); opponent.HasStarted = true; } RaceTimer = DateTime.Now; } } if (VoteEnd > 0) { VoteEnd--; if (VoteEnd == 0) { EndRace(); var raceWon = AvailableChoices[Votes.OrderByDescending(pair => pair.Value).ToList()[0].Key]; API.sendChatMessageToAll("Race ~b~" + raceWon.Name + "~w~ has won the vote!"); API.sleep(1000); StartRace(raceWon); } } } if (!IsRaceOngoing) { return; } lock (Opponents) { var count = 0; foreach (var playa in Opponents) { if (playa.Client.position.Z <= 0 || playa.Client.position.Z <= CurrentRace.Checkpoints[0].Z) { API.setPlayerHealth(playa.Client, -1); playa.IsAlive = false; } if (playa.IsAlive) { count++; } } if (count <= 1) { StartVote(); var winner = Opponents.FirstOrDefault(op => op.IsAlive); if (winner != null) { API.sendChatMessageToAll("The winner is ~b~" + winner.Client.name + "~w~!"); } else { API.sendChatMessageToAll("There are no winners!"); } IsRaceOngoing = false; } } }