Topic: [Tutorial] Basic Score Counter

Hello smile

I made a short tutorial, how to create a very simple score-counter in your UFE-game.


Video-Tutorial:

[media]https://www.youtube.com/watch?v=ad4l4TUofA4[/media]

Code Snippets:

UFE Score Code
==============




1. Assets > UFE > Scripts > UFE.CS
-------------------------------------------------------------------------------

after (line 83):
public static GUIText debugger1;
public static GUIText debugger2;


insert:
//*** Global Score Counter ***
public static int scorePlayerOne = 0;
public static int scorePlayerTwo = 0;







2. Assets > UFE > Scripts > ControlsScript.cs
-------------------------------------------------------------------------------

after (line 1959):
comboHitDamage = damage;
comboDamage += damage;
comboHits ++;


insert:
//*** increase Score if the opponent takes any damage ***
if (gameObject.name == "Player1" && damage > 0) 
{
            UFE.scorePlayerTwo = UFE.scorePlayerTwo + hit.scoreOnHit;
}
        
if (gameObject.name == "Player2" && damage > 0) 
{
            UFE.scorePlayerOne = UFE.scorePlayerOne + hit.scoreOnHit;
}






3. Assets > UFE > Scripts > UI > Templates > DefaultBattleGUI.cs
-------------------------------------------------------------------------------

after (line 12):
public Image lifeBar;
public Image gaugeMeter;


insert:
public Text score;




after (line 177):
if (this.player2GUI != null && this.player2GUI.gaugeMeter != null)
{
this.player2GUI.gaugeMeter.fillAmount = UFE.config.player2Character.currentGaugePoints / UFE.config.player2Character.maxGaugePoints;
}
}
      

insert:
//*** feed the Battle-GUI with current scores for player 1/2 ***
if (this.player1GUI.score != null) 
{
this.player1GUI.score.text = "P1 " + String.Format ("{0:00000000}", UFE.scorePlayerOne);
}

if (this.player2GUI.score != null) 
{
if (UFE.GetCPU (2) == false) this.player2GUI.score.text = "P2 " + String.Format ("{0:00000000}", UFE.scorePlayerTwo);
else this.player2GUI.score.text = "CPU";
}
      
      
      
      
4. Assets > UFE > Editor > MoveEditorWindow.cs
-------------------------------------------------------------------------------


after (line 675):

// Damage Toggle     
moveInfo.hits[i].damageOptionsToggle = EditorGUILayout.Foldout(moveInfo.hits[i].damageOptionsToggle, "Damage Options", EditorStyles.foldout);
if (moveInfo.hits[i].damageOptionsToggle)
{
EditorGUILayout.BeginVertical(subGroupStyle);
{
EditorGUI.indentLevel += 1;
moveInfo.hits[i].damageType = (DamageType) EditorGUILayout.EnumPopup("Damage Type:", moveInfo.hits[i].damageType, enumStyle);
moveInfo.hits[i].damageOnHit = EditorGUILayout.FloatField("Damage on Hit:", moveInfo.hits[i].damageOnHit);
moveInfo.hits[i].damageOnBlock = EditorGUILayout.FloatField("Damage on Block:", moveInfo.hits[i].damageOnBlock);
moveInfo.hits[i].damageScaling = EditorGUILayout.Toggle("Damage Scaling", moveInfo.hits[i].damageScaling, toggleStyle);
moveInfo.hits[i].doesntKill = EditorGUILayout.Toggle("Hit Doesn't Kill", moveInfo.hits[i].doesntKill, toggleStyle);
EditorGUI.indentLevel -= 1;
}
EditorGUILayout.EndVertical();
}
                      
insert:

//*** Score Toggle ***
moveInfo.hits[i].scoreOptionsToggle = EditorGUILayout.Foldout(moveInfo.hits[i].scoreOptionsToggle, "Score Options", EditorStyles.foldout);
if (moveInfo.hits[i].scoreOptionsToggle)
{
EditorGUILayout.BeginVertical(subGroupStyle);
{
EditorGUI.indentLevel += 1;
moveInfo.hits[i].scoreOnHit = EditorGUILayout.IntField("Score on Hit:", moveInfo.hits[i].scoreOnHit);
EditorGUI.indentLevel -= 1;
}
EditorGUILayout.EndVertical();
}
                      
                      
                      
