Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
samyycX authored May 29, 2023
2 parents 1b0249f + e702a2b commit 7b8fce2
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore a pasta plugins
plugins
28 changes: 14 additions & 14 deletions addons/sourcemod/scripting/weapons.sp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* CS:GO Weapons&Knives SourceMod Plugin
/* CS:GO Weapons&Knives SourceMod Plugin
*
* Copyright (C) 2017 Kağan 'kgns' Üstüngel
* Copyright (C) 2017 Kağan 'kgns' Üstüngel
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
Expand Down Expand Up @@ -39,15 +39,14 @@

#define UPDATE_URL "https://raw.githubusercontent.com/kgns/weapons/master/addons/sourcemod/updatefile.txt"


//#define DEBUG

public Plugin myinfo =
{
name = "Weapons & Knives",
author = "kgns | oyunhost.net",
description = "All in one CS:GO weapon skin management",
version = "1.7.7",
version = "1.7.8",
url = "https://github.com/kgns"
};

Expand Down Expand Up @@ -81,30 +80,31 @@ public void OnPluginStart()

LoadTranslations("weapons.phrases");

g_Cvar_DBConnection = CreateConVar("sm_weapons_db_connection", "storage-local", "Database connection name in databases.cfg to use");
g_Cvar_TablePrefix = CreateConVar("sm_weapons_table_prefix", "", "Prefix for database table (example: 'xyz_')");
g_Cvar_ChatPrefix = CreateConVar("sm_weapons_chat_prefix", "[oyunhost.net]", "Prefix for chat messages");
g_Cvar_KnifeStatTrakMode = CreateConVar("sm_weapons_knife_stattrak_mode", "0", "0: All knives show the same StatTrak counter (total knife kills) 1: Each type of knife shows its own separate StatTrak counter");
g_Cvar_EnableFloat = CreateConVar("sm_weapons_enable_float", "1", "Enable/Disable weapon float options");
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_DBConnection = CreateConVar("sm_weapons_db_connection", "storage-local", "Database connection name in databases.cfg to use");
g_Cvar_TablePrefix = CreateConVar("sm_weapons_table_prefix", "", "Prefix for database table (example: 'xyz_')");
g_Cvar_ChatPrefix = CreateConVar("sm_weapons_chat_prefix", "[oyunhost.net]", "Prefix for chat messages");
g_Cvar_KnifeStatTrakMode = CreateConVar("sm_weapons_knife_stattrak_mode", "0", "0: All knives show the same StatTrak counter (total knife kills) 1: Each type of knife shows its own separate StatTrak counter");
g_Cvar_EnableFloat = CreateConVar("sm_weapons_enable_float", "1", "Enable/Disable weapon float options");
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");
g_Cvar_InactiveDays = CreateConVar("sm_weapons_inactive_days", "30", "Number of days before a player (SteamID) is marked as inactive and his data is deleted. (0 or any negative value to disable deleting)");
g_Cvar_EnableC4 = CreateConVar("sm_weapons_enable_c4", "1", "Enable/Disable C4 Skins");
g_Cvar_EnableAllSkins = CreateConVar("sm_weapons_enable_all_skins", "1", "Enable/Disable showing all skins in menu");

AutoExecConfig(true, "weapons");

RegConsoleCmd("buyammo1", CommandWeaponSkins);
RegConsoleCmd("sm_ws", CommandWeaponSkins);
RegConsoleCmd("buyammo2", CommandKnife);
RegConsoleCmd("sm_knife", CommandKnife);
RegConsoleCmd("sm_kf", CommandKnife);
RegConsoleCmd("sm_nametag", CommandNameTag);
RegConsoleCmd("sm_wslang", CommandWSLang);
RegConsoleCmd("sm_seed", CommandSeedMenu);

RegAdminCmd("sm_wsreset", CommandResetWeaponSkins, ADMFLAG_ROOT, "Resets weapon skins and knife of a specific player.");

PTaH(PTaH_GiveNamedItemPre, Hook, GiveNamedItemPre);
Expand Down Expand Up @@ -332,7 +332,7 @@ void SetWeaponProps(int client, int entity)
static int IDHigh = 16384;
SetEntProp(entity, Prop_Send, "m_iItemIDLow", -1);
SetEntProp(entity, Prop_Send, "m_iItemIDHigh", IDHigh++);
SetEntProp(entity, Prop_Send, "m_nFallbackPaintKit", g_iSkins[client][index] == -1 ? GetRandomSkin(client, index) : g_iSkins[client][index]);
SetEntProp(entity, Prop_Send, "m_nFallbackPaintKit", g_iSkins[client][index] == -1 ? GetRandomSkin(client, index) : g_iSkins[client][index] == -2 ? GetRandomAllSkin(client, index) : g_iSkins[client][index]);
SetEntPropFloat(entity, Prop_Send, "m_flFallbackWear", !g_bEnableFloat || g_fFloatValue[client][index] == 0.0 ? 0.000001 : g_fFloatValue[client][index] == 1.0 ? 0.999999 : g_fFloatValue[client][index]);
if (g_bEnableSeed && g_iWeaponSeed[client][index] != -1)
{
Expand Down
26 changes: 26 additions & 0 deletions addons/sourcemod/scripting/weapons/config.sp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ public void ReadConfig()
menuWeapons[langCounter][k].AddItem("-1", "Random");
menuWeapons[langCounter][k].ExitBackButton = true;
}

if(g_bAllSkins) {
for (int k = 0; k < sizeof(g_WeaponClasses); k++)
{
if(menuWeaponsAll[langCounter][k] != null)
{
delete menuWeaponsAll[langCounter][k];
}
menuWeaponsAll[langCounter][k] = new Menu(WeaponsMenuAllHandler, MENU_ACTIONS_DEFAULT|MenuAction_DisplayItem);
menuWeaponsAll[langCounter][k].SetTitle("%T (%T)", g_WeaponClasses[k], LANG_SERVER, "AllSkins", LANG_SERVER);
menuWeaponsAll[langCounter][k].AddItem("0", "Default");
menuWeaponsAll[langCounter][k].AddItem("-2", "Random");
menuWeaponsAll[langCounter][k].ExitBackButton = true;
}
}

int counter = 0;
char weaponTemp[20];
Expand All @@ -78,6 +93,7 @@ public void ReadConfig()
char name[64];
char index[5];
char classes[1024];
int weaponIndex;

KvGetSectionName(kv, name, sizeof(name));
KvGetString(kv, "classes", classes, sizeof(classes));
Expand Down Expand Up @@ -110,6 +126,16 @@ public void ReadConfig()
menuSkins[counter].AddItem(weaponIndexStr, weaponName);
}

weaponIndex = k;
}
}

if(g_bAllSkins) {
char nameWeapon[64];
Format(nameWeapon, sizeof(nameWeapon), "%s (%T)", name, g_WeaponClasses[weaponIndex], LANG_SERVER);
for (int k = 0; k < sizeof(g_WeaponClasses); k++)
{
menuWeaponsAll[langCounter][k].AddItem(index, nameWeapon);
}
}

Expand Down
18 changes: 15 additions & 3 deletions addons/sourcemod/scripting/weapons/database.sp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,14 @@ void CreateMainTable(bool mysql, bool recreate = false)
knife_skeleton_trak int(1) NOT NULL DEFAULT '0', \
knife_skeleton_trak_count int(10) NOT NULL DEFAULT '0', \
knife_skeleton_tag varchar(256) NOT NULL DEFAULT '', \
knife_skeleton_seed int(10) NOT NULL DEFAULT '-1')");
knife_skeleton_seed int(10) NOT NULL DEFAULT '-1', ");
index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
c4 int(4) NOT NULL DEFAULT '0', \
c4_float decimal(3,2) NOT NULL DEFAULT '0.0', \
c4_trak int(1) NOT NULL DEFAULT '0', \
c4_trak_count int(10) NOT NULL DEFAULT '0', \
c4_tag varchar(256) NOT NULL DEFAULT '', \
c4_seed int(10) NOT NULL DEFAULT '-1')");

if (mysql)
{
Expand Down Expand Up @@ -552,7 +559,10 @@ public void T_ReCreateMainTableCallback(Database database, DBResultSet results,
knife_gypsy_jackknife_trak_count, knife_gypsy_jackknife_tag, knife_stiletto, knife_stiletto_float, knife_stiletto_trak, \
knife_stiletto_trak_count, knife_stiletto_tag, knife_widowmaker, knife_widowmaker_float, knife_widowmaker_trak, \
knife_widowmaker_trak_count, knife_widowmaker_tag, mp5sd, mp5sd_float, mp5sd_trak, mp5sd_trak_count, mp5sd_tag, knife_css, \
knife_css_float, knife_css_trak, knife_css_trak_count, knife_css_tag, knife_css_seed) \
knife_css_float, knife_css_trak, knife_css_trak_count, knife_css_tag, knife_css_seed, ");
index += FormatEx(migrateQuery[index], sizeof(migrateQuery) - index, " \
c4, \
c4_float, c4_trak, c4_trak_count, c4_tag, c4_seed) \
SELECT * FROM %sweapons_tmp", g_TablePrefix);

db.Query(T_MigrateOldDataCallback, migrateQuery, mysql, DBPrio_High);
Expand Down Expand Up @@ -609,6 +619,7 @@ public void T_CreateMainTableCallback(Database database, DBResultSet results, co
{
g_iMigrationStep = 0;
AddWeaponColumns(mysql, "knife_ursus", false);
AddWeaponColumns(mysql, "c4", true);

char createQuery[512];
Format(createQuery, sizeof(createQuery), " \
Expand Down Expand Up @@ -695,7 +706,8 @@ public void T_SeedColumnCallback(Database database, DBResultSet results, const c
ADD COLUMN knife_gypsy_jackknife_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_gypsy_jackknife_tag, \
ADD COLUMN knife_stiletto_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_stiletto_tag, \
ADD COLUMN knife_widowmaker_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_widowmaker_tag, \
ADD COLUMN mp5sd_seed int(10) NOT NULL DEFAULT '-1' AFTER mp5sd_tag");
ADD COLUMN mp5sd_seed int(10) NOT NULL DEFAULT '-1' AFTER mp5sd_tag, \
ADD COLUMN c4_seed int(10) NOT NULL DEFAULT '-1' AFTER c4_tag");

db.Query(T_SeedConfirmationCallback, seedColumnsQuery, mysql, DBPrio_High);
}
Expand Down
2 changes: 2 additions & 0 deletions addons/sourcemod/scripting/weapons/forwards.sp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public void OnConfigsExecuted()
g_iFloatIncrementPercentage = RoundFloat(g_fFloatIncrementSize * 100.0);
g_bOverwriteEnabled = g_Cvar_EnableWeaponOverwrite.BoolValue;
g_iGracePeriod = g_Cvar_GracePeriod.IntValue;
g_bEnableC4 = g_Cvar_EnableC4.BoolValue;
g_bAllSkins = g_Cvar_EnableAllSkins.BoolValue;
if(g_iGracePeriod > 0)
{
HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
Expand Down
11 changes: 9 additions & 2 deletions addons/sourcemod/scripting/weapons/globals.sp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ char g_WeaponClasses[][] = {
/*28*/ "weapon_ssg08", /*29*/ "weapon_aug", /*30*/ "weapon_sg556", /*31*/ "weapon_scar20", /*32*/ "weapon_g3sg1", /*33*/ "weapon_knife_karambit", /*34*/ "weapon_knife_m9_bayonet", /*35*/ "weapon_bayonet",
/*36*/ "weapon_knife_survival_bowie", /*37*/ "weapon_knife_butterfly", /*38*/ "weapon_knife_flip", /*39*/ "weapon_knife_push", /*40*/ "weapon_knife_tactical", /*41*/ "weapon_knife_falchion", /*42*/ "weapon_knife_gut",
/*43*/ "weapon_knife_ursus", /*44*/ "weapon_knife_gypsy_jackknife", /*45*/ "weapon_knife_stiletto", /*46*/ "weapon_knife_widowmaker", /*47*/ "weapon_mp5sd", /*48*/ "weapon_knife_css", /*49*/ "weapon_knife_cord",
/*50*/ "weapon_knife_canis", /*51*/ "weapon_knife_outdoor", /*52*/ "weapon_knife_skeleton"
/*50*/ "weapon_knife_canis", /*51*/ "weapon_knife_outdoor", /*52*/ "weapon_knife_skeleton", /*53*/ "weapon_c4"
};

int g_iWeaponDefIndex[] = {
Expand All @@ -32,7 +32,7 @@ int g_iWeaponDefIndex[] = {
/*28*/ 40, /*29*/ 8, /*30*/ 39, /*31*/ 38, /*32*/ 11, /*33*/ 507, /*34*/ 508, /*35*/ 500,
/*36*/ 514, /*37*/ 515, /*38*/ 505, /*39*/ 516, /*40*/ 509, /*41*/ 512, /*42*/ 506,
/*43*/ 519, /*44*/ 520, /*45*/ 522, /*46*/ 523, /*47*/ 23, /*48*/ 503, /*49*/ 517,
/*50*/ 518, /*51*/ 521, /*52*/ 525
/*50*/ 518, /*51*/ 521, /*52*/ 525, /*53*/ 49
};

int g_iKnifeIndices[] = {
Expand Down Expand Up @@ -87,6 +87,12 @@ int g_iGracePeriod;
ConVar g_Cvar_InactiveDays;
int g_iGraceInactiveDays;

ConVar g_Cvar_EnableC4;
int g_bEnableC4;

ConVar g_Cvar_EnableAllSkins;
int g_bAllSkins;

int g_iSkins[MAXPLAYERS+1][sizeof(g_WeaponClasses)];
int g_iStatTrak[MAXPLAYERS+1][sizeof(g_WeaponClasses)];
int g_iStatTrakCount[MAXPLAYERS+1][sizeof(g_WeaponClasses)];
Expand Down Expand Up @@ -124,6 +130,7 @@ char g_MigrationWeapons[][] = {
char g_Language[MAX_LANG][32];
int g_iClientLanguage[MAXPLAYERS+1];
Menu menuWeapons[MAX_LANG][sizeof(g_WeaponClasses)];
Menu menuWeaponsAll[MAX_LANG][sizeof(g_WeaponClasses)];
Menu menuPlayerSearchTemp[MAXPLAYERS+1];

StringMap g_smWeaponIndex;
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,15 @@ int GetRandomSkin(int client, int index)
return StringToInt(idStr);
}

int GetRandomAllSkin(int client, int index)
{
int max = menuWeaponsAll[g_iClientLanguage[client]][index].ItemCount;
int random = GetRandomInt(2, max);
char idStr[6];
menuWeaponsAll[g_iClientLanguage[client]][index].GetItem(random, idStr, sizeof(idStr));
return StringToInt(idStr);
}

int GetRandomKnife()
{
return g_iKnifeIndices[GetRandomInt(0, sizeof(g_iKnifeIndices) - 1)];
Expand Down
93 changes: 90 additions & 3 deletions addons/sourcemod/scripting/weapons/menus.sp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* CS:GO Weapons&Knives SourceMod Plugin
/* CS:GO Weapons&Knives SourceMod Plugin
*
* Copyright (C) 2017 Kağan 'kgns' Üstüngel
* Copyright (C) 2017 Kağan 'kgns' Üstüngel
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
Expand Down Expand Up @@ -63,6 +63,76 @@ public int WeaponsMenuHandler(Menu menu, MenuAction action, int client, int sele
Format(display, sizeof(display), "%T", "RandomSkin", client);
return RedrawMenuItem(display);
}
else if (StrEqual(info, "-2"))
{
Format(display, sizeof(display), "%T", "RandomAllSkin", client);
return RedrawMenuItem(display);
}
}
}
case MenuAction_Cancel:
{
if (IsClientInGame(client) && selection == MenuCancel_ExitBack)
{
int menuTime;
if((menuTime = GetRemainingGracePeriodSeconds(client)) >= 0)
{
CreateWeaponMenu(client).Display(client, menuTime);
}
}
}
}
return 0;
}

public int WeaponsMenuAllHandler(Menu menu, MenuAction action, int client, int selection)
{
switch(action)
{
case MenuAction_Select:
{
if(IsClientInGame(client))
{
int index = g_iIndex[client];

char skinIdStr[32];
menu.GetItem(selection, skinIdStr, sizeof(skinIdStr));
int skinId = StringToInt(skinIdStr);

g_iSkins[client][index] = skinId;
char updateFields[256];
char weaponName[32];
RemoveWeaponPrefix(g_WeaponClasses[index], weaponName, sizeof(weaponName));
Format(updateFields, sizeof(updateFields), "%s = %d", weaponName, skinId);
UpdatePlayerData(client, updateFields);

RefreshWeapon(client, index);

DataPack pack;
CreateDataTimer(0.5, WeaponsMenuTimer, pack);
pack.WriteCell(menu);
pack.WriteCell(GetClientUserId(client));
pack.WriteCell(GetMenuSelectionPosition());
}
}
case MenuAction_DisplayItem:
{
if(IsClientInGame(client))
{
char info[32];
char display[64];
menu.GetItem(selection, info, sizeof(info));

if (StrEqual(info, "0"))
{
Format(display, sizeof(display), "%T", "DefaultSkin", client);
return RedrawMenuItem(display);
}
else if (StrEqual(info, "-2"))
{
Format(display, sizeof(display), "%T", "RandomSkin", client);
return RedrawMenuItem(display);
}
}
}
case MenuAction_Cancel:
Expand Down Expand Up @@ -115,6 +185,14 @@ public int WeaponMenuHandler(Menu menu, MenuAction action, int client, int selec
menuWeapons[g_iClientLanguage[client]][g_iIndex[client]].Display(client, menuTime);
}
}
if(StrEqual(buffer, "skinall"))
{
int menuTime;
if((menuTime = GetRemainingGracePeriodSeconds(client)) >= 0)
{
menuWeaponsAll[g_iClientLanguage[client]][g_iIndex[client]].Display(client, menuTime);
}
}
else if(StrEqual(buffer, "float"))
{
int menuTime;
Expand Down Expand Up @@ -291,7 +369,6 @@ public int FloatMenuHandler(Menu menu, MenuAction action, int client, int select

public Action FloatTimer(Handle timer, DataPack pack)
{

ResetPack(pack);
int clientIndex = GetClientOfUserId(pack.ReadCell());
int index = pack.ReadCell();
Expand Down Expand Up @@ -632,6 +709,7 @@ Menu CreateAllWeaponsMenu(int client)
char name[32];
for (int i = 0; i < sizeof(g_WeaponClasses); i++)
{
if (!g_bEnableC4 && StrEqual(g_WeaponClasses[i], "weapon_c4")) continue;
Format(name, sizeof(name), "%T", g_WeaponClasses[i], client);
menu.AddItem(g_WeaponClasses[i], name);
}
Expand Down Expand Up @@ -689,6 +767,14 @@ Menu CreateWeaponMenu(int client)

Format(buffer, sizeof(buffer), "%T", "SetSkin", client);
menu.AddItem("skin", buffer);

// VIP Access - Thanks to Kento(https://github.com/rogeraabbccdd)
if(g_bAllSkins){
if(CheckCommandAccess (client, "sm_weapons_all_vip", ADMFLAG_RESERVATION, true)){
Format(buffer, sizeof(buffer), "%T (%T)", "SetSkin", client, "AllSkins", client);
menu.AddItem("skinall", buffer);
}
}

bool weaponHasSkin = (g_iSkins[client][index] != 0);

Expand Down Expand Up @@ -797,6 +883,7 @@ Menu CreateMainMenu(int client)
int weaponEntity = GetEntPropEnt(client, Prop_Send, "m_hMyWeapons", i);
if(weaponEntity != -1 && GetWeaponClass(weaponEntity, weaponClass, sizeof(weaponClass)))
{
if (!g_bEnableC4 && StrEqual(weaponClass, "weapon_c4")) continue;
Format(weaponName, sizeof(weaponName), "%T", weaponClass, client);
menu.AddItem(weaponClass, weaponName, (IsKnifeClass(weaponClass) && g_iKnife[client] == 0) ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
}
Expand Down
Loading

0 comments on commit 7b8fce2

Please sign in to comment.