mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-24 12:19:16 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b992433d44 | ||
|
|
06559af230 | ||
|
|
dfe6b200d8 | ||
|
|
3edcb5e52f | ||
|
|
28936e9bb5 | ||
|
|
2772fb59b9 | ||
|
|
0f6bb26ac9 | ||
|
|
be51e4d1e9 |
24
Commands.cs
24
Commands.cs
@@ -23,7 +23,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) =>
|
AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) =>
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player) || !player!.PlayerPawn.IsValid) return;
|
if (player == null || !Utility.IsPlayerValid(player) || player.PlayerPawn.Value == null || !player!.PlayerPawn.IsValid) return;
|
||||||
|
|
||||||
player.PlayerPawn.Value.CommitSuicide(true, false);
|
player.PlayerPawn.Value.CommitSuicide(true, false);
|
||||||
});
|
});
|
||||||
@@ -60,11 +60,11 @@ namespace WeaponPaints
|
|||||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_playersKnife[(int)player!.EntityIndex!.Value.Value] = knifeKey;
|
g_playersKnife[(int)player!.Index] = knifeKey;
|
||||||
|
|
||||||
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
||||||
{
|
{
|
||||||
g_changedKnife.Add((int)player.EntityIndex!.Value.Value);
|
//g_changedKnife.Add((int)player.Index);
|
||||||
RefreshWeapons(player);
|
RefreshWeapons(player);
|
||||||
//RefreshPlayerKnife(player);
|
//RefreshPlayerKnife(player);
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ namespace WeaponPaints
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(() => weaponSync.SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knifeKey));
|
Task.Run(() => weaponSync.SyncKnifeToDatabase((int)player.Index, knifeKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -84,9 +84,9 @@ 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!.EntityIndex!.Value.Value;
|
int playerIndex = (int)player!.Index;
|
||||||
|
|
||||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length)
|
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||||
ChatMenus.OpenMenu(player, giveItemMenu);
|
ChatMenus.OpenMenu(player, giveItemMenu);
|
||||||
@@ -110,7 +110,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
int playerIndex = (int)player!.EntityIndex!.Value.Value;
|
int playerIndex = (int)player!.Index;
|
||||||
string selectedWeapon = option.Text;
|
string selectedWeapon = option.Text;
|
||||||
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
|
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
|
||||||
{
|
{
|
||||||
@@ -126,9 +126,9 @@ namespace WeaponPaints
|
|||||||
// 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.EntityIndex.HasValue) return;
|
if (p == null || !p.IsValid || p.Index <= 0) return;
|
||||||
|
|
||||||
playerIndex = (int)p.EntityIndex.Value.Value;
|
playerIndex = (int)p.Index;
|
||||||
|
|
||||||
var steamId = new SteamID(p.SteamID);
|
var steamId = new SteamID(p.SteamID);
|
||||||
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
||||||
@@ -204,7 +204,7 @@ 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!.EntityIndex!.Value.Value;
|
int playerIndex = (int)player!.Index;
|
||||||
|
|
||||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length)
|
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length)
|
||||||
{
|
{
|
||||||
@@ -226,8 +226,8 @@ namespace WeaponPaints
|
|||||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
string temp = "";
|
string temp = "";
|
||||||
if (!player!.EntityIndex.HasValue) return;
|
if (player == null || player.Index <= 0) return;
|
||||||
int playerIndex = (int)player!.EntityIndex!.Value.Value;
|
int playerIndex = (int)player!.Index;
|
||||||
if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||||
|
|||||||
118
Events.cs
118
Events.cs
@@ -1,23 +1,26 @@
|
|||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
|
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
public partial class WeaponPaints
|
public partial class WeaponPaints
|
||||||
{
|
{
|
||||||
private void RegisterEvents()
|
private void RegisterListeners()
|
||||||
{
|
{
|
||||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
||||||
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
|
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
|
||||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||||
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
/*
|
||||||
|
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
||||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||||
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
||||||
RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
@@ -51,45 +54,88 @@ namespace WeaponPaints
|
|||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||||
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
||||||
|
|
||||||
|
if (Config.GlobalShare)
|
||||||
|
GlobalShareConnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
g_hTimerCheckSkinsData = AddTimer(10.0f, () =>
|
||||||
|
{
|
||||||
|
List<CCSPlayerController> players = Utilities.GetPlayers();
|
||||||
|
|
||||||
|
foreach (CCSPlayerController player in players)
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID == 0) continue;
|
||||||
|
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||||
|
|
||||||
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
|
||||||
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
||||||
|
|
||||||
|
}
|
||||||
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
||||||
{
|
{
|
||||||
int playerIndex = playerSlot + 1;
|
int playerIndex = playerSlot + 1;
|
||||||
|
|
||||||
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.IsHLTV) return;
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
||||||
|
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||||
|
|
||||||
/*
|
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
|
||||||
await weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
|
||||||
await weaponSync.GetKnifeFromDatabase(playerIndex);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
||||||
|
[GameEventHandler]
|
||||||
|
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return HookResult.Continue;
|
||||||
|
|
||||||
|
if (!gPlayerWeaponsInfo.ContainsKey((int)player.Index))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[WeaponPaints] Retrying to retrieve player {player.PlayerName} skins");
|
||||||
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
|
||||||
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
||||||
|
|
||||||
|
/*
|
||||||
|
AddTimer(2.0f, () =>
|
||||||
|
{
|
||||||
|
if (!gPlayerWeaponsInfo.ContainsKey((int)player.Index))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[WeaponPaints] Last try to retrieve player {player.PlayerName} skins");
|
||||||
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
|
||||||
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
private void OnClientDisconnect(int playerSlot)
|
private void OnClientDisconnect(int playerSlot)
|
||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.IsHLTV) return;
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
g_playersKnife.Remove((int)player.EntityIndex!.Value.Value);
|
g_playersKnife.Remove((int)player.Index);
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
gPlayerWeaponsInfo.Remove((int)player.EntityIndex!.Value.Value);
|
gPlayerWeaponsInfo.Remove((int)player.Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GameEventHandler]
|
||||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
@@ -100,7 +146,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
{
|
{
|
||||||
g_knifePickupCount[(int)player.EntityIndex!.Value.Value] = 0;
|
g_knifePickupCount[(int)player.Index] = 0;
|
||||||
if (!PlayerHasKnife(player))
|
if (!PlayerHasKnife(player))
|
||||||
GiveKnifeToPlayer(player);
|
GiveKnifeToPlayer(player);
|
||||||
}
|
}
|
||||||
@@ -112,6 +158,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
[GameEventHandler(HookMode.Pre)]
|
||||||
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||||
@@ -123,27 +170,29 @@ namespace WeaponPaints
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GameEventHandler]
|
||||||
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
g_bCommandsAllowed = false;
|
g_bCommandsAllowed = false;
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GameEventHandler]
|
||||||
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)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.EntityIndex!.Value.Value] >= 2) return HookResult.Continue;
|
if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||||
|
|
||||||
if (g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)
|
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||||
&&
|
&&
|
||||||
g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife")
|
g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||||
{
|
{
|
||||||
g_knifePickupCount[(int)player.EntityIndex!.Value.Value]++;
|
g_knifePickupCount[(int)player.Index]++;
|
||||||
|
|
||||||
RemovePlayerKnife(player, true);
|
RemovePlayerKnife(player, true);
|
||||||
AddTimer(0.3f, ()=> GiveKnifeToPlayer(player));
|
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
||||||
|
|
||||||
//RefreshPlayerKnife(player);
|
//RefreshPlayerKnife(player);
|
||||||
/*
|
/*
|
||||||
@@ -176,29 +225,32 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!weapon.IsValid) return;
|
if (!weapon.IsValid) return;
|
||||||
if (weapon.OwnerEntity.Value == null) return;
|
if (weapon.OwnerEntity.Value == null) return;
|
||||||
if (!weapon.OwnerEntity.Value.EntityIndex.HasValue)
|
/*
|
||||||
|
if (weapon.OwnerEntity.Index > 0)
|
||||||
{
|
{
|
||||||
for (int i = 1; i <= Server.MaxPlayers; i++)
|
for (int i = 1; i <= Server.MaxPlayers; i++)
|
||||||
{
|
{
|
||||||
CCSPlayerController? ghostPlayer = Utilities.GetPlayerFromIndex(i);
|
CCSPlayerController? ghostPlayer = Utilities.GetPlayerFromIndex(i);
|
||||||
if (!Utility.IsPlayerValid(ghostPlayer)) continue;
|
if (!Utility.IsPlayerValid(ghostPlayer)) continue;
|
||||||
if (g_changedKnife.Contains((int)ghostPlayer.EntityIndex!.Value.Value))
|
if (g_changedKnife.Contains((int)ghostPlayer.Index))
|
||||||
{
|
{
|
||||||
ChangeWeaponAttributes(weapon, ghostPlayer, isKnife);
|
ChangeWeaponAttributes(weapon, ghostPlayer, isKnife);
|
||||||
g_changedKnife.Remove((int)ghostPlayer.EntityIndex!.Value.Value);
|
g_changedKnife.Remove((int)ghostPlayer.Index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (!weapon.OwnerEntity.Value.EntityIndex.HasValue) return;
|
if (weapon.OwnerEntity.Index <= 0) return;
|
||||||
int weaponOwner = (int)weapon.OwnerEntity.Value.EntityIndex.Value.Value;
|
int weaponOwner = (int)weapon.OwnerEntity.Index;
|
||||||
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
||||||
if (!pawn.IsValid) return;
|
if (!pawn.IsValid) return;
|
||||||
var playerIndex = (int)pawn.Controller.Value.EntityIndex!.Value.Value;
|
|
||||||
|
var playerIndex = (int)pawn.Controller.Index;
|
||||||
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
@@ -213,6 +265,8 @@ namespace WeaponPaints
|
|||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GameEventHandler]
|
||||||
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
internal static string BuildDatabaseConnectionString()
|
internal static string BuildDatabaseConnectionString()
|
||||||
{
|
{
|
||||||
if (Config == null) return String.Empty;
|
if (Config == null) return string.Empty;
|
||||||
var builder = new MySqlConnectionStringBuilder
|
var builder = new MySqlConnectionStringBuilder
|
||||||
{
|
{
|
||||||
Server = Config.DatabaseHost,
|
Server = Config.DatabaseHost,
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ 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 (weapon == null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
if (player == null || weapon == null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
int playerIndex = (int)player!.EntityIndex!.Value.Value;
|
int playerIndex = (int)player.Index;
|
||||||
|
|
||||||
if (!gPlayerWeaponsInfo.ContainsKey(playerIndex)) return;
|
if (!gPlayerWeaponsInfo.ContainsKey(playerIndex)) return;
|
||||||
|
|
||||||
@@ -55,7 +55,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.EntityIndex!.Value.Value, out var knife))
|
if (g_playersKnife.TryGetValue((int)player.Index, out var knife))
|
||||||
{
|
{
|
||||||
player.GiveNamedItem(knife);
|
player.GiveNamedItem(knife);
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false)
|
internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false)
|
||||||
{
|
{
|
||||||
if (player == null || !player.IsValid || !player.PawnIsAlive) return;
|
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) 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;
|
||||||
@@ -88,16 +88,16 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
if (weapon != null && weapon.IsValid && weapon.Value.IsValid)
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
{
|
{
|
||||||
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
{
|
{
|
||||||
if (!force)
|
if (!force)
|
||||||
{
|
{
|
||||||
if (!weapon.Value.EntityIndex.HasValue) return;
|
if ((int)weapon.Index <= 0) return;
|
||||||
int weaponEntityIndex = (int)weapon.Value.EntityIndex!.Value.Value;
|
int weaponEntityIndex = (int)weapon.Index;
|
||||||
NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3");
|
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
||||||
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
|
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
|
||||||
|
|
||||||
AddTimer(1.0f, () =>
|
AddTimer(1.0f, () =>
|
||||||
@@ -123,35 +123,35 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
internal void RefreshPlayerKnife(CCSPlayerController? player)
|
internal void RefreshPlayerKnife(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (player == null || !player.IsValid || !player.PawnIsAlive) return;
|
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) 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);
|
CCSPlayer_ItemServices service = new(player.PlayerPawn.Value.ItemServices.Handle);
|
||||||
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
if (weapon != null && weapon.IsValid && weapon.Value.IsValid)
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
{
|
{
|
||||||
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
{
|
{
|
||||||
if (!weapon.Value.EntityIndex.HasValue) return;
|
if (weapon.Index <= 0) return;
|
||||||
int weaponEntityIndex = (int)weapon.Value.EntityIndex!.Value.Value;
|
int weaponEntityIndex = (int)weapon.Index;
|
||||||
NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3");
|
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
||||||
AddTimer(0.22f, () =>
|
AddTimer(0.22f, () =>
|
||||||
{
|
{
|
||||||
if (player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value.DesignerName.Contains("knife")
|
if (player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value!.DesignerName.Contains("knife")
|
||||||
||
|
||
|
||||||
player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value.DesignerName.Contains("bayonet")
|
player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value!.DesignerName.Contains("bayonet")
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (player.PawnIsAlive)
|
if (player.PawnIsAlive)
|
||||||
{
|
{
|
||||||
NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3");
|
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
||||||
service.DropActivePlayerWeapon(weapon.Value);
|
service.DropActivePlayerWeapon(weapon.Value);
|
||||||
GiveKnifeToPlayer(player);
|
GiveKnifeToPlayer(player);
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
||||||
|
|
||||||
if (knife != null && knife.IsValid && knife.Handle != -1 && knife.EntityIndex.HasValue)
|
if (knife != null && knife.IsValid && knife.Handle != -1 && knife.Index > 0)
|
||||||
{
|
{
|
||||||
knife.Remove();
|
knife.Remove();
|
||||||
}
|
}
|
||||||
@@ -183,14 +183,14 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player) || !player!.PawnIsAlive) return;
|
if (!Utility.IsPlayerValid(player) || !player!.PawnIsAlive) return;
|
||||||
|
|
||||||
AddTimer(0.18f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
|
AddTimer(0.18f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3"));
|
||||||
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot2"));
|
||||||
AddTimer(0.38f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 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.PawnIsAlive) return;
|
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) 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;
|
||||||
@@ -201,9 +201,9 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
if (weapon != null && weapon.IsValid && weapon.Value.IsValid)
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
{
|
{
|
||||||
if (!weapon.Value.EntityIndex.HasValue || !weapon.Value.DesignerName.Contains("weapon_")) continue;
|
if (weapon.Index <= 0 || !weapon.Value.DesignerName.Contains("weapon_")) continue;
|
||||||
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -224,11 +224,18 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
newWeapon.Clip1 = clip1;
|
if (newWeapon == null) return;
|
||||||
newWeapon.ReserveAmmo[0] = reservedAmmo;
|
try
|
||||||
|
{
|
||||||
|
newWeapon.Clip1 = clip1;
|
||||||
|
newWeapon.ReserveAmmo[0] = reservedAmmo;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch(Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
|
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
|
||||||
Console.WriteLine(ex.Message);
|
Console.WriteLine(ex.Message);
|
||||||
@@ -244,19 +251,19 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return false;
|
if (!_config.Additional.KnifeEnabled) return false;
|
||||||
|
|
||||||
if (player == null || !player.IsValid)
|
if (player == null || !player.IsValid || !player.Pawn.IsValid)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||||
if (weapons == null || weapons.Count <= 0) return false;
|
if (weapons == null) return false;
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
if (weapon != null && weapon.IsValid && weapon.Value.IsValid)
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
{
|
{
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
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 ModuleAuthor => "Nereziel & daffyy";
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
public override string ModuleVersion => "1.3a";
|
public override string ModuleVersion => "1.3b";
|
||||||
public WeaponPaintsConfig Config { get; set; } = new();
|
public WeaponPaintsConfig Config { get; set; } = new();
|
||||||
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
||||||
|
|
||||||
internal static WeaponSynchronization? weaponSync;
|
internal static WeaponSynchronization? weaponSync;
|
||||||
|
|
||||||
|
private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponPaints = new();
|
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponPaints = new();
|
||||||
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponSeed = new();
|
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponSeed = new();
|
||||||
@@ -31,7 +33,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
internal static Dictionary<int, Dictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new Dictionary<int, Dictionary<int, WeaponInfo>>();
|
internal static Dictionary<int, Dictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new Dictionary<int, Dictionary<int, WeaponInfo>>();
|
||||||
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 Dictionary<int, string> g_playersKnife = new();
|
||||||
internal static List<int> g_changedKnife = new();
|
//internal static List<int> g_changedKnife = new();
|
||||||
internal bool g_bCommandsAllowed = true;
|
internal bool g_bCommandsAllowed = true;
|
||||||
|
|
||||||
internal static List<JObject> skinsList = new List<JObject>();
|
internal static List<JObject> skinsList = new List<JObject>();
|
||||||
@@ -101,10 +103,6 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
Utility.TestDatabaseConnection();
|
Utility.TestDatabaseConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.GlobalShare)
|
|
||||||
GlobalShareConnect();
|
|
||||||
|
|
||||||
|
|
||||||
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
||||||
|
|
||||||
if (hotReload)
|
if (hotReload)
|
||||||
@@ -128,7 +126,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
SetupSkinsMenu();
|
SetupSkinsMenu();
|
||||||
|
|
||||||
RegisterEvents();
|
RegisterListeners();
|
||||||
RegisterCommands();
|
RegisterCommands();
|
||||||
|
|
||||||
Utility.LoadSkinsFromFile(ModuleDirectory + "/skins.json");
|
Utility.LoadSkinsFromFile(ModuleDirectory + "/skins.json");
|
||||||
|
|||||||
@@ -8,16 +8,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.80" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.84" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.24" />
|
<PackageReference Include="Dapper" Version="2.1.24" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="CounterStrikeSharp.API">
|
|
||||||
<HintPath>deps\CounterStrikeSharp.API.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -229,9 +229,9 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
internal async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player)
|
internal async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (player == null || !Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
int playerIndex = (int)player!.EntityIndex!.Value.Value;
|
int playerIndex = (int)player.Index;
|
||||||
string steamId = new SteamID(player.SteamID).SteamId64.ToString();
|
string steamId = new SteamID(player.SteamID).SteamId64.ToString();
|
||||||
|
|
||||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||||
|
|||||||
Reference in New Issue
Block a user