Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Essentials/AutoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public string VoteDuration
public int Percentage
{
get => _votepercentage;
set => SetValue(ref _votepercentage, Math.Min(value, 100));
set => SetValue(ref _votepercentage, Math.Abs(Math.Min(value, 100)));
}

[Display(Name = "Day of week", GroupName = "Schedule", Description = "Combined with Scheduled Time, will run the command on the given day of the week at the set time.")]
Expand Down
25 changes: 20 additions & 5 deletions Essentials/Commands/VotingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.World;
using Torch.API.Managers;
using Torch.Commands;
using Torch.Commands.Permissions;
Expand Down Expand Up @@ -183,7 +183,7 @@ public void VoteCount()
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Current vote: {voteInProgress}");
sb.AppendLine($"vote Status: {VoteStatus.ToString()}");
sb.AppendLine($"vote count: {_voteReg.Count} / player count: {MyMultiplayer.Static.MemberCount - 1}");
sb.AppendLine($"vote count: {_voteReg.Count} / player count: {MySession.Static.Players.GetOnlinePlayerCount()}");
sb.AppendLine($"vote percent: {votePercent}");
Context.Respond(sb.ToString());

Expand All @@ -202,7 +202,7 @@ private IEnumerable VoteCountdown(TimeSpan time)
{
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Vote for {voteInProgress} cancelled");
VoteReset();
VoteClear();
yield break;
}

Expand All @@ -222,7 +222,7 @@ private IEnumerable VoteCountdown(TimeSpan time)
}
else
{
votePercent = (int)Math.Round((double)100 * (_voteReg.Count / (MyMultiplayer.Static.MemberCount - 1)));
votePercent = (int)Math.Round((double)100 * (_voteReg.Count / (MySession.Static.Players.GetOnlinePlayerCount())));

if (votePercent >= command.Percentage)
{
Expand All @@ -235,13 +235,28 @@ private IEnumerable VoteCountdown(TimeSpan time)
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Vote for {voteInProgress} failed");
}
VoteReset();
VoteClear();
yield break;
}
}
}

[Command("vote reset", "Reset all vote logs")]
[Permission(MyPromoteLevel.Admin)]
public void VoteReset()
{
if (VoteStatus == Status.VoteInProgress)
{
VoteCancel();
}
else
VoteClear();
VoteClear();
votePercent = 0;
_votetimeout.Clear();
}

public void VoteClear()
{
Random rnd = new Random();
_cooldown = rnd.Next(5, 30);
Expand Down