LemonUIbyLemon / LemonUI

LemonUI for .NET (FiveM, RageMP, RagePluginHook and ScriptHookVDotNet 3)
MIT License
177 stars 40 forks source link

Bruteforce Mini-Game - Lives are not restored after a restart #175

Closed sruckstar closed 1 month ago

sruckstar commented 2 months ago

Once all lives have been lost and the minigame restarted, the number of lives will be zero. Also in this case, the bruteforce sometimes closes spontaneously.

using GTA;
using GTA.Native;
using GTA.UI;
using LemonUI;
using LemonUI.Elements;
using LemonUI.Scaleform;
using System;
using System.Windows.Forms;

public class HackingMinigameScript : Script
{
    private BruteForce hackingGame;
    private bool gameActive;

    public HackingMinigameScript()
    {
        Tick += OnTick;
        KeyDown += OnKeyDown;

        hackingGame = new BruteForce();
        hackingGame.HackFinished += OnHackFinished;
    }

    private void OnTick(object sender, EventArgs e)
    {
        if (gameActive)
        {
            hackingGame.Process();
        }
    }

    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.T)
        {
            StartHackingGame();
        }
    }

    private void StartHackingGame()
    {
        hackingGame.Word = "HACKTHIS";
        hackingGame.TotalLives = 5;
        hackingGame.Countdown = TimeSpan.FromMinutes(2);
        hackingGame.ShowLives = true;
        hackingGame.ResetOnRowFail = true;
        hackingGame.CloseAfter = 5000;
        hackingGame.CanRetry = true;
        hackingGame.Visible = true;
        gameActive = true;
    }

    private void OnHackFinished(object sender, BruteForceFinishedEventArgs e)
    {
        gameActive = false;
        hackingGame.Visible = false;

        switch (e.Status)
        {
            case BruteForceStatus.Completed:
                Notification.Show("The hack has been successfully completed!");
                hackingGame.Reset();
                break;
            case BruteForceStatus.OutOfTime:
                Notification.Show("Time's up!");
                hackingGame.Reset();
                break;
            case BruteForceStatus.OutOfLives:
                Notification.Show("All lives are lost!");
                hackingGame.Reset();
                break;
        }
    }
}
justalemon commented 1 month ago

I will push an update with the fix in a bit.

For the messages, I personally recommend using the SuccessMessages and FailMessages lists to specify the messages right in the Minigame, instead of using notifications.