Merge pull request #1100 from Gellipapa/main

fix(esx_core/main.lua, function.lua)
This commit is contained in:
Gellipapa
2023-07-09 01:01:12 +02:00
committed by GitHub
2 changed files with 74 additions and 60 deletions
+74 -56
View File
@@ -26,7 +26,7 @@ end
function ESX.SearchInventory(items, count)
if type(items) == 'string' then
items = { items }
items = {items}
end
local returnData = {}
@@ -154,7 +154,7 @@ if GetResourceState("esx_context") ~= "missing" then
end
function ESX.RefreshContext(...)
exports["esx_context"]:Refresh(...)
exports["esx_context"]:Refresh(...)
end
else
function ESX.OpenContext()
@@ -203,6 +203,7 @@ function ESX.UI.Menu.Open(type, namespace, name, data, submit, cancel, change, c
menu.change = change
menu.close = function()
ESX.UI.Menu.RegisteredTypes[type].close(namespace, name)
for i = 1, #ESX.UI.Menu.Opened, 1 do
@@ -217,9 +218,11 @@ function ESX.UI.Menu.Open(type, namespace, name, data, submit, cancel, change, c
if close then
close()
end
end
menu.update = function(query, newData)
for i = 1, #menu.data.elements, 1 do
local match = true
@@ -235,6 +238,7 @@ function ESX.UI.Menu.Open(type, namespace, name, data, submit, cancel, change, c
end
end
end
end
menu.refresh = function()
@@ -262,6 +266,7 @@ function ESX.UI.Menu.Open(type, namespace, name, data, submit, cancel, change, c
break
end
end
end
end
end
@@ -491,6 +496,7 @@ function ESX.Game.GetPlayers(onlyOtherPlayers, returnKeyValue, returnPeds)
return players
end
function ESX.Game.GetClosestObject(coords, modelFilter)
return ESX.Game.GetClosestEntity(ESX.Game.GetObjects(), false, coords, modelFilter)
end
@@ -598,23 +604,23 @@ function ESX.Game.GetVehicleProperties(vehicle)
local interiorColor = GetVehicleInteriorColour(vehicle)
local customPrimaryColor = nil
if hasCustomPrimaryColor then
customPrimaryColor = { GetVehicleCustomPrimaryColour(vehicle) }
customPrimaryColor = {GetVehicleCustomPrimaryColour(vehicle)}
end
local hasCustomXenonColor, customXenonColorR, customXenonColorG, customXenonColorB = GetVehicleXenonLightsCustomColor(vehicle)
local customXenonColor = nil
if hasCustomXenonColor then
customXenonColor = { customXenonColorR, customXenonColorG, customXenonColorB }
customXenonColor = {customXenonColorR, customXenonColorG, customXenonColorB}
end
local hasCustomSecondaryColor = GetIsVehicleSecondaryColourCustom(vehicle)
local customSecondaryColor = nil
if hasCustomSecondaryColor then
customSecondaryColor = { GetVehicleCustomSecondaryColour(vehicle) }
customSecondaryColor = {GetVehicleCustomSecondaryColour(vehicle)}
end
local extras = {}
for extraId = 0, 12 do
for extraId = 0, 20 do
if DoesExtraExist(vehicle, extraId) then
extras[tostring(extraId)] = IsVehicleExtraTurnedOn(vehicle, extraId)
end
@@ -628,11 +634,11 @@ function ESX.Game.GetVehicleProperties(vehicle)
local doorsBroken, windowsBroken, tyreBurst = {}, {}, {}
local numWheels = tostring(GetVehicleNumberOfWheels(vehicle))
local TyresIndex = { -- Wheel index list according to the number of vehicle wheels.
['2'] = { 0, 4 }, -- Bike and cycle.
['3'] = { 0, 1, 4, 5 }, -- Vehicle with 3 wheels (get for wheels because some 3 wheels vehicles have 2 wheels on front and one rear or the reverse).
['4'] = { 0, 1, 4, 5 }, -- Vehicle with 4 wheels.
['6'] = { 0, 1, 2, 3, 4, 5 } -- Vehicle with 6 wheels.
local TyresIndex = { -- Wheel index list according to the number of vehicle wheels.
['2'] = {0, 4}, -- Bike and cycle.
['3'] = {0, 1, 4, 5}, -- Vehicle with 3 wheels (get for wheels because some 3 wheels vehicles have 2 wheels on front and one rear or the reverse).
['4'] = {0, 1, 4, 5}, -- Vehicle with 4 wheels.
['6'] = {0, 1, 2, 3, 4, 5} -- Vehicle with 6 wheels.
}
if TyresIndex[numWheels] then
@@ -642,6 +648,7 @@ function ESX.Game.GetVehicleProperties(vehicle)
end
for windowId = 0, 7 do -- 13
RollUpWindow(vehicle, windowId) --fix when you put the car away with the window down
windowsBroken[tostring(windowId)] = not IsVehicleWindowIntact(vehicle, windowId)
end
@@ -657,6 +664,7 @@ function ESX.Game.GetVehicleProperties(vehicle)
doorsBroken = doorsBroken,
windowsBroken = windowsBroken,
tyreBurst = tyreBurst,
tyresCanBurst = GetVehicleTyresCanBurst(vehicle),
plate = ESX.Math.Trim(GetVehicleNumberPlateText(vehicle)),
plateIndex = GetVehicleNumberPlateTextIndex(vehicle),
@@ -682,8 +690,8 @@ function ESX.Game.GetVehicleProperties(vehicle)
xenonColor = GetVehicleXenonLightsColor(vehicle),
customXenonColor = customXenonColor,
neonEnabled = { IsVehicleNeonLightEnabled(vehicle, 0), IsVehicleNeonLightEnabled(vehicle, 1),
IsVehicleNeonLightEnabled(vehicle, 2), IsVehicleNeonLightEnabled(vehicle, 3) },
neonEnabled = {IsVehicleNeonLightEnabled(vehicle, 0), IsVehicleNeonLightEnabled(vehicle, 1),
IsVehicleNeonLightEnabled(vehicle, 2), IsVehicleNeonLightEnabled(vehicle, 3)},
neonColor = table.pack(GetVehicleNeonLightsColour(vehicle)),
extras = extras,
@@ -701,6 +709,7 @@ function ESX.Game.GetVehicleProperties(vehicle)
modFender = GetVehicleMod(vehicle, 8),
modRightFender = GetVehicleMod(vehicle, 9),
modRoof = GetVehicleMod(vehicle, 10),
modRoofLivery = GetVehicleRoofLivery(vehicle),
modEngine = GetVehicleMod(vehicle, 11),
modBrakes = GetVehicleMod(vehicle, 12),
@@ -714,7 +723,7 @@ function ESX.Game.GetVehicleProperties(vehicle)
modXenon = IsToggleModOn(vehicle, 22),
modFrontWheels = GetVehicleMod(vehicle, 23),
modCustomFrontWheels = GetVehicleModVariation(vehicle, 23),
modCustomFrontWheels = GetVehicleModVariation(vehicle, 23),
modBackWheels = GetVehicleMod(vehicle, 24),
modCustomBackWheels = GetVehicleModVariation(vehicle, 24),
@@ -739,7 +748,7 @@ function ESX.Game.GetVehicleProperties(vehicle)
modAerials = GetVehicleMod(vehicle, 43),
modTrimB = GetVehicleMod(vehicle, 44),
modTank = GetVehicleMod(vehicle, 45),
modDoorR = GetVehicleMod(vehicle, 47),
modWindows = GetVehicleMod(vehicle, 46),
modLivery = GetVehicleMod(vehicle, 48) == -1 and GetVehicleLivery(vehicle) or GetVehicleMod(vehicle, 48),
modLightbar = GetVehicleMod(vehicle, 49)
}
@@ -753,6 +762,10 @@ function ESX.Game.SetVehicleProperties(vehicle, props)
local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
SetVehicleModKit(vehicle, 0)
if props.tyresCanBurst ~= nil then
SetVehicleTyresCanBurst(vehicle, props.tyresCanBurst)
end
if props.plate ~= nil then
SetVehicleNumberPlateText(vehicle, props.plate)
end
@@ -823,7 +836,7 @@ function ESX.Game.SetVehicleProperties(vehicle, props)
end
end
if props.driftTyresEnabled then
if props.driftTyresEnabled then
SetDriftTyresEnabled(vehicle, true)
end
@@ -876,6 +889,11 @@ function ESX.Game.SetVehicleProperties(vehicle, props)
if props.modRoof ~= nil then
SetVehicleMod(vehicle, 10, props.modRoof, false)
end
if props.modRoofLivery ~= nil then
SetVehicleRoofLivery(vehicle, props.modRoofLivery)
end
if props.modEngine ~= nil then
SetVehicleMod(vehicle, 11, props.modEngine, false)
end
@@ -903,8 +921,8 @@ function ESX.Game.SetVehicleProperties(vehicle, props)
if props.modFrontWheels ~= nil then
SetVehicleMod(vehicle, 23, props.modFrontWheels, false)
end
if props.modCustomFrontWheels ~= nil then
SetVehicleMod(vehicle, 23, props.modCustomFrontWheels, false)
if props.modCustomFrontWheels ~= nil then
SetVehicleMod(vehicle, 23, props.modCustomFrontWheels, false)
end
if props.modBackWheels ~= nil then
SetVehicleMod(vehicle, 24, props.modBackWheels, false)
@@ -987,7 +1005,7 @@ function ESX.Game.SetVehicleProperties(vehicle, props)
if props.windowsBroken ~= nil then
for k, v in pairs(props.windowsBroken) do
if v then
SmashVehicleWindow(vehicle, tonumber(k))
RemoveVehicleWindow(vehicle, tonumber(k))
end
end
end
@@ -1056,7 +1074,7 @@ function ESX.ShowInventory()
local playerPed = ESX.PlayerData.ped
local elements = {
{ unselectable = true, icon = 'fas fa-box', title = 'Player Inventory' }
{unselectable = true, icon = 'fas fa-box', title = 'Player Inventory'}
}
local currentWeight = 0
@@ -1065,7 +1083,7 @@ function ESX.ShowInventory()
local formattedMoney = TranslateCap('locale_currency', ESX.Math.GroupDigits(ESX.PlayerData.accounts[i].money))
local canDrop = ESX.PlayerData.accounts[i].name ~= 'bank'
elements[#elements + 1] = {
elements[#elements+1] = {
icon = 'fas fa-money-bill-wave',
title = ('%s: <span style="color:green;">%s</span>'):format(ESX.PlayerData.accounts[i].label, formattedMoney),
count = ESX.PlayerData.accounts[i].money,
@@ -1082,7 +1100,7 @@ function ESX.ShowInventory()
if v.count > 0 then
currentWeight = currentWeight + (v.weight * v.count)
elements[#elements + 1] = {
elements[#elements+1] = {
icon = 'fas fa-box',
title = ('%s x%s'):format(v.label, v.count),
count = v.count,
@@ -1101,7 +1119,7 @@ function ESX.ShowInventory()
if HasPedGotWeapon(playerPed, weaponHash, false) then
local ammo = GetAmmoInPedWeapon(playerPed, weaponHash)
elements[#elements + 1] = {
elements[#elements+1] = {
icon = 'fas fa-gun',
title = v.ammo and ('%s - %s %s'):format(v.label, ammo, v.ammo.label) or v.label,
count = 1,
@@ -1116,10 +1134,10 @@ function ESX.ShowInventory()
end
end
elements[#elements + 1] = {
elements[#elements+1] = {
unselectable = true,
icon = "fas fa-weight",
title = "Current Weight: " .. currentWeight
title = "Current Weight: "..currentWeight
}
ESX.CloseContext()
@@ -1130,7 +1148,7 @@ function ESX.ShowInventory()
local elements2 = {}
if element.usable then
elements2[#elements2 + 1] = {
elements2[#elements2+1] = {
icon = "fas fa-utensils",
title = TranslateCap('use'),
action = 'use',
@@ -1141,7 +1159,7 @@ function ESX.ShowInventory()
if element.canRemove then
if player ~= -1 and distance <= 3.0 then
elements2[#elements2 + 1] = {
elements2[#elements2+1] = {
icon = "fas fa-hands",
title = TranslateCap('give'),
action = 'give',
@@ -1150,7 +1168,7 @@ function ESX.ShowInventory()
}
end
elements2[#elements2 + 1] = {
elements2[#elements2+1] = {
icon = "fas fa-trash",
title = TranslateCap('remove'),
action = 'remove',
@@ -1160,7 +1178,7 @@ function ESX.ShowInventory()
end
if element.type == 'item_weapon' and element.canGiveAmmo and element.ammo > 0 and player ~= -1 and distance <= 3.0 then
elements2[#elements2 + 1] = {
elements2[#elements2+1] = {
icon = "fas fa-gun",
title = TranslateCap('giveammo'),
action = 'give_ammo',
@@ -1169,7 +1187,7 @@ function ESX.ShowInventory()
}
end
elements2[#elements2 + 1] = {
elements2[#elements2+1] = {
icon = "fas fa-arrow-left",
title = TranslateCap('return'),
action = 'return'
@@ -1184,7 +1202,7 @@ function ESX.ShowInventory()
if #playersNearby > 0 then
local players = {}
local elements3 = {
{ unselectable = true, icon = "fas fa-users", title = "Nearby Players" }
{unselectable = true, icon = "fas fa-users", title = "Nearby Players"}
}
for _, playerNearby in ipairs(playersNearby) do
@@ -1193,7 +1211,7 @@ function ESX.ShowInventory()
ESX.TriggerServerCallback('esx:getPlayerNames', function(returnedPlayers)
for playerId, playerName in pairs(returnedPlayers) do
elements3[#elements3 + 1] = {
elements3[#elements3+1] = {
icon = "fas fa-user",
title = playerName,
playerId = playerId
@@ -1214,12 +1232,12 @@ function ESX.ShowInventory()
ESX.CloseContext()
else
local elementsG = {
{ unselectable = true, icon = "fas fa-trash", title = element.title },
{ icon = "fas fa-tally", title = "Amount.", input = true, inputType = "number", inputPlaceholder = "Amount to give..", inputMin = 1, inputMax = 1000 },
{ icon = "fas fa-check-double", title = "Confirm", val = "confirm" }
{unselectable = true, icon = "fas fa-trash", title = element.title},
{icon = "fas fa-tally", title = "Amount.", input = true, inputType = "number", inputPlaceholder = "Amount to give..", inputMin = 1, inputMax = 1000},
{icon = "fas fa-check-double", title = "Confirm", val = "confirm"}
}
ESX.OpenContext("right", elementsG, function(menuG)
ESX.OpenContext("right", elementsG, function(menuG, _)
local quantity = tonumber(menuG.eles[2].inputValue)
if quantity and quantity > 0 and element.count >= quantity then
@@ -1253,12 +1271,12 @@ function ESX.ShowInventory()
TriggerServerEvent('esx:removeInventoryItem', type, item)
else
local elementsR = {
{ unselectable = true, icon = "fas fa-trash", title = element.title },
{ icon = "fas fa-tally", title = "Amount.", input = true, inputType = "number", inputPlaceholder = "Amount to remove..", inputMin = 1, inputMax = 1000 },
{ icon = "fas fa-check-double", title = "Confirm", val = "confirm" }
{unselectable = true, icon = "fas fa-trash", title = element.title},
{icon = "fas fa-tally", title = "Amount.", input = true, inputType = "number", inputPlaceholder = "Amount to remove..", inputMin = 1, inputMax = 1000},
{icon = "fas fa-check-double", title = "Confirm", val = "confirm"}
}
ESX.OpenContext("right", elementsR, function(menuR)
ESX.OpenContext("right", elementsR, function(menuR, _)
local quantity = tonumber(menuR.eles[2].inputValue)
if quantity and quantity > 0 and element.count >= quantity then
@@ -1288,12 +1306,12 @@ function ESX.ShowInventory()
if closestPlayer ~= -1 and closestDistance < 3.0 then
if pedAmmo > 0 then
local elementsGA = {
{ unselectable = true, icon = "fas fa-trash", title = element.title },
{ icon = "fas fa-tally", title = "Amount.", input = true, inputType = "number", inputPlaceholder = "Amount to give..", inputMin = 1, inputMax = 1000 },
{ icon = "fas fa-check-double", title = "Confirm", val = "confirm" }
{unselectable = true, icon = "fas fa-trash", title = element.title},
{icon = "fas fa-tally", title = "Amount.", input = true, inputType = "number", inputPlaceholder = "Amount to give..", inputMin = 1, inputMax = 1000},
{icon = "fas fa-check-double", title = "Confirm", val = "confirm"}
}
ESX.OpenContext("right", elementsGA, function(menuGA)
ESX.OpenContext("right", elementsGA, function(menuGA, _)
local quantity = tonumber(menuGA.eles[2].inputValue)
if quantity and quantity > 0 then
@@ -1342,20 +1360,20 @@ end)
function ESX.GetVehicleType(model)
model = type(model) == 'string' and joaat(model) or model
if model == `submersible` or model == `submersible2` then
if model == `submersible` or model == `submersible2` then
return 'submarine'
end
end
local vehicleType = GetVehicleClassFromName(model)
local types = {
[8] = "bike",
[11] = "trailer",
[13] = "bike",
[14] = "boat",
[15] = "heli",
[16] = "plane",
[21] = "train",
}
local vehicleType = GetVehicleClassFromName(model)
local types = {
[8] = "bike",
[11] = "trailer",
[13] = "bike",
[14] = "boat",
[15] = "heli",
[16] = "plane",
[21] = "train",
}
return types[vehicleType] or "automobile"
end
-4
View File
@@ -293,8 +293,6 @@ if not Config.OxInventory then
if showNotification then
ESX.UI.ShowInventoryItemNotification(true, item, count)
end
ESX.ShowInventory()
end)
RegisterNetEvent('esx:removeInventoryItem')
@@ -310,8 +308,6 @@ if not Config.OxInventory then
if showNotification then
ESX.UI.ShowInventoryItemNotification(false, item, count)
end
ESX.ShowInventory()
end)
RegisterNetEvent('esx:addWeapon')