Skip to content

Commit 9d7a819

Browse files
Add Boss Blacklist (#470)
* Add scuffed blacklist * Get rid of potential excess on blacklist get * Improve selection feedback * x * ✨
1 parent 9a2ce98 commit 9d7a819

File tree

8 files changed

+359
-14
lines changed

8 files changed

+359
-14
lines changed

addons/sourcemod/configs/vsh/vsh.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,8 @@
24232423
"vsh_cookies_preferences" "1" //Should preferences use cookies to store? (Disable if you want to store preferences somewhere else)
24242424
"vsh_cookies_queue" "1" //Should queue use cookies to store? (Disable if you want to store queue somewhere else)
24252425
2426+
"vsh_blacklist_amount" "2" //How many bosses can a player blacklist? (0 disables this feature)
2427+
24262428
"vsh_class_limit" "1" //Enable/Disable entire class limit
24272429
"vsh_class_limit_scout" "6" //Max on how many players can play as that class, use -1 for no limit
24282430
"vsh_class_limit_soldier" "6"

addons/sourcemod/scripting/saxtonhale.sp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ ConVar tf_arena_preround_time;
449449
#include "vsh/config.sp"
450450

451451
#include "vsh/menu/menu_admin.sp"
452+
#include "vsh/menu/menu_blacklist.sp"
452453
#include "vsh/menu/menu_boss.sp"
453454
#include "vsh/menu/menu_weapon.sp"
454455
#include "vsh/menu.sp"
@@ -460,6 +461,7 @@ ConVar tf_arena_preround_time;
460461
#include "vsh/function/func_hook.sp"
461462
#include "vsh/function/func_native.sp"
462463

464+
#include "vsh/blacklist.sp"
463465
#include "vsh/classlimit.sp"
464466
#include "vsh/command.sp"
465467
#include "vsh/console.sp"
@@ -533,6 +535,7 @@ public void OnPluginStart()
533535

534536
Config_Init();
535537

538+
Blacklist_Init();
536539
ClassLimit_Init();
537540
Command_Init();
538541
Console_Init();
@@ -758,6 +761,7 @@ public void OnPluginStart()
758761
g_ConfigConvar.Create("vsh_telefrag_damage", "9001.0", "Damage amount to boss from telefrag", _, true, 0.0);
759762
g_ConfigConvar.Create("vsh_music_enable", "1", "Enable boss music?", _, true, 0.0, true, 1.0);
760763
g_ConfigConvar.Create("vsh_rps_enable", "1", "Allow everyone use Rock Paper Scissors Taunt?", _, true, 0.0, true, 1.0);
764+
g_ConfigConvar.Create("vsh_blacklist_amount", "2", "Maximum amount of bosses a player can blacklist for themselves (0 disables the feature)", _, true, 0.0);
761765

762766
//Incase of lateload, call client join functions
763767
for (int iClient = 1; iClient <= MaxClients; iClient++)
@@ -1324,6 +1328,7 @@ public void OnClientPutInServer(int iClient)
13241328
SDKHook(iClient, SDKHook_StartTouch, Client_OnStartTouch);
13251329
SDKHook(iClient, SDKHook_WeaponSwitchPost, Client_OnWeaponSwitchPost);
13261330

1331+
Blacklist_Load(iClient);
13271332
Cookies_OnClientJoin(iClient);
13281333
}
13291334

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#pragma semicolon 1
2+
#pragma newdecls required
3+
4+
static ArrayList g_aBlacklistedBosses[MAXPLAYERS];
5+
static Cookie g_hCookiesBlacklist;
6+
7+
enum BlacklistResult
8+
{
9+
BLACKLIST_ADDED,
10+
BLACKLIST_REMOVED,
11+
BLACKLIST_FAILED_TO_CHANGE
12+
}
13+
14+
void Blacklist_Init()
15+
{
16+
for (int i = 1; i <= MaxClients; i++)
17+
{
18+
g_aBlacklistedBosses[i] = new ArrayList(32);
19+
}
20+
21+
g_hCookiesBlacklist = new Cookie("vsh_blacklist", "Which bosses this player has blacklisted", CookieAccess_Protected);
22+
}
23+
24+
BlacklistResult Blacklist_Toggle(int iClient, const char[] sBoss)
25+
{
26+
BlacklistResult result;
27+
int iIndex = g_aBlacklistedBosses[iClient].FindString(sBoss);
28+
if (iIndex == -1)
29+
{
30+
int iMax = g_ConfigConvar.LookupInt("vsh_blacklist_amount");
31+
if (Blacklist_GetAmount(iClient) >= iMax)
32+
return BLACKLIST_FAILED_TO_CHANGE;
33+
34+
g_aBlacklistedBosses[iClient].PushString(sBoss);
35+
result = BLACKLIST_ADDED;
36+
}
37+
else
38+
{
39+
g_aBlacklistedBosses[iClient].Erase(iIndex);
40+
result = BLACKLIST_REMOVED;
41+
}
42+
43+
Blacklist_Save(iClient);
44+
return result;
45+
}
46+
47+
void Blacklist_Load(int iClient)
48+
{
49+
g_aBlacklistedBosses[iClient].Clear();
50+
51+
int iMax = g_ConfigConvar.LookupInt("vsh_blacklist_amount");
52+
if (iMax <= 0)
53+
return;
54+
55+
if (IsFakeClient(iClient))
56+
return;
57+
58+
// Get list of all bosses
59+
ArrayList aBosses = SaxtonHale_GetAllClassType(VSHClassType_Boss);
60+
61+
// Cookies can only be 99 chars long
62+
char sValue[100];
63+
g_hCookiesBlacklist.Get(iClient, sValue, sizeof(sValue));
64+
65+
char sExplode[100][16];
66+
int iCookieAmount = ExplodeString(sValue, ";", sExplode, sizeof(sExplode[]), sizeof(sExplode));
67+
int iPluginAmount;
68+
69+
for (int i = 0; i < iMax; i++)
70+
{
71+
if (sExplode[i][0] == '\0')
72+
{
73+
if (i == 0)
74+
iCookieAmount = 0;
75+
76+
break;
77+
}
78+
79+
// This boss doesn't exist. Maybe it was recently removed?
80+
if (aBosses.FindString(sExplode[i]) == -1)
81+
continue;
82+
83+
// This boss is hidden. Maybe it was set this way recently?
84+
if (SaxtonHale_CallFunction(sExplode[i], "IsBossHidden"))
85+
continue;
86+
87+
g_aBlacklistedBosses[iClient].PushString(sExplode[i]);
88+
iPluginAmount++;
89+
}
90+
91+
// Something changed since last time? Save the new data
92+
if (iCookieAmount != iPluginAmount)
93+
Blacklist_Save(iClient);
94+
95+
delete aBosses;
96+
}
97+
98+
void Blacklist_Save(int iClient)
99+
{
100+
// Cookies can only be 99 chars long
101+
char sValue[100];
102+
for (int i = 0; i < Blacklist_GetAmount(iClient); i++)
103+
{
104+
if (i > 0)
105+
StrCat(sValue, sizeof(sValue), ";");
106+
107+
char sBuffer[100];
108+
g_aBlacklistedBosses[iClient].GetString(i, sBuffer, sizeof(sBuffer));
109+
StrCat(sValue, sizeof(sValue), sBuffer);
110+
}
111+
112+
g_hCookiesBlacklist.Set(iClient, sValue);
113+
}
114+
115+
ArrayList Blacklist_Get(int iClient)
116+
{
117+
// If we somehow have more blacklisted bosses than allowed (ie convar recently changed), only use as many as we can
118+
int iLength = g_aBlacklistedBosses[iClient].Length;
119+
int iMax = g_ConfigConvar.LookupInt("vsh_blacklist_amount");
120+
121+
for (int i = iLength - 1; i >= iMax; i--)
122+
g_aBlacklistedBosses[iClient].Erase(i);
123+
124+
return g_aBlacklistedBosses[iClient].Clone();
125+
}
126+
127+
int Blacklist_GetAmount(int iClient)
128+
{
129+
return g_aBlacklistedBosses[iClient].Length;
130+
}
131+
132+
bool Blacklist_IsBossBlacklisted(int iClient, const char[] sBoss)
133+
{
134+
return g_aBlacklistedBosses[iClient].FindString(sBoss) != -1;
135+
}
136+
137+
void Blacklist_Clear(int iClient)
138+
{
139+
g_aBlacklistedBosses[iClient].Clear();
140+
Blacklist_Save(iClient);
141+
}

