84 lines
2.3 KiB
C#
84 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using ReallifeGamemode.Server.Services;
|
|
using GTANetworkAPI;
|
|
using System.Linq;
|
|
namespace ReallifeGamemode.Server.Util
|
|
{
|
|
public class CheckPointHandle : Script
|
|
{
|
|
public static List<CheckPointListForPlayer> listHandle = new List<CheckPointListForPlayer>();
|
|
public static void StartCheckPointRoute(Client player, IEnumerable<Vector3> nListCps, int delay, int markerID)
|
|
{
|
|
RemovePlayerHandlerFromList(player);
|
|
CheckPointListForPlayer playerHandle = new CheckPointListForPlayer(player, nListCps, delay, markerID);
|
|
listHandle.Add(playerHandle);
|
|
|
|
playerHandle.StartRoute();
|
|
}
|
|
public static void RemovePlayerHandlerFromList(Client 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(Client user)
|
|
{
|
|
CheckPointListForPlayer temp = null;
|
|
for (int a = 0; a < listHandle.Count; a++)
|
|
{
|
|
temp = listHandle[a];
|
|
if (temp.player == user)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
temp.NextCheckpoint();
|
|
}
|
|
}
|
|
|
|
public class CheckPointListForPlayer
|
|
{
|
|
public IEnumerable<Vector3> list = new List<Vector3>();
|
|
public Client player;
|
|
public int delay = 0;
|
|
public int markerID;
|
|
|
|
int checkPointsDone = 0;
|
|
|
|
public CheckPointListForPlayer(Client nPlayer, IEnumerable<Vector3> nList, int nDelay, int nMarkerID)
|
|
{
|
|
this.player = nPlayer;
|
|
this.list = nList;
|
|
this.delay = nDelay;
|
|
this.markerID = nMarkerID;
|
|
}
|
|
|
|
public void StartRoute()
|
|
{
|
|
player.TriggerEvent("setCheckPoint", this.list.ElementAt(0), player, this.delay, this.markerID);
|
|
}
|
|
public void NextCheckpoint()
|
|
{
|
|
this.checkPointsDone++;
|
|
if (this.list.Count() > checkPointsDone)
|
|
{
|
|
Vector3 nextCp = list.ElementAt(checkPointsDone);
|
|
this.player.TriggerEvent("setCheckPoint", nextCp, player, this.delay, this.markerID);
|
|
}
|
|
if (this.list.Count() == checkPointsDone)
|
|
{
|
|
ChatService.SendMessage(this.player, "Du hast alle Checkpoints abgefahren!");
|
|
CheckPointHandle.RemovePlayerHandlerFromList(this.player);
|
|
}
|
|
}
|
|
}
|
|
}
|