[Release] ActionMenu [1.0.1] (Updated April 2018)

Can you make a YouTube Video Tutorial on how to edit this please?

I am attempting to have my buttons type in chat their respective / codes, such as /hu references a hands up script in one resource, /cuff /drag and that like is another script in a different resource.

Is there a way to make the buttons type these ā€œ/commandsā€ in the chat?

The menu doest work for meā€¦ Help me to fix this??? Heres the html

<!-- 

	ActionMenu 
	Created by WolfKnight
	Additional help from lowheartrate, TheStonedTurtle, and Briglair. 

 -->

<html>
    <head>
        <script src="nui://game/ui/jquery.js" type="text/javascript"></script>
        <script src="ui.js" type="text/javascript"></script>
        <link href="ui.css" rel="stylesheet" type="text/css"/>
    </head>

    <body>
        <div id="actionmenu" style="display: none;">


        	<!-- 
        		This mainmenu div should be left as it is, you should change the buttons though.

        		If you want to make a submenu, then you must create a new div, with the ID of the 
        		div being the data-sub attribute of the button that will open it. For example, the 
        		below button Example Submenu, has the data-sub attribute of "examplesubmenu", which
        		is the same id as the div below. All submenus must also have a data-parent attribute. 
        	 -->
            <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>

send your cl_action.lua file aswell @MrGogels

I dont understand this?

I dont understand this and i want an straight version of to download???

You need a Lua file aswell. You can just have a HTML file. Your HTML file is fine but you actual Lua file isnā€™t

I donā€™t think he has functions. I think he assumes it is gonna work if he just adds what it is meant to do.

edit: looks like @rhys19 release

1 Like

lol a little tiny bit but i donā€™t have the assault rifle feature xD

Yes i had to add a little bit of sarcasm to this forum haha

Also my name is rhys or rhys19 not ryhs

What do i have to do in the cl_action.lua file?

send me it xD and any errors you get when launching your server

you need cl_action.lua in order to get the buttons on the menu working like mine

Ok here is the cl_action.lua

--[[------------------------------------------------------------------------

	ActionMenu 
	Created by WolfKnight
	Additional help from lowheartrate, TheStonedTurtle, and Briglair. 

------------------------------------------------------------------------]]--

-- Define the variable used to open/close the menu 
local menuEnabled = false 

--[[------------------------------------------------------------------------
	ActionMenu Toggle
	Calling this function will open or close the ActionMenu. 
------------------------------------------------------------------------]]--
function ToggleActionMenu()
	-- Make the menuEnabled variable not itself 
	-- e.g. not true = false, not false = true 
	menuEnabled = not menuEnabled

	if ( menuEnabled ) then 
		-- Focuses on the NUI, the second parameter toggles the 
		-- onscreen mouse cursor. 
		SetNuiFocus( true, true )

		-- Sends a message to the JavaScript side, telling it to 
		-- open the menu. 
		SendNUIMessage({
			showmenu = true 
		})
	else 
		-- Bring the focus back to the game
		SetNuiFocus( false )

		-- Sends a message to the JavaScript side, telling it to
		-- close the menu.
		SendNUIMessage({
			hidemenu = true 
		})
	end 
end 

--[[------------------------------------------------------------------------
	ActionMenu HTML Callbacks
	This will be called every single time the JavaScript side uses the
	sendData function. The name of the data-action is passed as the parameter
	variable data. 
------------------------------------------------------------------------]]--
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
	ToggleActionMenu()
end )


--[[------------------------------------------------------------------------
	ActionMenu Control and Input Blocking 
	This is the main while loop that opens the ActionMenu on keypress. It 
	uses the input blocking found in the ES Banking resource, credits to 
	the authors.
------------------------------------------------------------------------]]--
Citizen.CreateThread( function()
	-- This is just in case the resources restarted whilst the NUI is focused. 
	SetNuiFocus( false )

	while true do 
		-- Control ID 20 is the 'Z' key by default 
		-- Use https://wiki.fivem.net/wiki/Controls to find a different key 
		if ( IsControlJustPressed( 1, 20 ) ) then 
			ToggleActionMenu()
		end 

	    if ( menuEnabled ) then
            local ped = GetPlayerPed( -1 )	

            DisableControlAction( 0, 1, true ) -- LookLeftRight
            DisableControlAction( 0, 2, true ) -- LookUpDown
            DisableControlAction( 0, 24, true ) -- Attack
            DisablePlayerFiring( ped, true ) -- Disable weapon firing
            DisableControlAction( 0, 142, true ) -- MeleeAttackAlternate
            DisableControlAction( 0, 106, true ) -- VehicleMouseControlOverride
        end

		Citizen.Wait( 0 )
	end 
end )

function chatPrint( msg )
	TriggerEvent( 'chatMessage', "ActionMenu", { 255, 255, 255 }, msg )
end 
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 

That would be why you have no button action or any actions under

function chatPrint( msg )
TriggerEvent( ā€˜chatMessageā€™, ā€œActionMenuā€, { 255, 255, 255 }, msg )
end

I dont understandā€¦ sry.

your buttons are not calling an action. you have to have each button set to trigger a certain action, and that code must be somewhere in your server, you cant just make buttons without having an action for them to actually trigger.

Can someone send me an exmp to do it.

Im sry i am from finland and english is a little bit hard not too muchā€¦

1 Like

DOES anyone have a working spike strips in theirs? where you can set spikes and then delete spikes when you are done