addons/sourcemod/scripting/vsh/command.sp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public void Command_Init()
1919
Command_Create("modifiers", Command_Modifiers);
2020
Command_Create("next", Command_HaleNext);
2121
Command_Create("credits", Command_Credits);
22+
Command_Create("blacklist", Command_Blacklist);
2223

2324
Command_Create("settings", Command_Preferences);
2425
Command_Create("preferences", Command_Preferences);
@@ -120,6 +121,20 @@ public Action Command_Boss(int iClient, int iArgs)
120121
return Plugin_Handled;
121122
}
122123

124+
public Action Command_Blacklist(int iClient, int iArgs)
125+
{
126+
if (!g_bEnabled) return Plugin_Continue;
127+
128+
if (iClient == 0)
129+
{
130+
ReplyToCommand(iClient, "This command can only be used in-game.");
131+
return Plugin_Handled;
132+
}
133+
134+
MenuBlacklist_DisplayMain(iClient);
135+
return Plugin_Handled;
136+
}
137+
123138
public Action Command_MultiBoss(int iClient, int iArgs)
124139
{
125140
if (!g_bEnabled) return Plugin_Continue;
@@ -194,11 +209,11 @@ public Action Command_Preferences(int iClient, int iArgs)
194209
char buffer[512];
195210

196211
if (bValue)
197-
Format(buffer, sizeof(buffer), "Enable");
212+
Format(buffer, sizeof(buffer), "Enabled");
198213
else
199-
Format(buffer, sizeof(buffer), "Disable");
214+
Format(buffer, sizeof(buffer), "Disabled");
200215

201-
PrintToChat(iClient, "%s%s %s %s", TEXT_TAG, TEXT_COLOR, buffer, g_strPreferencesName[nPreferences]);
216+
PrintToChat(iClient, "%s%s %s %s.", TEXT_TAG, TEXT_COLOR, buffer, g_strPreferencesName[nPreferences]);
202217
return Plugin_Handled;
203218
}
204219
else

