Topic: Trying to make a self-refilling gauge?

Hey so I'm still poking around UFE2 but I'm trying to test an idea which requires a self-refilling gauge. Looking through the default tools, I can't see an option or a setting for that. I can only find options to it tied in the moves themselves.

I'm assuming there's a way to code it myself, but I just need to be pointed in the right direction to get started. I don't access to the source version of UFE2, if that's necessary info. Thanks in advanced!

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

When does the self-refilling gauge start/stop? Does it trigger at the start of the round and continue until the end? is it triggered by a specific move and cancelled after time elapses or another move cancels it?

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

MrPonton wrote:

When does the self-refilling gauge start/stop? Does it trigger at the start of the round and continue until the end? is it triggered by a specific move and cancelled after time elapses or another move cancels it?

My bad, should've mentioned specifics. It's a continuous state of refill from the start of the match, the gauge also starts full. When using specials or something similar it uses up X amount of the gauge, after a short pause it'd begin refilling again. There's no input activation or cancel or anything like that.

Share

Thumbs up Thumbs down

4 (edited by MrPonton 2020-10-31 20:33:59)

Re: Trying to make a self-refilling gauge?

Ok. So my suggestion would be to create a new script and attach it to the Battle GUI prefab. There you'd use the OnRoundBegins() and OnRoundEnds() event handler in the script. (See: http://www.ufe3d.com/doku.php/code )

Basically that new script would have a boolean like

increaseMeter

in it. And in the Update() of the script you'd do something like

if (increaseMeter) { 
// Add 1 to Player 1's gauge.
// Add 1 to Player 2's gauge.
// If Player 1's gauge is exceeding the maximum, set the gauge to the maximum
// If Player 2's gauge is exceeding the maximum, set the gauge to the maximum
}

Then in the above event handlers you just set the boolean to true/false.

Share

Thumbs up +1 Thumbs down

Re: Trying to make a self-refilling gauge?

MrPonton wrote:

Ok. So my suggestion would be to create a new script and attach it to the Battle GUI prefab. There you'd use the OnRoundBegins() and OnRoundEnds() event handler in the script. (See: http://www.ufe3d.com/doku.php/code )

Basically that new script would have a boolean like

increaseMeter

in it. And in the Update() of the script you'd do something like

if (increaseMeter) { 
// If Player 1's gauge is not maximum add 1
// if Player 2's gauge is not maximum add 1
}

Then in the above event handlers you just set the boolean to true/false.

Ah man I totally forgot there was a page with the code examples. Thanks a ton for the help, man! I appreciate it.

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

Np, I also edited my post with an updated pseudo script for the Update(). Basically add the amount you want to be added every frame, then check if the user exceeds the maximum, and set it to the maximum in case.

Also, I would not suggest updating the gauge every frame but instead adding some code that basically does it on a timed interval. It's just more difficult/complex to give as an example, but you can find plenty of resources online about how to do an interval based update on the meter.

I would also caution that I'm unsure how this will work in the rollback netcode system as I'm very unfamiliar with that system to say in any educated way. But at least it'd be a start.

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

I was struggling to get this to work still really. I couldn't figure out how to directly influence the gauge gain/loss. I'm looking at the DefaultBattleGUI script on the Battle GUI Prefab and noticing the fill amount is influenced from there I think? Is there a specific variable that I can change from my script to get the result I'm looking for?

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

from DefaultBattleGUI.cs:

this.player1GUI.gauges[i].fillAmount = (float)player1.controlsScript.currentGaugesPoints[i] / UFE.config.player1Character.maxGaugePoints;

That checks every frame to calculate the fillAmount for Player 1. So all you need to do is know which guage you're setting as this "always increase" gauge and somewhere basically just increase

player1.controlsScript.currentGaugesPoints[indexNumberOfSpecificGaugeThatIncreasesOnItsOwn]

and then the default battle gui will take care of the amount of fill for that.

Share

Thumbs up Thumbs down

9 (edited by Luima 2023-09-21 13:01:59)

