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.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
{
@@ -25,7 +16,6 @@ namespace WeaponPaints
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
RegisterEventHandler<EventItemPickup>(OnItemPickup);
}
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
@@ -59,8 +49,10 @@ namespace WeaponPaints
{
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
});
}
/*
private void OnClientAuthorized(int playerSlot, SteamID steamID)
{
int playerIndex = playerSlot + 1;
@@ -72,6 +64,7 @@ namespace WeaponPaints
await weaponSync.GetKnifeFromDatabase(playerIndex);
});
}
*/
private void OnClientDisconnect(int playerSlot)
{
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
@@ -110,6 +103,7 @@ namespace WeaponPaints
{
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
return HookResult.Continue;
}
@@ -118,22 +112,27 @@ namespace WeaponPaints
if (@event.Defindex == 42 || @event.Defindex == 59)
{
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)
&&
g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife")
{
g_knifePickupCount[(int)player.EntityIndex!.Value.Value]++;
RefreshPlayerKnife(player);
RemovePlayerKnife(player, true);
AddTimer(0.3f, ()=> GiveKnifeToPlayer(player));
//RefreshPlayerKnife(player);
/*
if (!PlayerHasKnife(player))
GiveKnifeToPlayer(player);
*/
if (Config.Additional.SkinVisibilityFix)
{
AddTimer(0.25f, () => RefreshSkins(player));
}
*/
}
}
return HookResult.Continue;

View File

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

View File

@@ -75,7 +75,7 @@ namespace WeaponPaints
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.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
@@ -92,6 +92,8 @@ namespace WeaponPaints
{
//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 (!force)
{
if (!weapon.Value.EntityIndex.HasValue) return;
int weaponEntityIndex = (int)weapon.Value.EntityIndex!.Value.Value;
@@ -106,6 +108,11 @@ namespace WeaponPaints
knife.Remove();
}
});
}
else
{
weapon.Value.Remove();
}
break;
}
@@ -151,13 +158,18 @@ namespace WeaponPaints
}
});
AddTimer(2.5f, () =>
Task.Delay(TimeSpan.FromSeconds(3.5)).ContinueWith(_ =>
{
try
{
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
if (knife != null && knife.IsValid && knife.EntityIndex.HasValue)
if (knife != null && knife.IsValid && knife.Handle != -1 && knife.EntityIndex.HasValue)
{
knife.Remove();
}
}
catch (Exception) { }
});
break;

View File

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

View File

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