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:
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:
Also, it can be inverted and execute the move only when the character has more than 50% of life, like the next picture:
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).
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!
I hope you find it useful!