Skip to content

Commit

Permalink
Merge pull request #240 from kgns/feature/random_knife
Browse files Browse the repository at this point in the history
added random option for knife selection
  • Loading branch information
kgns authored Oct 31, 2021
2 parents ba8d0a6 + 4d814b6 commit e75f912
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions addons/sourcemod/scripting/weapons/globals.sp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ int g_iWeaponDefIndex[] = {
/*50*/ 518, /*51*/ 521, /*52*/ 525
};

int g_iKnifeIndices[] = {
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52
};

const int MAX_LANG = 40;

Database db = null;
Expand Down
9 changes: 9 additions & 0 deletions addons/sourcemod/scripting/weapons/helpers.sp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ int GetRandomSkin(int client, int index)
return StringToInt(idStr);
}

int GetRandomKnife()
{
return g_iKnifeIndices[GetRandomInt(0, sizeof(g_iKnifeIndices))];
}

bool IsValidClient(int client)
{
if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || IsFakeClient(client) || IsClientSourceTV(client) || IsClientReplay(client))
Expand Down Expand Up @@ -201,6 +206,10 @@ void GetClientKnife(int client, char[] KnifeName, int Size)
{
Format(KnifeName, Size, "weapon_knife");
}
else if(g_iKnife[client] == -1)
{
Format(KnifeName, Size, "random");
}
else
{
Format(KnifeName, Size, g_WeaponClasses[g_iKnife[client]]);
Expand Down
9 changes: 8 additions & 1 deletion addons/sourcemod/scripting/weapons/hooks.sp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ Action GiveNamedItemPre(int client, char classname[64], CEconItemView &item, boo
if (g_iKnife[client] != 0 && IsKnifeClass(classname))
{
ignoredCEconItemView = true;
strcopy(classname, sizeof(classname), g_WeaponClasses[g_iKnife[client]]);
if (g_iKnife[client] == -1)
{
strcopy(classname, sizeof(classname), g_WeaponClasses[GetRandomKnife()]);
}
else
{
strcopy(classname, sizeof(classname), g_WeaponClasses[g_iKnife[client]]);
}
return Plugin_Changed;
}
}
Expand Down
11 changes: 9 additions & 2 deletions addons/sourcemod/scripting/weapons/menus.sp
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ Menu CreateKnifeMenu(int client)
char buffer[60];
Format(buffer, sizeof(buffer), "%T", "OwnKnife", client);
menu.AddItem("0", buffer, g_iKnife[client] != 0 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
Format(buffer, sizeof(buffer), "%T", "RandomKnife", client);
menu.AddItem("-1", buffer, g_iKnife[client] != -1 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
Format(buffer, sizeof(buffer), "%T", "weapon_knife_cord", client);
menu.AddItem("49", buffer, g_iKnife[client] != 49 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
Format(buffer, sizeof(buffer), "%T", "weapon_knife_canis", client);
Expand Down Expand Up @@ -909,6 +911,11 @@ public int KnifeMenuHandler(Menu menu, MenuAction menuaction, int client, int se
char knifeIdStr[32];
menu.GetItem(selection, knifeIdStr, sizeof(knifeIdStr));
int knifeId = StringToInt(knifeIdStr);
int knifeDB = knifeId;
if (knifeId == -1)
{
knifeId = GetRandomKnife();
}

Action action = Plugin_Continue;
Call_StartForward(g_hOnKnifeSelect_Pre);
Expand All @@ -929,9 +936,9 @@ public int KnifeMenuHandler(Menu menu, MenuAction menuaction, int client, int se
return;
}

g_iKnife[client] = knifeId;
g_iKnife[client] = knifeDB;
char updateFields[50];
Format(updateFields, sizeof(updateFields), "knife = %d", knifeId);
Format(updateFields, sizeof(updateFields), "knife = %d", knifeDB);
UpdatePlayerData(client, updateFields);

RefreshWeapon(client, knifeId, knifeId == 0);
Expand Down
4 changes: 4 additions & 0 deletions addons/sourcemod/translations/tr/weapons.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
{
"tr" "★ Kendi bıçağın"
}
"RandomKnife"
{
"tr" "★ Rastgele bıçak"
}
"SetSkin"
{
"tr" "Skin Seç"
Expand Down
4 changes: 4 additions & 0 deletions addons/sourcemod/translations/weapons.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
{
"en" "★ Your own knife"
}
"RandomKnife"
{
"en" "★ Random knife"
}
"SetSkin"
{
"en" "Choose Skin"
Expand Down

0 comments on commit e75f912

Please sign in to comment.