addons/sourcemod/scripting/vsh/menu.sp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void Menu_Init()
2323
g_hMenuMain.AddItem("modifiers", "Modifiers Info (!vshmodifiers)");
2424
g_hMenuMain.AddItem("queue", "Queue List (!vshnext)");
2525
g_hMenuMain.AddItem("preference", "Settings (!vshsettings)");
26+
g_hMenuMain.AddItem("blacklist", "Boss Blacklist (!vshblacklist)");
2627
g_hMenuMain.AddItem("credit", "Credits (!vshcredits)");
2728

2829
// Credits
@@ -85,6 +86,8 @@ public int Menu_SelectMain(Menu hMenu, MenuAction action, int iClient, int iSele
8586
Menu_DisplayQueue(iClient);
8687
else if (StrEqual(sSelect, "preference"))
8788
Menu_DisplayPreferences(iClient);
89+
else if (StrEqual(sSelect, "blacklist"))
90+
MenuBlacklist_DisplayMain(iClient);
8891
else if (StrEqual(sSelect, "credit"))
8992
Menu_DisplayCredits(iClient);
9093
else
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#pragma semicolon 1
2+
#pragma newdecls required
3+
4+
void MenuBlacklist_DisplayMain(int iClient)
5+
{
6+
int iMax = g_ConfigConvar.LookupInt("vsh_blacklist_amount");
7+
if (iMax <= 0)
8+
{
9+
PrintToChat(iClient, "%s%s The boss blacklist is currently disabled.", TEXT_TAG, TEXT_COLOR);
10+
return;
11+
}
12+
13+
Menu hMenu = new Menu(MenuBlacklist_SelectMain);
14+
ArrayList aBlacklist = Blacklist_Get(iClient);
15+
16+
char sTitle[512];
17+
18+
if (iMax == 1)
19+
FormatEx(sTitle, sizeof(sTitle), "Boss Blacklist Menu\n \nYou can blacklist a boss to avoid being selected as them.\n ");
20+
else
21+
FormatEx(sTitle, sizeof(sTitle), "Boss Blacklist Menu\n \nYou can blacklist up to %d bosses to avoid being selected as them.\n ", iMax);
22+
23+
int iLength = aBlacklist.Length;
24+
if (iLength)
25+
{
26+
StrCat(sTitle, sizeof(sTitle), "\nCurrent blacklist:");
27+
for (int i = 0; i < iLength; i++)
28+
{
29+
char sType[64], sName[64];
30+
aBlacklist.GetString(i, sType, sizeof(sType));
31+
SaxtonHale_CallFunction(sType, "GetBossName", sName, sizeof(sName));
32+
33+
Format(sTitle, sizeof(sTitle), "%s\n- %s", sTitle, sName);
34+
}
35+
36+
StrCat(sTitle, sizeof(sTitle), "\n ");
37+
}
38+
39+
hMenu.SetTitle(sTitle);
40+
hMenu.AddItem("back", "<- Back");
41+
hMenu.AddItem("list", "Select which bosses to blacklist");
42+
hMenu.AddItem("clear", "Clear blacklist");
43+
hMenu.Display(iClient, MENU_TIME_FOREVER);
44+
}
45+
46+
public int MenuBlacklist_SelectMain(Menu hMenu, MenuAction action, int iClient, int iSelect)
47+
{
48+
if (action != MenuAction_Select) return 0;
49+
50+
char sSelect[32];
51+
hMenu.GetItem(iSelect, sSelect, sizeof(sSelect));
52+
53+
if (StrEqual(sSelect, "back"))
54+
{
55+
Menu_DisplayMain(iClient);
56+
}
57+
else if (StrEqual(sSelect, "list"))
58+
{
59+
// Just offload this shit to the vshboss menu man
60+
PrintToChat(iClient, "%s%s You can blacklist bosses in their respective pages.", TEXT_TAG, TEXT_COLOR);
61+
MenuBoss_DisplayList(iClient, VSHClassType_Boss, MenuBoss_CallbackInfo);
62+
}
63+
else if (StrEqual(sSelect, "clear"))
64+
{
65+
MenuBlacklist_DisplayClear(iClient);
66+
}
67+
68+
return 0;
69+
}
70+
71+
void MenuBlacklist_DisplayClear(int iClient)
72+
{
73+
Menu hMenu = new Menu(MenuBlacklist_SelectClear);
74+
75+
hMenu.SetTitle("Blacklist Menu\n \nAre you sure you want to clear your blacklist?\n ");
76+
hMenu.AddItem("yes", "Yes");
77+
hMenu.AddItem("no", "No");
78+
79+
hMenu.Display(iClient, MENU_TIME_FOREVER);
80+
}
81+
82+
public int MenuBlacklist_SelectClear(Menu hMenu, MenuAction action, int iClient, int iSelect)
83+
{
84+
if (action != MenuAction_Select) return 0;
85+
86+
char sSelect[32];
87+
hMenu.GetItem(iSelect, sSelect, sizeof(sSelect));
88+
89+
if (StrEqual(sSelect, "yes"))
90+
{
91+
Blacklist_Clear(iClient);
92+
PrintToChat(iClient, "%s%s Your blacklist has been cleared.", TEXT_TAG, TEXT_COLOR);
93+
}
94+
95+
MenuBlacklist_DisplayMain(iClient);
96+
return 0;
97+
}

0 commit comments

Comments
 (0)