[LUA] [ESX] [MENU] help!

Hi. I have problems with ESX.UI.Menu.Open. Can someone tell me how to use esx menues ?

This is what i have:

function OpenMenu()
	ESX.UI.Menu.CloseAll()

	ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'cloakroom',
	{
		title    = _U('cloakroom'),
		elements = {
			{label = _U('job_wear'),     value = 'job_wear'},
			{label = _U('citizen_wear'), value = 'citizen_wear'}
		}
	}, function(data, menu)
		if data.current.value == 'citizen_wear' then
			onDuty = false
			ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
				TriggerEvent('skinchanger:loadSkin', skin)
			end)
		elseif data.current.value == 'job_wear' then
			onDuty = true
			ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
				if skin.sex == 0 then
					TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_male)
				else
					TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_female)
				end
			end)
		end

		menu.close()
	end, function(data, menu)
		menu.close()
	end)
end

AddEventHandler('esx_jobs:action', function(job, zone)
	menuIsShowed = true
	if zone.Type == "cloakroom" then
		OpenMenu()
	end
end)

Zones = {
	CloakRoom = {
		Pos   = {x = 728.08, y = 132.31, z = 79.963},
		Size  = {x = 3.0, y = 3.0, z = 1.0},
		Color = {r = 204, g = 204, b = 0},
		Marker= 1,
		Blip  = true,
		Name  = _U('fm_fish_locker'),
		Type  = "cloakroom",
		Hint  = _U('cloak_change'),
		GPS = {x = 728.08, y = 132.31, z = 79.963}
	}
}

(yes, i copied it from esx_jobs) but it’s not working

You seem to be missing portions of it.

Because it won’t work unless you define what to do when your in the zone.

You have the menu.

You have the zone config.

But what actually connects them?

The missing code, thats what.
Go back into esx jobs and have another look.

I thought thid connect menu and zone:

AddEventHandler('esx_jobs:action', function(job, zone)
	menuIsShowed = true
	if zone.Type == "cloakroom" then
		OpenMenu()
	end
end)

At what point in your code does that trigger get set off?

How does it know when you are in the zone, and sends that trigger to you?

It’s after Function OpenMenu() and after Zones. But I think it should be before Function OpemMenu() ya?

This is my whole client.lua

ESX = nil
local PlayerData                = {}

Citizen.CreateThread(function()

    while ESX == nil do
        TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
        Citizen.Wait(0)
    end
end)

Citizen.CreateThread(function() 
    while true do
        Citizen.Wait(1)

        local ped = PlayerPedId()
        if PlayerData.job == elektryk then
            local blip1 = AddBlipForCoord(728.08, 132.31, 79.96)
                SetBlipSprite(blip1, 354) --ikonka blipa
                SetBlipColour(blip1, 66)  --kolor blipa
                BeginTextCommandSetBlipName("STRING")
                AddTextComponentString("Elektrownia")
                EndTextCommandSetBlipName(blip1)
				break
        end
    end
end)

--function waypoint(marker)
--	SetNewWaypoint(728.08, 132.31)
--end

function OpenMenu()
	ESX.UI.Menu.CloseAll()

	ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'cloakroom',
	{
		title    = _U('cloakroom'),
		elements = {
			{label = _U('job_wear'),     value = 'job_wear'},
			{label = _U('citizen_wear'), value = 'citizen_wear'}
		}
	}, function(data, menu)
		if data.current.value == 'citizen_wear' then
			onDuty = false
			ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
				TriggerEvent('skinchanger:loadSkin', skin)
			end)
		elseif data.current.value == 'job_wear' then
			onDuty = true
			ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
				if skin.sex == 0 then
					TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_male)
				else
					TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_female)
				end
			end)
		end

		menu.close()
	end, function(data, menu)
		menu.close()
	end)
end

Zones = {
	CloakRoom = {
		Pos   = {x = 728.08, y = 132.31, z = 79.963},
		Size  = {x = 3.0, y = 3.0, z = 1.0},
		Color = {r = 204, g = 204, b = 0},
		Marker= 1,
		Blip  = true,
		Name  = _U('fm_fish_locker'),
		Type  = "cloakroom",
		Hint  = _U('cloak_change'),
		GPS = {x = 728.08, y = 132.31, z = 79.963}
	}
}

AddEventHandler('esx_jobs:action', function(job, zone)
	menuIsShowed = true
	if zone.Type == "cloakroom" then
		OpenMenu()
	end
end)

You’re kindof missing the point.

I recommend going back into the jobs script and going through the entire thing.

Something like a Citizen.CreateThread() needs to exist. And while your in x y z coords, send trigger to open menu.

Im on my phone at work, so I can’t help much more than that.

I think i found it.

Citizen.CreateThread(function()
	while true do

		Citizen.Wait(1)

		if PlayerData.job ~= nil and PlayerData.job.name ~= 'unemployed' then
			local zones = nil
			local job = nil

			for k,v in pairs(Config.Jobs) do
				if PlayerData.job.name == k then
					job = v
					zones = v.Zones
				end
			end

			if zones ~= nil then
				local coords      = GetEntityCoords(PlayerPedId())
				local currentZone = nil
				local zone        = nil
				local lastZone    = nil

				for k,v in pairs(zones) do
					if GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x then
						isInMarker  = true
						currentZone = k
						zone        = v
						break
					else
						isInMarker  = false
					end
				end

				if IsControlJustReleased(0, Keys['E']) and not menuIsShowed and isInMarker then
					if onDuty or zone.Type == "cloakroom" or PlayerData.job.name == "reporter" then
						TriggerEvent('esx_jobs:action', job, zone)
					end
				end
                        end
                end
        end
end)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.