mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
87
Commands.cs
87
Commands.cs
@@ -19,7 +19,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
Index = (int)player.Index,
|
Index = (int)player.Index,
|
||||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
SteamId = player?.SteamID.ToString(),
|
||||||
Name = player?.PlayerName,
|
Name = player?.PlayerName,
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
@@ -107,44 +107,39 @@ namespace WeaponPaints
|
|||||||
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||||
|
|
||||||
var giveItemMenu = new ChatMenu(Localizer["wp_knife_menu_title"]);
|
var giveItemMenu = new ChatMenu(Localizer["wp_knife_menu_title"]);
|
||||||
var handleGive = (CCSPlayerController? player, ChatMenuOption option) =>
|
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
||||||
{
|
{
|
||||||
if (Utility.IsPlayerValid(player))
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
|
var knifeName = option.Text;
|
||||||
|
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
||||||
|
if (!string.IsNullOrEmpty(knifeKey))
|
||||||
{
|
{
|
||||||
if (player == null) return;
|
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_select"]))
|
||||||
var knifeName = option.Text;
|
|
||||||
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
|
||||||
if (!string.IsNullOrEmpty(knifeKey))
|
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_select"]))
|
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
|
||||||
{
|
|
||||||
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.Additional.CommandKillEnabled)
|
|
||||||
{
|
|
||||||
player!.Print(Localizer["wp_knife_menu_kill"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
|
||||||
{
|
|
||||||
RefreshWeapons(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (weaponSync != null)
|
|
||||||
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.Additional.CommandKillEnabled)
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_knife_menu_kill"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player.SteamID.ToString(),
|
||||||
|
Name = player.PlayerName,
|
||||||
|
IpAddress = player.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
g_playersKnife[(int)player!.Index] = knifeKey;
|
||||||
|
|
||||||
|
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
|
||||||
|
RefreshKnife(player);
|
||||||
|
|
||||||
|
_ = weaponSync?.SyncKnifeToDatabase(playerInfo, knifeKey) ?? Task.CompletedTask;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
foreach (var knifePair in knivesOnly)
|
foreach (var knifePair in knivesOnly)
|
||||||
@@ -195,15 +190,13 @@ namespace WeaponPaints
|
|||||||
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
||||||
|
|
||||||
// Function to handle skin selection for the chosen weapon
|
// Function to handle skin selection for the chosen weapon
|
||||||
var handleSkinSelection = (CCSPlayerController? p, ChatMenuOption opt) =>
|
var handleSkinSelection = (CCSPlayerController p, ChatMenuOption opt) =>
|
||||||
{
|
{
|
||||||
if (p == null || !p.IsValid || p.Index <= 0) return;
|
if (!Utility.IsPlayerValid(p)) return;
|
||||||
|
|
||||||
playerIndex = (int)p.Index;
|
playerIndex = (int)p.Index;
|
||||||
|
|
||||||
if (p.AuthorizedSteamID == null) return;
|
string steamId = p.SteamID.ToString();
|
||||||
|
|
||||||
string steamId = p.AuthorizedSteamID.SteamId64.ToString();
|
|
||||||
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
||||||
{
|
{
|
||||||
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
||||||
@@ -234,13 +227,17 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = p.UserId,
|
||||||
Index = (int)player.Index,
|
Index = (int)p.Index,
|
||||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
SteamId = p.SteamID.ToString(),
|
||||||
Name = player?.PlayerName,
|
Name = p.PlayerName,
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = p.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE)
|
||||||
|
RefreshWeapons(p);
|
||||||
|
|
||||||
|
|
||||||
if (!Config.GlobalShare)
|
if (!Config.GlobalShare)
|
||||||
{
|
{
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
[JsonPropertyName("GiveRandomSkin")]
|
[JsonPropertyName("GiveRandomSkin")]
|
||||||
public bool GiveRandomSkin { get; set; } = false;
|
public bool GiveRandomSkin { get; set; } = false;
|
||||||
|
|
||||||
[JsonPropertyName("GiveKnifeAfterRemove")]
|
[JsonPropertyName("GiveKnifeAfterRemove")]
|
||||||
public bool GiveKnifeAfterRemove { get; set; } = false;
|
public bool GiveKnifeAfterRemove { get; set; } = false;
|
||||||
}
|
}
|
||||||
@@ -78,5 +79,4 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("Additional")]
|
[JsonPropertyName("Additional")]
|
||||||
public Additional Additional { get; set; } = new Additional();
|
public Additional Additional { get; set; } = new Additional();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
@@ -74,7 +74,8 @@ namespace WeaponPaints
|
|||||||
if (weapon.OwnerEntity.Value == null) return;
|
if (weapon.OwnerEntity.Value == null) return;
|
||||||
if (weapon.OwnerEntity.Index <= 0) return;
|
if (weapon.OwnerEntity.Index <= 0) return;
|
||||||
int weaponOwner = (int)weapon.OwnerEntity.Index;
|
int weaponOwner = (int)weapon.OwnerEntity.Index;
|
||||||
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
CBasePlayerPawn? pawn = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)weaponOwner);
|
||||||
|
//var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
||||||
if (!pawn.IsValid) return;
|
if (!pawn.IsValid) return;
|
||||||
|
|
||||||
var playerIndex = (int)pawn.Controller.Index;
|
var playerIndex = (int)pawn.Controller.Index;
|
||||||
@@ -110,7 +111,6 @@ namespace WeaponPaints
|
|||||||
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;
|
||||||
|
|
||||||
|
|
||||||
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||||
|
|
||||||
if (g_playersKnife.ContainsKey((int)player.Index)
|
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||||
@@ -345,7 +345,6 @@ namespace WeaponPaints
|
|||||||
HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup, HookMode.Pre);
|
HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup, HookMode.Pre);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
||||||
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,4 +8,4 @@
|
|||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public string? IpAddress { get; set; }
|
public string? IpAddress { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
42
Utility.cs
42
Utility.cs
@@ -29,22 +29,38 @@ namespace WeaponPaints
|
|||||||
return builder.ConnectionString;
|
return builder.ConnectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async void CheckDatabaseTables()
|
internal static async Task CheckDatabaseTables()
|
||||||
{
|
{
|
||||||
|
if (WeaponPaints._database is null) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new MySqlConnection(BuildDatabaseConnectionString());
|
await using var connection = await WeaponPaints._database.GetConnectionAsync();
|
||||||
await connection.OpenAsync();
|
|
||||||
|
|
||||||
using var transaction = await connection.BeginTransactionAsync();
|
await using var transaction = await connection.BeginTransactionAsync();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string createTable1 = "CREATE TABLE IF NOT EXISTS `wp_player_skins` (`steamid` varchar(64) NOT NULL, `weapon_defindex` int(6) NOT NULL, `weapon_paint_id` int(6) NOT NULL, `weapon_wear` float NOT NULL DEFAULT 0.000001, `weapon_seed` int(16) NOT NULL DEFAULT 0) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci";
|
string[] createTableQueries = new[]
|
||||||
string createTable2 = "CREATE TABLE IF NOT EXISTS `wp_player_knife` (`steamid` varchar(64) NOT NULL, `knife` varchar(64) NOT NULL, UNIQUE (`steamid`)) ENGINE = InnoDB";
|
{
|
||||||
|
@"CREATE TABLE IF NOT EXISTS `wp_player_skins` (
|
||||||
|
`steamid` varchar(64) NOT NULL,
|
||||||
|
`weapon_defindex` int(6) NOT NULL,
|
||||||
|
`weapon_paint_id` int(6) NOT NULL,
|
||||||
|
`weapon_wear` float NOT NULL DEFAULT 0.000001,
|
||||||
|
`weapon_seed` int(16) NOT NULL DEFAULT 0
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci",
|
||||||
|
@"CREATE TABLE IF NOT EXISTS `wp_player_knife` (
|
||||||
|
`steamid` varchar(64) NOT NULL,
|
||||||
|
`knife` varchar(64) NOT NULL,
|
||||||
|
UNIQUE (`steamid`)
|
||||||
|
) ENGINE = InnoDB"
|
||||||
|
};
|
||||||
|
|
||||||
await connection.ExecuteAsync(createTable1, transaction: transaction);
|
foreach (var query in createTableQueries)
|
||||||
await connection.ExecuteAsync(createTable2, transaction: transaction);
|
{
|
||||||
|
await connection.ExecuteAsync(query, transaction: transaction);
|
||||||
|
}
|
||||||
|
|
||||||
await transaction.CommitAsync();
|
await transaction.CommitAsync();
|
||||||
}
|
}
|
||||||
@@ -56,14 +72,18 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
throw new Exception("[WeaponPaints] Unknown MySQL exception! " + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool IsPlayerValid(CCSPlayerController? player)
|
internal static bool IsPlayerValid(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV && player.AuthorizedSteamID != null);
|
if (player is null) return false;
|
||||||
|
|
||||||
|
return (player is not null && player.IsValid && !player.IsBot && !player.IsHLTV
|
||||||
|
&& WeaponPaints.weaponSync != null && player.Connected == PlayerConnectedState.PlayerConnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LoadSkinsFromFile(string filePath)
|
internal static void LoadSkinsFromFile(string filePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -168,6 +188,7 @@ namespace WeaponPaints
|
|||||||
Console.WriteLine(" ");
|
Console.WriteLine(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*(
|
||||||
internal static void TestDatabaseConnection()
|
internal static void TestDatabaseConnection()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -186,5 +207,6 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
CheckDatabaseTables();
|
CheckDatabaseTables();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
157
WeaponAction.cs
157
WeaponAction.cs
@@ -11,7 +11,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
internal static void ChangeWeaponAttributes(CBasePlayerWeapon? weapon, CCSPlayerController? player, bool isKnife = false)
|
internal static void ChangeWeaponAttributes(CBasePlayerWeapon? weapon, CCSPlayerController? player, bool isKnife = false)
|
||||||
{
|
{
|
||||||
if (player == null || weapon == null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
int playerIndex = (int)player.Index;
|
int playerIndex = (int)player.Index;
|
||||||
|
|
||||||
@@ -144,6 +144,7 @@ namespace WeaponPaints
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
internal void RefreshPlayerKnife(CCSPlayerController? player)
|
internal void RefreshPlayerKnife(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -202,7 +203,9 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
internal void RefreshSkins(CCSPlayerController? player)
|
internal void RefreshSkins(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -212,10 +215,11 @@ namespace WeaponPaints
|
|||||||
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot2"));
|
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot2"));
|
||||||
AddTimer(0.38f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot1"));
|
AddTimer(0.38f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot1"));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
internal void RefreshWeapons(CCSPlayerController? player)
|
internal void RefreshWeapons(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || !player.PawnIsAlive)
|
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
||||||
@@ -225,40 +229,101 @@ namespace WeaponPaints
|
|||||||
if (weapons == null || weapons.Count == 0)
|
if (weapons == null || weapons.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var itemServices = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
// Dictionary to store weapons and their ammo
|
||||||
|
|
||||||
foreach (var weapon in weapons)
|
|
||||||
|
if (weapons != null && weapons.Count > 0)
|
||||||
{
|
{
|
||||||
if (weapon == null || !weapon.IsValid || weapon.Value == null || !weapon.Value.IsValid || weapon.Index <= 0 || !weapon.Value.DesignerName.Contains("weapon_"))
|
//Dictionary<string, (int, int)> weaponsWithAmmo = new Dictionary<string, (int, int)>();
|
||||||
continue;
|
Dictionary<string, List<(int, int)>> weaponsWithAmmo = new Dictionary<string, List<(int, int)>>();
|
||||||
|
bool bomb = false;
|
||||||
|
bool defuser = player.PawnHasDefuser;
|
||||||
|
bool healthshot = false;
|
||||||
|
|
||||||
try
|
// Iterate through each weapon
|
||||||
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
string? weaponByDefindex = null;
|
if (weapon == null || !weapon.IsValid || weapon.Value == null ||
|
||||||
|
!weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_"))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
try
|
||||||
{
|
{
|
||||||
player.RemoveItemByDesignerName(weapon.Value.DesignerName, false);
|
string? weaponByDefindex = null;
|
||||||
GiveKnifeToPlayer(player);
|
|
||||||
}
|
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
|
||||||
else
|
|
||||||
{
|
if (weaponData != null)
|
||||||
if (weaponDefindex.TryGetValue(weapon.Value.AttributeManager.Item.ItemDefinitionIndex, out weaponByDefindex) && weaponByDefindex != null)
|
{
|
||||||
|
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_C4)
|
||||||
|
bomb = true;
|
||||||
|
|
||||||
|
if (weaponData.Name.Equals("weapon_healtshot"))
|
||||||
|
healthshot = true;
|
||||||
|
|
||||||
|
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_GRENADES || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_UTILITY || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_BOOSTS)
|
||||||
|
{
|
||||||
|
int clip1 = weapon.Value.Clip1;
|
||||||
|
int reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||||
|
|
||||||
|
weaponsWithAmmo.Add(weapon.Value.DesignerName, new List<(int, int)>() { (clip1, reservedAmmo) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!weapon.Value.DesignerName.Contains("knife") && weaponDefindex.TryGetValue(weapon.Value.AttributeManager.Item.ItemDefinitionIndex, out weaponByDefindex) && weaponByDefindex != null)
|
||||||
{
|
{
|
||||||
int clip1 = weapon.Value.Clip1;
|
int clip1 = weapon.Value.Clip1;
|
||||||
int reservedAmmo = weapon.Value.ReserveAmmo[0];
|
int reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||||
|
|
||||||
player.RemoveItemByDesignerName(weapon.Value.DesignerName, false);
|
if (!weaponsWithAmmo.ContainsKey(weaponByDefindex))
|
||||||
var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(weaponByDefindex));
|
{
|
||||||
|
weaponsWithAmmo.Add(weaponByDefindex, new List<(int, int)>());
|
||||||
|
}
|
||||||
|
|
||||||
|
weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning(ex.Message);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.RemoveWeapons();
|
||||||
|
AddTimer(0.2f, () =>
|
||||||
|
{
|
||||||
|
if (bomb)
|
||||||
|
player.GiveNamedItem("weapon_c4");
|
||||||
|
|
||||||
|
if (defuser)
|
||||||
|
{
|
||||||
|
var itemServ = player.PlayerPawn?.Value?.ItemServices;
|
||||||
|
if (itemServ != null)
|
||||||
|
{
|
||||||
|
var items = new CCSPlayer_ItemServices(itemServ.Handle);
|
||||||
|
items.HasDefuser = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (healthshot)
|
||||||
|
player.GiveNamedItem("weapon_healtshot");
|
||||||
|
|
||||||
|
GiveKnifeToPlayer(player);
|
||||||
|
|
||||||
|
foreach (var entry in weaponsWithAmmo)
|
||||||
|
{
|
||||||
|
foreach (var ammo in entry.Value)
|
||||||
|
{
|
||||||
|
var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(entry.Key));
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (newWeapon != null)
|
if (newWeapon != null)
|
||||||
{
|
{
|
||||||
newWeapon.Clip1 = clip1;
|
newWeapon.Clip1 = ammo.Item1;
|
||||||
newWeapon.ReserveAmmo[0] = reservedAmmo;
|
newWeapon.ReserveAmmo[0] = ammo.Item2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -267,62 +332,46 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Logger.LogWarning("Unable to find weapon by defindex.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.LogWarning("Refreshing weapons exception: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false)
|
internal void RefreshKnife(CCSPlayerController? player, bool force = false)
|
||||||
{
|
{
|
||||||
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE)
|
||||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
|
return;
|
||||||
|
|
||||||
|
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||||
if (weapons != null && weapons.Count > 0)
|
if (weapons != null && weapons.Count > 0)
|
||||||
{
|
{
|
||||||
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
|
||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid && weapon.Index > 0)
|
||||||
{
|
{
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
try
|
||||||
{
|
{
|
||||||
if (!force)
|
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
|
||||||
{
|
|
||||||
if ((int)weapon.Index <= 0) return;
|
|
||||||
int weaponEntityIndex = (int)weapon.Index;
|
|
||||||
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
|
||||||
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
|
|
||||||
|
|
||||||
AddTimer(1.0f, () =>
|
if (weapon.Value.DesignerName.Contains("knife") || weaponData?.GearSlot == gear_slot_t.GEAR_SLOT_KNIFE)
|
||||||
{
|
|
||||||
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
|
||||||
if (knife != null && knife.IsValid)
|
|
||||||
{
|
|
||||||
knife.Remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
weapon.Value.Remove();
|
player.RemoveItemByDesignerName(weapon.Value.DesignerName, weapon.Value.Entity?.EntityInstance.IsValid ?? false);
|
||||||
|
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning($"Cannot remove knife: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetRandomPaint(int defindex)
|
private static int GetRandomPaint(int defindex)
|
||||||
{
|
{
|
||||||
if (skinsList == null || skinsList.Count == 0)
|
if (skinsList == null || skinsList.Count == 0)
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
internal int GlobalShareServerId = 0;
|
internal int GlobalShareServerId = 0;
|
||||||
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
|
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
|
||||||
internal static Database? _database;
|
internal static Database? _database;
|
||||||
|
|
||||||
//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>
|
||||||
{
|
{
|
||||||
@@ -150,7 +151,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.6a";
|
public override string ModuleVersion => "1.6b";
|
||||||
|
|
||||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||||
{
|
{
|
||||||
@@ -207,6 +208,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
Logger.LogError("You need to setup Database credentials in config!");
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
DatabaseConnectionString = Utility.BuildDatabaseConnectionString();
|
DatabaseConnectionString = Utility.BuildDatabaseConnectionString();
|
||||||
Utility.TestDatabaseConnection();
|
Utility.TestDatabaseConnection();
|
||||||
@@ -223,6 +225,8 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
};
|
};
|
||||||
|
|
||||||
_database = new(builder.ConnectionString);
|
_database = new(builder.ConnectionString);
|
||||||
|
|
||||||
|
_ = Utility.CheckDatabaseTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
Config = config;
|
Config = config;
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ namespace WeaponPaints
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await using (var connection = await _database.GetConnectionAsync())
|
await using (var connection = await _database.GetConnectionAsync())
|
||||||
{
|
{
|
||||||
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
||||||
@@ -189,6 +188,7 @@ namespace WeaponPaints
|
|||||||
Utility.Log(e.Message);
|
Utility.Log(e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task SyncWeaponPaintsToDatabase(PlayerInfo player)
|
internal async Task SyncWeaponPaintsToDatabase(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (player == null || player.Index <= 0 || player.SteamId == null) return;
|
if (player == null || player.Index <= 0 || player.SteamId == null) return;
|
||||||
|
|||||||
@@ -11,4 +11,4 @@
|
|||||||
"wp_skin_menu_weapon_title": "Ieroču Izvēlne",
|
"wp_skin_menu_weapon_title": "Ieroču Izvēlne",
|
||||||
"wp_skin_menu_skin_title": "Izvēlies skinu ierocim: {lime}{0}{default}",
|
"wp_skin_menu_skin_title": "Izvēlies skinu ierocim: {lime}{0}{default}",
|
||||||
"wp_skin_menu_select": "Tu esi izvēlējies {lime}{0}{default} kā savu skinu"
|
"wp_skin_menu_select": "Tu esi izvēlējies {lime}{0}{default} kā savu skinu"
|
||||||
}
|
}
|
||||||
@@ -11,4 +11,4 @@
|
|||||||
"wp_skin_menu_weapon_title": "Menu de Armas",
|
"wp_skin_menu_weapon_title": "Menu de Armas",
|
||||||
"wp_skin_menu_skin_title": "Selecionou a skin para {lime}{0}{default}",
|
"wp_skin_menu_skin_title": "Selecionou a skin para {lime}{0}{default}",
|
||||||
"wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin"
|
"wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin"
|
||||||
}
|
}
|
||||||
@@ -11,4 +11,4 @@
|
|||||||
"wp_skin_menu_weapon_title": "Menu de Armas",
|
"wp_skin_menu_weapon_title": "Menu de Armas",
|
||||||
"wp_skin_menu_skin_title": "Escolhe a skin para {lime}{0}{default}",
|
"wp_skin_menu_skin_title": "Escolhe a skin para {lime}{0}{default}",
|
||||||
"wp_skin_menu_select": "Tu escolheste {lime}{0}{default} como a tua skin"
|
"wp_skin_menu_select": "Tu escolheste {lime}{0}{default} como a tua skin"
|
||||||
}
|
}
|
||||||
@@ -11,4 +11,4 @@
|
|||||||
"wp_skin_menu_weapon_title": "Silah Menüsü",
|
"wp_skin_menu_weapon_title": "Silah Menüsü",
|
||||||
"wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}",
|
"wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}",
|
||||||
"wp_skin_menu_select": "Teniniz olarak {lime}{0}{default} seçtiniz"
|
"wp_skin_menu_select": "Teniniz olarak {lime}{0}{default} seçtiniz"
|
||||||
}
|
}
|
||||||
@@ -11,4 +11,4 @@
|
|||||||
"wp_skin_menu_weapon_title": "武器菜单",
|
"wp_skin_menu_weapon_title": "武器菜单",
|
||||||
"wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤",
|
"wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤",
|
||||||
"wp_skin_menu_select": "你选择了 {lime}{0}{default} 作为你的皮肤"
|
"wp_skin_menu_select": "你选择了 {lime}{0}{default} 作为你的皮肤"
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
.bg-primary {
|
.bg-primary {
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-title item-name{
|
.card-title item-name {
|
||||||
//text-align:center;
|
//text-align:center;
|
||||||
font-weight:bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.skin-image {
|
.skin-image {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
display:block;
|
display: block;
|
||||||
text-align:center;
|
text-align: center;
|
||||||
width:50%;
|
width: 50%;
|
||||||
//border-bottom: solid 1px #eee;
|
//border-bottom: solid 1px #eee;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user