after (line 2162):

// Damage Toggle
moveInfo.projectiles[i].damageOptionsToggle = EditorGUILayout.Foldout(moveInfo.projectiles[i].damageOptionsToggle, "Damage Options", EditorStyles.foldout);
if (moveInfo.projectiles[i].damageOptionsToggle)
{
EditorGUILayout.BeginVertical(subGroupStyle);
{
EditorGUI.indentLevel += 1;
moveInfo.projectiles[i].damageType = (DamageType) EditorGUILayout.EnumPopup("Damage Type:", moveInfo.projectiles[i].damageType, enumStyle);
moveInfo.projectiles[i].damageOnHit = EditorGUILayout.FloatField("Damage on Hit:", moveInfo.projectiles[i].damageOnHit);
moveInfo.projectiles[i].damageOnBlock = EditorGUILayout.FloatField("Damage on Block:", moveInfo.projectiles[i].damageOnBlock);
moveInfo.projectiles[i].damageScaling = EditorGUILayout.Toggle("Damage Scaling", moveInfo.projectiles[i].damageScaling, toggleStyle);
EditorGUI.indentLevel -= 1;
}
EditorGUILayout.EndVertical();
}    
                  
insert:
//*** Score Toggle ***
moveInfo.projectiles[i].scoreOptionsToggle = EditorGUILayout.Foldout(moveInfo.projectiles[i].scoreOptionsToggle, "Score Options", EditorStyles.foldout);
if (moveInfo.projectiles[i].scoreOptionsToggle)
{
EditorGUILayout.BeginVertical(subGroupStyle);
{
EditorGUI.indentLevel += 1;
moveInfo.projectiles[i].scoreOnHit = EditorGUILayout.IntField("Score on Hit:", moveInfo.projectiles[i].scoreOnHit);
EditorGUI.indentLevel -= 1;
}
EditorGUILayout.EndVertical();
}                  
                      
                      

5. Assets > UFE > Scripts > MoveInfo.cs
-------------------------------------------------------------------------------



public class Projectile (line 238):

after (line 278):
public float damageOnHit;
public float damageOnBlock;
public bool damageScaling;

insert:
public int scoreOnHit;


after (line 293):
[HideInInspector] public bool moveLinksToggle;
[HideInInspector] public bool damageOptionsToggle;

insert:
[HideInInspector] public bool scoreOptionsToggle;






public class Hit (line 343):

after (line 369):
public bool damageScaling;
public DamageType damageType;
public float damageOnHit;

insert:
public int scoreOnHit;


after (line 386):
[HideInInspector] public bool damageOptionsToggle;

insert 
[HideInInspector] public bool scoreOptionsToggle;





5. Assets > UFE > Scripts > ProjectileMoveScript.cs
------------------------------------------------------------------------------

after (line 88):
hit.damageScaling = data.damageScaling;
hit.damageType = data.damageType;


insert:
hit.scoreOnHit = data.scoreOnHit;



6. Assets > UFE > UI > Templates > DefaultMainMenuScreen.cs
-------------------------------------------------------------------------------

after (line 26):
base.OnShow ();
this.HighlightOption(this.FindFirstSelectable());


insert:
//*** reset player score when entering main menu ***
UFE.scorePlayerOne = 0;
UFE.scorePlayerTwo = 0;

Copy & paste the code-snippets in a new text-file with your editor.



http://s29.postimg.org/m6q9fx153/game_1.jpg


http://s30.postimg.org/xzfxtwnap/game_2.jpg

shubi's Website

Share

Thumbs up +5 Thumbs down

Re: [Tutorial] Basic Score Counter

Nice work

Share

Thumbs up Thumbs down

Re: [Tutorial] Basic Score Counter

amazing! for that classic arcade style flavor!

Me encontraste en un negro camino como un peregrino sin rumbo ni fe, pero la luz de tus ojos divinos cambió mi suerte por dicha y placer.

Re: [Tutorial] Basic Score Counter

nice work

