This commit is contained in:
daffyyyy
2023-11-28 23:44:28 +01:00
parent 93e8af07d2
commit 8e7a2a2923
5 changed files with 42 additions and 41 deletions

View File

@@ -1,14 +1,5 @@
using CounterStrikeSharp.API; using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
namespace WeaponPaints namespace WeaponPaints
{ {
@@ -25,7 +16,6 @@ namespace WeaponPaints
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre); RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
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)
@@ -59,8 +49,10 @@ 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");
}); });
} }
/*
private void OnClientAuthorized(int playerSlot, SteamID steamID) private void OnClientAuthorized(int playerSlot, SteamID steamID)
{ {
int playerIndex = playerSlot + 1; int playerIndex = playerSlot + 1;
@@ -72,6 +64,7 @@ namespace WeaponPaints
await weaponSync.GetKnifeFromDatabase(playerIndex); await weaponSync.GetKnifeFromDatabase(playerIndex);
}); });
} }
*/
private void OnClientDisconnect(int playerSlot) private void OnClientDisconnect(int playerSlot)
{ {
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot); CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
@@ -110,6 +103,7 @@ 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");
return HookResult.Continue; return HookResult.Continue;
} }
@@ -118,22 +112,27 @@ namespace WeaponPaints
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] >= 1) return HookResult.Continue; if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.EntityIndex!.Value.Value] >= 2) return HookResult.Continue;
if (g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value) if (g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)
&& &&
g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife") g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife")
{ {
g_knifePickupCount[(int)player.EntityIndex!.Value.Value]++; g_knifePickupCount[(int)player.EntityIndex!.Value.Value]++;
RefreshPlayerKnife(player);
RemovePlayerKnife(player, true);
AddTimer(0.3f, ()=> GiveKnifeToPlayer(player));
//RefreshPlayerKnife(player);
/* /*
if (!PlayerHasKnife(player)) if (!PlayerHasKnife(player))
GiveKnifeToPlayer(player); GiveKnifeToPlayer(player);
*/
if (Config.Additional.SkinVisibilityFix) if (Config.Additional.SkinVisibilityFix)
{ {
AddTimer(0.25f, () => RefreshSkins(player)); AddTimer(0.25f, () => RefreshSkins(player));
} }
*/
} }
} }
return HookResult.Continue; return HookResult.Continue;

View File

@@ -1,5 +1,4 @@
using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Utils; using CounterStrikeSharp.API.Modules.Utils;
using Dapper; using Dapper;
using MySqlConnector; using MySqlConnector;

View File

@@ -75,7 +75,7 @@ namespace WeaponPaints
player.GiveNamedItem(defaultKnife); player.GiveNamedItem(defaultKnife);
} }
} }
internal void RemovePlayerKnife(CCSPlayerController? player) internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false)
{ {
if (player == null || !player.IsValid || !player.PawnIsAlive) return; if (player == null || !player.IsValid || !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;
@@ -93,19 +93,26 @@ namespace WeaponPaints
//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 (!force)
int weaponEntityIndex = (int)weapon.Value.EntityIndex!.Value.Value;
NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3");
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
AddTimer(1.0f, () =>
{ {
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex); if (!weapon.Value.EntityIndex.HasValue) return;
if (knife != null && knife.IsValid) int weaponEntityIndex = (int)weapon.Value.EntityIndex!.Value.Value;
NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3");
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
AddTimer(1.0f, () =>
{ {
knife.Remove(); CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
} if (knife != null && knife.IsValid)
}); {
knife.Remove();
}
});
}
else
{
weapon.Value.Remove();
}
break; break;
} }
@@ -151,13 +158,18 @@ namespace WeaponPaints
} }
}); });
AddTimer(2.5f, () => Task.Delay(TimeSpan.FromSeconds(3.5)).ContinueWith(_ =>
{ {
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex); try
if (knife != null && knife.IsValid && knife.EntityIndex.HasValue)
{ {
knife.Remove(); CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
if (knife != null && knife.IsValid && knife.Handle != -1 && knife.EntityIndex.HasValue)
{
knife.Remove();
}
} }
catch (Exception) { }
}); });
break; break;

View File

@@ -1,10 +1,4 @@
using System; namespace WeaponPaints
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WeaponPaints
{ {
public class WeaponInfo public class WeaponInfo
{ {

View File

@@ -1,14 +1,11 @@
using CounterStrikeSharp.API; 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.Memory;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Cvars;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace WeaponPaints; namespace WeaponPaints;
[MinimumApiVersion(61)] [MinimumApiVersion(71)]
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig> public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{ {
public override string ModuleName => "WeaponPaints"; public override string ModuleName => "WeaponPaints";