ContextMenu - Create a new kind of menu! [OUTDATED - Check description]

This version is now outdated. Head on over to the new topic to find an updated post!

.
.
.
.
.
.

What exactly is the “ContextMenu” and what can you do with it?

ContextMenu is a script that allows you to create your own menus for any kind of purpose. It does nothing by itself.
You hold a button and your cursor appears on the screen. You can then click on any object and open specific menus for specific objects. This is kind of like your default rightclick menu in every other application.
E.g. clicking on a player can have a completely different menu than clicking on a vehicle.
An example of what can be done with this script can be found in this video:

Check out the “Advanced Vehicle Interaction” Script that is using this menu.

Features

  • Create custom menus using LUA.
  • Menu items include:
    • TextItem: Just has text and can be clicked.
    • CheckboxItem: Has a text and a checkbox that can be checked.
    • SubmenuItem: Automatically created when creating a submenu to a menu.
    • Separator: Just a separator line to group items together.
    • More to come depending on demand.
  • Use custom sprites on the right side of an item.
  • Fully customizable with width, height and colors (background, highlighted background, text, highlighted text, sprite, menu border, separator lines).
  • Includes the full source code.
  • Compatible with basically everything? Let me know if you find any issues!

Performance

  • The script itself draws no performance at all.
  • When you have created your own menu, the performance depends on the amount of items that are currently displayed on the screen.
  • The Client side performance of the “Advanced Vehicle Interaction” menu is around 0.25ms when the main menu is shown.

FAQ

Where can I get this script?

Is this still WIP and will it be expanded upon?

  • Yes, this script is very much a work-in-progress project.
  • A lot of things will be added and changed throughout this process.
  • I’ll try to keep updates as compatible as possible, but new versions might break backwards compatibility here or there.
  • If you have any suggestions on changes or find features missing, just let me know and I’ll see what is possible and can be done.

How can I create a custom menu?

  • The documentation is currently WIP and not yet accessible. You can however take a look at the example and try and figure it out for yourself. It is not difficult!

Known Issues

  • Resolutions wider than 21:9 will cause dislocation problems of the cursor and menu. This issue is being worked on.
  • Controller support is not working as of now.

Patchnotes

Open Me

Update (v1.1):

  • Breaking change: removed Process() function (example updated to reflect this change)
  • Added more functions to the MenuPool:
    • OnOpenMenu: gets called, when the menu should open
    • OnAltFunction: gets called, when alt button is clicked
    • OnMouseOver: gets called while the button for the menu is held
  • Added TextItem: No functionality, just text.
  • Added camera rotation when touching the screen edge with the mouse (can be turned off).
  • Renamed variable “opacity” to “alpha” in all instances.
  • Renamed variable “text” from Text class to “title”.
18 Likes

Nice release Kiminaze !

I love u and hate u at the same time, I just finished my bt-target adaptation in all my scripts today and now I need to redo it :crazy_face:

PS: Only question do the checkbox is memorized only on a specific target ? Or for all targets with the same models (I’m reading the script actually not testing :nerd_face:)

2 Likes

No way! Love it!

2 Likes

<3

Well now I’m sooorry :wink:

No. It is only memorized for the menu itself. But e.g. in Advanced Vehicle Interaction the menu is re-generated every time it is opened and thus setting it depending on what you set it to.
If you only generate it once, it is only saved per menu.

2 Likes

is this different from the other ContextMenu ?

I don’t personally know how other context menus work but I would say the core might be the same.

My script only uses natives. I don’t use any HTML / CSS etc. in this :slight_smile:

1 Like

Good job, i think this can change the script Game :wink:

1 Like

Man, this is beautiful! Pure art! Incredible. Tnks for share this free! You are amazing <3

1 Like

dopeeeeeee
good job homie

1 Like

Good job but i will still prefer NUI based instead of native system…why? Its more optimized
But still very nice share

1 Like

how to fuck open it

That is a real nice way to introduce yourself to a community. Thanks for that.

This script does nothing by itself.
If you want to see the example menu, make sure it is active in the fxmanifest.lua and then ingame hold Left Alt and right click things.

how to open menu

Literally the message above you :smiley:

New update adding more functionality.

And as an additional note:
The wiki is now actively being worked on and can be found here:

It would be great If you could have the option of creating job menus! I have more or less done something like that but when I change jobs from police to mechanic I still have the police menu, until I restart the script or reconnect

Well, that depends on how you build the menu.

If you create it once with e.g. police job and then change to another job, you need to change the contents of the menu ofc.
Or create several menus for the jobs, but only the display the one for the job theplayer has.

I have something like that!

itizen.CreateThread(function()
            if ESX.PlayerData.job and ESX.PlayerData.job.name == 'mechanic' then
                local menu_meca = menuPool:AddSubmenu(contextMenu, "Mechanic")
                local itemDelete = menu_meca:AddItem("Eliminar vehiculo")
                itemDelete.OnClick = function()
                    if (vehicle ~= nil and DoesEntityExist(vehicle)) then
                        SetEntityAsMissionEntity(vehicle)
                        DeleteEntity(vehicle)
                    end
                end
            elseif ESX.PlayerData.job and ESX.PlayerData.job.name == 'taxi' then
                local menu_taxi = menuPool:AddSubmenu(contextMenu, "Taxi")
                local itemDelete = menu_taxi:AddItem("Bill")
                itemDelete.OnClick = function()
                    if (vehicle ~= nil and DoesEntityExist(vehicle)) then
                        SetEntityAsMissionEntity(vehicle)
                        DeleteEntity(vehicle)
                    end
                end
            end   
        end)  

But until I change jobs and restart the plugin, or reconnect I don’t have the appropriate menu :frowning:

That thread only checks the job once when the script starts. That is your problem.

You also need to use the esx events for setJob etc. (I don’t know them as I don’t use esx, but they are usually in every job script).

2 Likes