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

Fix QBCore Compatibility #113

Merged
merged 7 commits into from
Jul 24, 2024
Merged

Conversation

RobertGrubb
Copy link
Member

@RobertGrubb RobertGrubb commented Jul 21, 2024

Version 1.0.6

To understand the first bullet point, here is an example of an inventory add item call from latest QB Core (This was after the rename from qb-inventory to ps-inventory):

Notice the last parameter passed

exports['ps-inventory']:AddItem(src, Config.LuckyItem, random, false, false, 'qb-recyclejob:server:getItem')
  • Updated "AddItem" method to take parameter for "reason" before "created" as this was causing the issue with the inventory to spit out the error SCRIPT ERROR: @ps-inventory/server/main.lua.2544: attempt to sub a 'number' with a 'string'. The "reason" was being passed as the "created" timestamp which caused "created" to come through as an unexpected string.
  • During the "AddItem" method, "info" was being passed as an empty string at times, there is now a check to make sure the type is a table. If it is not, it will define it as an empty table so the assignment of "info.quality" will pass.
  • Added CreateShop and OpenShop exports to server.lua so shops can correctly be created and opened.
  • RegisteredShops table added at the top of the server file.

Previews (Latest QBCore) - Inventory opens, shops are functioning, images are working fine, and decay is good.
image
image

NOTE: I'd appreciate it if we can get some eyes on this in terms of testing before merging just to confirm that all is well.

@lenzh
Copy link
Contributor

lenzh commented Jul 21, 2024

still recieved a error
image
this happened when opened a stash

@lenzh
Copy link
Contributor

lenzh commented Jul 21, 2024

ive changed the function ConvertQuality(item) to

function ConvertQuality(item)
    local StartDate = item.created
    local DecayRate = QBCore.Shared.Items[item.name:lower()]['decay'] ~= nil and QBCore.Shared.Items[item.name:lower()]['decay'] or 0.0
    if not DecayRate then
        DecayRate = 0.0
    end
    if not (type(StartDate) == "number") then
        if not (tonumber(StartDate)) then return 0 end
        StartDate = tonumber(StartDate)
    end
    local TimeExtra = math.ceil((TimeAllowed * DecayRate))
    local percentDone = 100 - math.ceil((((os.time() - StartDate) / TimeExtra) * 100))
    if DecayRate == 0 then
        percentDone = 100
    end
    if percentDone <= 0 then
        percentDone = 0
    end
    return percentDone
end

might wanna use that because this fixed that issue for me

@Project-Sloth Project-Sloth deleted a comment from Quenixx Jul 21, 2024
@RobertGrubb
Copy link
Member Author

RobertGrubb commented Jul 22, 2024

@lenzh I have added your suggestion as I did test the following:

  • Changed item.created in the database to be a string
  • Hit error during the convertQuality method because of it
  • Added your patch
  • Restarted ps-inventory
  • Was able to load the inventory as expected.

Thanks for the suggestion

@RobertGrubb
Copy link
Member Author

RobertGrubb commented Jul 22, 2024

It's worth noting someone pointed out that the export doesn't work server side with the following:

exports['ps-inventory']:OpenInventory(source, name, data)

This is actually because if you call the server-side export directly, you also have to pass the source so the export can check the player's state bag:

exports['ps-inventory']:OpenInventory(name, id, data, origin)

@lenzh
Copy link
Contributor

lenzh commented Jul 22, 2024

so you paste the source twice?

@lenzh
Copy link
Contributor

lenzh commented Jul 22, 2024

and for some reason when items are in stash at for example slot 2 and 4 it will be displayed in DB
[NULL, {item bla bla bla}, NULL, {seconditem}]

so it will place null in the json format for a empty slot, we might need to look into that aswell. idk it that was before like that

@RobertGrubb
Copy link
Member Author

RobertGrubb commented Jul 22, 2024

so you paste the source twice?

@lenzh Sorry about that, lol, got the params mixed up there.

P1: name ("stash", etc)
P2: id
P3: data
P4: origin (source)

Had to look at it again, the export takes params in a different order than the server's event

Updated my original comment to reflect this

@lenzh
Copy link
Contributor

lenzh commented Jul 22, 2024

@RobertGrubb aah oke now i get you

@lenzh
Copy link
Contributor

lenzh commented Jul 22, 2024

also gotta check the commit ur behind with the items going missing in stashes, i never had that issue even with your pr but we might need to bug hunt that

@xFutte
Copy link
Member

xFutte commented Jul 22, 2024

Please rebase before merging.

@RobertGrubb
Copy link
Member Author

@lenzh @xFutte It's good now, thanks for noticing.

@MonkeyWhisper MonkeyWhisper merged commit 02e3a06 into Project-Sloth:main Jul 24, 2024
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.

4 participants