Log in to reply
 

[C#][NativeUI] How to create a mod menu using NativeUI(Part 1)



  • Hello guys, with my last tutorial done and dusted, I was requested to make a mod menu tutorial. I thought it was a very good idea, and so I am creating a mod menu tutorial, using NativeUI. It is very simple, you will get to know how to create menus more than just simple mod menu functions.

    REQUIREMENTS:
    ScriptHookVDotNet
    NativeUI

    First, lets make a new project:
    alt text
    Lets add our references to ScriptHookVDotNet.dll and NativeUI.dll:
    alt text
    Also add a reference to System.Windows.Forms and System.Drawing:
    alt text
    alt text
    With that done, lets add our using namespaces:
    alt text
    Awesome, now lets make our class inherit GTA.Script and be done with setting everything up:
    alt text
    Awesome! Now, lets talk a bit about NativeUI. NativeUI contains all its menus in a MenuPool, and we can put all our menus in it. Right now, we need one mainmenu, which can be than divided into many other submenus, and one MenuPool. Let's do that:
    alt text
    Let's make a script constructor, which can instantiate and start all these classes:
    alt text
    Lets go over this one... the first line,

    modMenuPool = new MenuPool();

    instantiates the menuPool class so we can add it to the pool. The second line,

    mainMenu = new UIMenu("Mod Menu", "SELECT AN OPTION");

    instantiates a new UIMenu, whose title, is Mod Menu and the subtitle is SELECT AN OPTION. You can of course edit these to whatever you want, but I will be keeping these throughout the tutorial. In the last line, we add our mainMenu to our menuPool. Simple, right? Now lets also add the basic events(OnKeyDown, OnTick):
    alt text
    One thing we need to do is in our tick we need to add a menuPool.ProcessMenu line, if you dont do that, the menus wont show up:
    alt text
    This is just something to do with every NativeUI menu you create. Now, let's make a little keypress to open/close our nativeUI menu, which surprisingly is very easy:
    alt text
    This little piece of code checks if we press the key F10, and if we do, no menus are open. If they arent, we open/close our menu using the visible property. Let's check if this code works ingame:
    alt text
    As you can see, we don't have any options, but this does work! Next, we'll add some simple items which you can select. But before, we need to set everything up. I would like to do that in a little private function which we can call later on. This is how I do it:
    alt text
    First, I declare a global variable resetWantedLevel of type UIMenuItem, which I set its value in the Setup function. Than, I add the item to our mainMenu. Now this will give us an Item which we can click, but nothing will happen. For that, we need another event, which is built-in NativeUI's UIMenu class:|
    alt text
    Fairly easy to understand, just another event. This event gets called whenever we select an item, and it also passes through which Item was selected. This way, we can expand our menu easily by checking the returned item with other items, and make more and more functions. Let's however implement our basic reset wanted level script:
    alt text
    Easy to understand, as explained before. Let's test this script ingame!
    alt text
    As you can see, this script works! Now, you can add as much to it as you want, but I am also going to show you other basics of how you can use this. For example, why not make a little weapon selector? You select a weapon, and press a button and you get the desired weapon? Well, I am going to make this in a submenu. And this is how you create a submenu:
    alt text
    This creates a submenu inside our mainMenu, and its name is Weapon Selector Menu. Now that we have the menu, lets get to work on it. For lists, we use something called UIMenuListItem, which can contain a dynamic list and return the index of what is selected. We will be using this. Lets first make a dynamic list:
    alt text
    Now, this is where the most complicated part begins. We need to get all the values from the WeaponHash array, and cast it into a WeaponHash:
    alt text
    Basically what is happening is we get all the weapon hashes and cast it into a weaponhash array. Now we need to add all those weapon hashes into our list:
    alt text
    Now we have all the weapon hashes. Let's setup our other half of the menu:
    alt text
    I will show you another way of creating an event, if you dont want another function. It would be very good, since all the code could come into one function. This is how you do it:
    alt text
    Now, lets put our button code in:
    alt text
    We need to do two things now, get the index of our List item, and get the WeaponHash from our our whole array of weapons. This is pretty easy. We get the index by list.Index and the other by just allWeaponHashes[index]. Easy:
    alt text
    I believe this code is straightforward, so now lets put this function in:
    alt text
    Now, lets test this!
    alt text
    as you can see I have no weapons. But now I want the heavy shotgun:
    alt text
    And I got the heavy shotgun!
    alt text
    I think this wraps up the first part of the tutorial, in the second half, we will be doing more of these types of functions, like car spawning, car god mode, stuff like that. And I will also move the Reset Wanted Level into its own Player submenu. Until then, bye!

    Second tutorial:
    https://forums.gta5-mods.com/topic/1027/c-nativeui-how-to-create-a-mod-menu-using-nativeui-part-2



  • @GTAVModder4Life perfect, good explanation. i am very interested in spawning cars by name. so im looking forward to your next tutorial. thank you again for all your tutorials!!



  • @TobsiCred Thanks dude! And nice idea, will cover in the next one.



  • @GTAVModder4Life Thank you for this tutorial :) i want to know how to create Pickups.. For Example: When the player drive with a car in this pickup he can sell it..



  • @GTAVModder4Life Hey man i was trying to install VS but that thing wont install for me kept getting errors (package failed) ,so can you please convert these two source code files to a working .asi ? please ?
    files



  • @MK sorry dude, I need the whole project, I dont have most of the files needed. Like IniWriter, you didnt give me all the files to build the project.



  • @GTAVModder4Life The files that i sent you are the source code for this mod
    https://www.gta5-mods.com/scripts/create-your-own-natural-vehicle-spawns
    So wait a second,the source code isn't for editing an stuff like what I'm trying to do here ?



  • @GTAVModder4Life What i did was edited the codes to include ADDON vehicles.



  • I been wanting to get the police package how do you get it? I have Xbox 360 HELP!!!!



  • @Xxkc95xX Im sorry, this website is only for PC mods not Xbox or PS.



  • @GTAVModder4Life oh how do you do mods on Xbox?



  • @Xxkc95xX I'm sorry but I dont make or have ever made mods for Xbox 360, and like I said this website is only for PC.



  • @GTAVModder4Life Nevermind i found a solution.



  • @GTAVModder4Life okay don't get stupid I was just asking smh



  • @Xxkc95xX Drop the attitude.
    @GTAVModder4Life was in no way "stupid" towards you.

    You come here and hijack a thread, ask for mods for consoles on a PC modding website,
    and then proceed to get hostile when you don't get your way. That is not how we do things here.



  • @yeahhmonkey you start in the class, like I mentioned in the start. If you dont know how to create a normal GTA 5 script, refer to my How to create a Basic script tutorial.



  • @GTAVModder4Life Awesome explanations, Now I am gonna implement this with my script for too many options I was thinking to add to. :D Thank you so much.
    @GTATerminal I could be late at party, but very nicely said.



  • @ashishcw Thank you :3



  • This post is deleted!


  • Can't Get this to work

    https://gyazo.com/77930228f799093f46f4a553f0cddfdb

    Please Help



  • This post is deleted!


  • Hello,

    So i get the Issue that my "KeyCode is not in an EventArgs Implemented... Does anyone know how to fix that?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Drawing;
    using GTA;
    using GTA.Native;
    using GTA.Math;
    using NativeUI;

    namespace GTA_Script1
    {
    public class Class1 : Script
    {
    MenuPool modMenuPool;
    UIMenu mainMenu;

        public Class1()
        {
            modMenuPool = new MenuPool();
            mainMenu = new UIMenu("Mod Menu", "Select an Option");
            modMenuPool.Add(mainMenu);
    
            Tick += onTick;
            KeyDown += onKeyDown;
        }
    
        void onTick(object sender, EventArgs e)
        {
            if (modMenuPool != null)
                modMenuPool.ProcessMenus();
        }
    
        void onKeyDown(object sender, EventArgs e)
        {
            if (e.KeyCode == Keys.F10 && !modMenuPool.IsAnyMenuOpen())
            {
                mainMenu.Visible = !mainMenu.Visible;
            }
        }
    }
    

    }



  • @DoemeZH Change EventArgs to KeyEventArgs in your onKeyDown



  • So the menu does not pop up when I press the button, the code is 100% the same. Do I have to install nativeUI into the GTA folder or something? It's not mentioned in this post...



  • NativeUI needs to be in you Scripts folder, yes.


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.