Skip to content

Commit

Permalink
fix: Moved health to nextframe
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-wos committed Jun 7, 2024
1 parent 8a1ff53 commit 06fa5f8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Publish
uses: actions/upload-artifact@v4
with:
name: Sessions-${{ github.sha }}
name: Refiller-${{ github.sha }}
path: plugin

- name: Create Release
Expand All @@ -91,6 +91,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./plugin/Sessions-${{ github.sha }}.zip
asset_name: Sessions.zip
asset_path: ./plugin/Refiller-${{ github.sha }}.zip
asset_name: Refiller.zip
asset_content_type: application/zip
2 changes: 0 additions & 2 deletions Refiller.sln.DotSettings

This file was deleted.

34 changes: 20 additions & 14 deletions src/Refiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
List<CCSPlayerController?> players =
[
@event.Attacker,
Config.AssistRefill && @event.Attacker != @event.Assister ? @event.Assister : null
Config.AssistRefill ? @event.Assister : null
];

List<CHandle<CBasePlayerWeapon>> weapons = [];
Expand All @@ -38,17 +38,6 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
weapons.AddRange(player!.PlayerPawn!.Value!.WeaponServices!.MyWeapons);
else if (Config.AmmoRefill == "current")
weapons.Add(player!.PlayerPawn!.Value!.WeaponServices!.ActiveWeapon);

var currentHealth = player!.PlayerPawn.Value!.Health;

player!.PlayerPawn.Value!.Health = Config.HealthRefill switch
{
"all" => 100,
_ => currentHealth + int.Parse(Config.HealthRefill) >= 100 ? 100 : currentHealth + int.Parse(Config.HealthRefill)
};

if (Config.ArmorRefill)
player!.PlayerPawn.Value!.ArmorValue = 100;
}

Server.NextFrame(() =>
Expand All @@ -60,12 +49,29 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
if (weaponData == null)
continue;
Console.WriteLine($"{weaponData.Name}");
weapon.Value!.Clip1 = weaponData.MaxClip1;
weapon.Value!.ReserveAmmo[0] = weaponData.PrimaryReserveAmmoMax;
Utilities.SetStateChanged(weapon.Value!.As<CCSWeaponBase>(), "CBasePlayerWeapon", "m_pReserveAmmo");
}
foreach (var player in players.Where(player => player != null && player.IsValid))
{
var currentHealth = player!.PlayerPawn.Value!.Health;
player!.PlayerPawn.Value!.Health = Config.HealthRefill switch
{
"all" => 100,
_ => currentHealth + int.Parse(Config.HealthRefill) >= 100 ? 100 : currentHealth + int.Parse(Config.HealthRefill)
};
Utilities.SetStateChanged(player!.PlayerPawn.Value!, "CBaseEntity", "m_iHealth");
if (!Config.ArmorRefill)
continue;
player!.PlayerPawn.Value!.ArmorValue = 100;
Utilities.SetStateChanged(player!.PlayerPawn.Value!, "CCSPlayerPawn", "m_ArmorValue");
}
});

return HookResult.Continue;
Expand Down

0 comments on commit 06fa5f8

Please sign in to comment.