Re: Trying to make a self-refilling gauge?

Hi MrProton, im not a coder, i tried to attach this script to the BattleGui prefab so the gauge 3 have the refill action with no luck, can you please share the complete script so i can see how it should look?

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

I whipped up this example script.

using UnityEngine;
using UFE3D;
using FPLibrary;

public class RefillingGaugeExample : MonoBehaviour
{
    private enum Player
    {
        Player1,
        Player2
    }
    [SerializeField]
    private Player player;
    [SerializeField]
    private GaugeId gaugeId;
    [Range(-100, 100)]
    [SerializeField]
    private float percent;

    private void Update()
    {
        switch (player)
        {
            case Player.Player1:
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer1ControlsScript(), gaugeId, percent);
                break;

            case Player.Player2:
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer2ControlsScript(), gaugeId, percent);
                break;
        }     
    }

    /// <summary>
    /// A positive percent value will add. A negative percent value will subtract.
    /// </summary>
    /// <param name="player"></param>
    /// <param name="percent"></param>
    public static void AddOrSubtractGaugePointsPercent(ControlsScript player, GaugeId gaugeId, Fix64 percent)
    {
        if (player == null)
        {
            return;
        }

        player.currentGaugesPoints[(int)gaugeId] += player.myInfo.maxGaugePoints * (percent / 100);

        if (player.currentGaugesPoints[(int)gaugeId] > player.myInfo.maxGaugePoints)
        {
            player.currentGaugesPoints[(int)gaugeId] = player.myInfo.maxGaugePoints;
        }
        else if (player.currentGaugesPoints[(int)gaugeId] < 0)
        {
            player.currentGaugesPoints[(int)gaugeId] = 0;
        }
    }
}

Share

Thumbs up +2 Thumbs down

Re: Trying to make a self-refilling gauge?

Wow!!! thanks a lot FreedTerror!! thats exactly what i needed, thank you, thank you, thank you!!

Share

Thumbs up +1 Thumbs down

Re: Trying to make a self-refilling gauge?

Any advice if I want a gauge to drain if a player is on idle or doing a basics move like jump or crouch?

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

apollo wrote:

Any advice if I want a gauge to drain if a player is on idle or doing a basics move like jump or crouch?

Some advice:
If you have coding knowledge you should be able to figure out how and what to do checks on.
I recommend making helper methods to make your life easier.
My

IsBasicMoveReferenceMatch

method is an example of a helper method.

This script can check basic moves.

using UnityEngine;
using UFE3D;
using FPLibrary;

public class NewBehaviourScript1 : MonoBehaviour
{
    private enum Player
    {
        Player1,
        Player2
    }
    [SerializeField]
    private Player player;
    /*[SerializeField]
    private GaugeId gaugeId;
    [Range(-100, 100)]
    [SerializeField]
    private float percent;
    [SerializeField]*/

    [System.Serializable]
    private class BasicMoveReferenceOptions
    {
        [SerializeField]
        private GaugeId gaugeId;
        [Range(-100, 100)]
        [SerializeField]
        private float percent;
        [SerializeField]
        private BasicMoveReference[] basicMoveReferenceArray;     

        public static void CheckBasicMoveReferenceOptions(ControlsScript player, BasicMoveReferenceOptions basicMoveReferenceOptions)
        {
            if (player == null
                || basicMoveReferenceOptions == null)
            {
                return;
            }

            if (IsBasicMoveReferenceMatch(player.currentBasicMove, basicMoveReferenceOptions.basicMoveReferenceArray) == true)
            {
                AddOrSubtractGaugePointsPercent(player, basicMoveReferenceOptions.gaugeId, basicMoveReferenceOptions.percent);
            }
        }

        public static void CheckBasicMoveReferenceOptions(ControlsScript player, BasicMoveReferenceOptions[] basicMoveReferenceOptionsArray)
        {
            if (player == null
                || basicMoveReferenceOptionsArray == null)
            {
                return;
            }

            int length = basicMoveReferenceOptionsArray.Length;
            for (int i = 0; i < length; i++)
            {
                CheckBasicMoveReferenceOptions(player, basicMoveReferenceOptionsArray[i]);
            }
        }
    }
    [SerializeField]
    private BasicMoveReferenceOptions[] basicMoveReferenceOptionsArray;

