-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cs
More file actions
117 lines (106 loc) · 3.88 KB
/
Main.cs
File metadata and controls
117 lines (106 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using Rocket.API.Collections;
using Rocket.Core.Plugins;
using Rocket.Unturned;
using Rocket.Unturned.Player;
using SDG.Unturned;
using Steamworks;
using System;
using Logger = Rocket.Core.Logging.Logger;
namespace Tortellio.MaxplayerModifier
{
public class Main : RocketPlugin<Config>
{
public static Main Instance;
public static string PluginName = "MaxplayerModifier";
public static string PluginVersion = " 1.0.7";
public static byte baseMaxPlayers;
protected override void Load()
{
Instance = this;
baseMaxPlayers = Provider.maxPlayers;
if (Configuration.Instance.EnableMaxPlayerOnStart)
{
baseMaxPlayers = Configuration.Instance.MaxPlayerOnStart;
}
if (Configuration.Instance.EnableDynamicMaxPlayer)
{
U.Events.OnPlayerConnected += OnPlayerConnect;
U.Events.OnPlayerDisconnected += OnPlayerDisconnect;
}
if (Level.isLoaded)
{
ClampMaxPlayers();
}
Logger.Log("MaxplayerModifier has been loaded!", ConsoleColor.Yellow);
Logger.Log(PluginName + PluginVersion, ConsoleColor.Yellow);
Logger.Log("Made by Tortellio", ConsoleColor.Yellow);
Level.onPreLevelLoaded += ClampMaxPlayers;
}
protected override void Unload()
{
Instance = null;
Provider.maxPlayers = baseMaxPlayers;
Logger.Log("MaxplayerModifier has been unloaded!");
Logger.Log("Visit Tortellio Discord for more! https://discord.gg/pzQwsew", ConsoleColor.Yellow);
Level.onPreLevelLoaded -= ClampMaxPlayers;
if (Configuration.Instance.EnableDynamicMaxPlayer)
{
U.Events.OnPlayerConnected -= OnPlayerConnect;
U.Events.OnPlayerDisconnected -= OnPlayerDisconnect;
}
}
public override TranslationList DefaultTranslations => new TranslationList()
{
{ "mp_set", "Succesfully set max player to : " },
{ "mp_set_normal", "Succesfully set max player to normal" },
{ "mps", "Current server max players : " },
{ "mps_usage", "Error in command. Try /mps or /mplayers" },
{ "mp_usage", "Error in command. Try /mp amount or /setmp amount or /maxplayer amount" },
{ "mp_error", "Something went wrong. Input a number." },
};
private void ClampMaxPlayers()
{
if (Provider.maxPlayers > 24)
{
SteamGameServer.SetMaxPlayerCount(24);
}
}
private void ClampMaxPlayers(int level)
{
if (Provider.maxPlayers > 24)
{
SteamGameServer.SetMaxPlayerCount(24);
}
if (Configuration.Instance.EnableMaxPlayerOnStart)
{
Provider.maxPlayers = Configuration.Instance.MaxPlayerOnStart;
}
}
private void OnPlayerConnect(UnturnedPlayer player)
{
if (Provider.maxPlayers == Provider.clients.Count && Provider.maxPlayers + 1 != Configuration.Instance.MaximumDynamicSlot)
{
Provider.maxPlayers++;
if (Provider.maxPlayers > 24)
{
SteamGameServer.SetMaxPlayerCount(24);
}
}
}
private void OnPlayerDisconnect(UnturnedPlayer player)
{
if (Provider.clients.Count >= baseMaxPlayers)
{
Provider.maxPlayers--;
if (Provider.maxPlayers < baseMaxPlayers)
{
Provider.maxPlayers = baseMaxPlayers;
}
}
if (Provider.maxPlayers > 24)
{
SteamGameServer.SetMaxPlayerCount(24);
}
}
}
}