using System.Collections.Generic; using ReallifeGamemode.Server.Services; using GTANetworkAPI; using System.Linq; using ReallifeGamemode.Server.Extensions; namespace ReallifeGamemode.Server.Util { public class CheckPointHandle : Script { public static List listHandle = new List(); public static void DeleteCheckpoints(Player player) { RemovePlayerHandlerFromList(player); player.TriggerEvent("destroyCP"); } public static void StartCheckPointRoute(Player player, IEnumerable nListCps, int delay, int markerID, int markerSize, string nEvent) { RemovePlayerHandlerFromList(player); CheckPointListForPlayer playerHandle = new CheckPointListForPlayer(player, nListCps, delay, markerID, markerSize, nEvent); playerHandle.DeleteCheckpoints(); listHandle.Add(playerHandle); playerHandle.StartRoute(); } public static void RemovePlayerHandlerFromList(Player player) { CheckPointListForPlayer temp = null; for (int a = 0; a < listHandle.Count; a++) { temp = listHandle[a]; if (temp.player == player) { listHandle.Remove(temp); } } } [RemoteEvent("playerInCheckpoint")] public void PlayerInCheckpoint(Player user) { CheckPointListForPlayer temp = null; Job.BusDriverJob temp2 = null; for (int a = 0; a < listHandle.Count; a++) { temp = listHandle[a]; if (temp.player == user) { break; } } if (temp.LastCheckpoint != 1) { if (user.GetUser().JobId == 4) { Job.BusDriverJob.payWage(user, 100); } } else { if (user.GetUser().JobId == 4) { Job.BusDriverJob.payWage(user, 200); temp2.BusLetzterCheckpoint(user); } } temp.NextCheckpoint(); } } public class CheckPointListForPlayer { public int LastCheckpoint; public IEnumerable list = new List(); public Player player; public int delay = 0; public int markerID; public int markerSize; public string eventInCheckpoint = ""; int checkPointsDone = 0; public CheckPointListForPlayer(Player nPlayer, IEnumerable nList, int nDelay, int nMarkerID, int nMarkerSize, string nEvent) { this.player = nPlayer; this.list = nList; this.delay = nDelay; this.markerID = nMarkerID; this.markerSize = nMarkerSize; this.eventInCheckpoint = nEvent; this.checkPointsDone = 0; } public void StartRoute() { player.TriggerEvent("setCheckPoint", this.list.ElementAt(0), player, 0, this.delay, this.markerID, this.markerSize, this.eventInCheckpoint); } public void NextCheckpoint() { this.checkPointsDone++; if (this.list.Count() > checkPointsDone) { LastCheckpoint = 0; Vector3 nextCp = list.ElementAt(checkPointsDone); this.player.TriggerEvent("setCheckPoint", nextCp, player, this.checkPointsDone, delay, this.markerID, this.markerSize, this.eventInCheckpoint); } if (this.list.Count() == checkPointsDone-1) { LastCheckpoint = 1; } if (this.list.Count() == checkPointsDone) { LastCheckpoint = 0; CheckPointHandle.RemovePlayerHandlerFromList(this.player); } } public void DeleteCheckpoints() { this.player.TriggerEvent("destroyCP"); } } }