mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 15:01:32 +00:00
refactor(es_extended): ESX.GetVehicleType and add client side
This commit is contained in:
@@ -1308,4 +1308,27 @@ AddEventHandler('esx:showAdvancedNotification',
|
||||
RegisterNetEvent('esx:showHelpNotification')
|
||||
AddEventHandler('esx:showHelpNotification', function(msg, thisFrame, beep, duration)
|
||||
ESX.ShowHelpNotification(msg, thisFrame, beep, duration)
|
||||
end)
|
||||
end)
|
||||
|
||||
---@param model number|string
|
||||
---@return string
|
||||
function ESX.GetVehicleType(model)
|
||||
model = type(model) == 'string' and joaat(model) or model
|
||||
|
||||
if model == `submersible` or model == `submersible2` then
|
||||
return 'submarine'
|
||||
end
|
||||
|
||||
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
|
||||
@@ -615,27 +615,8 @@ AddEventHandler("esx:freezePlayer", function(input)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:GetVehicleType", function(Model, Request)
|
||||
if not IsModelInCdimage(Model) then
|
||||
return TriggerServerEvent("esx:ReturnVehicleType", false, Request)
|
||||
end
|
||||
|
||||
if Model == `submersible` or Model == `submersible2` then
|
||||
return TriggerServerEvent("esx:ReturnVehicleType", "submarine", Request)
|
||||
end
|
||||
|
||||
local VehicleType = GetVehicleClassFromName(Model)
|
||||
local types = {
|
||||
[8] = "bike",
|
||||
[11] = "trailer",
|
||||
[13] = "bike",
|
||||
[14] = "boat",
|
||||
[15] = "heli",
|
||||
[16] = "plane",
|
||||
[21] = "train",
|
||||
}
|
||||
|
||||
TriggerServerEvent("esx:ReturnVehicleType", types[VehicleType] or "automobile", Request)
|
||||
ESX.RegisterClientCallback("esx:GetVehicleType", function(cb, model)
|
||||
cb(ESX.GetVehicleType(model))
|
||||
end)
|
||||
|
||||
local DoNotUse = {
|
||||
|
||||
@@ -11,6 +11,8 @@ Core.PlayerFunctionOverrides = {}
|
||||
|
||||
Core.playersByIdentifier = {}
|
||||
|
||||
Core.vehicleTypesByModel = {}
|
||||
|
||||
AddEventHandler("esx:getSharedObject", function()
|
||||
local Invoke = GetInvokingResource()
|
||||
print(("[^1ERROR^7] Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/sharedevent for how to fix!"):format(Invoke))
|
||||
|
||||
@@ -246,10 +246,21 @@ function ESX.GetIdentifier(playerId)
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.GetVehicleType(Vehicle, Player, cb)
|
||||
Core.CurrentRequestId = Core.CurrentRequestId < 65535 and Core.CurrentRequestId + 1 or 0
|
||||
Core.ClientCallbacks[Core.CurrentRequestId] = cb
|
||||
TriggerClientEvent("esx:GetVehicleType", Player, Vehicle, Core.CurrentRequestId)
|
||||
---@param model string|number
|
||||
---@param player number playerId
|
||||
---@param cb function
|
||||
|
||||
function ESX.GetVehicleType(model, player, cb)
|
||||
model = type(model) == 'string' and joaat(model) or model
|
||||
|
||||
if Core.vehicleTypesByModel[model] then
|
||||
return cb(Core.vehicleTypesByModel[model])
|
||||
end
|
||||
|
||||
ESX.TriggerClientCallback(player, "esx:GetVehicleType", function(vehicleType)
|
||||
Core.vehicleTypesByModel[model] = vehicleType
|
||||
cb(vehicleType)
|
||||
end)
|
||||
end
|
||||
|
||||
function ESX.DiscordLog(name, title, color, message)
|
||||
|
||||
Reference in New Issue
Block a user