Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
daffyyyy committed Nov 29, 2023
1 parent 73e3a05 commit 00f9207
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 40 deletions.
37 changes: 19 additions & 18 deletions Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private void RegisterCommands()
});
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) =>
{
if (!Utility.IsPlayerValid(player)) return;
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
OnCommandRefresh(player, info);
});
if (Config.Additional.CommandKillEnabled)
Expand All @@ -31,7 +31,7 @@ private void RegisterCommands()
}
private void SetupKnifeMenu()
{
if (!Config.Additional.KnifeEnabled) return;
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;

var knivesOnly = weaponList
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
Expand Down Expand Up @@ -62,13 +62,11 @@ private void SetupKnifeMenu()
g_playersKnife[(int)player!.EntityIndex!.Value.Value] = knifeKey;
if (player!.PawnIsAlive)
if (player!.PawnIsAlive && g_bCommandsAllowed)
{
g_changedKnife.Add((int)player.EntityIndex!.Value.Value);
if (PlayerHasKnife(player))
{
RefreshPlayerKnife(player);
}
RefreshWeapons(player);
//RefreshPlayerKnife(player);
/*
AddTimer(1.0f, () => GiveKnifeToPlayer(player));
Expand All @@ -85,7 +83,7 @@ private void SetupKnifeMenu()
}
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
{
if (!Utility.IsPlayerValid(player)) return;
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
int playerIndex = (int)player!.EntityIndex!.Value.Value;
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length)
Expand Down Expand Up @@ -128,9 +126,11 @@ private void SetupSkinsMenu()
// Function to handle skin selection for the chosen weapon
var handleSkinSelection = (CCSPlayerController? p, ChatMenuOption opt) =>
{
if (p == null || !p.IsValid) return;
if (p == null || !p.IsValid || !p.EntityIndex.HasValue) return;
var steamId = new SteamID(player.SteamID);
playerIndex = (int)p.EntityIndex.Value.Value;
var steamId = new SteamID(p.SteamID);
var firstSkin = skinsList?.FirstOrDefault(skin =>
{
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
Expand All @@ -151,22 +151,23 @@ private void SetupSkinsMenu()
string temp = $" {Config.Prefix} {Config.Messages.ChosenSkinMenu}".Replace("{SKIN}", selectedSkin);
p.PrintToChat(Utility.ReplaceTags(temp));
/*
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
{
gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = new WeaponInfo();
}
*/
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.0f;
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Seed = 0;
if (weaponSync == null) return;
Task.Run(async () =>
if (!Config.GlobalShare)
{
await weaponSync.SyncWeaponPaintsToDatabase(player);
});
if (weaponSync == null) return;
Task.Run(async () =>
{
await weaponSync.SyncWeaponPaintsToDatabase(p);
});
}
}
};
Expand Down Expand Up @@ -222,7 +223,7 @@ private void SetupSkinsMenu()

private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
{
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return;
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
if (!Utility.IsPlayerValid(player)) return;
string temp = "";
if (!player!.EntityIndex.HasValue) return;
Expand Down
11 changes: 10 additions & 1 deletion Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private void RegisterEvents()
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
RegisterEventHandler<EventItemPickup>(OnItemPickup);
}
Expand Down Expand Up @@ -66,7 +67,6 @@ private void OnClientAuthorized(int playerSlot, SteamID steamID)
if (Config.Additional.KnifeEnabled && weaponSync != null)
_ = weaponSync.GetKnifeFromDatabase(playerIndex);


/*
Task.Run(async () =>
{
Expand Down Expand Up @@ -118,8 +118,17 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");

g_bCommandsAllowed = true;

return HookResult.Continue;
}

private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
{
g_bCommandsAllowed = false;
return HookResult.Continue;
}

private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
{
if (@event.Defindex == 42 || @event.Defindex == 59)
Expand Down
47 changes: 27 additions & 20 deletions WeaponAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ internal void RefreshWeapons(CCSPlayerController? player)
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
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"));

foreach (var weapon in weapons)
Expand All @@ -205,31 +205,38 @@ internal void RefreshWeapons(CCSPlayerController? player)
{
if (!weapon.Value.EntityIndex.HasValue || !weapon.Value.DesignerName.Contains("weapon_")) continue;
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
{
weapon.Value.Remove();
GiveKnifeToPlayer(player);
}
else
try
{
int clip1, reservedAmmo;
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
{
weapon.Value.Remove();
GiveKnifeToPlayer(player);
}
else
{
int clip1, reservedAmmo;

clip1 = weapon.Value.Clip1;
reservedAmmo = weapon.Value.ReserveAmmo[0];
clip1 = weapon.Value.Clip1;
reservedAmmo = weapon.Value.ReserveAmmo[0];

weapon.Value.Remove();
CBasePlayerWeapon newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(weapon.Value.DesignerName));
weapon.Value.Remove();
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weapon.Value.DesignerName));

Server.NextFrame(() =>
{
newWeapon.Clip1 = clip1;
newWeapon.ReserveAmmo[0] = reservedAmmo;
});

Server.NextFrame(() =>
{
newWeapon.Clip1 = clip1;
newWeapon.ReserveAmmo[0] = reservedAmmo;
});
}
} catch(Exception ex)
{
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
Console.WriteLine(ex.Message);
}
}
}
RefreshSkins(player);
if (Config.Additional.SkinVisibilityFix)
RefreshSkins(player);
}
}

Expand Down Expand Up @@ -273,7 +280,7 @@ private static int GetRandomPaint(int defindex)
if (WeaponPaints.skinsList != null)
{
// Filter weapons by the provided defindex
var filteredWeapons = WeaponPaints.skinsList.FindAll(w => w["weapon_defindex"]?.ToString() == defindex.ToString());
var filteredWeapons = skinsList.FindAll(w => w["weapon_defindex"]?.ToString() == defindex.ToString());

if (filteredWeapons.Count > 0)
{
Expand Down
3 changes: 2 additions & 1 deletion WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Newtonsoft.Json.Linq;

namespace WeaponPaints;
[MinimumApiVersion(71)]
[MinimumApiVersion(82)]
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{
public override string ModuleName => "WeaponPaints";
Expand All @@ -32,6 +32,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
internal static Dictionary<int, string> g_playersKnife = new();
internal static List<int> g_changedKnife = new();
internal bool g_bCommandsAllowed = true;

internal static List<JObject> skinsList = new List<JObject>();
internal static readonly Dictionary<string, string> weaponList = new()
Expand Down

0 comments on commit 00f9207

Please sign in to comment.