Re: [Tutorial] Basic Score Counter

Confirmed working in UFE 1.7.

Share

Thumbs up +3 Thumbs down

Re: [Tutorial] Basic Score Counter

i have a question im trying to convert your score counter into a win counter i think i almost got it but im stuck do you mind helping me out a lil

Share

Thumbs up Thumbs down

7 (edited by shubi 2016-11-08 11:42:06)

Re: [Tutorial] Basic Score Counter

shannonrattler33 wrote:

i have a question im trying to convert your score counter into a win counter i think i almost got it but im stuck do you mind helping me out a lil

Hello.

This should be a very easy one.
Open up UFE.cs and find the "FireGameEnds"-function. There you can read the winner and set your counter:

public static void FireGameEnds(CharacterInfo winner, CharacterInfo loser){
        // I've commented the next line because it worked with the old GUI, but not with the new one.
        //UFE.EndGame();

        Time.timeScale = UFE.config.gameSpeed;
        UFE.gameRunning = false;
        UFE.newRoundCasted = false;
        UFE.player1WonLastBattle = (winner == UFE.GetPlayer1());

        if (UFE.OnGameEnds != null) {
            UFE.OnGameEnds(winner, loser);

            if (winner.playerNum) == 1 ........ increase your Win-Count .......
        }
    }

winner.playerNum is 1 when player one is the winner of the match and 2 if the opponent wins.

Re: [Tutorial] Basic Score Counter

I'm getting a error "Assets/UFE Addons/Fuzzy AI/Runtime/RuleBasedAI.cs(1365,97): error CS0117: `PossibleStates' does not contain a definition for `NeutralJump'"

Assets/UFE Addons/Fuzzy AI/Runtime/RuleBasedAI.cs(1424,105): error CS0117: `PossibleStates' does not contain a definition for `NeutralJump'

Very new to this but when I remove the projectile script the error message disappears. Not sure why im getting a error in that script..I did not touch it.

9 (edited by mayureshete 2017-09-03 01:22:23)

Re: [Tutorial] Basic Score Counter

How can I add scores to the Perfect!! play.. like if player wins round with perfect!!! add 10000 to score....

Edit: For now i have manages to give both players get perfect score when perfect command is executed.. will try for player specific..

Share

Thumbs up Thumbs down

Re: [Tutorial] Basic Score Counter

How can i Save score and show in mainMenu ?

Share

Thumbs up Thumbs down

Re: [Tutorial] Basic Score Counter

Just call for UFE.scorePlayerOne in the main menu scripts or components.

Share

Thumbs up +2 Thumbs down

12 (edited by ElvinStrawhat 2018-09-12 07:39:50)

Re: [Tutorial] Basic Score Counter

Thanks for the video really appreciate.



brass knuckle

Share

Thumbs up 0 Thumbs down

Re: [Tutorial] Basic Score Counter

Is it work in UFE 2 ?

Share

Thumbs up Thumbs down

Re: [Tutorial] Basic Score Counter

Im wondering the same if this still works. has anyone tried this in ufe2 yet?

Re: [Tutorial] Basic Score Counter

Same Request Is it work in UFE 2 ?

Share

Thumbs up Thumbs down

Re: [Tutorial] Basic Score Counter

Here's my approach to this, I think using scriptable objects and the event system could work here
I wrote some untested prototype scripts for this.

This is a scriptable object which can be setup per character using moveinfos.

using UnityEngine;
using UFE3D;

namespace FreedTerror
{
    [CreateAssetMenu(fileName = "New UFE_2 Move Info Score Data", menuName = "FreedTerror/UFE_2 Move Info Score Data", order = 1)]
    public class UFE_2MoveInfoScoreData : ScriptableObject
    {
        [System.Serializable]
        public struct ScoreData
        {
            public int onHitScore;
            public int onBlockScore;
            public int onParryScore;
            public MoveInfo[] moveInfos;
        }

        public ScoreData[] scoreData;
    }
}

This will handle the actual score variables.

using UnityEngine;
using UFE3D;

namespace FreedTerror
{
    public class UFE_2Score : MonoBehaviour
    {
        public int player1Score;
        public int player2Score;
        public UFE_2MoveInfoScoreData[] moveInfoScoreData;

