Skip to content

Instantly share code, notes, and snippets.

@tabarra
Created April 19, 2023 06:52
Show Gist options
  • Save tabarra/32ef90524188093ab4218ee7b5121269 to your computer and use it in GitHub Desktop.
Save tabarra/32ef90524188093ab4218ee7b5121269 to your computer and use it in GitHub Desktop.
Listing FiveM/GTA5 vehicle model classes/types that diverge.

If you need to spawn a vehicle on the server side, you can use CreateVehicleServerSetter(), but the issue is that you need the vehicle type, but on the server there is no native to get it from a vehicle model.
In txAdmin this was initially "solved" by getting the vehicle class on the client and sending that to the server use it as a type when creating the vehicle. The logic used on the client is to check for the class on the vehClassNamesEnum table and assuming automobile for classes not on that table.

Later it was noticed that the server needs "type" instead of "class", and there is also no GetVehicleTypeFromName() on the client.
To solve this issue, it was created a lookup table to fix mismatched types.

This gist shows how to generate that table.
This must be run every now and then since new vehicles are added to the game on new DLC releases.

-- Save the output as "allModels.json"
local classesEnumOld = {
[8] = "bike",
[11] = "trailer",
[13] = "bike",
[14] = "boat",
[15] = "heli",
[16] = "plane",
[21] = "train",
}
local allModels = GetAllVehicleModels()
local allModelClasses = {}
for index, model in pairs(allModels) do
local modelClassNumber = GetVehicleClassFromName(model)
local modelClass = classesEnumOld[modelClassNumber] or "automobile"
allModelClasses[model] = modelClass
end
return json.encode(allModelClasses)
-- As per game build 2802/mpchristmas3 - April 2023
-- The output has been sorted and formatted
local divergent = {
["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
}
RegisterCommand('run_comparator', function()
print("==== Started")
local divergentTable = 'local divergent = {\n'
local allModelClasses = json.decode(LoadResourceFile(GetCurrentResourceName(), "allModels.json"))
for vehModel, vehClass in pairs(allModelClasses) do
-- spawn vehicle
local veh = CreateVehicle(GetHashKey(vehModel), 0.0, 0.0, 0.0, 0.0, true, false)
while not DoesEntityExist(veh) do
Wait(5)
end
local vehType = GetVehicleType(veh)
DeleteEntity(veh)
--check type vs class
if vehType ~= vehClass then
print(vehModel, vehClass, vehType)
divergentTable = divergentTable .. string.format(
' ["%s"] = "%s", -- %s\n',
vehModel, vehType, vehClass
)
end
end
divergentTable = divergentTable .. '}\n'
SaveResourceFile(GetCurrentResourceName(), 'output.lua', divergentTable)
print("==== Finished")
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment