1 (edited by Dodo44 2018-03-02 15:21:28)

Topic: (Source) Life conditionals for character moves

Hi.

I was coding my project and also I was watching other fighting games that implement a particular combat method: execute Special Moves when the Character’s life is equal or less than a specific life point (Example, Iori Yagami from The King of Fighters, when his life points is critical).
Also, another and maybe popular method, is execute a specific move when the Opponent’s life is critical (Example: Mortal Kombat’s Fatalities).

So, my intention in this topic, is share you the next code that I’ve implemented in my project. This code, also, has two other combat methods (that I sincerely don’t know any game or character example), that let the character execute when his life is NOT critical (even only when the character’s life is Healthy). And the same method for the Opponent.

(Before all, sorry about the Image Links. I've tried to upload images directly. But when I tried, the images always breaks. I don't know why)

The next picture shows what I'm talking about:

https://ibb.co/cOZ58S

For example: the next picture shows when the character, if he has equal or less than 50% of life, he’ll be able to execute the move:

https://ibb.co/efxQ8S

Also, it can be inverted and execute the move only when the character has more than 50% of life, like the next picture:

https://ibb.co/dD2ghn

Finally, the same condition when the opponent’s life is equal or less than, in this case, 25% (ideal for fatality or others special moves).

https://ibb.co/f2pSNn

Note that if you prefer that the character execute the move any time, just let all Invert toggle options unchecked and the value parameters at zero.

Now, I'd like to share you the code:


In MoveInfo.cs

Find the line:

public int frameWindowRotation;

Insert these lines below:

public bool invert;
public float lifeRequired;
public float lifeInvertRequired;

public bool opInvert;
public float opLifeRequired;
public float opLifeInvertRequired;

In MoveEditorWindow.cs

Find and look at:

moveInfo.gaugeUsage = StyledSlider("Gauge Cost (%)", moveInfo.gaugeUsage, EditorGUI.indentLevel, 0, 100);

Insert these codes below:

EditorGUILayout.Space();
EditorGUILayout.Space();

if (moveInfo.invert)
{
moveInfo.lifeInvertRequired = StyledSlider("You Have Less Life (<=)", moveInfo.lifeInvertRequired, EditorGUI.indentLevel, 0, 100);
}
else
{
moveInfo.lifeRequired = StyledSlider("You Have More Life (>)",   moveInfo.lifeRequired, 
EditorGUI.indentLevel, 0, 100);
} 
                       
moveInfo.invert = EditorGUILayout.Toggle("Invert", moveInfo.invert, toggleStyle);

EditorGUILayout.Space();
                        
if (moveInfo.opInvert)
{
moveInfo.opLifeInvertRequired = StyledSlider("Op Has Less Life (<=)", moveInfo.opLifeInvertRequired, EditorGUI.indentLevel, 0, 100);
}
else
{
moveInfo.opLifeRequired = StyledSlider("Op Has More Life (>)", moveInfo.opLifeRequired, EditorGUI.indentLevel, 0, 100);
}
moveInfo.opInvert = EditorGUILayout.Toggle("Invert", moveInfo.opInvert, toggleStyle);
EditorGUILayout.Space();
EditorGUILayout.Space();

In MoveSetScript.cs

Find this function:

private bool hasEnoughGauge(float gaugeNeeded)
{
                if (!UFE.config.gameGUI.hasGauge) return true;
if (controlsScript.myInfo.currentGaugePoints < (controlsScript.myInfo.maxGaugePoints * (gaugeNeeded / 100))) return false;
            return true;
}

Under this function, insert these functions:

private bool hasLessLife(float lifeNeeded)
            {                
return controlsScript.myInfo.currentLifePoints >= (controlsScript.myInfo.lifePoints * (lifeNeeded / 100));
            }

            private bool OpponentHasLessLife(float lifeNeeded)
            {
return controlsScript.opInfo.currentLifePoints >= (controlsScript.opInfo.lifePoints * (lifeNeeded / 100));
            }

            private bool hasMoreLife(float lifeNeeded)
            {        
 return controlsScript.myInfo.currentLifePoints < (controlsScript.myInfo.lifePoints * (lifeNeeded / 100));

            }

            private bool opponentHasMoreLife(float lifeNeeded)
            {        
 return controlsScript.opInfo.currentLifePoints < (controlsScript.opInfo.lifePoints * (lifeNeeded / 100));
            }

Find this function:

