Skip to content

Commit

Permalink
Update WeaponPaints.cs
Browse files Browse the repository at this point in the history
Improved knife giving
And small changes to the code
  • Loading branch information
daffyyyy authored Nov 15, 2023
1 parent 8beaee9 commit c99acbc
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,17 @@ private void OnClientDisconnect(int playerSlot)
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsValid || !player.PlayerPawn.IsValid || !player.PawnIsAlive)
if (!player.IsValid || !player.PlayerPawn.IsValid)
{
return HookResult.Continue;
}
if (player.IsBot)
{
player.GiveNamedItem("weapon_knife");
return HookResult.Continue;
}

if (!PlayerHasKnife(player))
{
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
{
player.GiveNamedItem(knife);
}
else
{
player.GiveNamedItem("weapon_knife");
}
}
GiveKnifeToPlayer(player);

// Check the best slot and set it. Weird solution but works xD
AddTimer(0.1f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
AddTimer(0.1f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
AddTimer(0.1f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
AddTimer(0.35f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));

return HookResult.Continue;
}
Expand Down Expand Up @@ -212,9 +197,28 @@ private void OnEntitySpawned(CEntityInstance entity)
}
});
}
public void GiveKnifeToPlayer(CCSPlayerController player)
{
if (player.IsBot)
{
player.GiveNamedItem("weapon_knife");
return;
}

if (!PlayerHasKnife(player))
{
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
{
player.GiveNamedItem(knife);
}
else
{
player.GiveNamedItem("weapon_knife");
}
}
}
public void RemoveKnifeFromPlayer(CCSPlayerController player)
{
if (!player.PawnIsAlive) return;
if (!g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
foreach (var weapon in weapons)
Expand All @@ -225,15 +229,13 @@ public void RemoveKnifeFromPlayer(CCSPlayerController player)
if (weapon.Value.DesignerName.Contains("knife"))
{
weapon.Value.Remove();
player.GiveNamedItem(g_playersKnife[(int)player.EntityIndex!.Value.Value]);
break;
}
}
}
}
public static bool PlayerHasKnife(CCSPlayerController player)
{
if (!player.PawnIsAlive) return false;
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
foreach (var weapon in weapons)
{
Expand Down Expand Up @@ -261,6 +263,7 @@ private void SetupMenus()
player.PrintToChat(ReplaceTags(temp));
}
RemoveKnifeFromPlayer(player);
GiveKnifeToPlayer(player);
}
};
foreach (var knife in knifeTypes)
Expand Down

0 comments on commit c99acbc

Please sign in to comment.