    private void Update()
    {
        switch (player)
        {
            case Player.Player1:
                //AddOrSubtractGaugePointsPercent(UFE.GetPlayer1ControlsScript(), gaugeId, percent);

                BasicMoveReferenceOptions.CheckBasicMoveReferenceOptions(UFE.GetPlayer1ControlsScript(), basicMoveReferenceOptionsArray);
                break;

            case Player.Player2:
                //AddOrSubtractGaugePointsPercent(UFE.GetPlayer2ControlsScript(), gaugeId, percent);

                BasicMoveReferenceOptions.CheckBasicMoveReferenceOptions(UFE.GetPlayer2ControlsScript(), basicMoveReferenceOptionsArray);
                break;
        }
    }

    /// <summary>
    /// A positive percent value will add. A negative percent value will subtract.
    /// </summary>
    /// <param name="player"></param>
    /// <param name="percent"></param>
    public static void AddOrSubtractGaugePointsPercent(ControlsScript player, GaugeId gaugeId, Fix64 percent)
    {
        if (player == null)
        {
            return;
        }

        player.currentGaugesPoints[(int)gaugeId] += player.myInfo.maxGaugePoints * (percent / 100);

        if (player.currentGaugesPoints[(int)gaugeId] > player.myInfo.maxGaugePoints)
        {
            player.currentGaugesPoints[(int)gaugeId] = player.myInfo.maxGaugePoints;
        }
        else if (player.currentGaugesPoints[(int)gaugeId] < 0)
        {
            player.currentGaugesPoints[(int)gaugeId] = 0;
        }
    }

    public static bool IsBasicMoveReferenceMatch(BasicMoveReference comparing, BasicMoveReference matching)
    {
        if (comparing == matching)
        {
            return true;
        }

        return false;
    }

    public static bool IsBasicMoveReferenceMatch(BasicMoveReference comparing, BasicMoveReference[] matchingArray)
    {
        if (matchingArray == null)
        {
            return false;
        }

        int length = matchingArray.Length;
        for (int i = 0; i < length; i++)
        {
            if (IsBasicMoveReferenceMatch(comparing, matchingArray[i]) == false)
            {
                continue;
            }

            return true;
        }

        return false;
    }
}

Share

Thumbs up +1 Thumbs down

Re: Trying to make a self-refilling gauge?

FreedTerror wrote:

I whipped up this example script.

using UnityEngine;
using UFE3D;
using FPLibrary;

public class RefillingGaugeExample : MonoBehaviour
{
    private enum Player
    {
        Player1,
        Player2
    }
    [SerializeField]
    private Player player;
    [SerializeField]
    private GaugeId gaugeId;
    [Range(-100, 100)]
    [SerializeField]
    private float percent;

    private void Update()
    {
        switch (player)
        {
            case Player.Player1:
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer1ControlsScript(), gaugeId, percent);
                break;

            case Player.Player2:
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer2ControlsScript(), gaugeId, percent);
                break;
        }     
    }

    /// <summary>
    /// A positive percent value will add. A negative percent value will subtract.
    /// </summary>
    /// <param name="player"></param>
    /// <param name="percent"></param>
    public static void AddOrSubtractGaugePointsPercent(ControlsScript player, GaugeId gaugeId, Fix64 percent)
    {
        if (player == null)
        {
            return;
        }

        player.currentGaugesPoints[(int)gaugeId] += player.myInfo.maxGaugePoints * (percent / 100);

        if (player.currentGaugesPoints[(int)gaugeId] > player.myInfo.maxGaugePoints)
        {
            player.currentGaugesPoints[(int)gaugeId] = player.myInfo.maxGaugePoints;
        }
        else if (player.currentGaugesPoints[(int)gaugeId] < 0)
        {
            player.currentGaugesPoints[(int)gaugeId] = 0;
        }
    }
}

