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

Added "Pressets" feature! #228

Open
wants to merge 10 commits into
base: dev
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
59 changes: 59 additions & 0 deletions addons/sourcemod/configs/weapons_presets.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"Skins"
{
"Random Skins All Weapons"
{
"weapon_awp" "-1"
"weapon_ak47" "-1"
"weapon_m4a1" "-1"
"weapon_m4a1_silencer" "-1"
"weapon_deagle" "-1"
"weapon_usp_silencer" "-1"
"weapon_hkp2000" "-1"
"weapon_glock" "-1"
"weapon_elite" "-1"
"weapon_p250" "-1"
"weapon_cz75a" "-1"
"weapon_fiveseven" "-1"
"weapon_tec9" "-1"
"weapon_revolver" "-1"
"weapon_nova" "-1"
"weapon_xm1014" "-1"
"weapon_mag7" "-1"
"weapon_sawedoff" "-1"
"weapon_m249" "-1"
"weapon_negev" "-1"
"weapon_mp9" "-1"
"weapon_mac10" "-1"
"weapon_mp7" "-1"
"weapon_ump45" "-1"
"weapon_p90" "-1"
"weapon_bizon" "-1"
"weapon_famas" "-1"
"weapon_galilar" "-1"
"weapon_ssg08" "-1"
"weapon_aug" "-1"
"weapon_sg556" "-1"
"weapon_scar20" "-1"
"weapon_g3sg1" "-1"
"weapon_knife_karambit" "-1"
"weapon_knife_m9_bayonet" "-1"
"weapon_bayonet" "-1"
"weapon_knife_survival_bowie" "-1"
"weapon_knife_butterfly" "-1"
"weapon_knife_flip" "-1"
"weapon_knife_push" "-1"
"weapon_knife_tactical" "-1"
"weapon_knife_falchion" "-1"
"weapon_knife_gut" "-1"
"weapon_knife_ursus" "-1"
"weapon_knife_gypsy_jackknife" "-1"
"weapon_knife_stiletto" "-1"
"weapon_knife_widowmaker" "-1"
"weapon_mp5sd" "-1"
"weapon_knife_css" "-1"
"weapon_knife_cord" "-1"
"weapon_knife_canis" "-1"
"weapon_knife_outdoor" "-1"
"weapon_knife_skeleton" "-1"
}
}
Binary file added addons/sourcemod/plugins/test_natives.smx
Binary file not shown.
Binary file added addons/sourcemod/plugins/weapons.smx
Binary file not shown.
15 changes: 15 additions & 0 deletions addons/sourcemod/scripting/include/weapons.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ forward Action Weapons_OnClientKnifeSelectPre(int client, int knifeId, char[] kn

//Called after client selects a knife from !knife.
forward void Weapons_OnClientKnifeSelectPost(int client, int knifeId, char[] knifeName);

//Sets client's skins for a weapons.
native void Weapons_SetClientSkin(int client, const char[] weapon, int skin);

// Set client's float(wear) for a weapon.
native void Weapons_SetClientWear(int client, const char[] weapon, float wear);

// Set client's seed for a weapon.
native void Weapons_SetClientSeed(int client, const char[] weapon, int seed);

// Set client's nametag for a weapon
native void Weapons_SetClientNameTag(int client, const char[] weapon, const char[] name);

// Set client's startrack for a weapon
native void Weapons_ToggleClientStarTrack(int client, const char[] weapon);
12 changes: 10 additions & 2 deletions addons/sourcemod/scripting/weapons.sp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "weapons/config.sp"
#include "weapons/menus.sp"
#include "weapons/natives.sp"
#include "weapons/presets.sp"

//#define DEBUG

Expand All @@ -41,7 +42,7 @@ public Plugin myinfo =
name = "Weapons & Knives",
author = "kgns | oyunhost.net",
description = "All in one weapon skin management",
version = "1.7.3",
version = "1.7.5",
url = "https://www.oyunhost.net"
};

Expand All @@ -51,6 +52,11 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max

CreateNative("Weapons_SetClientKnife", Weapons_SetClientKnife_Native);
CreateNative("Weapons_GetClientKnife", Weapons_GetClientKnife_Native);
CreateNative("Weapons_SetClientSkin", Weapons_SetClientSkin_Native);
CreateNative("Weapons_SetClientWear", Weapons_SetClientWear_Native);
CreateNative("Weapons_SetClientSeed", Weapons_SetClientSeed_Native);
CreateNative("Weapons_SetClientNameTag", Weapons_SetClientNameTag_Native);
CreateNative("Weapons_ToggleClientStarTrack", Weapons_ToggleClientStarTrack_Native);

g_hOnKnifeSelect_Pre = CreateGlobalForward("Weapons_OnClientKnifeSelectPre", ET_Event, Param_Cell, Param_Cell, Param_String);
g_hOnKnifeSelect_Post = CreateGlobalForward("Weapons_OnClientKnifeSelectPost", ET_Ignore, Param_Cell, Param_Cell, Param_String);
Expand Down Expand Up @@ -87,6 +93,7 @@ public void OnPluginStart()
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_SavePresetAcces = CreateConVar("sm_weapons_save_preset_adminsonly", "1", "Who have the acces to save a preset of skins? 1 = Admin only | 0 = Everyone", 0, true, 0.0, true, 1.0);

AutoExecConfig(true, "weapons");

Expand All @@ -97,7 +104,7 @@ public void OnPluginStart()
RegConsoleCmd("sm_nametag", CommandNameTag);
RegConsoleCmd("sm_wslang", CommandWSLang);
RegConsoleCmd("sm_seed", CommandSeedMenu);

PTaH(PTaH_GiveNamedItemPre, Hook, GiveNamedItemPre);
PTaH(PTaH_GiveNamedItemPost, Hook, GiveNamedItemPost);

Expand Down Expand Up @@ -189,6 +196,7 @@ public Action CommandWeaponSkins(int client, int args)
PrintToChat(client, " %s \x02%t", g_ChatPrefix, "GracePeriod", g_iGracePeriod);
}
}

return Plugin_Handled;
}

Expand Down
18 changes: 18 additions & 0 deletions addons/sourcemod/scripting/weapons/config.sp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public void ReadConfig()
g_smWeaponDefIndex = new StringMap();
delete g_smLanguageIndex;
g_smLanguageIndex = new StringMap();
delete g_smSkinsNames;
g_smSkinsNames = new StringMap();

for (int i = 0; i < sizeof(g_WeaponClasses); i++)
{
Expand Down Expand Up @@ -79,6 +81,8 @@ public void ReadConfig()
KvGetString(kv, "classes", classes, sizeof(classes));
KvGetString(kv, "index", index, sizeof(index));

g_smSkinsNames.SetString(index, name);

for (int k = 0; k < sizeof(g_WeaponClasses); k++)
{
Format(weaponTemp, sizeof(weaponTemp), "%s;", g_WeaponClasses[k]);
Expand All @@ -99,4 +103,18 @@ public void ReadConfig()
{
SetFailState("Could not find a config file for any languages.");
}

ReadPressets();
}

void ReadPressets() // We just need a global handle of the KVs
{
BuildPath(Path_SM, g_sPressetsFile, sizeof(g_sPressetsFile), "configs/weapons_presets.cfg");

delete g_hPresets;
g_hPresets = new KeyValues("Skins");
if(!g_hPresets.ImportFromFile(g_sPressetsFile))
{
LogError("File \"%s\" is missing.", g_sPressetsFile);
}
}
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/weapons/forwards.sp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void OnClientPutInServer(int client)
g_FloatTimer[client] = INVALID_HANDLE;
g_bWaitingForNametag[client] = false;
g_bWaitingForSeed[client] = false;
g_bWaitingForPressetName[client] = false;
for (int i = 0; i < sizeof(g_WeaponClasses); i++)
{
g_iSeedRandom[client][i] = 0;
Expand Down
11 changes: 10 additions & 1 deletion addons/sourcemod/scripting/weapons/globals.sp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ int g_iGracePeriod;
ConVar g_Cvar_InactiveDays;
int g_iGraceInactiveDays;

ConVar g_Cvar_SavePresetAcces;

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 @@ -121,4 +123,11 @@ StringMap g_smWeaponDefIndex;
StringMap g_smLanguageIndex;

GlobalForward g_hOnKnifeSelect_Pre;
GlobalForward g_hOnKnifeSelect_Post;
GlobalForward g_hOnKnifeSelect_Post;

StringMap g_smSkinsNames;

bool g_bWaitingForPressetName[MAXPLAYERS + 1];

KeyValues g_hPresets;
char g_sPressetsFile[PLATFORM_MAX_PATH];
10 changes: 10 additions & 0 deletions addons/sourcemod/scripting/weapons/helpers.sp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ int GetWeaponIndex(int entity)
return -1;
}

int GetIndex(const char[] classname)
{
int index;
if(g_smWeaponIndex.GetValue(classname, index))
{
return index;
}
return -1;
}

bool GetWeaponClass(int entity, char[] weaponClass, int size)
{
int id = GetEntProp(entity, Prop_Send, "m_iItemDefinitionIndex");
Expand Down
7 changes: 7 additions & 0 deletions addons/sourcemod/scripting/weapons/hooks.sp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ public Action ChatListener(int client, const char[] command, int args)

return Plugin_Handled;
}
else if(g_bWaitingForPressetName[client] && IsValidClient(client) && !IsChatTrigger())
{
SavePresset(client, msg);
g_bWaitingForPressetName[client] = false;

return Plugin_Handled;
}

return Plugin_Continue;
}
Expand Down
132 changes: 129 additions & 3 deletions addons/sourcemod/scripting/weapons/menus.sp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,20 @@ public int MainMenuHandler(Menu menu, MenuAction action, int client, int selecti
CreateLanguageMenu(client).Display(client, menuTime);
}
}
else if(StrEqual(info, "load"))
{
ShowPressets(client);
}
else if(StrEqual(info, "save"))
{
PrintToChat(client, " %s \x04%t", g_ChatPrefix, "WaitingForPresset", client);

g_bWaitingForPressetName[client] = true;
}
else if(StrEqual(info, "delete"))
{
ShowPressets(client, true);
}
else
{
g_smWeaponIndex.GetValue(info, g_iIndex[client]);
Expand Down Expand Up @@ -795,15 +809,41 @@ Menu CreateMainMenu(int client)
}
}
}

Format(buffer, sizeof(buffer), "%T", "LoadPresset", client);
menu.AddItem("load", buffer);

switch(g_Cvar_SavePresetAcces.IntValue)
{
case 1: // Admin only
{
if(GetUserAdmin(client) != INVALID_ADMIN_ID)
{
Format(buffer, sizeof(buffer), "%T", "SavePresset", client);
menu.AddItem("save", buffer);

Format(buffer, sizeof(buffer), "%T", "DeletePresset", client);
menu.AddItem("delete", buffer);
}
}
case 0: // Everyone
{
Format(buffer, sizeof(buffer), "%T", "SavePresset", client);
menu.AddItem("save", buffer);

Format(buffer, sizeof(buffer), "%T", "DeletePresset", client);
menu.AddItem("delete", buffer);
}
}

for(int i = index; i < 6; i++)
for(int i = index; i < 4; i++)
{
menu.AddItem("", "", ITEMDRAW_SPACER);
}

Format(buffer, sizeof(buffer), "%T", "ChangeLang", client);
menu.AddItem("lang", buffer);

return menu;
}

Expand Down Expand Up @@ -960,3 +1000,89 @@ public int LanguageMenuHandler(Menu menu, MenuAction action, int client, int sel
}
}
}

public int SeePressetsHandler(Menu menu, MenuAction action, int client, int selection)
{
switch(action)
{
case MenuAction_Select:
{
if(IsClientInGame(client))
{
char info[32];
menu.GetItem(selection, info, sizeof(info));

ShowPressetInfo(client, info);
}
}
case MenuAction_End:
{
delete menu;
}
}

if(selection == MenuCancel_ExitBack)
{
int menuTime;
if((menuTime = GetRemainingGracePeriodSeconds(client)) >= 0)
{
CreateMainMenu(client).Display(client, menuTime);
}
}
}

public int SeeDeletePressetsHandler(Menu menu, MenuAction action, int client, int selection)
{
switch(action)
{
case MenuAction_Select:
{
if(IsClientInGame(client))
{
char info[64];
menu.GetItem(selection, info, sizeof(info));

DeletePresset(client, info);
}
}
case MenuAction_End:
{
delete menu;
}
}

if(selection == MenuCancel_ExitBack)
{
int menuTime;
if((menuTime = GetRemainingGracePeriodSeconds(client)) >= 0)
{
CreateMainMenu(client).Display(client, menuTime);
}
}
}

public int SeePressetSkinsHandler(Menu menu, MenuAction action, int client, int selection)
{
switch(action)
{
case MenuAction_Select:
{
if(IsClientInGame(client))
{
char item[64];
menu.GetItem(selection, item, sizeof(item));

LoadPresset(client, item);
}
}
case MenuAction_End:
{
delete menu;
}
}

if(selection == MenuCancel_ExitBack)
{
ShowPressets(client);
}
}
Loading