Topic: Trying to make a universal guage drain to work

Hello:

Trying to make a universal guage drain to work. Some instances I want the Guage 2 to drain after being hit by a projectible. There's nothing available in the Editor yet for it.

I tried to modify this code in ControlsScript.cs but it didn't work. Please advise.

   public void DoFixedUpdate(
        IDictionary<InputReferences, InputEvents> previousInputs,
        IDictionary<InputReferences, InputEvents> currentInputs
    )
    {  

      // Gauge Drain
        if (gaugeDPS != 0)
        {


           UFE.p1ControlsScript.currentGaugesPoints[1] -= (1000 * (gaugeDPS / 100) / UFE.config.fps) * UFE.timeScale;

           UFE.p2ControlsScript.currentGaugesPoints[1] -= (1000 * (gaugeDPS / 100) / UFE.config.fps) * UFE.timeScale;

        }

}

Share

Thumbs up Thumbs down

Re: Trying to make a universal guage drain to work

I don't recommend modifying UFE scripts to do something like this unless you absolutely have to.

Instead we can write are own separate script to modify certain variables UFE uses.

Certain code we write needs to be executed in a network safe manner so you need to spawn somethings in using UFE.SpawnGameObject().

I was only able to get UFE.SpawnGameObject() to spawn objects when in a match so be aware of that.

using UnityEngine;

namespace FreedTerror
{
    public class UFE2NetworkGameObjectSpawner : MonoBehaviour
    {
        [SerializeField]
        private GameObject[] prefabs;

        // Start is called before the first frame update
        void Start()
        {
            int length = prefabs.Length;
            for (int i = 0; i < length; i++)
            {
                UFE.SpawnGameObject(prefabs[i], new Vector3(0, 0, 0), Quaternion.identity, true, 0);
            }
        }
    }
}

This script should help you get started with changing gauges in a network safe way.

using UnityEngine;
using UFE3D;
using UFENetcode;
using FPLibrary;

public class NetworkGaugeExample : UFEBehaviour, UFEInterface
{
    [SerializeField]
    private GaugeId gaugeID;

    [SerializeField]
    [Range(-100, 100)]
    private float percentAmount;

    public override void UFEFixedUpdate()
    {
        if (UFE.p1ControlsScript == null
            || UFE.p2ControlsScript == null) return;

        UpdateGauge(UFE.p1ControlsScript);

        UpdateGauge(UFE.p2ControlsScript);
    }

    private void UpdateGauge(ControlsScript player)
    {
        player.currentGaugesPoints[(int)gaugeID] += (player.myInfo.maxGaugePoints * ((Fix64)percentAmount / 100));
    }
}

Share

Thumbs up Thumbs down