mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-24 12:19:16 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89c425c170 | ||
|
|
c744f2898b | ||
|
|
d04bc0879a | ||
|
|
4417b093dd | ||
|
|
3f8533ab94 | ||
|
|
55905ccc33 | ||
|
|
24fcfa0222 |
23
Commands.cs
23
Commands.cs
@@ -22,9 +22,12 @@ namespace WeaponPaints
|
|||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
|
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
||||||
|
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
@@ -145,11 +148,13 @@ namespace WeaponPaints
|
|||||||
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
|
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||||
int playerIndex = (int)player!.Index;
|
|
||||||
|
|
||||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
|
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
||||||
|
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
ChatMenus.OpenMenu(player, giveItemMenu);
|
ChatMenus.OpenMenu(player, giveItemMenu);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -271,11 +276,13 @@ namespace WeaponPaints
|
|||||||
AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) =>
|
AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) =>
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
int playerIndex = (int)player!.Index;
|
|
||||||
|
|
||||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length)
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
|
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
||||||
|
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
ChatMenus.OpenMenu(player, weaponSelectionMenu);
|
ChatMenus.OpenMenu(player, weaponSelectionMenu);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
36
Events.cs
36
Events.cs
@@ -37,18 +37,28 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.UserId == null) return;
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
g_playersKnife.Remove((int)player.Index);
|
g_playersKnife.TryRemove((int)player.Index, out _);
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
gPlayerWeaponsInfo.Remove((int)player.Index);
|
{
|
||||||
|
if (gPlayerWeaponsInfo.TryRemove((int)player.Index, out var innerDictionary))
|
||||||
|
{
|
||||||
|
innerDictionary.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (commandsCooldown.ContainsKey((int)player.UserId))
|
||||||
|
{
|
||||||
|
commandsCooldown.Remove((int)player.UserId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEntityCreated(CEntityInstance entity)
|
private void OnEntityCreated(CEntityInstance entity)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.SkinEnabled) return;
|
||||||
var designerName = entity.DesignerName;
|
if (entity == null || !entity.IsValid || string.IsNullOrEmpty(entity.DesignerName)) return;
|
||||||
|
string designerName = entity.DesignerName;
|
||||||
if (!weaponList.ContainsKey(designerName)) return;
|
if (!weaponList.ContainsKey(designerName)) return;
|
||||||
bool isKnife = false;
|
bool isKnife = false;
|
||||||
var weapon = new CBasePlayerWeapon(entity.Handle);
|
var weapon = new CBasePlayerWeapon(entity.Handle);
|
||||||
@@ -91,28 +101,22 @@ namespace WeaponPaints
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||||
{
|
{
|
||||||
Server.PrintToChatAll("test1");
|
|
||||||
|
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
if (player == null || !player.IsValid || !g_knifePickupCount.ContainsKey((int)player.Index) || player.IsBot || !g_playersKnife.ContainsKey((int)player.Index))
|
if (player == null || !player.IsValid || !g_knifePickupCount.ContainsKey((int)player.Index) || player.IsBot || !g_playersKnife.ContainsKey((int)player.Index))
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
|
|
||||||
Server.PrintToChatAll("test2");
|
|
||||||
|
|
||||||
|
|
||||||
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||||
Server.PrintToChatAll("test3");
|
|
||||||
|
|
||||||
|
|
||||||
if (g_playersKnife.ContainsKey((int)player.Index)
|
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||||
&&
|
&&
|
||||||
g_playersKnife[(int)player.Index] != "weapon_knife")
|
g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||||
{
|
{
|
||||||
Server.PrintToChatAll("usuwam noz");
|
|
||||||
g_knifePickupCount[(int)player.Index]++;
|
g_knifePickupCount[(int)player.Index]++;
|
||||||
|
|
||||||
RemovePlayerKnife(player, true);
|
RemovePlayerKnife(player, true);
|
||||||
@@ -123,6 +127,7 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
|
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
|
||||||
{
|
{
|
||||||
@@ -145,15 +150,14 @@ namespace WeaponPaints
|
|||||||
if (g_playersKnife[(int)player.Index] != "weapon_knife")
|
if (g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||||
{
|
{
|
||||||
g_knifePickupCount[(int)player.Index]++;
|
g_knifePickupCount[(int)player.Index]++;
|
||||||
weapon.Remove();
|
player.RemoveItemByDesignerName(weapon.DesignerName);
|
||||||
if (!PlayerHasKnife(player) && Config.Additional.GiveKnifeAfterRemove)
|
if (Config.Additional.GiveKnifeAfterRemove)
|
||||||
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnMapStart(string mapName)
|
private void OnMapStart(string mapName)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
@@ -231,12 +235,12 @@ namespace WeaponPaints
|
|||||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
if (player == null || !player.IsValid || player.IsBot)
|
if (player == null || !player.IsValid)
|
||||||
{
|
{
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled && !PlayerHasKnife(player))
|
||||||
{
|
{
|
||||||
g_knifePickupCount[(int)player.Index] = 0;
|
g_knifePickupCount[(int)player.Index] = 0;
|
||||||
AddTimer(0.1f, () => GiveKnifeToPlayer(player));
|
AddTimer(0.1f, () => GiveKnifeToPlayer(player));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public static class PlayerExtensions
|
|||||||
{
|
{
|
||||||
public static void Print(this CCSPlayerController controller, string message)
|
public static void Print(this CCSPlayerController controller, string message)
|
||||||
{
|
{
|
||||||
|
if (WeaponPaints._localizer == null) return;
|
||||||
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
||||||
_message.Append(message);
|
_message.Append(message);
|
||||||
controller.PrintToChat(_message.ToString());
|
controller.PrintToChat(_message.ToString());
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
|||||||
- Translations support, submit a PR if you want to share your translation
|
- Translations support, submit a PR if you want to share your translation
|
||||||
|
|
||||||
## CS2 Server
|
## CS2 Server
|
||||||
- Compile and copy plugin to plugins, [more info here](https://docs.cssharp.dev/guides/hello-world-plugin/)
|
- Download from Release and copy plugin to plugins
|
||||||
- Setup **`addons/counterstrikesharp/configs/plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials
|
- Setup **`addons/counterstrikesharp/configs/plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials
|
||||||
- in **`addons/counterstrikesharp/configs/core.json`** set **FollowCS2ServerGuidelines** to **`false`**
|
- In **`addons/counterstrikesharp/configs/core.json`** set **FollowCS2ServerGuidelines** to **`false`**
|
||||||
|
|
||||||
## Plugin Configuration
|
## Plugin Configuration
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ namespace WeaponPaints
|
|||||||
internal static void GiveKnifeToPlayer(CCSPlayerController? player)
|
internal static void GiveKnifeToPlayer(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
||||||
|
|
||||||
if (g_playersKnife.TryGetValue((int)player.Index, out var knife))
|
if (g_playersKnife.TryGetValue((int)player.Index, out var knife))
|
||||||
{
|
{
|
||||||
player.GiveNamedItem(knife);
|
player.GiveNamedItem(knife);
|
||||||
@@ -197,7 +198,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
{
|
{
|
||||||
weapon.Value.Remove();
|
player.RemoveItemByDesignerName(weapon.Value.DesignerName, true);
|
||||||
GiveKnifeToPlayer(player);
|
GiveKnifeToPlayer(player);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -208,8 +209,8 @@ namespace WeaponPaints
|
|||||||
clip1 = weapon.Value.Clip1;
|
clip1 = weapon.Value.Clip1;
|
||||||
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||||
|
|
||||||
weapon.Value.Remove();
|
|
||||||
string weaponByDefindex = weaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex];
|
string weaponByDefindex = weaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex];
|
||||||
|
player.RemoveItemByDesignerName(weapon.Value.DesignerName, true);
|
||||||
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weaponByDefindex));
|
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weaponByDefindex));
|
||||||
|
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ using CounterStrikeSharp.API;
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes;
|
using CounterStrikeSharp.API.Core.Attributes;
|
||||||
using CounterStrikeSharp.API.Modules.Cvars;
|
using CounterStrikeSharp.API.Modules.Cvars;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
[MinimumApiVersion(121)]
|
[MinimumApiVersion(142)]
|
||||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
internal static readonly Dictionary<string, string> weaponList = new()
|
internal static readonly Dictionary<string, string> weaponList = new()
|
||||||
@@ -72,16 +73,15 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
||||||
internal static IStringLocalizer? _localizer;
|
internal static IStringLocalizer? _localizer;
|
||||||
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
||||||
internal static Dictionary<int, string> g_playersKnife = new();
|
internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
|
||||||
internal static Dictionary<int, Dictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new Dictionary<int, Dictionary<int, WeaponInfo>>();
|
internal static ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>>();
|
||||||
internal static List<JObject> skinsList = new List<JObject>();
|
internal static List<JObject> skinsList = new List<JObject>();
|
||||||
internal static WeaponSynchronization? weaponSync;
|
internal static WeaponSynchronization? weaponSync;
|
||||||
//internal static List<int> g_changedKnife = new();
|
|
||||||
internal bool g_bCommandsAllowed = true;
|
internal bool g_bCommandsAllowed = true;
|
||||||
|
|
||||||
internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php");
|
internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php");
|
||||||
internal int GlobalShareServerId = 0;
|
internal int GlobalShareServerId = 0;
|
||||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
|
||||||
private string DatabaseConnectionString = string.Empty;
|
private string DatabaseConnectionString = string.Empty;
|
||||||
private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
||||||
public static Dictionary<int, string> weaponDefindex { get; } = new Dictionary<int, string>
|
public static Dictionary<int, string> weaponDefindex { get; } = new Dictionary<int, string>
|
||||||
@@ -145,7 +145,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
public override string ModuleVersion => "1.3g";
|
public override string ModuleVersion => "1.3i";
|
||||||
|
|
||||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.121" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.147" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.24" />
|
<PackageReference Include="Dapper" Version="2.1.28" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
<PackageReference Include="MySqlConnector" Version="2.3.4" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -94,7 +95,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
||||||
{
|
{
|
||||||
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new Dictionary<int, WeaponInfo>();
|
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new ConcurrentDictionary<int, WeaponInfo>();
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user