Jump to content

Typo in VehicleCommands.lua always causes vehicle part damage on uninstallation failures


Aronai

Recommended Posts

Bug present in: 41.78.16

 

In media/lua/server/Vehicles/Vehicles.lua we can see the generation of the success/failure chances for vehicle part installation/removal, on line 1350 with calculateInstallationSuccess()

 

It generates and returns a tuple with the success and failure chance, using some math. The math results in, for example, success=65, failure=35 for being 1 level under the part's 'desired' skill level.

 

This tuple is consumed for vehicle part uninstallation in the function starting on line 96 in media/lua/server/Vehicles/VehicleCommands.lua, in the uninstallPart() function.

The problem is that on line 127, you do...

-- from uninstallPart(), failure chance structured incorrectly
if ZombRand(100) < success then
 [...]
elseif ZombRand(failure) < 100 then -- <- Mistake, note the transposed 'failure' and '100'. Compare to above and below examples.
 [...]

But this makes no sense. Compare it to the installPart() function above this one, which is almost identical but structured correctly...

-- from installPart(), written correctly
if ZombRand(100) < success then
 [...]
elseif ZombRand(100) < failure then
 [...]

 

The issue: You are generating a random number between 0 and 35 (to use our '1 level too low, 35% failure chance' example), and then checking if it's < 100. Well, of course it will be. Compare this to what it SHOULD be in the second code block above from installPart(), which actually gives a 35% chance. Technically it's actually still possible to 'not succeed and not damage the part' with this code by having a >= 6 level difference, because that will produce a 110% chance of failure, and thus have a 10% chance of actually 'missing' that code block.

 

I'm sure someone just inverted the order of things there and meant to put the 100 as the argument to ZombRand and compare the result to failure instead of the other way around in uninstallPart() and nobody caught it.

Edited by Aronai
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...