From 808315921b34f796bd9cb87f7256ef85611d68ad Mon Sep 17 00:00:00 2001 From: RockySouthpaw <55056068+RockySouthpaw@users.noreply.github.com> Date: Wed, 9 Sep 2020 17:22:56 -0400 Subject: [PATCH] (Feature): Added phone as an item --- resources/client/cl_main.lua | 115 ++++++++++++++++++++++++++--------- resources/config.lua | 1 + resources/server/sv_main.lua | 11 ++++ 3 files changed, 98 insertions(+), 29 deletions(-) diff --git a/resources/client/cl_main.lua b/resources/client/cl_main.lua index 22c66eb..c898e8d 100644 --- a/resources/client/cl_main.lua +++ b/resources/client/cl_main.lua @@ -132,6 +132,23 @@ function phoneCloseAnim() --Phone Close Animation end end +function carryingPhone(cb) + cb(true) +end + +function carryingPhone(cb) + if (ESX == nil) then return cb(0) end + ESX.TriggerServerCallback('phone:getItemAmount', function(qtty) + cb(qtty > 0) + end, 'phone') +end + +function noPhone() + if (ESX == nil) then return end + --exports['mythic_notify']:SendAlert('error', 'Oi Mate, No El Telephono') + ESX.ShowNotification('Oi Mate, No El Telephono') + end + Citizen.CreateThread(function() while true do Citizen.Wait(0) @@ -142,35 +159,75 @@ Citizen.CreateThread(function() end) function Phone() --Open/close phone - if isPhoneOpen == false then - isPhoneOpen = true - phoneOpenAnim() - print("phone is now open") --Left for testing purposes. - TriggerServerEvent('phone:getCredentials', source) - SetCursorLocation(0.936, 0.922) -- Experimental - local res = GetActiveScreenResolution() - --print(res) - SendNUIMessage( -- Shows phone - { - app = 'PHONE', - method = 'setVisibility', - data = true - } - ) - SetNuiFocus(true, true) - else - isPhoneOpen = false - print("phone is now closed") --Left for testing purposes. - SendNUIMessage( -- Hides phone - { - app = 'PHONE', - method = 'setVisibility', - data = false - } - ) - SetNuiFocus(false, false) - phoneCloseAnim() - end + if Config.PhoneAsItem == true then + --print("ConfigOn") + carryingPhone(function (carryingPhone) + if carryingPhone == true then + if isPhoneOpen == false then + isPhoneOpen = true + phoneOpenAnim() + print("phone is now open") --Left for testing purposes. + TriggerServerEvent('phone:getCredentials', source) + SetCursorLocation(0.936, 0.922) -- Experimental + local res = GetActiveScreenResolution() + --print(res) + SendNUIMessage( -- Shows phone + { + app = 'PHONE', + method = 'setVisibility', + data = true + } + ) + SetNuiFocus(true, true) + else + isPhoneOpen = false + print("phone is now closed") --Left for testing purposes. + SendNUIMessage( -- Hides phone + { + app = 'PHONE', + method = 'setVisibility', + data = false + } + ) + SetNuiFocus(false, false) + phoneCloseAnim() + end + else + noPhone() + end + end) + elseif Config.PhoneAsItem == false then + --print("ConfigOff") + if isPhoneOpen == false then + isPhoneOpen = true + phoneOpenAnim() + print("phone is now open") --Left for testing purposes. + TriggerServerEvent('phone:getCredentials', source) + SetCursorLocation(0.936, 0.922) -- Experimental + local res = GetActiveScreenResolution() + --print(res) + SendNUIMessage( -- Shows phone + { + app = 'PHONE', + method = 'setVisibility', + data = true + } + ) + SetNuiFocus(true, true) + else + isPhoneOpen = false + print("phone is now closed") --Left for testing purposes. + SendNUIMessage( -- Hides phone + { + app = 'PHONE', + method = 'setVisibility', + data = false + } + ) + SetNuiFocus(false, false) + phoneCloseAnim() + end + end end RegisterCommand('phone', function(source) -- Toggles Phone diff --git a/resources/config.lua b/resources/config.lua index 8e9297e..dd545a0 100644 --- a/resources/config.lua +++ b/resources/config.lua @@ -4,3 +4,4 @@ Config.Locale = 'en' Config.KeyTogglePhone = 288 -- F1 Config.KeyTakeCall = 38 -- E +Config.PhoneAsItem = true \ No newline at end of file diff --git a/resources/server/sv_main.lua b/resources/server/sv_main.lua index ff84144..ec3922b 100644 --- a/resources/server/sv_main.lua +++ b/resources/server/sv_main.lua @@ -29,4 +29,15 @@ RegisterCommand('getnumber', function(source, args) local xPlayer = ESX.GetPlayerFromId(_source) local _identifier = xPlayer.getIdentifier() print(_identifier) +end) + +ESX.RegisterServerCallback('phone:getItemAmount', function(source, cb, item) + local xPlayer = ESX.GetPlayerFromId(source) + local items = xPlayer.getInventoryItem(item) + + if items == nil then + cb(0) + else + cb(items.count) + end end) \ No newline at end of file