public bool ValidateMoveExecution(MoveInfo move) 
{

Under the line:

if (!hasEnoughGauge(move.gaugeRequired)) return false;

Insert these lines:

if (move.invert)
            {
                    if (!hasMoreLife(move.lifeInvertRequired))
                        return false;                      
            }else
            {
                    if (!hasLessLife(move.lifeRequired))           
                        return false;
            }

              if (move.opInvert)
              {
                    if (!opponentHasMoreLife(move.opLifeInvertRequired))
                        return false;
            }
            else
            {
                    if (!OpponentHasLessLife(move.opLifeRequired))
                        return false;
            }

Finally, find this function:

private MoveInfo TestMoveExecution(MoveInfo move, MoveInfo currentMove, ButtonPress[] buttonPress, bool inputUp, bool fromSequence, bool forceExecution) { 

Under this line:

if (!hasEnoughGauge(move.gaugeRequired)) return null;

Insert these code lines:

if (move.invert)
       {
            if (!hasMoreLife(move.lifeInvertRequired))
            {
                return null;
            }                
       }
       else
       {
            if (!hasLessLife(move.lifeRequired))
            {
                return null;
            }
       }

       if (move.opInvert)
       {
            if (!opponentHasMoreLife(move.opLifeInvertRequired))
            {
                return null;
            }
       }
       else
       {
            if (!OpponentHasLessLife(move.opLifeRequired))
            {
                return null;
            }            
       }

And this should be all. If you have any problem, let me know! smile
I hope you find it useful!

Share

Thumbs up +7 Thumbs down

Re: (Source) Life conditionals for character moves

Very nice! I have tinkered around with creating a stamina system with similar intent.

Share

Thumbs up Thumbs down

Re: (Source) Life conditionals for character moves

A useful feature. In our game, we used to have it switch player stances depending on your health, and each stance had various moves available

Share

Thumbs up Thumbs down

Re: (Source) Life conditionals for character moves

Thank you, guys! I'm glad that it has helped you! smile

Share

Thumbs up Thumbs down

Re: (Source) Life conditionals for character moves

Interesting will be using this

Eternal Rift Studios
    Current Projects:
         Destined Soels
Always happy to help when possible. If its something pretty minor ill just help you out. But i do commissions as well. Hit me up if you need a commission.

Share

Thumbs up Thumbs down

Re: (Source) Life conditionals for character moves

Stickied this topic so other users can see.

Great work. smile

Share

Thumbs up +2 Thumbs down

Re: (Source) Life conditionals for character moves

Thank you very much!! smile

Share

Thumbs up Thumbs down

Re: (Source) Life conditionals for character moves

Amazing! Thanks!

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: (Source) Life conditionals for character moves

It looks like UFE2 broke this solution. Any chance anyone here knows the changed names to be able to fix it?

For MoveSetScript.cs changes, I'm getting this error for each of the four new functions:

" 'CharacterInfo' does not contain a definition for 'currentLifePoints' and no accessible extension method 'currentLifePoints' accepting a first argument of type 'CharacterInfo' could be found (are you missing a using directive or an assembly reference?)"

I'm guessing the name of "currentLifePoints" has changed or is accessed differently in UFE2?

Share

Thumbs up +1 Thumbs down

Re: (Source) Life conditionals for character moves

does this still work in ufe2

Share

Thumbs up Thumbs down

Re: (Source) Life conditionals for character moves

@Mistermind do this still work in ufe2

Share

Thumbs up Thumbs down

12 (edited by Starcutter 2021-09-05 18:54:08)

Re: (Source) Life conditionals for character moves

burbwalrus wrote:

It looks like UFE2 broke this solution. Any chance anyone here knows the changed names to be able to fix it?

For MoveSetScript.cs changes, I'm getting this error for each of the four new functions:

" 'CharacterInfo' does not contain a definition for 'currentLifePoints' and no accessible extension method 'currentLifePoints' accepting a first argument of type 'CharacterInfo' could be found (are you missing a using directive or an assembly reference?)"

I'm guessing the name of "currentLifePoints" has changed or is accessed differently in UFE2?

I got the same error. I believe if you replace all instances of "controlsScript.opInfo.currentLifePoints" in your MoveSetScript with just "controlsScript.currentLifePoints" it should work.

Share

Thumbs up +1 Thumbs down

Re: (Source) Life conditionals for character moves

So I decided to experiment with this source code for adding a finisher move, the GUI works but I don't think the function are doing anything, as I tried experimenting to add finisher state but I won 2 rounds but immediately ends the fight without having loser/p2 into Fatality state, as it just doesn't delay end of the round. I'm still trying to go for Fatality mode on my "recreation" of Mortal Kombat and I am using UFE 2.5 Source, does anyone know updated version for this script?

Share

Thumbs up Thumbs down

Re: (Source) Life conditionals for character moves

So I decided to experiment with this source code for adding a finisher move, the GUI works but I don't think the function are doing anything, as I tried experimenting to add finisher state but I won 2 rounds but immediately ends the fight without having loser/p2 into Fatality state, as it just doesn't delay end of the round. I'm still trying to go for Fatality mode on my "recreation" of Mortal Kombat and I am using UFE 2.5 Source, does anyone know updated version for this script?

Share

Thumbs up Thumbs down