Implementing Super Jump Script - KimonoBoy/SHVDNTutorial-NucleiLite GitHub Wiki

It's self-explanatory, isn't it? Yes. We're going to implement the Super Jump script in our Player Menu

The Code

  1. Copy and Paste the following
using System;
using System.Windows.Forms;
using GTA;
using GTA.UI;
using LemonUI;
using LemonUI.Menus;

namespace NucleiLite
{
    public class Main : Script
    {
        ObjectPool menuPool = new ObjectPool();
        NativeMenu mainMenu = new NativeMenu("NucleiLite", "Main Menu");
        NativeMenu playerMenu = new NativeMenu("NucleiLite", "Player Menu");
        NativeMenu vehicleSpawnerMenu = new NativeMenu("NucleiLite", "Vehicle Spawner Menu");
        NativeMenu weaponsMenu = new NativeMenu("NucleiLite", "Weapons Menu");

        bool canSuperJump = false;

        public Main()
        {
            CreateMainMenu();
            CreatePlayerMenu();
            CreateVehicleSpawnerMenu();
            CreateWeaponsMenu();

            AddMenusToPool();

            KeyDown += OnKeyDown;
            Tick += OnTick;
        }

        private void CreateMainMenu()
        {
            mainMenu.AddSubMenu(playerMenu);
            mainMenu.AddSubMenu(vehicleSpawnerMenu);
            mainMenu.AddSubMenu(weaponsMenu);
        }

        private void CreatePlayerMenu()
        {
            // Fix Player
            NativeItem itemFixPlayer = new NativeItem("Fix Player", "Restores Player's Health and Armor");
            itemFixPlayer.Activated += (sender, args) =>
            {
                Game.Player.Character.Health = Game.Player.Character.MaxHealth;
                Game.Player.Character.Armor = Game.Player.MaxArmor;
                Notification.Show("Health and Armor Restored!");
            };
            playerMenu.Add(itemFixPlayer);

            // Invincible
            NativeCheckboxItem checkBoxInvincible = new NativeCheckboxItem("Invincible", "Your character can no longer die.");
            checkBoxInvincible.CheckboxChanged += (sender, args) =>
            {
                Game.Player.Character.IsInvincible = checkBoxInvincible.Checked;
                Notification.Show($"Invincible: {Game.Player.Character.IsInvincible}");
            };
            playerMenu.Add(checkBoxInvincible);

            // Wanted Level
            NativeListItem<int> listItemWantedLevel = new NativeListItem<int>("Wanted Level", "Adjust Player's Wanted Level.", 0, 1, 2, 3, 4, 5);
            listItemWantedLevel.ItemChanged += (sender, args) =>
            {
                Game.Player.WantedLevel = args.Object;
            };
            playerMenu.Add(listItemWantedLevel);

            // Super Jump
            NativeCheckboxItem checkBoxSuperJump = new NativeCheckboxItem("Super Jump", "Allows the Player to Jump higher than a building.");
            checkBoxSuperJump.CheckboxChanged += (sender, args) =>
            {
                canSuperJump = checkBoxSuperJump.Checked;
            };
            playerMenu.Add(checkBoxSuperJump);
        }

        private void CreateWeaponsMenu()
        {
        }

        private void CreateVehicleSpawnerMenu()
        {
        }

        private void AddMenusToPool()
        {
            menuPool.Add(mainMenu);
            menuPool.Add(playerMenu);
            menuPool.Add(vehicleSpawnerMenu);
            menuPool.Add(weaponsMenu);
        }

        private void OnTick(object sender, EventArgs e)
        {
            menuPool.Process();

            if (canSuperJump)
            {
                Game.Player.SetSuperJumpThisFrame();
            }
        }

        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                mainMenu.Visible = !mainMenu.Visible;                
            }
        }
    }
}
  1. Build, Reload() and Test by checking the Super Jump-item and jumping

image

Code Breakdown - Simplified

We've defined a new variable at the top

bool canSuperJump = false;

This variable is used to store the state of whether or not the Player can Super Jump - we need this variable as we want to use it in our Tick-event


            // Super Jump
            NativeCheckboxItem checkBoxSuperJump = new NativeCheckboxItem("Super Jump", "Allows the Player to Jump higher than a building.");
            checkBoxSuperJump.CheckboxChanged += (sender, args) =>
            {
                canSuperJump = checkBoxSuperJump.Checked;
            };
            playerMenu.Add(checkBoxSuperJump);

We create a new NativeCheckboxItem called checkBoxSuperJump and set the CheckboxChanged-event to trigger the code inside the curly braces

canSuperJump = checkBoxSuperJump.Checked;

canSuperJump-value is being set to be equal to that of the checkBoxSuperJump.Checked-state


        private void OnTick(object sender, EventArgs e)
        {
            menuPool.Process();

            if (canSuperJump)
            {
                Game.Player.SetSuperJumpThisFrame();
            }
        }

In order to Super Jump we need to call it each frame, so we place it inside our Tick-event - if canSuperJump is true we call the method SetSuperJumpThisFrame() and if it's not, we do nothing.

Conclusion

We've created a simple Super Jump-script, using everything we've learned so far. This one was easy - the next one is harder, be ready!

Previous - Implementing Wanted Level Script
Next - Implementing Spawn Vehicle Script

⚠️ **GitHub.com Fallback** ⚠️