works good my dude ;D THANK U
I got it installed and the menu comes up but i cannot exit out of the menu. My keyboard will not work at all when the menu is activated and I pretty much have to ctrl+alt+del to get out of the game.
Amazing job on the menu!
Couple of suggestions if you plan on updating this:
- You should probably implement a “Back” button. It would be very useful for someone creating multiple sub-menus inside a main menu, that or a “Home” button.
I added a “home” button for the time being to the sub menus, basically all it does is hit your “ResetMenu” function.
<button onclick="ResetMenu()">Home</button>
- Add A Wait after button pressed. For some reason, after I clicked one of the buttons other than the EXIT button, the menu always hid itself, even though the ToggleActionMenu() function was still called after each button press, it never actually toggled it, only Hid itself. Must be a timing issue.
I added a wait after the button press and then it stayed active. Not sure if that was intended, assumed it wasn’t based on your commented text. Just a minor thing anyways. Then again, maybe that was only happening for me and no one else. Either way, that solved my problem there.
RegisterNUICallback( "ButtonClick", function( data, cb )
if ( data == "button1" ) then
chatPrint( "Button 1 pressed!" )
elseif ( data == "button2" ) then
chatPrint( "Button 2 pressed!" )
elseif ( data == "button3" ) then
chatPrint( "Button 3 pressed!" )
elseif ( data == "button4" ) then
chatPrint( "Button 4 pressed!" )
elseif ( data == "exit" ) then
-- We toggle the ActionMenu and return here, otherwise the function
-- call below would be executed too, which would just open the menu again
ToggleActionMenu()
return
end
-- This will only be called if any button other than the exit button is pressed
Citizen.Wait( 0 ) --Added Wait Here <-----
ToggleActionMenu()
end )
Buttons wont do anything they wont write in chat or close the menu
Can you give an example on how to send data to JS (and show or hide elements based on data)?
Also, yes, “Back” button is almost a must have.
@SWood press ‘ESC’ or click the ‘EXIT’ button.
@Decon You have some good suggestions, I’ll take a look when I next have some time.
@NoamKvet Have you modified any of the files? If so send me your modifications. Also, what FX build are you on?
@MJRamon You should take a look at this guide.
You send data from Lua to the JS side using SendNUIMessage, take a look at the ui.js file in the ActionMenu resource, there’s a function called init(), which loops through all of the HTML buttons, checks if they have a data-action attribute, then assigns them a click function, which is just the sendData function, but with the button’s data-action.
Download a fresh copy of FXServer with just this resource in it, if it works, then one of your other resources is conflicting.
I have a fresh install of Latest FX, the only resource is wk_actionmenu and when I press “Z” nothing happens.
and I have made no modifications to the actionmenu
What kind of keyboard are you using? Also, try resetting your keybinds, that sometimes does the trick.
I am gonna try changing the key to open the menu. Will report back to you
EDIT: Changed key to F6 and it works great. Thanks @WolfKnight179 !
Does anyone know why my sub menus are not working? I read the page, but it was kinda confusing to me. I have tried a variety of things and the menus itself works but the sub menus dont. Here is my code for the menu:
<div id="mainmenu">
<button class="menuoption" data-action="Vehicle">Vehicle</button>
<button class="menuoption" data-action="LEO">LEO</button>
<button class="menuoption" data-action="Civilian">Civilian</button>
</div>
<div id="vehicle" data-parent="mainmenu" style="display: none;">
<button class="menuoption" data-sub="Engine">Turns Engine On/Off</button>
<button class="menuoption" data-sub="Trunk">Opens Trunk</button>
<button class="menuoption" data-sub="Windows">Rolls Down Window</button>
<button class="menuoption" data-sub="Doors">Opens Doors</button>
</div>
<div id="LEO" data-parent="mainmenu" style="display: none;">
<button class="menuoption" data-sub="Stun Gun">Equips Stun Gun</button>
<button class="menuoption" data-sub="Cuff">Cuffs Player</button>
<button class="menuoption" data-sub="Drag Player">Drags Player</button>
<button class="menuoption" data-sub="Put In Vehicle">Puts Player In Vehicle</button>
<button class="menuoption" data-sub="Take Player Out Of Vehicle">Takes Player Out Of Vehicle</button>
</div>
<div id="Civilian" data-parent="mainmenu" style="display: none;">
<button class="menuoption" data-sub="Assault Rifle">Equips Assault Rifle</button>
<button class="menuoption" data-sub="Pistol">Equips Pistol</button>
<button class="menuoption" data-sub="Handsup">Puts Hands Up</button>
<button class="menuoption" data-sub="Handsup Knees">Gets On Knees With Hands Up</button>
You have a few missing <div>
tags in your code. Make sure you are opening and close each <div>
and it should work fine.
You’re code needs to look like this. You had “data-sub” where “data-action” should of been.
<div id="mainmenu">
<button class="menuoption" data-sub="vehicle">Vehicle</button>
<button class="menuoption" data-sub="leo">LEO</button>
<button class="menuoption" data-sub="civ">Civilian</button>
</div>
<div id="vehicle" data-parent="mainmenu" style="display: none;">
<button class="menuoption" data-action="engine">Turns Engine On/Off</button>
<button class="menuoption" data-action="trunk">Opens Trunk</button>
<button class="menuoption" data-action="windows">Rolls Down Window</button>
<button class="menuoption" data-action="doors">Opens Doors</button>
</div>
<div id="leo" data-parent="mainmenu" style="display: none;">
<button class="menuoption" data-action="stun_gun">Equips Stun Gun</button>
<button class="menuoption" data-action="cuff">Cuffs Player</button>
<button class="menuoption" data-action="drag">Drags Player</button>
<button class="menuoption" data-action="seat">Puts Player In Vehicle</button>
<button class="menuoption" data-action="unseat">Takes Player Out Of Vehicle</button>
</div>
<div id="civ" data-parent="mainmenu" style="display: none;">
<button class="menuoption" data-action="assault_rifle">Equips Assault Rifle</button>
<button class="menuoption" data-action="pistol">Equips Pistol</button>
<button class="menuoption" data-action="handsup">Puts Hands Up</button>
<button class="menuoption" data-action="handsup_knees">Gets On Knees With Hands Up</button>
</div>
<!-- Do not remove this or you will not be able to exit the menu -->
<button class="menuoption" data-action="exit">Exit</button>
</div>
Anyone no how to properly trigger a .lua script to one of these buttons?
Thanks man it worked!
Now I am like you, just need to get the lua to trigger
How can I make this open only for as long as I hold the control down? I want to be able to quickly enter and exit the menu without having to click exit?
You have to implement the menu to your .lua script or vice-versa or just call specific events in other scripts instead of the chatPrint.
Say you had a function for handsUp and a button for it. When you click the button for Hands Up, it sends the button data to the callback buttonclick. If the hands up button was set to button1, where it says " chatPrint( “Button 1 pressed!” ) " You would put in there, what happens when you press button1.
So instead of " chatPrint( “Button 1 pressed!” ) " you could have " handsUp() "
RegisterNUICallback( "ButtonClick", function( data, cb )
if ( data == "button1" ) then
handsUp()
elseif ( data == "button2" ) then
chatPrint( "Button 2 pressed!" )
elseif ( data == "button3" ) then
chatPrint( "Button 3 pressed!" )
elseif ( data == "button4" ) then
chatPrint( "Button 4 pressed!" )
elseif ( data == "exit" ) then
-- We toggle the ActionMenu and return here, otherwise the function
-- call below would be executed too, which would just open the menu again
ToggleActionMenu()
return
end
Which would go into the example function "handsUp() " like I have below and do all this junk.
local handsup = false
function handsUp()
local dict = "missminuteman_1ig_2"
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Citizen.Wait(0)
end
if not handsup then
TaskPlayAnim(GetPlayerPed(-1), dict, "handsup_enter", 8.0, 8.0, -1, 50, 0, false, false, false)
handsup = true
else
handsup = false
ClearPedTasks(GetPlayerPed(-1))
end
end
You just replace the chatPrint with where ever you want the code to go. It can go anywhere… You could even slap your whole function right in there, only that’s not very tidy and not a good idea. Better to send the code off to do something.