Merge pull request #691 from fivemland/refactor-1

Refactor: some es_extended functions
This commit is contained in:
Gellipapa
2022-11-27 20:50:01 +01:00
committed by GitHub
2 changed files with 389 additions and 410 deletions
+31 -48
View File
@@ -80,34 +80,36 @@ function ESX.SetPlayerData(key, val)
end end
function ESX.Progressbar(message, length, Options) function ESX.Progressbar(message, length, Options)
exports["esx_progressbar"]:Progressbar(message, length, Options) if GetResourceState("esx_progressbar") ~= "missing" then
return exports["esx_progressbar"]:Progressbar(message, length, Options)
end
print("[^1ERROR^7] ^5ESX Progressbar^7 is Missing!")
end end
function ESX.ShowNotification(message, type, length) function ESX.ShowNotification(message, type, length)
if GetResourceState("esx_notify") ~= "missing" then if GetResourceState("esx_notify") ~= "missing" then
exports["esx_notify"]:Notify(type, length, message) return exports["esx_notify"]:Notify(type, length, message)
else
print("[^1ERROR^7] ^5ESX Notify^7 is Missing!")
end end
print("[^1ERROR^7] ^5ESX Notify^7 is Missing!")
end end
function ESX.TextUI(message, type) function ESX.TextUI(message, type)
if GetResourceState("esx_textui") ~= "missing" then if GetResourceState("esx_textui") ~= "missing" then
exports["esx_textui"]:TextUI(message, type) return exports["esx_textui"]:TextUI(message, type)
else
print("[^1ERROR^7] ^5ESX TextUI^7 is Missing!")
return
end end
print("[^1ERROR^7] ^5ESX TextUI^7 is Missing!")
end end
function ESX.HideUI() function ESX.HideUI()
if GetResourceState("esx_textui") ~= "missing" then if GetResourceState("esx_textui") ~= "missing" then
exports["esx_textui"]:HideUI() return exports["esx_textui"]:HideUI()
else
print("[^1ERROR^7] ^5ESX TextUI^7 is Missing!")
return
end end
print("[^1ERROR^7] ^5ESX TextUI^7 is Missing!")
end end
function ESX.ShowAdvancedNotification(sender, subject, msg, textureDict, iconType, flash, saveToBrief, hudColorIndex) function ESX.ShowAdvancedNotification(sender, subject, msg, textureDict, iconType, flash, saveToBrief, hudColorIndex)
@@ -151,7 +153,7 @@ ESX.HashString = function(str)
local gsub = string.gsub local gsub = string.gsub
local hash = joaat(str) local hash = joaat(str)
local input_map = format("~INPUT_%s~", upper(format("%x", hash))) local input_map = format("~INPUT_%s~", upper(format("%x", hash)))
input_map = string.gsub(input_map, "FFFFFFFF", "") input_map = gsub(input_map, "FFFFFFFF", "")
return input_map return input_map
end end
@@ -426,8 +428,7 @@ function ESX.Game.GetPedMugshot(ped, transparent)
end end
function ESX.Game.Teleport(entity, coords, cb) function ESX.Game.Teleport(entity, coords, cb)
local vector = type(coords) == "vector4" and coords or type(coords) == "vector3" and vector4(coords, 0.0) or local vector = type(coords) == "vector4" and coords or type(coords) == "vector3" and vector4(coords, 0.0) or vec(coords.x, coords.y, coords.z, coords.heading or 0.0)
vec(coords.x, coords.y, coords.z, coords.heading or 0.0)
if DoesEntityExist(entity) then if DoesEntityExist(entity) then
RequestCollisionAtCoord(vector.xyz) RequestCollisionAtCoord(vector.xyz)
@@ -666,14 +667,16 @@ function ESX.Game.GetVehicleInDirection()
end end
function ESX.Game.GetVehicleProperties(vehicle) function ESX.Game.GetVehicleProperties(vehicle)
if DoesEntityExist(vehicle) then if not DoesEntityExist(vehicle) then
return
end
local colorPrimary, colorSecondary = GetVehicleColours(vehicle) local colorPrimary, colorSecondary = GetVehicleColours(vehicle)
local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle) local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
local hasCustomPrimaryColor = GetIsVehiclePrimaryColourCustom(vehicle) local hasCustomPrimaryColor = GetIsVehiclePrimaryColourCustom(vehicle)
local customPrimaryColor = nil local customPrimaryColor = nil
if hasCustomPrimaryColor then if hasCustomPrimaryColor then
local r, g, b = GetVehicleCustomPrimaryColour(vehicle) customPrimaryColor = {GetVehicleCustomPrimaryColour(vehicle)}
customPrimaryColor = {r, g, b}
end end
local hasCustomXenonColor, customXenonColorR, customXenonColorG, customXenonColorB = GetVehicleXenonLightsCustomColor(vehicle) local hasCustomXenonColor, customXenonColorR, customXenonColorG, customXenonColorB = GetVehicleXenonLightsCustomColor(vehicle)
@@ -685,15 +688,13 @@ function ESX.Game.GetVehicleProperties(vehicle)
local hasCustomSecondaryColor = GetIsVehicleSecondaryColourCustom(vehicle) local hasCustomSecondaryColor = GetIsVehicleSecondaryColourCustom(vehicle)
local customSecondaryColor = nil local customSecondaryColor = nil
if hasCustomSecondaryColor then if hasCustomSecondaryColor then
local r, g, b = GetVehicleCustomSecondaryColour(vehicle) customSecondaryColor = {GetVehicleCustomSecondaryColour(vehicle)}
customSecondaryColor = {r, g, b}
end end
local extras = {}
local extras = {}
for extraId = 0, 12 do for extraId = 0, 12 do
if DoesExtraExist(vehicle, extraId) then if DoesExtraExist(vehicle, extraId) then
local state = IsVehicleExtraTurnedOn(vehicle, extraId) extras[tostring(extraId)] = IsVehicleExtraTurnedOn(vehicle, extraId)
extras[tostring(extraId)] = state
end end
end end
@@ -709,30 +710,18 @@ function ESX.Game.GetVehicleProperties(vehicle)
if TyresIndex[numWheels] then if TyresIndex[numWheels] then
for tyre, idx in pairs(TyresIndex[numWheels]) do for tyre, idx in pairs(TyresIndex[numWheels]) do
if IsVehicleTyreBurst(vehicle, idx, false) then tyreBurst[tostring(idx)] = IsVehicleTyreBurst(vehicle, idx, false)
tyreBurst[tostring(idx)] = true
else
tyreBurst[tostring(idx)] = false
end
end end
end end
for windowId = 0, 7 do -- 13 for windowId = 0, 7 do -- 13
if not IsVehicleWindowIntact(vehicle, windowId) then windowsBroken[tostring(windowId)] = not IsVehicleWindowIntact(vehicle, windowId)
windowsBroken[tostring(windowId)] = true
else
windowsBroken[tostring(windowId)] = false
end
end end
local numDoors = GetNumberOfVehicleDoors(vehicle) local numDoors = GetNumberOfVehicleDoors(vehicle)
if numDoors and numDoors > 0 then if numDoors and numDoors > 0 then
for doorsId = 0, numDoors do for doorsId = 0, numDoors do
if IsVehicleDoorDamaged(vehicle, doorsId) then doorsBroken[tostring(doorsId)] = IsVehicleDoorDamaged(vehicle, doorsId)
doorsBroken[tostring(doorsId)] = true
else
doorsBroken[tostring(doorsId)] = false
end
end end
end end
@@ -821,13 +810,12 @@ function ESX.Game.GetVehicleProperties(vehicle)
modLivery = GetVehicleMod(vehicle, 48) == -1 and GetVehicleLivery(vehicle) or GetVehicleMod(vehicle, 48), modLivery = GetVehicleMod(vehicle, 48) == -1 and GetVehicleLivery(vehicle) or GetVehicleMod(vehicle, 48),
modLightbar = GetVehicleMod(vehicle, 49) modLightbar = GetVehicleMod(vehicle, 49)
} }
else
return
end
end end
function ESX.Game.SetVehicleProperties(vehicle, props) function ESX.Game.SetVehicleProperties(vehicle, props)
if DoesEntityExist(vehicle) then if not DoesEntityExist(vehicle) then
return
end
local colorPrimary, colorSecondary = GetVehicleColours(vehicle) local colorPrimary, colorSecondary = GetVehicleColours(vehicle)
local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle) local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
SetVehicleModKit(vehicle, 0) SetVehicleModKit(vehicle, 0)
@@ -889,11 +877,7 @@ function ESX.Game.SetVehicleProperties(vehicle, props)
if props.extras ~= nil then if props.extras ~= nil then
for extraId, enabled in pairs(props.extras) do for extraId, enabled in pairs(props.extras) do
if enabled then SetVehicleExtra(vehicle, tonumber(extraId), enabled and 0 or 0)
SetVehicleExtra(vehicle, tonumber(extraId), 0)
else
SetVehicleExtra(vehicle, tonumber(extraId), 1)
end
end end
end end
@@ -1072,7 +1056,6 @@ function ESX.Game.SetVehicleProperties(vehicle, props)
end end
end end
end end
end
function ESX.Game.Utils.DrawText3D(coords, text, size, font) function ESX.Game.Utils.DrawText3D(coords, text, size, font)
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z) local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
+1 -5
View File
@@ -7,11 +7,7 @@ for i = 97, 122 do table.insert(Charset, string.char(i)) end
function ESX.GetRandomString(length) function ESX.GetRandomString(length)
math.randomseed(GetGameTimer()) math.randomseed(GetGameTimer())
if length > 0 then return length > 0 and ESX.GetRandomString(length - 1) .. Charset[math.random(1, #Charset)] or ''
return ESX.GetRandomString(length - 1) .. Charset[math.random(1, #Charset)]
else
return ''
end
end end
function ESX.GetConfig() function ESX.GetConfig()