Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still knife fix :D (Previous sometimes give random knife to player) #64

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ public override void Load(bool hotReload)
{
for (int i = 1; i <= Server.MaxPlayers; i++)
{
if (Config.Additional.KnifeEnabled)
await GetKnifeFromDatabase(i);
if (Config.Additional.SkinEnabled)
await GetWeaponPaintsFromDatabase(i);

if (Config.Additional.KnifeEnabled)
await GetKnifeFromDatabase(i);
}
});
}
Expand Down Expand Up @@ -340,15 +341,8 @@ private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)

if (Config.Additional.KnifeEnabled)
{
/*
if (!PlayerHasKnife(player))
GiveKnifeToPlayer(player);
*/
RemoveKnifeFromPlayer(player);
AddTimer(0.2f, () =>
{
GiveKnifeToPlayer(player);
});
}

return HookResult.Continue;
Expand Down Expand Up @@ -376,10 +370,17 @@ private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife")
{
RemoveKnifeFromPlayer(player);
AddTimer(0.2f, () =>

AddTimer(0.1f, () =>
{
GiveKnifeToPlayer(player);
if (!PlayerHasKnife(player))
GiveKnifeToPlayer(player);
});

if (Config.Additional.SkinVisibilityFix)
{
AddTimer(0.25f, () => RefreshSkins(player));
}
}
}
return HookResult.Continue;
Expand Down Expand Up @@ -472,25 +473,23 @@ private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventIn
}
private void GiveKnifeToPlayer(CCSPlayerController? player)
{
if (!Config.Additional.KnifeEnabled) return;
if (player == null || !player.IsValid || !player.PawnIsAlive) return;
if (!Config.Additional.KnifeEnabled || player == null || !player.IsValid) return;

if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
{
player.GiveNamedItem(knife);
}
else if (Config.Additional.GiveRandomKnife)
{
Random random = new Random();
int index = random.Next(knifeTypes.Count);
var randomKnife = knifeTypes.Values.ElementAt(index);
player.GiveNamedItem(randomKnife);
}
else
{
if (Config.Additional.GiveRandomKnife)
{
Random random = new Random();
int index = random.Next(knifeTypes.Count);
player.GiveNamedItem(knifeTypes.Values.ElementAt(index));
}
else
{
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
}
var defaultKnife = (CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife";
player.GiveNamedItem(defaultKnife);
}
}
private void RemoveKnifeFromPlayer(CCSPlayerController? player)
Expand Down