mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-03-05 15:09:52 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
813a9abcc8 | ||
|
|
b0790729be |
13
Commands.cs
13
Commands.cs
@@ -109,6 +109,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (Utility.IsPlayerValid(player))
|
if (Utility.IsPlayerValid(player))
|
||||||
{
|
{
|
||||||
|
if (player == null) return;
|
||||||
var knifeName = option.Text;
|
var knifeName = option.Text;
|
||||||
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
||||||
if (!string.IsNullOrEmpty(knifeKey))
|
if (!string.IsNullOrEmpty(knifeKey))
|
||||||
@@ -127,14 +128,24 @@ namespace WeaponPaints
|
|||||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
g_playersKnife[(int)player!.Index] = knifeKey;
|
g_playersKnife[(int)player!.Index] = knifeKey;
|
||||||
|
|
||||||
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
||||||
{
|
{
|
||||||
RefreshWeapons(player);
|
RefreshWeapons(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(() => weaponSync.SyncKnifeToDatabase((int)player.Index, knifeKey));
|
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
RemovePlayerKnife(player, true);
|
RemovePlayerKnife(player, true);
|
||||||
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
@@ -207,6 +208,7 @@ namespace WeaponPaints
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
g_bCommandsAllowed = false;
|
g_bCommandsAllowed = false;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Memory;
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -81,7 +82,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return false;
|
if (!_config.Additional.KnifeEnabled) return false;
|
||||||
|
|
||||||
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
if (player == null || !player.IsValid || player.PlayerPawn == null || !player.PlayerPawn.IsValid || !player.PawnIsAlive)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -221,6 +222,7 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Logger.LogWarning("Refreshing weapons exception");
|
||||||
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
|
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
|
||||||
Console.WriteLine(ex.Message);
|
Console.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
@@ -240,6 +242,7 @@ namespace WeaponPaints
|
|||||||
if (weapons != null && weapons.Count > 0)
|
if (weapons != null && weapons.Count > 0)
|
||||||
{
|
{
|
||||||
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
||||||
|
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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 Newtonsoft.Json.Linq;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
@@ -142,7 +143,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.3c";
|
public override string ModuleVersion => "1.3d";
|
||||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||||
{
|
{
|
||||||
return _config;
|
return _config;
|
||||||
@@ -203,6 +204,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
{
|
{
|
||||||
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||||
{
|
{
|
||||||
|
Logger.LogError("You need to setup Database credentials in config!");
|
||||||
throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
|
throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,10 +248,12 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Logger.LogError("Unable to retrieve serverid from GlobalShare!");
|
||||||
throw new Exception("[WeaponPaints] Unable to retrieve serverid from GlobalShare!");
|
throw new Exception("[WeaponPaints] Unable to retrieve serverid from GlobalShare!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.LogInformation("GlobalShare ONLINE!");
|
||||||
Console.WriteLine("[WeaponPaints] GlobalShare ONLINE");
|
Console.WriteLine("[WeaponPaints] GlobalShare ONLINE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,20 +190,17 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task SyncKnifeToDatabase(int playerIndex, string knife)
|
internal async Task SyncKnifeToDatabase(PlayerInfo player, string knife)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return;
|
if (!_config.Additional.KnifeEnabled) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
if (player.SteamId == null || player.Index == 0) return;
|
||||||
if (player == null || !player.IsValid) return;
|
|
||||||
if (player.AuthorizedSteamID == null) return;
|
|
||||||
string steamId = player.AuthorizedSteamID.SteamId64.ToString();
|
|
||||||
|
|
||||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
||||||
await connection.ExecuteAsync(query, new { steamid = steamId, newKnife = knife });
|
await connection.ExecuteAsync(query, new { steamid = player.SteamId, newKnife = knife });
|
||||||
await connection.CloseAsync();
|
await connection.CloseAsync();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
Reference in New Issue
Block a user