-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOptoutSystem.cs
More file actions
130 lines (100 loc) · 4.17 KB
/
Copy pathOptoutSystem.cs
File metadata and controls
130 lines (100 loc) · 4.17 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
118
119
120
121
122
123
124
125
126
127
128
129
130
using LabApi.Events.Arguments.Scp049Events;
using MEC;
using PlayerRoles;
using SimpleCustomRoles.RoleYaml;
using UnityEngine;
namespace ZombieOptOut;
public class OptOutSystem
{
public static uint waitingForCompensationFrom = 0;
private static Player optedOutPlayer = null;
private static Player main049Player = null;
private static CustomRoleBaseInfo savedCustomRole = null;
public static void RevivedZombie(Scp049ResurrectedBodyEventArgs ev)
{
main049Player = ev.Player;
ReferenceHub refHub = ev.Target.ReferenceHub;
if (ServerSpecificSettings.savedSettings[refHub].Item1 == false)
return;
Timing.CallDelayed(1f, () =>
{
if (SimpleCustomRoles.Helpers.CustomRoleHelpers.Contains(ev.Target))
{
SimpleCustomRoles.Helpers.CustomRoleHelpers.GetPlayerAndRoles().TryGetValue(ev.Target, out savedCustomRole);
CL.Info("Custom role saved: " + savedCustomRole.Rolename);
}
ev.Target.SendBroadcast($"<size=36>[ZombieOptOut] You've opted out of being revived as a zombie in your Settings!</size>", 5);
if (ev.Target.Role == RoleTypeId.Scp0492)
ev.Target.SetRole(RoleTypeId.Spectator);
});
optedOutPlayer = ev.Target;
foreach (Player player in Player.ReadyList)
{
if (player == ev.Target)
continue;
if (player.IsDummy)
continue;
if (player.IsAlive)
continue;
if (player == null)
continue;
ReferenceHub listHub = player.ReferenceHub;
if (listHub == null)
continue;
if (ServerSpecificSettings.savedSettings[listHub].Item2 != true)
continue;
ev.Player.SendBroadcast($"<size=36>[ZombieOptOut] <b>{ev.Target.DisplayName}</b> Opted out of being revived and has been replaced with <b>{player.DisplayName}</b></size>", 5);
RoleFill(player);
return;
}
CL.Info("No players had Auto-Fill enabled!");
ClampedCompensation();
foreach (Player player in Player.ReadyList)
{
if (player == optedOutPlayer)
continue;
if (player.IsAlive)
continue;
if (player.IsDummy)
continue;
player.SendBroadcast($"<size=40>[ZombieOptOut] <b>{ev.Target.DisplayName}</b> Has opted out of being a zombie, you can take their spot!\n</size><size=34>By typing <b>.optin</b> in your console (`)!</size>", 5);
}
Timing.CallDelayed(ZombieOptOut.Main.Instance.Config.ZombieFillDuration, () =>
{
if (waitingForCompensationFrom != 0)
{
foreach (Player player in Player.ReadyList)
{
if (player.Role != RoleTypeId.Scp049)
continue;
player.Heal(ZombieOptOut.Main.Instance.Config.HealthCompensation);
player.SendBroadcast($"<size=36>[ZombieOptOut] You were compenstaed for a zombie opting out with <b>+{ZombieOptOut.Main.Instance.Config.HealthCompensation}HP</b></size>", 5);
}
ClampedCompensation(-1);
}
});
}
public static void RoleFill(Player player)
{
CL.Info($"Player {player.DisplayName} Auto-Filled!");
player.SetRole(RoleTypeId.Scp0492, RoleChangeReason.Revived);
Timing.CallDelayed(0.5f, () => player.Position = main049Player.Position);
ClampedCompensation(-1);
Timing.CallDelayed(1.5f, () =>
{
if (savedCustomRole == null)
return;
Server.RunCommand($"/scr set {savedCustomRole.Rolename} {player.PlayerId}");
savedCustomRole = null;
});
XPSystem.BackEnd.XpSystemAPI.AddXP(player, 100, "Opted-in as a Zombie [+100]");
}
internal static void RoundStart()
{
savedCustomRole = null;
}
private static void ClampedCompensation(int value = 1)
{
waitingForCompensationFrom = (uint)(Mathf.Clamp(waitingForCompensationFrom + value, 0, 50));
}
}