Skip to content

Commit e5ba501

Browse files
committed
fixed issue with modules and autocommands not getting correct player count due to phantom IDs.
1 parent f0b74e1 commit e5ba501

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

‎Essentials/AutoCommands.cs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ private bool CanRun(AutoCommand command)
7272
}
7373
case Trigger.PlayerCount:
7474

75-
if (command.Compare == GreaterThan)
76-
{
77-
return MySession.Static?.Players.GetOnlinePlayerCount() > command.TriggerCount;
78-
}
79-
else if (command.Compare == LessThan)
75+
switch (command.Compare)
8076
{
81-
return MySession.Static?.Players.GetOnlinePlayerCount() < command.TriggerCount;
77+
case GreaterThan:
78+
return Utilities.GetOnlinePlayerCount() > command.TriggerCount;
79+
case LessThan:
80+
return Utilities.GetOnlinePlayerCount() < command.TriggerCount;
81+
case Equal:
82+
return Math.Abs(Utilities.GetOnlinePlayerCount() - command.TriggerCount) < 1;
8283
}
8384
break;
8485

‎Essentials/Commands/VotingModule.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private IEnumerable VoteCountdown(TimeSpan time)
261261
}
262262
else
263263
{
264-
double vr = (double)_voteReg.Count / MySession.Static.Players.GetOnlinePlayerCount();
264+
double vr = (double)_voteReg.Count / Utilities.GetOnlinePlayerCount();
265265
if (vr >= _command.TriggerRatio)
266266
{
267267
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()

‎Essentials/Utilities.cs‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
64
using Sandbox.Game.Entities;
75
using Sandbox.Game.World;
86
using Sandbox.ModAPI;
9-
using Torch;
107
using VRage.Game.ModAPI;
118
using VRage.ModAPI;
129
using VRage.Utils;
@@ -99,6 +96,23 @@ public static IMyPlayer GetPlayerByNameOrId(string nameOrPlayerId)
9996
return null;
10097
}
10198

99+
public static int GetOnlinePlayerCount()
100+
{
101+
var result = 0;
102+
103+
result = MySession.Static.Players.GetOnlinePlayers()
104+
.Count(x => x.IsRealPlayer && !string.IsNullOrEmpty(x.DisplayName));
105+
106+
return result;
107+
}
108+
109+
public static List<MyPlayer> GetOnlinePlayers()
110+
{
111+
var result = new List<MyPlayer>(MySession.Static.Players.GetOnlinePlayers()
112+
.Where(x => x.IsRealPlayer && !string.IsNullOrEmpty(x.DisplayName)));
113+
return result;
114+
}
115+
102116
public static string FormatDataSize(double size)
103117
{
104118
string p = MyUtils.FormatByteSizePrefix(ref size);

0 commit comments

Comments
 (0)