        // Start is called before the first frame update
        void Start()
        {
            SubscribeToUFE_2Events();
        }

        // Update is called once per frame
        void Update()
        {

        }

        void OnDisable()
        {
            UnsubscribeFromUFE_2Events();
        }

        void OnDestroy()
        {
            UnsubscribeFromUFE_2Events();
        }

        public void SubscribeToUFE_2Events()
        {
            UFE.OnHit += this.OnHit;
            UFE.OnBlock += this.OnBlock;
            UFE.OnParry += this.OnParry;
        }

        public void UnsubscribeFromUFE_2Events()
        {
            UFE.OnHit -= this.OnHit;
            UFE.OnBlock -= this.OnBlock;
            UFE.OnParry -= this.OnParry;
        }

        private void OnHit(HitBox strokeHitBox, MoveInfo move, Hit hitInfo, ControlsScript player)
        {
            ChangeScoreEvent(UFE_2EventTypeScore.OnHit, player, move);
        }

        private void OnBlock(HitBox strokeHitBox, MoveInfo move, Hit hitInfo, ControlsScript player)
        {
            ChangeScoreEvent(UFE_2EventTypeScore.OnBlock, player, move);
        }

        private void OnParry(HitBox strokeHitBox, MoveInfo move, Hit hitInfo, ControlsScript player)
        {
            ChangeScoreEvent(UFE_2EventTypeScore.OnParry, player, move);
        }

        public void ChangeScoreEvent(UFE_2EventTypeScore eventType, ControlsScript controlsScript, MoveInfo move)
        {
            switch (controlsScript.playerNum)
            {
                case 1:
                    int p1Length = moveInfoScoreData.Length;
                    for (int i = 0; i < p1Length; i++)
                    {
                        int p1LengthA = moveInfoScoreData[i].scoreData.Length;
                        for (int a = 0; a < p1LengthA; a++)
                        {
                            int p1LengthB = moveInfoScoreData[i].scoreData[a].moveInfos.Length;
                            for (int b = 0; b < p1LengthB; b++)
                            {
                                if (move.moveName == moveInfoScoreData[i].scoreData[a].moveInfos[b].moveName)
                                {
                                    switch (eventType)
                                    {
                                        case UFE_2EventTypeScore.OnHit:
                                            player1Score += moveInfoScoreData[i].scoreData[a].onHitScore;
                                            break;

                                        case UFE_2EventTypeScore.OnBlock:
                                            player1Score += moveInfoScoreData[i].scoreData[a].onBlockScore;
                                            break;

                                        case UFE_2EventTypeScore.OnParry:
                                            player1Score += moveInfoScoreData[i].scoreData[a].onParryScore;
                                            break;
                                    }
                                }
                            }
                        }
                    }
                    break;

                case 2:
                    int p2Length = moveInfoScoreData.Length;
                    for (int i = 0; i < p2Length; i++)
                    {
                        int p2LengthA = moveInfoScoreData[i].scoreData.Length;
                        for (int a = 0; a < p2LengthA; a++)
                        {
                            int p2LengthB = moveInfoScoreData[i].scoreData[a].moveInfos.Length;
                            for (int b = 0; b < p2LengthB; b++)
                            {
                                if (move.moveName == moveInfoScoreData[i].scoreData[a].moveInfos[b].moveName)
                                {
                                    switch (eventType)
                                    {
                                        case UFE_2EventTypeScore.OnHit:
                                            player2Score += moveInfoScoreData[i].scoreData[a].onHitScore;
                                            break;

                                        case UFE_2EventTypeScore.OnBlock:
                                            player2Score += moveInfoScoreData[i].scoreData[a].onBlockScore;
                                            break;

                                        case UFE_2EventTypeScore.OnParry:
                                            player2Score += moveInfoScoreData[i].scoreData[a].onParryScore;
                                            break;
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        }

        public enum UFE_2EventTypeScore
        {
            OnBasicMove,
            OnMove,
            OnHit,
            OnBlock,
            OnParry
        }
    }
}

Share

Thumbs up +1 Thumbs down