Just a few more tweaks to improve things (other than the incorrect indenting ); you are using GetHashKey for the new vehicle whitelist which is inherently slower than Jenkins hashing. That is when you use backticks for a string and FiveM will treat it as the hash of the string. It’s converted at runtime as well, whereas the way you had it, it gets the hash for every vehicle, every time the command is called.
Example of Jenkins hashing;
local WLVeh = {
`adder`,
}
Note the backticks instead of single/double quotes. This is like GetHashKey(“adder”) but faster.
Also, once the vehicle has been found, you should break from the loop or return the function, so you don’t loop, find the vehicle and set the drive chain, then keep looping for no reason until the end of the table.
And finally, you are getting the vehicle model and looping through the WLVeh table, comparing the vehicle model to the WLVeh table, then checking if they are even in a vehicle and are the driver. Do that check first or you could be fetching the model and then looping a table for a non-existent vehicle.
So what you probably want is this;
local WLVeh = {
`adder`,
}
function SetDriveChain(driveType)
local ped = PlayerPedId()
local veh = GetVehiclePedIsIn(ped, false)
if veh ~= 0 and GetPedInVehicleSeat(veh, -1) == ped then
local model = GetEntityModel(veh)
for i = 1, #WLVeh do
if WLVeh[i] == model then
SetVehicleHandlingField(veh, 'CHandlingData', 'fDriveBiasFront', DriveBias[driveType])
SetVehicleWheelIsPowered(veh, 0, driveType ~= "RWD")
SetVehicleWheelIsPowered(veh, 1, driveType ~= "RWD")
SetVehicleWheelIsPowered(veh, 3, driveType ~= "FWD")
SetVehicleWheelIsPowered(veh, 4, driveType ~= "FWD")
return
end
end
end
end
HOWEVER, I am a bit of a perfectionist at times and this can be improved AGAIN. Instead of looping a table at all, you could just use key values for WLVeh, like this;
local WLVeh = {
[`adder`] = true,
}
function SetDriveChain(driveType)
local ped = PlayerPedId()
local veh = GetVehiclePedIsIn(ped, false)
if veh ~= 0 and GetPedInVehicleSeat(veh, -1) == ped and WLVeh[GetEntityModel(veh)] then
SetVehicleHandlingField(veh, 'CHandlingData', 'fDriveBiasFront', DriveBias[driveType])
SetVehicleWheelIsPowered(veh, 0, driveType ~= "RWD")
SetVehicleWheelIsPowered(veh, 1, driveType ~= "RWD")
SetVehicleWheelIsPowered(veh, 3, driveType ~= "FWD")
SetVehicleWheelIsPowered(veh, 4, driveType ~= "FWD")
end
end
That should be the fastest possible solution. Again, feel free to push this to GitHub.
EDIT: Don’t forget the other stuff I didn’t include. The loop that registers commands, the commands table and the drive bias table. This code block is only for what was changed. The rest was good. Also, the README.md and the fxmanifest.lua both need updating as they mention the config.lua file that no longer exists.