qb-core icon indicating copy to clipboard operation
qb-core copied to clipboard

[FIX] Neon Colours not working correctly

Open MatthewRorke opened this issue 2 years ago • 2 comments

Currently, the Neon colours are referring to indexes that assume that the vehicle mod propertyneonEnabled is an array. Instead, due to the way the the JSON properties are encoding their children, we are reading and writing objects. Where we currently attempt to set the vehicle's neon enabled status by using the following excerpt of code found in client/functions.lua:688

SetVehicleNeonLightEnabled(vehicle, 0, props.neonEnabled[1])
SetVehicleNeonLightEnabled(vehicle, 1, props.neonEnabled[2])
SetVehicleNeonLightEnabled(vehicle, 2, props.neonEnabled[3])
SetVehicleNeonLightEnabled(vehicle, 3, props.neonEnabled[4])

We should be refering to the STRING index with a 0 base (0 to 3) like so:

SetVehicleNeonLightEnabled(vehicle, 0, props.neonEnabled["0"])
SetVehicleNeonLightEnabled(vehicle, 1, props.neonEnabled["1"])
SetVehicleNeonLightEnabled(vehicle, 2, props.neonEnabled["2"])
SetVehicleNeonLightEnabled(vehicle, 3, props.neonEnabled["3"])

However, this is still not safe as this assumes a complete object containing all 4 indexes. The method in the previous versions of QB Core function function QBCore.Functions.SetVehicleProperties was far safer. The previous version used a for loop to iterate over the object pairs and then only make changes to what was available. This allows us to allow users to be a bit more careless and avoid potential problems in the future where we only have portions of the neonEnabled object available.

In short, this PR involved me reverting to a previous version of QB Core where an iteration was taking place, and converting the index to a number.

Questions (please complete the following information):

  • Have you personally loaded this code into an updated qbcore project and checked all it's functionality? Yes
  • Does your code fit the style guidelines? Yes
  • Does your PR fit the contribution guidelines? Yes

MatthewRorke avatar Apr 14 '22 09:04 MatthewRorke

@MatthewRorke Please Update branch

amantu-qbit avatar Jul 29 '22 11:07 amantu-qbit

We should be refering to the STRING index with a 0 base (0 to 3) like so:

That is not true actually, the neonEnabled variable is created as an array, meaing the indexes are numbers generated by lua, the only thing that is hardcoded are the value, but those are booleans, reference https://github.com/qbcore-framework/qb-core/blob/main/client/functions.lua#L520

BerkieBb avatar Aug 15 '22 06:08 BerkieBb

This PR has had 60 days of inactivity & will close within 7 days

github-actions[bot] avatar Sep 25 '23 15:09 github-actions[bot]