Intégrer jsfour-idcard dans votre menu

jsfour-idcard
Intégration

#1

Bonjour,

Vous venez d’installer jsfour-idcard et vous n’arrivez à l’intégrer ?
Voici deux exemples inspiré par le readme de la ressource et par mon propre menu.

Méthode de base

  1. Ajoutez cette ligne dans votre menu dans la liste d’éléments
{label = 'Mes papiers', value = 'idcard'},
  1. Ensuite, après
ESX.UI.Menu.Open(
        'default', GetCurrentResourceName(), 'Portefeuille',
        {
            title = 'Portefeuille',
            align = 'top-left',
            elements = elems
        },
        function(data,menu)

rajoutez cette condition à celle(s) existante(s)

if data.current.value == "idcard" then
    openMenu()
end

-- OU, suivant la structure de votre menu

elseif data.current.value == "idcard" then
    openMenu()
end
  1. Puis cette fonction en fin de page
function openMenu()
    ESX.UI.Menu.CloseAll()
    ESX.UI.Menu.Open(
	'default', GetCurrentResourceName(), 'id_card_menu',
	{
		title    = 'ID menu',
		elements = {
			{label = 'Regarder ma carte d\'identité', value = 'checkID'},
			{label = 'Montrer ma carte d\'identité', value = 'showID'},
			{label = 'Regarder mon permis de conduire', value = 'checkDriver'},
			{label = 'Montrer mon permis de conduire', value = 'showDriver'},
			{label = 'Regarder ma licence d\'armes', value = 'checkFirearms'},
			{label = 'Montrer ma licence d\'armes', value = 'showFirearms'},
		}
	},
	function(data, menu)
		local val = data.current.value
		
		if val == 'checkID' then
			TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()))
		elseif val == 'checkDriver' then
			TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()), 'driver')
		elseif val == 'checkFirearms' then
			TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()), 'weapon')
		else
			local player, distance = ESX.Game.GetClosestPlayer()
			
			if distance ~= -1 and distance <= 3.0 then
				if val == 'showID' then
				TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(player))
				elseif val == 'showDriver' then
			TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(player), 'driver')
				elseif val == 'showFirearms' then
			TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(player), 'weapon')
				end
			else
			  ESX.ShowNotification('No players nearby')
			end
		end
	end,
	function(data, menu)
		menu.close()
                -- retourMenu() -- Nom de la fonction de votre menu principale
	end
)
end

Méthode personnalisée

  1. Ajoutez ces lignes dans votre menu dans la liste d’éléments
        {label = 'Sortir ma carte d\'identité', value = 'idCard'},
        {label = 'Sortir mon permis de conduire', value = 'licVeh'},
        {label = 'Sortir ma licence d\'armes', value = 'licArmes'},
  1. Ensuite rajoutez ces conditions
            if data.current.value == 'idCard' then
                local player, distance = ESX.Game.GetClosestPlayer()
                if distance ~= -1 and distance <= 3.0 then
                    TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(player))
                else
                    ESX.ShowNotification('Il n\'y a personne à qui montrer la carte !')
                end
                TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()))
            elseif data.current.value == 'licVeh' then
                local player, distance = ESX.Game.GetClosestPlayer()
                if distance ~= -1 and distance <= 3.0 then
                    TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(player), 'driver')
                else
                    ESX.ShowNotification('Il n\'y a personne à qui montrer la carte !')
                end
                TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()), 'driver')
            elseif data.current.value == 'licArmes' then
                local player, distance = ESX.Game.GetClosestPlayer()
                if distance ~= -1 and distance <= 3.0 then
                    TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(player), 'weapon')
                else
                    ESX.ShowNotification('Il n\'y a personne à qui montrer la carte !')
                end
                TriggerServerEvent('jsfour-idcard:open', GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()), 'weapon')
            end

Besoin d'aide integrer isfour_idcard sur le menu perso