Utiliser le GCPhone que si vous l'avez acheté

Tutoriel originel (EN) : https://forum.fivem.net/t/tutorial-for-gcphone-with-call-and-job-message-other/177904/163

Ajoutez dans votre base de données

INSERT INTO `items` (`name`, `label`, `weight`) VALUES  
    ('phone', 'Téléphone', 1)
;
INSERT INTO shops (id, name, item, price) VALUES (98, 'TwentyFourSeven', 'phone', 175), (99, 'RobsLiquor', 'phone', 175), (100, 'LTDgasoline', 'phone', 175);

Recherchez dans "client/main.lua"

Citizen.CreateThread(function()

        while true do
            Citizen.Wait(0)
            if IsControlJustPressed(1, KeyOpenClose) and GetLastInputMethod( 0 ) then
                TooglePhone()
            end
            if menuIsOpen == true then
                for _, value in ipairs(KeyToucheCloseEvent) do
                    if IsControlJustPressed(1, value.code) then
                        SendNUIMessage({keyUp = value.event})
                    end
                end
            end
        end
end)

Et remplacez par

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		if IsControlJustPressed(1, KeyOpenClose) and GetLastInputMethod( 0 ) then
			ESX.TriggerServerCallback('gcphone:getItemAmount', function(qtty)
				if qtty > 0 then
					TooglePhone()
				else
					ESX.ShowNotification("Vous n'avez pas de ~r~téléphone~s~")
				end
			end, 'phone')
		end
		if menuIsOpen == true then
			for _, value in ipairs(KeyToucheCloseEvent) do
				if IsControlJustPressed(1, value.code) then
					SendNUIMessage({keyUp = value.event})
				end
			end
		end
	end
end)

Ajoutez dans "server/main.lua"

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj)
    ESX = obj
end)

ESX.RegisterServerCallback('gcphone:getItemAmount', function(source, cb, item)
    local xPlayer = ESX.GetPlayerFromId(source)
    local qtty = xPlayer.getInventoryItem(item).count
    cb(qtty)
end)
1 « J'aime »

Correctif 27/02/2019


Dans votre « client/main.lua » rajoutez ceci :

ESX = nil

Tout en haut de votre fichier, exemple :


Ajoutez ceci quelque part toujours côté client/main.lua :


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

Ensuite, remplacer ceci côté client/main.lua :


Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		if IsControlJustPressed(1, KeyOpenClose) and GetLastInputMethod( 0 ) then
			ESX.TriggerServerCallback('gcphone:getItemAmount', function(qtty)
				if qtty > 0 then
					TooglePhone()
				else
					ESX.ShowNotification("Vous n'avez pas de ~r~téléphone~s~")
				end
			end, 'phone')
		end
		if menuIsOpen == true then
			for _, value in ipairs(KeyToucheCloseEvent) do
				if IsControlJustPressed(1, value.code) then
					SendNUIMessage({keyUp = value.event})
				end
			end
		end
	end
end)

Par ceci :


Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		if IsControlJustPressed(1, KeyOpenClose) and GetLastInputMethod( 0 ) then
			ESX.TriggerServerCallback('esx_gcphone:getItemAmount', function(qtty)
				if qtty > 0 then
					TooglePhone()
				else
					ESX.ShowNotification("Vous n'avez pas de ~r~téléphone~s~")
				end
			end, 'phone')
		end
		if menuIsOpen == true then
			for _, value in ipairs(KeyToucheCloseEvent) do
				if IsControlJustPressed(1, value.code) then
					SendNUIMessage({keyUp = value.event})
				end
			end
		end
	end
end)

Au final vous aurez ça :


Remplacez dans "server/main.lua"


ESX = nil

TriggerEvent('esx:getSharedObject', function(obj)
    ESX = obj
end)

ESX.RegisterServerCallback('gcphone:getItemAmount', function(source, cb, item)
    local xPlayer = ESX.GetPlayerFromId(source)
    local qtty = xPlayer.getInventoryItem(item).count
    cb(qtty)
end)

Par ceci :


ESX = nil

TriggerEvent('esx:getSharedObject', function(obj)
    ESX = obj
end)

ESX.RegisterServerCallback('esx_gcphone:getItemAmount', function(source, cb, item)
    local xPlayer = ESX.GetPlayerFromId(source)
    local qtty = xPlayer.getInventoryItem(item).count
    cb(qtty)
end)