#Update vehicle inventory in database if fakeplate is installed

1 messages · Page 1 of 1 (latest)

graceful light
#
  1. Get vehicle out of garage
  2. Put items in car trunk
  3. Install fakeplate
  4. Items are still there after fakeplate is installed
  5. Remove 1 item from the trunk with fakeplate installed
  6. Remove fakeplate
  7. Open trunk, the item that i removed from trunk when fakeplate is installed duplicates. It'ss in my inventory + trunk.
    So database of trunk is not updated.

I made this work before on old ox inventory version, but that part changed since I did it and now I cant figure it out.
I will upload the new code and the old code that worked, maybe someone can help me.

static surge
#

this is the fault of whatever fakeplate script you have

#

it isnt compatible with ox_inventory it appears

graceful light
#

I'm using Brazzers

#

And like I said before

#

I made it work

#

On an older inventory version

dense acorn
#

So are you on an old ox_inventory version now then? Are these player or NPC vehicles, or a mix of both?

graceful light
#

No

#

I'm on the new ox inv

#

They are player vehicles

dense acorn
#

How does the fake plate code work?

graceful light
#

Replaces plate and puts in player_vehicles table in the database

#

When changing the plates I use
exports.ox_inventory:UpdateVehicle(oldPlate, newPlate)

#

And transfers the inventory to the new plate

#

But It does not update trunk/glovebox in database.

dense acorn
#

The inventory is attached to the vehicle id, not the plate. What is your ox_inventory version?

graceful light
#

Latest

dense acorn
#

How are you spawning these vehicles?

graceful light
#

2.43.1

#

Qbox garages

#

If you compare the 2 files that I uploaded

#

You'll see what I did there.

#

And worked like a charm.

#

But that was 10 months ago.

dense acorn
#

Try removing the UpdateVehicle call

graceful light
#

If I do that I won't update the glovebox and trunk for the new plate(fake)

dense acorn
#

Not quite sure what could be the issue here. I would file an ox_inventory bug

graceful light
#

I don't think it's a bug

#

This is what update vehicle export does

#

10 months ago when I worked on the problem. I opened a support post on ox discord. And linden told me that I have to do it my self.

dense acorn
#

Do what yourself? This seems to be a supported feature. Did this export exist 10 months ago?

graceful light
#

Yes

#

Check this out.

dense acorn
#

It's a bit unclear to me if changing plates is a supported feature or not. It doesn't seem like it is

graceful light
#

If it's not, what is that export for?

dense acorn
#

That would be a question for Ox lol

graceful light
#

Anyway. I made it work one time. I'll make it work again. It will take me hours cuz my backend dev skills are sh1tty, but I'll make it work.

#

That if no1 is willing to take a look at those files that I uploaded.

graceful light
#

Shouldn't the trunks table be structured like this?

trunks = {
{Inventory data1, vehicle id1}
{Inventory data2, vehicle id2}
}

#

trunks isn't a table of tables?

graceful light
#

After 2 days of debbuging. I figured out that when fake plate was on the vehicle the id of the vehicle was not sent to trunks and gloveboxes table. The id was nil when fakeplate was on. So i figured out that i had to modify the qbx_vehicles export GetVehicleIdByPlate.
I changed that to:

local function getVehicleIdByPlate(plate)
    return MySQL.scalar.await('SELECT id FROM player_vehicles WHERE (fakeplate IS NOT NULL AND fakeplate = ?) OR plate = ?', {
        qbx.string.trim(plate),
        qbx.string.trim(plate)
    })
end
#

But there is still a problem. I will write here in a minute.

#

Now it gets vehicle id when fake plate is on or not.

#

but only when ox inventory is restarted after changing plates.

dense acorn
#

It should get vehicleid from the statebag though regardless of plate

graceful light
#

well its not

dense acorn
#

That sounds like the statebag isn't being set then?

graceful light
#

function server.getOwnedVehicleId(entityId)
return Entity(entityId).state.vehicleid or exports.qbx_vehicles:GetVehicleIdByPlate(GetVehicleNumberPlateText(entityId))
end

dense acorn
#

GetVehicleIdByPlate is a fallback in case the statebag isn't set

graceful light
#

i tried to remove the statebag and only keep the export. same problem.

#

looks like loadInventoryData is run only once when the inventory is starting

dense acorn
#

If you have a vehicle with the vehicleid statebag set, and then change the plate, it should still open the same inventory

#

I would double check the statebag value. If the vehicle was spawned with a recent version of qbx_garages it should have it set

graceful light
#

im on the last version of all qbox resources. unstable recipe

#

ok so

#

if i park the vehicle and then take it out again it works

#

oh no it does not.

#

my bad

dense acorn
#

The theory here is that the inventory is loaded off of the vehicleid, which doesn't change when plate changes

#

You can run a simple test where you change the vehicleid statebag to different vehicleIds in the player_vehicles table and then you should see the inventory open based on the vehicleId

#

Maybe trunks and gloveboxes are set via plate though and this is an ox_inventory bug?

graceful light
#

no. 100% they are set via id

dense acorn
#

Ok. Keep us updated as to your findings

graceful light
#

So when changing plates im trying to print the vehicleid statebag but comes out nil

#

i added
Entity(veh).state:set('vehicleid', vehInfo.id, false)
when spawning the vehicle with garages and now the id is not nil

#

comes out correctly

#

but still not saving if the plate is changed and then the save cron is triggered.

#

but if i change plate, restart inventory, then it saves corectly.

#

this is a pain...im starting to lose it

#

yesterday i was so close to punch one of my monitors

dense acorn
#

Why was the vehicleid statebag nil? Shouldn't it have been set by qbx_garages?

Anyway, if the plate is changed and you access the trunk, is it the same inventory or different?

graceful light
#

the inventory is the same when changing plates. loads corectly.

dense acorn
#

Oh. I thought you were using qbx_garages for some reason. What's the remaining issue now then?

graceful light
#

If i change plates, ox inventory is grabbing and sending the vehicle id only after it restarts.

#

ox inventory is reading the id only once when it starts or restarts...its not like a loop that checks if vehicle id changed or plate changed.

#

i feel like I should modify something here also, somehow update the vehid for the new plate.

function Inventory.UpdateVehicle(oldPlate, newPlate)
    oldPlate = oldPlate:upper()
    newPlate = newPlate:upper()

    if server.trimplate then
        oldPlate = string.strtrim(oldPlate)
        newPlate = string.strtrim(newPlate)
    end

    local trunk = Inventory(('trunk%s'):format(oldPlate))
    local glove = Inventory(('glove%s'):format(oldPlate))

    if trunk then
        Inventory.CloseAll(trunk)

        Inventories[trunk.id] = nil
        trunk.label = newPlate
        trunk.dbId = type(trunk.id) == 'number' and trunk.dbId or newPlate
        trunk.id = ('trunk%s'):format(newPlate)
        Inventories[trunk.id] = trunk
    end

    if glove then
        Inventory.CloseAll(glove)

        Inventories[glove.id] = nil
        glove.label = newPlate
        glove.dbId = type(glove.id) == 'number' and glove.dbId or newPlate
        glove.id = ('glove%s'):format(newPlate)
        Inventories[glove.id] = glove
    end
end
graceful light
#

im starting to believe its a inventory bug