(C#) MenuAPI - MAPI v3.0.3 [RedM & FiveM]

Thank you !!! :smiley:

if i use OnMenuClose event… the code get exectued whenever i select a submenu… is there a way to NOT execute the code in the OnMenuClose event whenever i enter a submenu?
fixed issue #15

Well, i m try to close all menus from client when the player put name of character in GetUserInput and an event in server is calling to see if character name exist, and if dont exist create table on SQL and call an event on client side to close menu and apply the skin .

Well now the strange is: for apply skin this work, but to close menu dont work.

Code::

Server Side to Client ;

Server:

TriggerClientEvent("Creator:OnLoadCharacter", PlayerData.player_variable[Main.GetPlayerDataIndex(player)].player_customization);

Client:

     public CreatorClient()
        {

            EventHandlers.Add("Creator:OnLoadCharacter", new Action<string>(OnLoadCharacter));
   
        }

     public async void OnLoadCharacter(string jsonString)
        {
            try
            {
                currentCharacter = JsonConvert.DeserializeObject<CharacterData>(jsonString);
            }
            catch (JsonException e)
            {
                Debug.WriteLine(e.Message);
            }

            createCharacterMenu.CloseMenu();
            await SpawnPed();
        }


But if i call this “createCharacterMenu.CloseMenu();” from direct client this work, but if i call this from server event to client event dont work. :((

OnLoadCharacter is called apply ped skin but dont close the menu.

But if i create a command of test inside CreatorClient() and execute this command while i m in the menu this close. Just dont work if i call this from server event to client event, any idea how i can make this ?

Update time! :tada:

It’s been a while since I’ve updated this topic. All changes haven’t really been documented on the docs or on here, they’re all just on GitHub.

MenuAPI is currently at version 3.0.3, and there are 2 versions available right now. One for FiveM and one for RedM. You can download these both on GitHub or (starting now) you can also include MenuAPI to your projects using NuGet, instructions for both methods have been added to the main topic post and you can also find that here:


Installation

Note, this is only for resource developers, don’t install this on your server manually if you’re not making a resource with it.

You have 2 options:

  1. Download the latest release zip and use the correct version (FiveM/RedM) for your resource. Simply include the DLL as a reference in your C# project and add using MenuAPI; to each file where you need to use MenuAPI.
  2. Use the NuGet package, which can be found here for FiveM, and here for RedM.

After doing either of the above and you’re ready to build and publish your resource, add files {'MenuAPI.dll'} to your fxmanifest.lua or __resource.lua file, and make sure that you include the MenuAPI.dll file in the folder of your resource.


I’ll try to keep this topic a bit more up to date when it comes to new releases. I’ll also be reworking the documentation website to be a bit more useful soon™! :mascot:

If I’m using vMenu but also making my own resource with this, how can I give each menu a different toggle key since MenuToggleKey is not per-menu?

I would like to remove the title text in vMenu. I have searched for information but we do not know how to use the files and their compilations. Could someone help me with this or provide me with a file with this modification?

Is this possible and if so how would I go about doing it,

Not with MenuAPI, simply because there are not enough images and names for all possible combinations of the heritage options. Rockstar doesn’t use all possible combinations.

Hey guys, I need some help, I am really confused about where i need to put my reference file.
I am working on C# visual studios, I added reference using github. Now when i try to open the menu on keydown, I get the error


And i tried two different variation, I found the file path to the .dll reference for menuAPI , copied it and pasted it into my resource folder names MenuAPI and added a __resource to start the client and go into server config to start it up. Didnt work. So then i tried puting MenuAPI.dll file inside one of the resource folder and added files{“MenuAPI.dll”} and it still didnt work. I have the scripting done, all I need is how to get the reference right.

You have to copy the MenuAPI.dll assembly in the same resource folder of the script which is using it, and be sure that such specific resource has it referenced in its manifest. (fxmanifest.lua)

Example of how your fxmanifest.lua should look like:

fx_version 'bodacious'
games { 'gta5' }

files {
	'MenuAPI.dll'
}

client_scripts {
	'MyClientScript.net.dll'
}

I suggest you to use MenuAPI from nuget

2 Likes

That works, thanks a lot man, guess i was too tired to notice that under __resource.lua i put menuAPI.net.dll

menu.OnItemSelect += (_menu, _item, _index) =>
{
// Code in here would get executed whenever an item is pressed.
Debug.WriteLine($“OnItemSelect: [{_menu}, {_item}, {_index}]”);
};

_menu is the name of the menu you created
_item is the button you placed in the menu
but what is index? I dont get it??
can someone explain to me please?

Index is the item’s index in that specific menu.

Let’s say you have 4 items added to the menu:

MenuItem one = new MenuItem("one");
MenuItem two = new MenuItem("two");
MenuItem three = new MenuItem("three");
MenuItem four= new MenuItem("four");

// make sure to add them in that order.

You select item three:

menu.OnItemSelect += (menu, item, index) =>
{
    // index is now 2
    // item == three
}

Because it has index 2 in the menu.

one has index 0, two has index 1, three has index 2, four has index 3

hey thanks, so you have to spell out one, two and three. I been putting 1, 2 and 3 XD THANK YOU so much!
I appreciate your work man, you made things so EZ

I cant seem to find the problem over here. Everytime when i choose either the LSPD_Male or LSPD_Female button, both skins will turn into female regardless. Could someone point out my error for this please?

This is basic programming knowledge, I suggest you look up some basic C# courses. Because you don’t seem to understand what the code does that you’re writing.

Also take a look at the example menu provided with MenuAPI. And look at how the OnItemSelect event is used there.

Hello, I don’t know if anyone has had this issue before, but I can’t find anything.
Basically, my menu (created with MenuAPI of course), can be reopened indefinitely with the “Menu” key (M), but I don’t want that to happen.
I want the script to control when the menu will be opened, I don’t want the player to be able to reopen that menu whenever they want.

Code:

var menu = new Menu("Character Selection", "Select your character");
menu.InstructionalButtons.Remove(Control.FrontendCancel);
menu.InstructionalButtons.Add(Control.FrontendX, "Variation");
menu.InstructionalButtons.Add(Control.FrontendY, "Accessory");

int i = 1;
foreach (var s in skins)
{
    var item = new MenuItem(s.Name ?? $"Character #{i}");
    item.ItemData = s;
    menu.AddMenuItem(item);
    i++;
}

bool inSelection = true;

// prevents player closing the menu
menu.OnMenuClose += (Menu m) =>
{
    if (inSelection)
        m.Visible = true;
};

// sets the requested model every time the player changes the selection
int selectedPed = 0;
menu.OnIndexChange += async (Menu m, MenuItem oldItem, MenuItem newItem, int oldIndex, int newIndex) =>
{
    if (newItem.ItemData is Skin skin)
    {
        selectedPed = (int)skin.PedHash;
        SetPlayerModel(PlayerId(), (uint)selectedPed);
    }
};

// when the secondary button is pressed, set a random component variation
menu.ButtonPressHandlers.Add(
    new Menu.ButtonPressHandler(
        Control.FrontendX,
        Menu.ControlPressCheckType.JUST_PRESSED,
        new Action<Menu, Control>((m, c) =>
        {
            SetPedRandomComponentVariation(PlayerPedId(), false);
        }), true
    )
);

// when the tertiary button is pressed, set a random prop
menu.ButtonPressHandlers.Add(
    new Menu.ButtonPressHandler(
        Control.FrontendY,
        Menu.ControlPressCheckType.JUST_PRESSED,
        new Action<Menu, Control>((m, c) =>
        {
            SetPedRandomProps(PlayerPedId());
        }), true
    )
);

// when the player chooses a model
menu.OnItemSelect += (Menu m, MenuItem menuItem, int itemIndex) =>
{
    // sets selectModel to false, to allow exiting the method
    inSelection = false;

    if (camera != null)
    {
        RenderScriptCams(false, false, 0, true, false);
        camera.Delete();
        camera = null;
    }

    m.Visible = false;
    m.CloseMenu();
    MenuController.CloseAllMenus();
};

MenuController.AddMenu(menu);
MenuController.MenuAlignment = MenuController.MenuAlignmentOption.Right;
menu.Visible = true;

// block the method here until selectModel stops being true
while (inSelection)
    await Delay(0);

Instructional buttons don’t seem to be working for me, all I see is a blank box.
I am using submenu.InstructionalButtons.Add(Control.Context, "Check"); (copied straight from the example menu)
I don’t see any errors in console. The blank box is still there even if I comment out adding the instructional button

Hello, does anyone know how to change the banner image of a menu?
Example: How to put an image on its menu?

Is drawing the banner as a sprite over the menu banner the only option?

EDIT

You need to set the HeaderTexture property on the Menu.
Example:

Menu.HeaderTexture = new KeyValuePair<string, string>("txdName", "imageName");

Drawing it as a sprite over the menu will glitch, because the order in which the two items will be drawn is not guaranteed and not controllable, so in some ticks it will draw over the menu, and during other ticks it will draw below it

Hello,

I made a stream (\assets\stream) folder + added ‘assets’ within config server file

I’v got few questions :

  • How do I get txdName and imageName from a PNJ file ? What are the steps ?
  • I heard about ytd, is that the texture file ? How do I create my own ?

I really want to change my Header MenuImage but I’m kinda Lost :slight_smile:

ref :
menu.HeaderTexture = new KeyValuePair<string, string>(“txdName”, “imageName”);