qb-core
qb-core copied to clipboard
feat: remove usable item fn after stopped resource
Description
This PR aims to fix an error that can be recreated by trying to use an item after the resource which said item callback from is stopped.
Recreation:
- Give yourself a radio
- Stop qb-radio
- Use the radio item
And you'll see the following error:
[ script:qb-core] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:479: attempt to concatenate a nil value (local 'err')
[ script:qb-core] > UseItem (@qb-inventory/server/functions.lua:167)
[ script:qb-core] > handler (@qb-inventory/server/main.lua:177)
[ script:qb-inventory] SCRIPT ERROR: error object is not a string
The way it fixes the error is by saving which resource the "useable item callback" is created by. And then listening for stopped resources and removing said "useable item callback" upon said resource being stopped.
Checklist
- [x] I have personally loaded this code into an updated qbcore project and checked all of its functionality.
- [x] My code fits the style guidelines.
- [x] My PR fits the contribution guidelines.
This needs to be merged alongside: https://github.com/qbcore-framework/qb-inventory/pull/519