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

Weight discrepancy during crafting #1848

Closed
Pilouxs opened this issue Dec 6, 2024 · 1 comment
Closed

Weight discrepancy during crafting #1848

Pilouxs opened this issue Dec 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Pilouxs
Copy link

Pilouxs commented Dec 6, 2024

Describe the bug

There is a weight discrepancy when crafting items using ingredients with durability. After crafting, the server-side weight calculation does not match the client-side weight. This difference increases further if an ingredient’s durability reaches zero and the item is removed.

As a result, the player may receive a notification saying they don't have enough space in their inventory, even though they technically do.

Framework
qbox

Resource version
2.43.3

To Reproduce
Steps to reproduce the behavior:

  1. Add item and ingredients to your crafting configuration :

For my test :
{ label = 'Pâtes', items = { { name = 'pate_tomate', ingredients = { pate_crue = 0.25, sauce_tomate = 0.2 }, duration = 5000, count = 1, }, zones = { { label = 'Faire un plat de pâtes', icon = 'fas fa-fire-burner', coords = vec3(381.65, 804.45, 187.73), size = vec3(1.0, 1.55, 1.0), groups = {['pizzeria'] = 0}, distance = 2.0, rotation = 270.0, }, }, }

  1. Ensure your inventory contains :

10 * pate_crue (100g each, total 1kg).
10 * sauce_tomate (25g each, total 250g).

  1. Craft the item pate_tomate (400g).
  2. Observe the total weights:
    After the first craft, the weight is correct: 1250g (initial) + 400g = 1650g.
    After the second craft, the client-side weight shows 2050g (correct), but the server-side weight shows 2175g.

Expected behavior
The server-side weight calculation should match the client-side weight. Ingredients with remaining durability should not cause a weight discrepancy, and removing ingredients with zero durability should not further increase the difference.

Screenshots

print in ./module/crafting/server

First print = i print local newWeight = left.weight + (craftedItem.weight + (recipe.metadata?.weight or 0)) * craftCount
Second print = I print newWeight and left.maxWeight just before checking if the player can carry the item or not
if newWeight > left.maxWeight then return false, 'cannot_carry' end

  • First craft :
    (Starter items)
    image

image
image

  • Second craft :
    image
    image

Additional context
The discrepancy (125g in this case) occurs because the server adds the remaining durability of used ingredients to a new slot, causing an incorrect weight adjustment.
If an ingredient’s durability reaches zero during crafting, it is correctly removed, but the weight discrepancy increases further.

@Pilouxs Pilouxs added the bug Something isn't working label Dec 6, 2024
@subhampro
Copy link
Contributor

1 >Add a weightAdjustment variable to track weight changes from durability modifications:

local weightAdjustment = 0 

2 > Calculate weight adjustments based on durability before checking inventory capacity:

for name, needs in pairs(recipe.ingredients) do
    if needs < 1 then
        local item = Items(name)
        if item and item.weight then
            weightAdjustment -= item.weight * needs
        end
    end
end

newWeight += weightAdjustment

3 > Update how you calculate and apply remaining durability for ingredients:

if count < 1 then
    local item = Items(invSlot.name)
    local durability = invSlot.metadata.durability or 100
    
    if durability > 100 then
        local degrade = (invSlot.metadata.degrade or item.degrade) * 60
        durability -= degrade * count
    else
        durability -= count * 100
    end
    
    // ...rest of durability logic
end

It may fix your issue 🙂

subhampro added a commit to subhampro/ox_inventory that referenced this issue Dec 9, 2024
ulasdemirci0 added a commit to ulasdemirci0/ox_inventory-qbcore that referenced this issue Jan 10, 2025
commit 2af2ccd
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Fri Jan 3 23:35:01 2025 +0000

    chore: bump manifest version to v2.43.5

commit 3dbeb5f
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sat Jan 4 10:33:18 2025 +1100

    fix(server): nil plate in entity mismatch

    See overextended#1856.

commit 20b1e40
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Thu Dec 19 04:36:27 2024 +0000

    chore: bump manifest version to v2.43.4

commit 0b09b6b
Author: Subham PRO <33375250+subhampro@users.noreply.github.com>
Date:   Tue Dec 10 14:03:24 2024 +0530

    fix(server/crafting): weight discrepancy during crafting (overextended#1849)

    Resolves overextended#1848.

commit 44d09a5
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Tue Dec 10 19:29:52 2024 +1100

    refactor(server/esx): check esx version and update config error

commit 9b08f82
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Tue Dec 10 19:19:39 2024 +1100

    fix(server): compare inventory entity plate to requested plate

    Further expand on the last commit, in case the entityid
    tied to an inventory has changed.

commit 9711fde
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sat Dec 7 13:56:02 2024 +1100

    fix(server): check for entity deletion when accessing vehicle inventory

    Resolve overextended#1847.

commit f96ab12
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Sun Nov 24 08:44:28 2024 +0000

    chore: bump manifest version to v2.43.3

commit 24e5c1c
Author: Frowmza <66181451+Frowmza@users.noreply.github.com>
Date:   Thu Nov 21 02:41:11 2024 +0100

    fix(server/mysql): stashes save error when bulk saving is disabled (overextended#1841)

commit 8b502d4
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Mon Nov 18 16:04:16 2024 +1100

    fix(server): check stash distance in getClosestStashCoordss

commit 51099d4
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Mon Nov 18 16:03:37 2024 +1100

    fix(server/inventory): register stash distance on inventories

commit ed50569
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Thu Nov 14 08:21:54 2024 +0000

    chore: bump manifest version to v2.43.2

commit e22a9ee
Author: Kasey Fitton <kaseyfitton@hotmail.co.uk>
Date:   Thu Nov 14 08:20:58 2024 +0000

    refactor(server/esx): error messaging for esx 1.11 (overextended#1833)

commit 425a4bd
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Sat Nov 9 16:01:39 2024 +0000

    chore: bump manifest version to v2.43.1

commit 8a65a5c
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Nov 10 03:00:53 2024 +1100

    fix(client): remove debugging code

commit 7602847
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Sat Nov 9 14:54:52 2024 +0000

    chore: bump manifest version to v2.43.0

commit 2882976
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Nov 10 01:06:46 2024 +1100

    refactor: prevent errors when data files are missing

commit 4c530d0
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Nov 10 00:46:06 2024 +1100

    refactor(client): adjust prints on weapon hash mismatch

commit 39c50fb
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Nov 10 00:37:33 2024 +1100

    refactor(server): tighten security for vehicle inv access

commit f14934c
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Nov 10 00:15:17 2024 +1100

    refactor(client): don't send plate to server when opening vehicle inv

commit 70abcfd
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Fri Oct 4 01:34:16 2024 +1000

    feat(server): add 'usingItem' event hook

commit c0abafb
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sat Sep 28 05:10:59 2024 +1000

    fix(server): prevent cascading errors on resource start

    Prevent some errors caused by other errors (which people
    always ignore).

commit c5027d5
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Sun Sep 15 02:07:19 2024 +0000

    chore: bump manifest version to v2.42.3

commit 8c8d057
Author: retro <128739748+hearondale@users.noreply.github.com>
Date:   Sun Sep 15 03:06:18 2024 +0100

    fix(server/crafting): update weight and sync slot when splitting stack (overextended#1802)

    Co-authored-by: Linden <65407488+thelindat@users.noreply.github.com>

commit 43d735f
Author: Maximus7474 <94017712+Maximus7474@users.noreply.github.com>
Date:   Sun Sep 15 03:59:22 2024 +0200

    fix(client/shops): target icons (overextended#1804)

commit 6ce273c
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sat Sep 14 12:27:31 2024 +1000

    fix(client): replicate invBusy state

    Should resolve overextended#1801.

commit d4445fa
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Fri Sep 13 00:45:35 2024 +0000

    chore: bump manifest version to v2.42.2

commit 65b38e8
Author: EdyzPW <94766321+EdyzPW@users.noreply.github.com>
Date:   Fri Sep 13 03:44:32 2024 +0300

    chore(locales): create ro.json (overextended#1789)

commit 322a5e4
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Fri Sep 13 10:42:52 2024 +1000

    refactor(server/inventory): disable giveItem if target inv is busy

commit e29e0c1
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Fri Sep 13 10:42:10 2024 +1000

    refactor: use callback event for giveItem

commit 8a0b920
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Fri Sep 13 10:41:16 2024 +1000

    refactor(client): replicate invBusy

commit bb654f2
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Fri Sep 13 10:05:57 2024 +1000

    fix(server/crafting): don't start crafting when item is missing

    Generally crafting cannot be triggered by the UI if missing items,
    however this fails when trying to craft multiple times.

    Without this, the item count is only checked after finishing the
    progress bar. Aside from poor UX, it may also fail to remove items
    from the inventory if they are given during the crafting process.

    Fixes overextended#1800.

commit 35fc62b
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Fri Sep 13 09:33:48 2024 +1000

    fix(server/inventory): set metadata.weight of petrolcan

    Fixes overextended#1799

commit 8e96447
Author: 0Programmer <60280452+0Programmer@users.noreply.github.com>
Date:   Fri Sep 13 01:19:18 2024 +0200

    fix(client): use client.dropmodel on invalid point.model (overextended#1798)

commit cf88913
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Sun Sep 1 00:58:55 2024 +0000

    chore: bump manifest version to v2.42.1

commit 50a79b0
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Sep 1 10:39:37 2024 +1000

    refactor(client): print when weapon is disarmed by game

    Since we've have a billion issues posted complaining about
    default game behaviour.

commit 868eeb3
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Sep 1 10:38:49 2024 +1000

    refactor(init): use lib.print.info

commit e63bad5
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Sep 1 10:25:07 2024 +1000

    refactor(client): tweak inventory access distance checking

    Lazy workaround for overextended#1766.

commit d4049b0
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Sep 1 10:02:55 2024 +1000

    fix(client/shops): pass distance to targets

commit 9127e81
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sun Sep 1 09:24:32 2024 +1000

    refactor(server/mysql): silent error on improper configuration

commit 3978cac
Author: Manason <clanerp@gmail.com>
Date:   Thu Aug 29 19:20:26 2024 -0700

    fix(server/qbx): default NPC vehicle database id to nil (overextended#1774)

commit 8278a1d
Author: Solareon <769465+solareon@users.noreply.github.com>
Date:   Fri Aug 30 04:20:10 2024 +0200

    fix(server/qbx): sync inventory items to player object (overextended#1775)

commit 4561261
Author: ARottenberger <69944020+iplayer1337fivem@users.noreply.github.com>
Date:   Fri Aug 30 04:19:19 2024 +0200

    chore(locales): update da.json (overextended#1784)

commit c1a5a7a
Author: Pegos <stelios@pegos.net>
Date:   Fri Aug 30 05:18:47 2024 +0300

    fix(client): infinite textui (overextended#1786)

commit 0317d14
Author: Manifest Bumper <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Sat Aug 17 02:48:31 2024 +0000

    chore: bump manifest version to v2.42.0

commit 696b38d
Author: Linden <65407488+thelindat@users.noreply.github.com>
Date:   Sat Aug 17 12:47:14 2024 +1000

    fix(server/qbx): invalid statebag access

commit 9f816e4
Author: Master Mind <70486873+SOH69@users.noreply.github.com>
Date:   Sat Aug 17 08:15:07 2024 +0530

    fix(server/inventory): ignore owner/group checks when forcing open inventory (overextended#1769)

commit 5618523
Author: toshko <toshko0003@gmail.com>
Date:   Fri Aug 16 06:08:54 2024 +0300

    fix(server/inventory): stash coords (overextended#1768)

commit 9512721
Author: Solareon <769465+solareon@users.noreply.github.com>
Date:   Wed Aug 14 19:13:09 2024 +0200

    feat(bridge/qbx): sync dynamic account types (overextended#1767)

commit 937f775
Author: Solareon <769465+solareon@users.noreply.github.com>
Date:   Wed Aug 14 05:10:58 2024 +0200

    feat: qbx_core support (overextended#1763)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants