Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement skins search #274

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions addons/sourcemod/scripting/weapons.sp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <weapons>
#undef REQUIRE_PLUGIN
#include <updater>
#include <regex>

#pragma semicolon 1
#pragma newdecls required
Expand Down Expand Up @@ -88,6 +89,7 @@ public void OnPluginStart()
g_Cvar_EnableNameTag = CreateConVar("sm_weapons_enable_nametag", "1", "Enable/Disable name tag options");
g_Cvar_EnableStatTrak = CreateConVar("sm_weapons_enable_stattrak", "1", "Enable/Disable StatTrak options");
g_Cvar_EnableSeed = CreateConVar("sm_weapons_enable_seed", "1", "Enable/Disable Seed options");
g_Cvar_EnableSearch = CreateConVar("sm_weapons_enable_search", "1", "Enable/Disable Search Function");
g_Cvar_FloatIncrementSize = CreateConVar("sm_weapons_float_increment_size", "0.05", "Increase/Decrease by value for weapon float");
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");
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");
Expand Down Expand Up @@ -202,13 +204,33 @@ public Action CommandWeaponSkins(int client, int args)
int menuTime;
if((menuTime = GetRemainingGracePeriodSeconds(client)) >= 0)
{
if (args > 0) {

if (g_bEnableSearch)
{
char searchSkinName[32];
GetCmdArgString(searchSkinName, sizeof(searchSkinName));

Menu resultMenu = SearchSkins(client, searchSkinName);
menuPlayerSearchTemp[client] = resultMenu;
resultMenu.Display(client, menuTime);
}
else
{
PrintToChat(client, " %s \x02%T", g_ChatPrefix, "SearchDisabled");
}
return Plugin_Handled;

}

CreateMainMenu(client).Display(client, menuTime);
}
else
{
PrintToChat(client, " %s \x02%t", g_ChatPrefix, "GracePeriod", g_iGracePeriod);
}
}

return Plugin_Handled;
}

Expand Down
57 changes: 57 additions & 0 deletions addons/sourcemod/scripting/weapons/config.sp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void ReadConfig()
CloseHandle(kv);
}

delete g_smSkinMenuMap[langCounter];
g_smSkinMenuMap[langCounter] = new StringMap();

for (int k = 0; k < sizeof(g_WeaponClasses); k++)
{
if(menuWeapons[langCounter][k] != null)
Expand All @@ -70,6 +73,7 @@ public void ReadConfig()

int counter = 0;
char weaponTemp[20];

do {
char name[64];
char index[5];
Expand All @@ -79,14 +83,67 @@ public void ReadConfig()
KvGetString(kv, "classes", classes, sizeof(classes));
KvGetString(kv, "index", index, sizeof(index));

Menu menuSkins[MAX_SKIN];

for (int k = 0; k < sizeof(g_WeaponClasses); k++)
{
Format(weaponTemp, sizeof(weaponTemp), "%s;", g_WeaponClasses[k]);
if(StrContains(classes, weaponTemp) > -1)
{
menuWeapons[langCounter][k].AddItem(index, name);

if (g_bEnableSearch)
{
if (menuSkins[counter] == null)
{
menuSkins[counter] = new Menu(SkinsMenuHandler, MENU_ACTIONS_DEFAULT | MenuAction_DisplayItem);
menuSkins[counter].SetTitle(name);
menuSkins[counter].AddItem("-1", "Apply all");
menuSkins[counter].AddItem("-2", "Apply current");
menuSkins[counter].ExitBackButton = true;
}

char weaponName[32];
Format(weaponName, sizeof(weaponName), "%T (%s)", g_WeaponClasses[k], LANG_SERVER, index);
char weaponIndexStr[32];
Format(weaponIndexStr, sizeof(weaponIndexStr), "%d", k);
menuSkins[counter].AddItem(weaponIndexStr, weaponName);
}

}
}

if (g_bEnableSearch)
{
for (int j = 0; j < MAX_SKIN; j++)
{
Menu currentMenu = menuSkins[j];
if (currentMenu == null)continue;

char currentMenuName[32];
currentMenu.GetTitle(currentMenuName, sizeof(currentMenuName));
if (g_smSkinMenuMap[langCounter].ContainsKey(name))
{
Menu fatherMenu;
g_smSkinMenuMap[langCounter].GetValue(name, fatherMenu);
for (int l = 2; l < currentMenu.ItemCount; l++)
{
char info[32];
char display[64];
int a;
currentMenu.GetItem(l, info, sizeof(info), a, display, sizeof(display));
fatherMenu.AddItem(info, display);
}

delete currentMenu;
}
else
{
g_smSkinMenuMap[langCounter].SetValue(name, currentMenu);
}
}
}

counter++;
} while (KvGotoNextKey(kv));

Expand Down
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/weapons/forwards.sp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void OnConfigsExecuted()
g_bEnableNameTag = g_Cvar_EnableNameTag.BoolValue;
g_bEnableStatTrak = g_Cvar_EnableStatTrak.BoolValue;
g_bEnableSeed = g_Cvar_EnableSeed.BoolValue;
g_bEnableSearch = g_Cvar_EnableSearch.BoolValue;
g_fFloatIncrementSize = g_Cvar_FloatIncrementSize.FloatValue;
g_iFloatIncrementPercentage = RoundFloat(g_fFloatIncrementSize * 100.0);
g_bOverwriteEnabled = g_Cvar_EnableWeaponOverwrite.BoolValue;
Expand Down
6 changes: 6 additions & 0 deletions addons/sourcemod/scripting/weapons/globals.sp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int g_iKnifeIndices[] = {
};

const int MAX_LANG = 40;
const int MAX_SKIN = 1255;

Database db = null;

Expand Down Expand Up @@ -74,6 +75,9 @@ bool g_bEnableStatTrak;
ConVar g_Cvar_EnableSeed;
bool g_bEnableSeed;

ConVar g_Cvar_EnableSearch;
bool g_bEnableSearch;

ConVar g_Cvar_EnableWeaponOverwrite;
bool g_bOverwriteEnabled;

Expand Down Expand Up @@ -120,10 +124,12 @@ char g_MigrationWeapons[][] = {
char g_Language[MAX_LANG][32];
int g_iClientLanguage[MAXPLAYERS+1];
Menu menuWeapons[MAX_LANG][sizeof(g_WeaponClasses)];
Menu menuPlayerSearchTemp[MAXPLAYERS+1];

StringMap g_smWeaponIndex;
StringMap g_smWeaponDefIndex;
StringMap g_smLanguageIndex;
StringMap g_smSkinMenuMap[MAX_LANG];

GlobalForward g_hOnKnifeSelect_Pre;
GlobalForward g_hOnKnifeSelect_Post;
31 changes: 31 additions & 0 deletions addons/sourcemod/scripting/weapons/helpers.sp
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,34 @@ bool IsWarmUpPeriod()
{
return view_as<bool>(GameRules_GetProp("m_bWarmupPeriod"));
}

int GetSkinIdFromSkinMenuDisplay(char display[32])
{
Regex regex = CompileRegex(".+ \\((.+)\\)");
regex.Match(display);

char skinIdStr[32];
regex.GetSubString(1, skinIdStr, sizeof(skinIdStr));
return StringToInt(skinIdStr);
}

Menu SearchSkins(int client, char skinName[32])
{
StringMapSnapshot snapshot = g_smSkinMenuMap[g_iClientLanguage[client]].Snapshot();
menuPlayerSearchTemp[client] = null;
Menu result = new Menu(SearchMenuHandler, MENU_ACTIONS_DEFAULT);

for (int i = 0; i < snapshot.Length; i++)
{
char name[32]
snapshot.GetKey(i, name, sizeof(name));

// if current menu is the menu we searched for
if (StrContains(skinName, name, false) > -1 || StrContains(name, skinName, false) > -1)
{
result.AddItem(name, name);
}
}

return result;
}
Loading