Where would this code go? A character's prefab?

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

I personally recommend placing it in the scene since it targets the static ControlsScript variables.
Static variables can be accessed from anywhere.

It would need to be reworked slightly to support proper prefab usage.

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

I tinkered around and mad a Self Draining Guage. Both players have self drain but the drain is too fast.

Any help is apprecited.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


using UFE3D;
using FPLibrary;

public class SelfDrainingGuage : MonoBehaviour
{
    private enum Player
    {
        Player1,
        Player2
    }
    [SerializeField]
    private Player player;
    [SerializeField]
    private GaugeId gaugeId;
    [Range(-100, 100)]
    [SerializeField]
    private float percent;

    private void Update()
    {
        
        switch (player)
        {
            case Player.Player1:
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer1ControlsScript(), gaugeId, percent);
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer2ControlsScript(), gaugeId, percent);
                break;

            case Player.Player2:
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer1ControlsScript(), gaugeId, percent);
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer2ControlsScript(), gaugeId, percent);
                break;
        }     
    }

    /// <summary>
    /// A positive percent value will add. A negative percent value will subtract.
    /// </summary>
    /// <param name="player"></param>
    /// <param name="percent"></param>
    public static void AddOrSubtractGaugePointsPercent(ControlsScript player, GaugeId gaugeId, Fix64 percent)
    {
        if (player == null)
        {
            return;
        }

        player.currentGaugesPoints[(int)gaugeId] -= (player.myInfo.maxGaugePoints * (percent / 100) / UFE.config.fps) * UFE.timeScale;

        if (player.currentGaugesPoints[(int)gaugeId] > player.myInfo.maxGaugePoints)
        {
            player.currentGaugesPoints[(int)gaugeId] = player.myInfo.maxGaugePoints;
        }
        else if (player.currentGaugesPoints[(int)gaugeId] < 0)
        {
            player.currentGaugesPoints[(int)gaugeId] = 0;
        }
    }
}

Share

Thumbs up Thumbs down

Re: Trying to make a self-refilling gauge?

Here's my modification. I made a Self Draining Guage that affects both players. The speed of the drain is how I want it. It works for me but feel free to make modifications.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UFE3D;
using FPLibrary;

public class VPSelfDrainingGuageVP : MonoBehaviour
{
    private enum Player
    {
        Player1,
        Player2
    }
    [SerializeField]
    private Player player;
    [SerializeField]
    private GaugeId gaugeId;
    [Range(-100, 100)]
    [SerializeField]
    private float percent;

    private void Update()
    {
        
        switch (player)
        {
            case Player.Player1:
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer1ControlsScript(), gaugeId, percent);
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer2ControlsScript(), gaugeId, percent);
                break;

            case Player.Player2:
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer1ControlsScript(), gaugeId, percent);
                AddOrSubtractGaugePointsPercent(UFE.GetPlayer2ControlsScript(), gaugeId, percent);
                break;
        }     
    }

    /// <summary>
    /// A positive percent value will add. A negative percent value will subtract.
    /// </summary>
    /// <param name="player"></param>
    /// <param name="percent"></param>
    public static void AddOrSubtractGaugePointsPercent(ControlsScript player, GaugeId gaugeId, Fix64 percent)
    {
        if (player == null)
        {
            return;
        }

        player.currentGaugesPoints[(int)gaugeId] -= (player.myInfo.maxGaugePoints * (percent / 100) / UFE.config.fps) * 0.1;

        if (player.currentGaugesPoints[(int)gaugeId] > player.myInfo.maxGaugePoints)
        {
            player.currentGaugesPoints[(int)gaugeId] = player.myInfo.maxGaugePoints;
        }
        else if (player.currentGaugesPoints[(int)gaugeId] < 0)
        {
            player.currentGaugesPoints[(int)gaugeId] = 0;
        }
    }
}

Share

Thumbs up Thumbs down