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)