73 lines
2.4 KiB
C#
Raw Normal View History

2021-08-20 17:28:13 +02:00
using System.Collections.Generic;
using System.ComponentModel;
2021-08-18 11:47:59 +02:00
using System.Timers;
2021-08-18 12:47:36 +02:00
using CoopServer;
using CoopServer.Entities;
2021-08-18 11:47:59 +02:00
namespace FirstGameMode
{
public class Main : ServerScript
{
private static readonly Timer RunningSinceTimer = new() { Interval = 1000 };
private static int RunningSince = 0;
2021-08-20 17:28:13 +02:00
public static bool ShowPlayerPosition = false;
private static List<string> SecretLocation = new List<string>();
2021-08-18 11:47:59 +02:00
2021-08-18 12:47:36 +02:00
public Main()
2021-08-18 11:47:59 +02:00
{
RunningSinceTimer.Start();
RunningSinceTimer.Elapsed += new ElapsedEventHandler((sender, e) => RunningSince += 1);
2021-08-18 12:47:36 +02:00
API.OnPlayerConnected += OnPlayerConnected;
API.OnPlayerDisconnected += OnPlayerDisconnected;
API.OnChatMessage += OnChatMessage;
2021-08-20 17:28:13 +02:00
API.OnPlayerPositionUpdate += OnPlayerPositionUpdate;
2021-08-18 12:47:36 +02:00
API.RegisterCommand("running", RunningCommand);
API.RegisterCommands<Commands>();
2021-08-18 11:47:59 +02:00
}
public static void RunningCommand(CommandContext ctx)
{
2021-08-18 12:47:36 +02:00
API.SendChatMessageToPlayer(ctx.Player.Username, "Server has been running for: " + RunningSince + " seconds!");
2021-08-18 11:47:59 +02:00
}
2021-08-22 13:59:15 +02:00
public static void OnPlayerConnected(EntitiesPlayer player)
2021-08-18 11:47:59 +02:00
{
2021-08-22 13:59:15 +02:00
API.SendChatMessageToAll("Player " + player.Username + " connected!");
2021-08-18 11:47:59 +02:00
}
2021-08-18 12:47:36 +02:00
public static void OnPlayerDisconnected(EntitiesPlayer player)
2021-08-18 11:47:59 +02:00
{
2021-08-18 12:47:36 +02:00
API.SendChatMessageToAll("Player " + player.Username + " disconnected!");
2021-08-18 11:47:59 +02:00
}
2021-08-18 12:47:36 +02:00
public static void OnChatMessage(string username, string message, CancelEventArgs e)
2021-08-18 11:47:59 +02:00
{
2021-08-18 12:47:36 +02:00
e.Cancel = true;
2021-08-18 11:47:59 +02:00
if (message.StartsWith("EASTEREGG"))
{
2021-08-18 12:47:36 +02:00
API.SendChatMessageToPlayer(username, "You found the EASTEREGG! *-*");
return;
2021-08-18 11:47:59 +02:00
}
2021-08-18 12:47:36 +02:00
API.SendChatMessageToAll(message, username);
2021-08-18 11:47:59 +02:00
}
2021-08-20 17:28:13 +02:00
public static void OnPlayerPositionUpdate(EntitiesPlayer player)
{
if (ShowPlayerPosition)
{
if (!SecretLocation.Contains(player.Username) && player.IsInRangeOf(new LVector3(0, 0, 75), 7f))
{
API.SendChatMessageToPlayer(player.Username, "Hey! you find this secret location!");
SecretLocation.Add(player.Username);
return;
}
}
}
2021-08-18 11:47:59 +02:00
}
}