mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 10:43:22 +00:00
Changes changes
This commit is contained in:
10
Commands.cs
10
Commands.cs
@@ -151,10 +151,12 @@ namespace WeaponPaints
|
|||||||
string temp = $" {Config.Prefix} {Config.Messages.ChosenSkinMenu}".Replace("{SKIN}", selectedSkin);
|
string temp = $" {Config.Prefix} {Config.Messages.ChosenSkinMenu}".Replace("{SKIN}", selectedSkin);
|
||||||
p.PrintToChat(Utility.ReplaceTags(temp));
|
p.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
|
|
||||||
|
/*
|
||||||
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
||||||
{
|
{
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = new WeaponInfo();
|
gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = new WeaponInfo();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.0f;
|
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.0f;
|
||||||
@@ -223,15 +225,16 @@ namespace WeaponPaints
|
|||||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return;
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
string temp = "";
|
string temp = "";
|
||||||
|
if (!player!.EntityIndex.HasValue) return;
|
||||||
int playerIndex = (int)player!.EntityIndex!.Value.Value;
|
int playerIndex = (int)player!.EntityIndex!.Value.Value;
|
||||||
if (commandCooldown != null && 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;
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerIndex));
|
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerIndex));
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
{
|
{
|
||||||
if (PlayerHasKnife(player))
|
/*if (PlayerHasKnife(player))
|
||||||
RefreshPlayerKnife(player);
|
RefreshPlayerKnife(player);
|
||||||
/*
|
/*
|
||||||
AddTimer(1.0f, () =>
|
AddTimer(1.0f, () =>
|
||||||
@@ -264,8 +267,7 @@ namespace WeaponPaints
|
|||||||
if (!Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.SkinEnabled) return;
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
string temp = "";
|
string temp;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand))
|
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand))
|
||||||
{
|
{
|
||||||
temp = $" {Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
temp = $" {Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
||||||
|
|||||||
32
Events.cs
32
Events.cs
@@ -17,15 +17,39 @@ namespace WeaponPaints
|
|||||||
private void RegisterEvents()
|
private void RegisterEvents()
|
||||||
{
|
{
|
||||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
||||||
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
/*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<EventPlayerSpawn>(OnPlayerSpawn);
|
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||||
|
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
||||||
RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid || !player.EntityIndex.HasValue || player.IsHLTV) return HookResult.Continue;
|
||||||
|
|
||||||
|
int playerIndex = (int)player.EntityIndex.Value.Value;
|
||||||
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
||||||
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||||
|
/*
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnMapStart(string mapName)
|
private void OnMapStart(string mapName)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
@@ -42,10 +66,10 @@ namespace WeaponPaints
|
|||||||
int playerIndex = playerSlot + 1;
|
int playerIndex = playerSlot + 1;
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
|
||||||
await weaponSync.GetKnifeFromDatabase(playerIndex);
|
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
await weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
await weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
||||||
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
await weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private void OnClientDisconnect(int playerSlot)
|
private void OnClientDisconnect(int playerSlot)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
internal static bool IsPlayerValid(CCSPlayerController? player)
|
internal static bool IsPlayerValid(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV);
|
return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV && player.SteamID.ToString() != "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string BuildDatabaseConnectionString()
|
internal static string BuildDatabaseConnectionString()
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ 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.PawnIsAlive) return;
|
||||||
@@ -134,17 +135,28 @@ namespace WeaponPaints
|
|||||||
if (!weapon.Value.EntityIndex.HasValue) return;
|
if (!weapon.Value.EntityIndex.HasValue) return;
|
||||||
int weaponEntityIndex = (int)weapon.Value.EntityIndex!.Value.Value;
|
int weaponEntityIndex = (int)weapon.Value.EntityIndex!.Value.Value;
|
||||||
NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3");
|
NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3");
|
||||||
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
|
AddTimer(0.22f, () =>
|
||||||
|
{
|
||||||
|
if (player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value.DesignerName.Contains("knife")
|
||||||
|
||
|
||||||
|
player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value.DesignerName.Contains("bayonet")
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (player.PawnIsAlive)
|
||||||
|
{
|
||||||
|
NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3");
|
||||||
|
service.DropActivePlayerWeapon(weapon.Value);
|
||||||
|
GiveKnifeToPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
AddTimer(1.0f, () =>
|
AddTimer(2.5f, () =>
|
||||||
{
|
{
|
||||||
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
||||||
if (knife != null && knife.IsValid)
|
if (knife != null && knife.IsValid && knife.EntityIndex.HasValue)
|
||||||
{
|
{
|
||||||
knife.Remove();
|
knife.Remove();
|
||||||
|
|
||||||
if (player.PawnIsAlive)
|
|
||||||
GiveKnifeToPlayer(player);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -165,14 +177,17 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
internal static bool PlayerHasKnife(CCSPlayerController? player)
|
internal static bool PlayerHasKnife(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (!WeaponPaints._config.Additional.KnifeEnabled) return false;
|
if (!_config.Additional.KnifeEnabled) return false;
|
||||||
|
|
||||||
if (player == null || !player.IsValid)
|
if (player == null || !player.IsValid)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||||
if (weapons == null || weapons.Count <= 0) return false;
|
if (weapons == null || weapons.Count <= 0) return false;
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,10 +124,9 @@ namespace WeaponPaints
|
|||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
|
|
||||||
var steamId = new SteamID(player.SteamID);
|
var steamId = new SteamID(player.SteamID);
|
||||||
|
|
||||||
if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(playerIndex))
|
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(playerIndex, out _))
|
||||||
{
|
{
|
||||||
WeaponPaints.gPlayerWeaponsInfo[playerIndex] = new Dictionary<int, WeaponInfo>();
|
WeaponPaints.gPlayerWeaponsInfo[playerIndex] = new Dictionary<int, WeaponInfo>();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user