Skip to content

Commit 82a927a

Browse files
authored
Update ReadyUp and SpecHUD (#438)
* readyup * spechud * readyup2 * spechud2 * readyup3 * readyup4 * Update SpecHUD * Update ReadyUp * Ready Up: Fix possible glitch causing survivor to die from falling * Ready Up: Spilt up into many modules Ready Up: Minimum players for auto start * Revert "Ready Up: Spilt up into many modules" This reverts commit 78eca74. * Ready Up: Spilt up into many modules Ready Up: Minimum players for auto start * Ready Up: Fix multiple issues Fix: - Fix empty string false positive. - Fix countdown timers not correctly set, leading to mob spawning / player teleporting during ready up. (Target5150/MoYu_Server_Stupid_Plugins#28 Target5150/MoYu_Server_Stupid_Plugins#30)
1 parent c406449 commit 82a927a

18 files changed

Lines changed: 1605 additions & 1507 deletions

File tree

1.81 KB
Binary file not shown.
1.3 KB
Binary file not shown.

addons/sourcemod/scripting/readyup.sp

Lines changed: 99 additions & 1413 deletions
Large diffs are not rendered by default.
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
#if defined _readyup_action_included
2+
#endinput
3+
#endif
4+
#define _readyup_action_included
5+
6+
#include "sound.inc"
7+
8+
static int
9+
s_readyDelay,
10+
s_autoStartDelay,
11+
s_expireTime;
12+
13+
static Handle
14+
s_readyCountdownTimer,
15+
s_autoStartTimer;
16+
17+
void InitiateReadyUp(bool real = true)
18+
{
19+
if (real)
20+
{
21+
readyUpMode = l4d_ready_enabled.IntValue;
22+
if (!readyUpMode) return;
23+
24+
UTIL_WrapperForward(g_hPreInitiateForward);
25+
26+
for (int i = 1; i <= MaxClients; i++)
27+
{
28+
SetPlayerReady(i, false);
29+
}
30+
31+
InitPanel();
32+
UpdatePanel();
33+
}
34+
35+
inReadyUp = true;
36+
inLiveCountdown = false;
37+
isForceStart = false;
38+
s_readyCountdownTimer = null;
39+
40+
fStartTimestamp = GetGameTime();
41+
42+
SetAllowSpawns(l4d_ready_disable_spawns.BoolValue);
43+
CreateTimer(0.3, Timer_RestartCountdowns, false, TIMER_FLAG_NO_MAPCHANGE);
44+
45+
sv_infinite_primary_ammo.SetBool(true, .notify = false);
46+
god.SetBool(true, .notify = false);
47+
sb_stop.SetBool(true, .notify = false);
48+
49+
if (real)
50+
{
51+
nativeFooter.Clear();
52+
53+
ToggleCommandListeners(true);
54+
55+
if (readyUpMode == ReadyMode_AutoStart)
56+
{
57+
s_expireTime = l4d_ready_autostart_wait.IntValue;
58+
CreateTimer(1.0, Timer_AutoStartHelper, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
59+
}
60+
61+
UTIL_WrapperForward(g_hInitiateForward);
62+
}
63+
}
64+
65+
void InitiateLive(bool real = true)
66+
{
67+
if (real)
68+
{
69+
UTIL_WrapperForward(g_hPreLiveForward);
70+
}
71+
72+
inReadyUp = false;
73+
inLiveCountdown = false;
74+
isForceStart = false;
75+
76+
SetTeamFrozen(L4D2Team_Survivor, false);
77+
78+
sv_infinite_primary_ammo.SetBool(false, .notify = false);
79+
god.SetBool(false, .notify = false);
80+
sb_stop.SetBool(false, .notify = false);
81+
82+
ToggleCommandListeners(false);
83+
84+
if (real)
85+
{
86+
ClearSurvivorProgress();
87+
RestartCountdowns(true);
88+
89+
UTIL_WrapperForward(g_hLiveForward);
90+
}
91+
92+
s_readyCountdownTimer = null;
93+
}
94+
95+
void InitiateLiveCountdown()
96+
{
97+
if (s_readyCountdownTimer == null)
98+
{
99+
UTIL_WrapperForward(g_hPreCountdownForward);
100+
101+
ReturnTeamToSaferoom(L4D2Team_Survivor);
102+
PrintHintTextToAll("%t", "LiveCountdownBegin");
103+
inLiveCountdown = true;
104+
s_readyDelay = l4d_ready_delay.IntValue + l4d_ready_force_extra.IntValue * view_as<int>(isForceStart);
105+
s_readyCountdownTimer = CreateTimer(1.0, ReadyCountdownDelay_Timer, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
106+
107+
UTIL_WrapperForward(g_hCountdownForward);
108+
}
109+
}
110+
111+
static Action ReadyCountdownDelay_Timer(Handle timer)
112+
{
113+
if (s_readyDelay == 0)
114+
{
115+
PrintHintTextToAll("%t", "RoundIsLive");
116+
InitiateLive();
117+
PlayLiveSound();
118+
s_readyCountdownTimer = null;
119+
return Plugin_Stop;
120+
}
121+
122+
PrintHintTextToAll("%t", "LiveCountdown", s_readyDelay);
123+
PlayCountdownSound();
124+
s_readyDelay--;
125+
return Plugin_Continue;
126+
}
127+
128+
static Action Timer_AutoStartHelper(Handle timer)
129+
{
130+
if (GetSeriousClientCount(true) <= GetMaxAllowedPlayers() * l4d_ready_autostart_min.FloatValue)
131+
{
132+
// not enough players in game
133+
s_expireTime = l4d_ready_autostart_wait.IntValue;
134+
PrintHintTextToAll("%t", "AutoStartNotEnoughPlayers");
135+
return Plugin_Continue;
136+
}
137+
138+
if (IsAnyPlayerLoading())
139+
{
140+
if (s_expireTime > 0)
141+
{
142+
s_expireTime--;
143+
PrintHintTextToAll("%t", "AutoStartWaiting");
144+
return Plugin_Continue;
145+
}
146+
}
147+
148+
CreateTimer(8.0, Timer_InitiateAutoStart, _, TIMER_FLAG_NO_MAPCHANGE);
149+
return Plugin_Stop;
150+
}
151+
152+
static Action Timer_InitiateAutoStart(Handle timer)
153+
{
154+
InitiateAutoStart();
155+
return Plugin_Stop;
156+
}
157+
158+
void InitiateAutoStart(bool real = true)
159+
{
160+
if (!real)
161+
{
162+
s_autoStartTimer = null;
163+
return;
164+
}
165+
166+
if (s_autoStartTimer == null)
167+
{
168+
PrintHintTextToAll("%t", "InitiateAutoStart");
169+
s_autoStartDelay = l4d_ready_autostart_delay.IntValue;
170+
s_autoStartTimer = CreateTimer(1.0, AutoStartDelay_Timer, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
171+
}
172+
}
173+
174+
static Action AutoStartDelay_Timer(Handle timer)
175+
{
176+
if (s_autoStartDelay == 0)
177+
{
178+
s_autoStartTimer = null;
179+
InitiateLiveCountdown();
180+
return Plugin_Stop;
181+
}
182+
183+
PrintHintTextToAll("%t", "AutoStartCountdown", s_autoStartDelay);
184+
PlayAutoStartSound();
185+
s_autoStartDelay--;
186+
return Plugin_Continue;
187+
}
188+
189+
bool CheckFullReady()
190+
{
191+
if (readyUpMode == ReadyMode_AutoStart)
192+
return false;
193+
194+
int survReadyCount = 0, infReadyCount = 0;
195+
for (int i = 1; i <= MaxClients; i++)
196+
{
197+
if (IsClientInGame(i) && IsPlayerReady(i))
198+
{
199+
switch (GetClientTeam(i))
200+
{
201+
case L4D2Team_Survivor: survReadyCount++;
202+
case L4D2Team_Infected: infReadyCount++;
203+
}
204+
}
205+
}
206+
207+
if (readyUpMode == ReadyMode_TeamReady)
208+
return survReadyCount && infReadyCount;
209+
210+
int survLimit = survivor_limit.IntValue;
211+
int zombLimit = z_max_player_zombies.IntValue;
212+
213+
if (l4d_ready_unbalanced_start.BoolValue)
214+
{
215+
int iBaseline = l4d_ready_unbalanced_min.IntValue;
216+
217+
if (iBaseline > survLimit) iBaseline = survLimit;
218+
if (iBaseline > zombLimit) iBaseline = zombLimit;
219+
220+
int survCount = GetTeamHumanCount(L4D2Team_Survivor);
221+
int infCount = GetTeamHumanCount(L4D2Team_Infected);
222+
223+
return (iBaseline <= survCount && survCount <= survReadyCount)
224+
&& (iBaseline <= infCount && infCount <= infReadyCount);
225+
}
226+
227+
return (survReadyCount + infReadyCount) >= survLimit + zombLimit;
228+
}
229+
230+
void CancelFullReady(int client, disruptType type)
231+
{
232+
if (readyUpMode == ReadyMode_AutoStart)
233+
return;
234+
235+
if (s_readyCountdownTimer != null)
236+
{
237+
delete s_readyCountdownTimer;
238+
InitiateReadyUp(false);
239+
240+
SetTeamFrozen(L4D2Team_Survivor, l4d_ready_survivor_freeze.BoolValue);
241+
if (type == teamShuffle) // fix spectating
242+
SetClientFrozen(client, false);
243+
244+
PrintHintTextToAll("%t", "LiveCountdownCancelled");
245+
CPrintToChatAllEx(client, "%t", g_sDisruptReason[type], client);
246+
247+
if (g_hCountdownCancelledForward.FunctionCount)
248+
{
249+
Call_StartForward(g_hCountdownCancelledForward);
250+
Call_PushCell(client);
251+
Call_PushString(g_sDisruptReason[type]);
252+
Call_Finish();
253+
}
254+
}
255+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#if defined _readyup_command_included
2+
#endinput
3+
#endif
4+
#define _readyup_command_included
5+
6+
void ToggleCommandListeners(bool hook)
7+
{
8+
static bool hooked = false;
9+
if (hooked && !hook)
10+
{
11+
RemoveCommandListener(Vote_Callback, "Vote");
12+
hooked = false;
13+
}
14+
else if (!hooked && hook)
15+
{
16+
AddCommandListener(Vote_Callback, "Vote");
17+
hooked = true;
18+
}
19+
}
20+
21+
// ========================
22+
// Ready Commands
23+
// ========================
24+
25+
Action Ready_Cmd(int client, int args)
26+
{
27+
if (inReadyUp && IsPlayer(client))
28+
{
29+
if (!SetPlayerReady(client, true))
30+
PlayNotifySound();
31+
if (l4d_ready_secret.BoolValue)
32+
DoSecrets(client);
33+
if (CheckFullReady())
34+
InitiateLiveCountdown();
35+
return Plugin_Handled;
36+
}
37+
return Plugin_Continue;
38+
}
39+
40+
Action Unready_Cmd(int client, int args)
41+
{
42+
if (inReadyUp && client)
43+
{
44+
AdminId id = GetUserAdmin(client);
45+
bool hasflag = (id != INVALID_ADMIN_ID && GetAdminFlag(id, Admin_Ban)); // Check for specific admin flag
46+
47+
if (isForceStart)
48+
{
49+
if (!hasflag) return Plugin_Handled;
50+
CancelFullReady(client, adminAbort);
51+
isForceStart = false;
52+
}
53+
else
54+
{
55+
if (IsPlayer(client))
56+
{
57+
SetButtonTime(client);
58+
if (SetPlayerReady(client, false))
59+
PlayNotifySound();
60+
}
61+
else if (!hasflag)
62+
{
63+
return Plugin_Handled;
64+
}
65+
CancelFullReady(client, readyStatus);
66+
}
67+
return Plugin_Handled;
68+
}
69+
return Plugin_Continue;
70+
}
71+
72+
Action ToggleReady_Cmd(int client, int args)
73+
{
74+
if (inReadyUp)
75+
{
76+
return IsPlayerReady(client) ? Unready_Cmd(client, 0) : Ready_Cmd(client, 0);
77+
}
78+
return Plugin_Continue;
79+
}
80+
81+
// ========================
82+
// Admin Commands
83+
// ========================
84+
85+
Action ForceStart_Cmd(int client, int args)
86+
{
87+
if (inReadyUp && readyUpMode != ReadyMode_AutoStart)
88+
{
89+
// Check if admin always allowed to do so
90+
AdminId id = GetUserAdmin(client);
91+
if (id != INVALID_ADMIN_ID && GetAdminFlag(id, Admin_Ban)) // Check for specific admin flag
92+
{
93+
isForceStart = true;
94+
InitiateLiveCountdown();
95+
CPrintToChatAll("%t", "ForceStartAdmin", client);
96+
return Plugin_Handled;
97+
}
98+
}
99+
return Plugin_Continue;
100+
}
101+
102+
// ========================
103+
// Player Commands
104+
// ========================
105+
106+
Action Hide_Cmd(int client, int args)
107+
{
108+
if (inReadyUp)
109+
{
110+
SetPlayerHiddenPanel(client, true);
111+
CPrintToChat(client, "%t", "PanelHide");
112+
return Plugin_Handled;
113+
}
114+
return Plugin_Continue;
115+
}
116+
117+
Action Show_Cmd(int client, int args)
118+
{
119+
if (inReadyUp)
120+
{
121+
SetPlayerHiddenPanel(client, false);
122+
CPrintToChat(client, "%t", "PanelShow");
123+
return Plugin_Handled;
124+
}
125+
return Plugin_Continue;
126+
}
127+
128+
Action Return_Cmd(int client, int args)
129+
{
130+
if (inReadyUp
131+
&& client > 0
132+
&& GetClientTeam(client) == L4D2Team_Survivor)
133+
{
134+
ReturnPlayerToSaferoom(client, false);
135+
return Plugin_Handled;
136+
}
137+
return Plugin_Continue;
138+
}

0 commit comments

Comments
 (0)