Skip to content

Commit 6dcfe3a

Browse files
committed
Implement skins search
for #273
1 parent 1223332 commit 6dcfe3a

8 files changed

Lines changed: 347 additions & 0 deletions

File tree

addons/sourcemod/scripting/weapons.sp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <weapons>
2424
#undef REQUIRE_PLUGIN
2525
#include <updater>
26+
#include <regex>
2627

2728
#pragma semicolon 1
2829
#pragma newdecls required
@@ -88,6 +89,7 @@ public void OnPluginStart()
8889
g_Cvar_EnableNameTag = CreateConVar("sm_weapons_enable_nametag", "1", "Enable/Disable name tag options");
8990
g_Cvar_EnableStatTrak = CreateConVar("sm_weapons_enable_stattrak", "1", "Enable/Disable StatTrak options");
9091
g_Cvar_EnableSeed = CreateConVar("sm_weapons_enable_seed", "1", "Enable/Disable Seed options");
92+
g_Cvar_EnableSearch = CreateConVar("sm_weapons_enable_search", "1", "Enable/Disable Search Function");
9193
g_Cvar_FloatIncrementSize = CreateConVar("sm_weapons_float_increment_size", "0.05", "Increase/Decrease by value for weapon float");
9294
g_Cvar_EnableWeaponOverwrite = CreateConVar("sm_weapons_enable_overwrite", "1", "Enable/Disable players overwriting other players' weapons (picked up from the ground) by using !ws command");
9395
g_Cvar_GracePeriod = CreateConVar("sm_weapons_grace_period", "0", "Grace period in terms of seconds counted after round start for allowing the use of !ws command. 0 means no restrictions");
@@ -202,13 +204,26 @@ public Action CommandWeaponSkins(int client, int args)
202204
int menuTime;
203205
if((menuTime = GetRemainingGracePeriodSeconds(client)) >= 0)
204206
{
207+
if (args > 0) {
208+
209+
char searchSkinName[32];
210+
GetCmdArgString(searchSkinName, sizeof(searchSkinName));
211+
212+
Menu resultMenu = SearchSkins(client, searchSkinName);
213+
menuPlayerSearchTemp[client] = resultMenu;
214+
resultMenu.Display(client, menuTime);
215+
216+
return Plugin_Handled;
217+
}
218+
205219
CreateMainMenu(client).Display(client, menuTime);
206220
}
207221
else
208222
{
209223
PrintToChat(client, " %s \x02%t", g_ChatPrefix, "GracePeriod", g_iGracePeriod);
210224
}
211225
}
226+
212227
return Plugin_Handled;
213228
}
214229

addons/sourcemod/scripting/weapons/config.sp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public void ReadConfig()
5555
CloseHandle(kv);
5656
}
5757

58+
delete g_smSkinMenuMap[langCounter];
59+
g_smSkinMenuMap[langCounter] = new StringMap();
60+
5861
for (int k = 0; k < sizeof(g_WeaponClasses); k++)
5962
{
6063
if(menuWeapons[langCounter][k] != null)
@@ -70,6 +73,7 @@ public void ReadConfig()
7073

7174
int counter = 0;
7275
char weaponTemp[20];
76+
7377
do {
7478
char name[64];
7579
char index[5];
@@ -79,14 +83,67 @@ public void ReadConfig()
7983
KvGetString(kv, "classes", classes, sizeof(classes));
8084
KvGetString(kv, "index", index, sizeof(index));
8185

86+
Menu menuSkins[MAX_SKIN];
87+
8288
for (int k = 0; k < sizeof(g_WeaponClasses); k++)
8389
{
8490
Format(weaponTemp, sizeof(weaponTemp), "%s;", g_WeaponClasses[k]);
8591
if(StrContains(classes, weaponTemp) > -1)
8692
{
8793
menuWeapons[langCounter][k].AddItem(index, name);
94+
95+
if (g_bEnableSearch)
96+
{
97+
if (menuSkins[counter] == null)
98+
{
99+
menuSkins[counter] = new Menu(SkinsMenuHandler, MENU_ACTIONS_DEFAULT | MenuAction_DisplayItem);
100+
menuSkins[counter].SetTitle(name);
101+
menuSkins[counter].AddItem("-1", "Apply all");
102+
menuSkins[counter].AddItem("-2", "Apply current");
103+
menuSkins[counter].ExitBackButton = true;
104+
}
105+
106+
char weaponName[32];
107+
Format(weaponName, sizeof(weaponName), "%T (%s)", g_WeaponClasses[k], LANG_SERVER, index);
108+
char weaponIndexStr[32];
109+
Format(weaponIndexStr, sizeof(weaponIndexStr), "%d", k);
110+
menuSkins[counter].AddItem(weaponIndexStr, weaponName);
111+
}
112+
88113
}
89114
}
115+
116+
if (g_bEnableSearch)
117+
{
118+
for (int j = 0; j < MAX_SKIN; j++)
119+
{
120+
Menu currentMenu = menuSkins[j];
121+
if (currentMenu == null)continue;
122+
123+
char currentMenuName[32];
124+
currentMenu.GetTitle(currentMenuName, sizeof(currentMenuName));
125+
if (g_smSkinMenuMap[langCounter].ContainsKey(name))
126+
{
127+
Menu fatherMenu;
128+
g_smSkinMenuMap[langCounter].GetValue(name, fatherMenu);
129+
for (int l = 2; l < currentMenu.ItemCount; l++)
130+
{
131+
char info[32];
132+
char display[64];
133+
int a;
134+
currentMenu.GetItem(l, info, sizeof(info), a, display, sizeof(display));
135+
fatherMenu.AddItem(info, display);
136+
}
137+
138+
delete currentMenu;
139+
}
140+
else
141+
{
142+
g_smSkinMenuMap[langCounter].SetValue(name, currentMenu);
143+
}
144+
}
145+
}
146+
90147
counter++;
91148
} while (KvGotoNextKey(kv));
92149

addons/sourcemod/scripting/weapons/forwards.sp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void OnConfigsExecuted()
4444
g_bEnableNameTag = g_Cvar_EnableNameTag.BoolValue;
4545
g_bEnableStatTrak = g_Cvar_EnableStatTrak.BoolValue;
4646
g_bEnableSeed = g_Cvar_EnableSeed.BoolValue;
47+
g_bEnableSearch = g_Cvar_EnableSearch.BoolValue;
4748
g_fFloatIncrementSize = g_Cvar_FloatIncrementSize.FloatValue;
4849
g_iFloatIncrementPercentage = RoundFloat(g_fFloatIncrementSize * 100.0);
4950
g_bOverwriteEnabled = g_Cvar_EnableWeaponOverwrite.BoolValue;

addons/sourcemod/scripting/weapons/globals.sp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ int g_iKnifeIndices[] = {
4040
};
4141

4242
const int MAX_LANG = 40;
43+
const int MAX_SKIN = 1255;
4344

4445
Database db = null;
4546

@@ -74,6 +75,9 @@ bool g_bEnableStatTrak;
7475
ConVar g_Cvar_EnableSeed;
7576
bool g_bEnableSeed;
7677

78+
ConVar g_Cvar_EnableSearch;
79+
bool g_bEnableSearch;
80+
7781
ConVar g_Cvar_EnableWeaponOverwrite;
7882
bool g_bOverwriteEnabled;
7983

@@ -120,10 +124,12 @@ char g_MigrationWeapons[][] = {
120124
char g_Language[MAX_LANG][32];
121125
int g_iClientLanguage[MAXPLAYERS+1];
122126
Menu menuWeapons[MAX_LANG][sizeof(g_WeaponClasses)];
127+
Menu menuPlayerSearchTemp[MAXPLAYERS+1];
123128

124129
StringMap g_smWeaponIndex;
125130
StringMap g_smWeaponDefIndex;
126131
StringMap g_smLanguageIndex;
132+
StringMap g_smSkinMenuMap[MAX_LANG];
127133

128134
GlobalForward g_hOnKnifeSelect_Pre;
129135
GlobalForward g_hOnKnifeSelect_Post;

addons/sourcemod/scripting/weapons/helpers.sp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,34 @@ bool IsWarmUpPeriod()
262262
{
263263
return view_as<bool>(GameRules_GetProp("m_bWarmupPeriod"));
264264
}
265+
266+
int GetSkinIdFromSkinMenuDisplay(char display[32])
267+
{
268+
Regex regex = CompileRegex(".+ \\((.+)\\)");
269+
regex.Match(display);
270+
271+
char skinIdStr[32];
272+
regex.GetSubString(1, skinIdStr, sizeof(skinIdStr));
273+
return StringToInt(skinIdStr);
274+
}
275+
276+
Menu SearchSkins(int client, char skinName[32])
277+
{
278+
StringMapSnapshot snapshot = g_smSkinMenuMap[g_iClientLanguage[client]].Snapshot();
279+
menuPlayerSearchTemp[client] = null;
280+
Menu result = new Menu(SearchMenuHandler, MENU_ACTIONS_DEFAULT);
281+
282+
for (int i = 0; i < snapshot.Length; i++)
283+
{
284+
char name[32]
285+
snapshot.GetKey(i, name, sizeof(name));
286+
287+
// if current menu is the menu we searched for
288+
if (StrContains(skinName, name, false) > -1 || StrContains(name, skinName, false) > -1)
289+
{
290+
result.AddItem(name, name);
291+
}
292+
}
293+
294+
return result;
295+
}

0 commit comments

Comments
 (0)