Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - Replace canAdd with CBA_fnc_canAddItem #1561

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Dystopian
Copy link
Contributor

When merged this pull request will:

  • replace canAdd with CBA_fnc_canAddItem;
  • add backpack support to CBA_fnc_canAddItem;
  • fix float rounding error leading to wrong CBA_fnc_canAddItem result.

Mostly because ACE towing rope can disappear in the ground because of full load.

Adding backpack support is required for addBackpackCargo function.

In some cases current function implementation can't count correctly. This code puts 28 designators to quadbike and 2 designators to player inventory (or near player):

private _v = createVehicle ["B_Quadbike_01_F", player];
clearItemCargoGlobal _v;
[_v, "LaserDesignator", 28, true] call CBA_fnc_addItemCargo;
[player, "LaserDesignator", true] call CBA_fnc_addItem;
[player, "LaserDesignator", true] call CBA_fnc_addItem;
[_v, "LaserDesignator", 2] call CBA_fnc_canAddItem

The result is false but you can put exactly 2 designators to quadbike inventory.
Here is why (cursorObject is quadbike with 28 designators):

maxLoad cursorObject = 600
designator mass = 20
load cursorObject = 0.9(3) (==20*28/600)
maxLoad cursorObject * (1 - load cursorObject) / 20 = 600 * 0.0(6) / 20 = 39.(9) / 20 = 1.(9)
floor 1.(9) = 1
1 < 2

To work around this problem I added 0.0001 to number before floor. I think it's small enough not to make troubles.

Also floor parseNumber (maxLoad cursorObject * (1 - load cursorObject) / 20 toFixed 5) can be used as workaround. It's slower but maybe looks better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant