Skip to content

Commit

Permalink
Event to update mismatched vehicle types list
Browse files Browse the repository at this point in the history
- Adds event to update the mismatched vehicle types list.
- Moves mismatched types to server.

Example usage:

```lua
TriggerEvent('txAdmin:menu:addMismatchedTypes', {
    caddy3 = 'automobile',
    trailersmall2 = 'trailer',
    scrap = 'automobile',
    tractor3 = 'automobile'
})
```
  • Loading branch information
Scullyy committed Jan 17, 2025
1 parent 8cbc767 commit 9c598d1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 63 deletions.
62 changes: 2 additions & 60 deletions resource/menu/client/cl_vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,74 +22,16 @@ local function getPedVehicle()
end
end

-- NOTE: this is not a complete list, but most others have the type "automobile"
local vehClassNamesEnum = {
[8] = "bike",
[11] = "trailer",
[13] = "bike",
[14] = "boat",
[15] = "heli",
[16] = "plane",
[21] = "train",
}

-- Since we don't have the vehicle types on the server, we need this translation table
-- NOTE: this list was generated for game build 2802/mpchristmas3
-- How to update the list: https://gist.github.com/tabarra/32ef90524188093ab4218ee7b5121269
local mismatchedTypes = {
["airtug"] = "automobile", -- trailer
["avisa"] = "submarine", -- boat
["blimp"] = "heli", -- plane
["blimp2"] = "heli", -- plane
["blimp3"] = "heli", -- plane
["caddy"] = "automobile", -- trailer
["caddy2"] = "automobile", -- trailer
["caddy3"] = "automobile", -- trailer
["chimera"] = "automobile", -- bike
["docktug"] = "automobile", -- trailer
["forklift"] = "automobile", -- trailer
["kosatka"] = "submarine", -- boat
["mower"] = "automobile", -- trailer
["policeb"] = "bike", -- automobile
["ripley"] = "automobile", -- trailer
["rrocket"] = "automobile", -- bike
["sadler"] = "automobile", -- trailer
["sadler2"] = "automobile", -- trailer
["scrap"] = "automobile", -- trailer
["slamtruck"] = "automobile", -- trailer
["Stryder"] = "automobile", -- bike
["submersible"] = "submarine", -- boat
["submersible2"] = "submarine", -- boat
["thruster"] = "heli", -- automobile
["towtruck"] = "automobile", -- trailer
["towtruck2"] = "automobile", -- trailer
["tractor"] = "automobile", -- trailer
["tractor2"] = "automobile", -- trailer
["tractor3"] = "automobile", -- trailer
["trailersmall2"] = "trailer", -- automobile
["utillitruck"] = "automobile", -- trailer
["utillitruck2"] = "automobile", -- trailer
["utillitruck3"] = "automobile", -- trailer
}

local function handleSpawnRequestFivem(model)
if not IsModelAVehicle(model) then
debugPrint("^1Model provided is not a vehicle: " .. model)
return false
end

--Resolve vehicle type, required for server setter
--NOTE: check if GetVehicleTypeFromName is already available
local modelType
if mismatchedTypes[model] then
modelType = mismatchedTypes[model]
else
local modelClassNumber = GetVehicleClassFromName(model)
modelType = vehClassNamesEnum[modelClassNumber] or "automobile"
end
local modelClassNumber = GetVehicleClassFromName(model)

--Request from server
TriggerServerEvent('txsv:req:vehicle:spawn:fivem', model, modelType)
TriggerServerEvent('txsv:req:vehicle:spawn:fivem', model, modelClassNumber)
return true
end

Expand Down
72 changes: 69 additions & 3 deletions resource/menu/server/sv_vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,64 @@ if not TX_MENU_ENABLED then return end
-- actions defined on Menu's "Main Page"
-- =============================================

-- NOTE: this is not a complete list, but most others have the type "automobile"
local vehClassNamesEnum = {
[8] = "bike",
[11] = "trailer",
[13] = "bike",
[14] = "boat",
[15] = "heli",
[16] = "plane",
[21] = "train",
}

-- Since we don't have the vehicle types on the server, we need this translation table
-- NOTE: this list was generated for game build 2802/mpchristmas3
-- How to update the list: https://gist.github.com/tabarra/32ef90524188093ab4218ee7b5121269
local mismatchedTypes = {
["airtug"] = "automobile", -- trailer
["avisa"] = "submarine", -- boat
["blimp"] = "heli", -- plane
["blimp2"] = "heli", -- plane
["blimp3"] = "heli", -- plane
["caddy"] = "automobile", -- trailer
["caddy2"] = "automobile", -- trailer
["caddy3"] = "automobile", -- trailer
["chimera"] = "automobile", -- bike
["docktug"] = "automobile", -- trailer
["forklift"] = "automobile", -- trailer
["kosatka"] = "submarine", -- boat
["mower"] = "automobile", -- trailer
["policeb"] = "bike", -- automobile
["ripley"] = "automobile", -- trailer
["rrocket"] = "automobile", -- bike
["sadler"] = "automobile", -- trailer
["sadler2"] = "automobile", -- trailer
["scrap"] = "automobile", -- trailer
["slamtruck"] = "automobile", -- trailer
["Stryder"] = "automobile", -- bike
["submersible"] = "submarine", -- boat
["submersible2"] = "submarine", -- boat
["thruster"] = "heli", -- automobile
["towtruck"] = "automobile", -- trailer
["towtruck2"] = "automobile", -- trailer
["tractor"] = "automobile", -- trailer
["tractor2"] = "automobile", -- trailer
["tractor3"] = "automobile", -- trailer
["trailersmall2"] = "trailer", -- automobile
["utillitruck"] = "automobile", -- trailer
["utillitruck2"] = "automobile", -- trailer
["utillitruck3"] = "automobile", -- trailer
}

---Update mismatched vehicle types list
---@param list table
AddEventHandler('txAdmin:menu:addMismatchedTypes', function(list)
for model, modelType in pairs(list) do
mismatchedTypes[model] = modelType
end
end)

RegisterNetEvent('txsv:req:vehicle:fix', function()
local src = source
local allow = PlayerHasTxPermission(src, 'menu.vehicle')
Expand Down Expand Up @@ -41,18 +99,26 @@ end)

--- Spawn a vehicle on the server at the request of a client (fivem)
---@param model string
---@param modelType string
RegisterNetEvent('txsv:req:vehicle:spawn:fivem', function(model, modelType)
---@param modelClassNumber number
RegisterNetEvent('txsv:req:vehicle:spawn:fivem', function(model, modelClassNumber)
if not IS_FIVEM then return end
local src = source
if type(model) ~= 'string' then return end
if type(modelType) ~= 'string' then return end

--check permission
local allow = PlayerHasTxPermission(src, 'menu.vehicle')
TriggerEvent('txsv:logger:menuEvent', src, 'spawnVehicle', allow, model)
if not allow then return end

--Resolve vehicle type, required for server setter
--NOTE: check if GetVehicleTypeFromName is already available
local modelType
if mismatchedTypes[model] then
modelType = mismatchedTypes[model]
else
modelType = vehClassNamesEnum[modelClassNumber] or "automobile"
end

--resolve source ped
local ped = GetPlayerPed(src)
local coords = GetEntityCoords(ped)
Expand Down

0 comments on commit 9c598d1

Please sign in to comment.