Synchronizes additional player information like ammo clip and stamina
For feedback and issues, DM @uwufood on the GTFO Modding Discord Server
The vanilla game doesn't perform synchronization for information such as stamina and weapon clip ammo count (only total ammo count is synced).
This mod adds synchronization for these values. It also performs these updates at a higher frequency than the vanilla game. For the mod to function, both ends needs to have the mod installed.
Synchronization is done on every shot and reload by hooking BulletWeapon.Fire, Shotgun.Fire,
and PlayerInventoryLocal.DoReload. This is then capped at maximum frequency as defined in the config.
Clip information is written directly into all items and can be accessed via
ItemEquippable.GetCurrentClip for the respective item.
AmmoInPack information is simply updated at the same tigher frequency as clip information and can be access via PlayerAmmoStorage just like in the vanilla game.
The ammo information for non-local players/bots will include the clip count in the reserve count. This is to ensure correct display in vanilla inventory UI. To obtain the actual reserve count for non-local players/bots, subtract their clip count from the reserve count.
There is a convenience function AmmoSync.ReserveIncludesClip for determining if clip should be subtracted from reserve count to get actual reserve count, the logic is rather simple.
/// <summary>
/// Returns whether a given player's reserve ammo count includes the clip
/// ammo count, which means whether if the player is not local.
/// For bots this means checking if master is remote.
/// </summary>
/// <returns>
/// true if clip ammo count should be subtracted from
/// reserve ammo count to obtain the actual reserve ammo count.
/// For non-supporting clients, this has no side effects in interpretation
/// since clip would always be 0 for them.
/// </returns>
public static bool ReserveIncludesClip(SNet_Player player) {
if (player.IsBot) player = SNet.Master;
return !player.IsLocal;
}
Stamina information is synced and managed by PlayerSync since the vanilla game does not provide a mechanism to track it for other players. The values can be queried via:
namespace PlayerSync.Sync.Stamina;
class StaminaSync {
/// <summary>
/// Tries to get the stamina info for a given player, returns false if
/// player doesn't exist or unsupported (i.e. not synced).
/// </summary>
/// <param name="player">player to query</param>
/// <param name="info">stamina information</param>
/// <returns>true if found</returns>
public static bool GetStaminaInfo(SNet_Player player, out StaminaInfo info) { ... }
}
In general, no configuration is needed. Clients with this mod installed will update each other with the information.
The frequency for updates, however, can be configured in the config; this is hard capped at 60Hz.