Files
reallife-gamemode/ReallifeGamemode.Server/Util/CheckPointHandle.cs

92 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using ReallifeGamemode.Server.Entities;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Finance;
using ReallifeGamemode.Server.Models;
using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Server.Util;
using GTANetworkAPI;
using System.Collections;
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, List<Vector3> nListCps)
{
checkPointListForPlayer playerHandle = new checkPointListForPlayer(player, nListCps);
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();
ChatService.Broadcast("neuer cp");
}
}
public class checkPointListForPlayer
{
public List<Vector3> list = new List<Vector3>();
public Client player;
Vector3 checkPoint;
Boolean done;
int checkPointsDone = 0;
public checkPointListForPlayer(Client nPlayer, List<Vector3> nList)
{
this.player = nPlayer;
this.list = nList;
}
public void startRoute()
{
player.TriggerEvent("setCheckPoint", this.list.ElementAt(0), player);
}
public void nextCheckpoint()
{
this.checkPointsDone++;
if (this.list.Count > checkPointsDone)
{
Vector3 nextCp = list.ElementAt(checkPointsDone);
ChatService.SendMessage(this.player, "cp set at " + nextCp.ToString());
this.player.TriggerEvent("setCheckPoint", nextCp, player);
}
if (this.list.Count == checkPointsDone)
{
ChatService.SendMessage(this.player, "Du hast alle Checkpoints abgefahren!");
CheckPointHandle.removePlayerHandlerFromList(this.player);
}
}
}
}