0

框架:QBCore

我正在尝试制作一个脚本,该脚本获取车辆数据库,然后在菜单中列出,当有人单击该特定车辆菜单时,如果它已经存在,则将其从地图上删除,然后重新生成它。

我试过用它的盘子删除它,但我得到一个数字而不是一个字符串,并用它的盘子用 tonumber() 尝试它,但它不会删除然后我已经尝试了几天但就是无法得到它. 当我使用 DeleteVehicle(GetVehiclePedIsIn(PlayerPedId(), true)) 执行此操作时,它可以工作,但是当他们来获取它时可能不在他们的车辆中,因此它只会删除随机车辆。

代码客户端

QBCore = exports['qb-core']:GetCoreObject()

RegisterCommand("sora", function(source)
    TriggerServerEvent("Sora:GetVehiclesList", source)
end)

RegisterNetEvent("sora:garageVehicleList")
AddEventHandler("sora:garageVehicleList", function(vehicle, k)
    local garageList = {
        {
            id = k,
            header = vehicle.vehicle,
            txt = vehicle.plate,
            params = {
                event = "sora:SpawnVehicle",
                args = vehicle,
                TriggerEvent("sora:SpawnVehicle", args, vehicle)
            },
        },
    }
    exports['zf_context']:openMenu(garageList)
end)

RegisterNetEvent("sora:SpawnVehicle")
AddEventHandler("sora:SpawnVehicle", function(args, vehicle, id)
    local src = source
    print("Args")
    print(args.vehicle)
    DeleteVehicle(args.vehicle) -- Return expected number not string
    local test = NetworkGetEntityFromNetworkId(args.vehicle)

    local test = GetVehiclePedIsIn(PlayerPedId(), true) --This one delete the vehicle the last person is in but want just the vehicle they are trying to spawn to be deleted
    DeleteVehicle(test)

end)

服务器

QBCore = exports['qb-core']:GetCoreObject()

RegisterServerEvent("Sora:GetVehiclesList")
AddEventHandler("Sora:GetVehiclesList", function()
    local src = source
    local pData = QBCore.Functions.GetPlayer(src)
    exports.oxmysql:fetch('SELECT * FROM player_vehicles WHERE citizenid = ?', {pData.PlayerData.citizenid}, function(result)
        for k, v in ipairs(result) do
            print(result)
            print(v.vehicle)
            if v.state == 0 then
                TriggerClientEvent("sora:garageVehicleList", src, v, k)
            end
        end
    end)
end)
4

0 回答 0