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

Show ammo percentage of sentries #59

Open
Neubulae opened this issue Sep 30, 2023 · 3 comments
Open

Show ammo percentage of sentries #59

Neubulae opened this issue Sep 30, 2023 · 3 comments

Comments

@Neubulae
Copy link

...is that possible?

@randomuserhi
Copy link

What do you specifically mean?

  • on HUD -> instead of displaying "DEPLOYED" still show sentry percentage?
  • on in-game Sentry screen -> show percentage instead of raw bullet count
  • on Sentry Marker (extension to sentry marker feature)

All should be possible, but not sure what exactly you are looking for.

@Neubulae
Copy link
Author

What do you specifically mean?

* on HUD -> instead of displaying "DEPLOYED" still show sentry percentage?

* on in-game Sentry screen -> show percentage instead of raw bullet count

* on Sentry Marker (extension to sentry marker feature)

All should be possible, but not sure what exactly you are looking for.

Ah I initially meant the third choice but any of these three are interesting options....

@randomuserhi
Copy link

randomuserhi commented Feb 19, 2024

In the case of the third choice, I assume something like this can work (possibly wrapped under a Feature option or something):

Just replace this area with something along the lines of:

// Attach a behaviour to update marker name accordingly in real time
UpdateMarkerInfo info = navMarkerPlacer.gameObject.GetComponent<UpdateMarkerInfo>();
if (info == null)
{
    info = navMarkerPlacer.gameObject.AddComponent<UpdateMarkerInfo>();
}
info.ammo = PlayerBackpackManager.GetBackpack(snetPlayer).AmmoStorage.GetInventorySlotAmmo(AmmoType.Class);
info.navMarkerPlacer = navMarkerPlacer;
info.sentry = __instance;
info.snetPlayer = snetPlayer;

Then use a behaviour to update the marker:

#if IL2CPP
public override void Init()
{
    LoaderWrapper.ClassInjector.RegisterTypeInIl2Cpp<UpdateMarkerInfo>();
}
#endif

private class UpdateMarkerInfo : MonoBehaviour
{
    public PlaceNavMarkerOnGO navMarkerPlacer;
    public InventorySlotAmmo ammo;
    public SentryGunInstance sentry;
    public SNet_Player snetPlayer;

    private void Update()
    {
        if (!navMarkerPlacer.m_marker.IsVisible) return;

        var col = MARKER_GREEN;
        var name = string.Empty;

        if (Settings.DisplayPlayerNameAboveMarker)
        {
            name = $"<size={Settings.PlayerNameSize * 100f}%>{snetPlayer.NickName}</size>";
        }

        if (Settings.UsePlayerColorForMarkers)
        {
            col = snetPlayer.PlayerColor;
            name = $"<#{ColorUtility.ToHtmlStringRGB(snetPlayer.PlayerColor)}>{name}</color>";
        }
        else
        {
            name = $"<color=white>{name}</color>";
        }

        var sentryArch = string.Empty;

        if (Settings.ShowSentryArchetype)
        {
            int bulletsInPack = (int)(sentry.m_ammo / ammo.CostOfBullet);
            int percentage = (int)(bulletsInPack * ammo.BulletsToRelConv * 100);
            sentryArch = $"<color=white><size={Settings.PlayerNameSize * 100f}%>{sentry.ArchetypeName} [{percentage}%]</size></color>";
        }

        navMarkerPlacer.UpdateName(name, sentryArch);
        navMarkerPlacer.UpdatePlayerColor(col);
    }
}

image

Ig for flavour you can alter this to change colour for different ammo states (green=full, yellow=medium/low, red=completely out)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants