JG Scripts Docs
DiscordSupportStore
  • Welcome!
  • Claim Purchase
  • FiveM Escrow Errors
  • Permissions Troubleshooting
  • Translations
  • 🛠️Mechanic
    • Introduction
    • Installation & Configuration
      • ox_inventory
      • qb-inventory
      • esx_inventory
      • Setup New Mechanic Location
    • Job Setup
      • ESX Framework Jobs
    • Inventory Items
    • Props
    • Tuning
    • Manual Transmissions & Smooth First Gear
    • Integrations
    • Commands, Events & Exports
      • Commands
      • Events
      • Exports
    • Changelog
      • v1.3.0
      • v1.2.0
      • v1.1.3
      • v1.1.2
      • v1.1.1
      • v1.1
      • v1.0.12
      • v1.0.11
      • v1.0.10
      • v1.0.9
      • v1.0.8
      • v1.0.7
      • v1.0.6
      • v1.0.5 - hotfix
      • v1.0.5
      • v1.0.4
      • v1.0.3
      • v1.0.2
      • v1.0.1
  • 🚘Dealerships
    • Introduction
    • Installation & Configuration
    • Advanced Configuration
    • Job Dealership Setup
    • License Check
    • Importing Vehicles
    • Dealership Locations
    • Employees
    • Custom Payment Options
    • Plate Format
    • Vehicle Images
    • Languages
    • Commands, Events & Exports
      • Commands
      • Events
    • Integrations
      • Quasar Garages
      • Pickle Mods Documents
      • okokContract
      • qb-vehiclesales
    • Changelog
      • v1.4.0
      • v1.3.1
      • v1.3.0
      • v1.2.6
      • v1.2.5
      • v1.2.4
      • v1.2.3
      • v1.2.2
      • v1.2.1
      • v1.2
      • v1.1.9
      • v1.1.8
      • v1.1.7
      • v1.1.6
      • v1.1.5
      • v1.1.4
      • v1.1.3
      • v1.1.2
      • v1.1.1
      • v1.1
      • v1.0.3
      • v1.0.2
      • v1.0.1
  • 🚗Advanced Garages v3
    • Introduction
    • Installation & Configuration
    • Migration from v1
    • Public, Private & Impound Garages
    • Job & Gang Garages
    • Transferring Vehicles
    • Vehicle Duplication Prevention
    • Vehicle Images
    • Languages
    • Commands, Events & Exports
      • Commands
      • Events
      • Exports
    • Misc
      • Spawn Vehicles with ServerSetter
      • Why are you not using CreateVehicleServerSetter by default?
    • Troubleshooting
      • Execution of native... SetDriftTyresEnabled error
      • ucrtbase.dll!strcmp crash
      • SQL error: foreign key constraint fails
    • Integrations
      • qb-phone
      • npwd
      • RoadPhone
      • Quasar Smartphone
      • Quasar Housing
      • okokDeleteVehicles
      • ps-housing
      • nolag_properties
      • Brazzers-FakePlate
      • Custom Fuel System
      • Custom Key System
    • Guides
      • ESX Guides
        • Vehicle Labels
      • QBCore Guides
        • Why isn't /admincar working?!
        • Liveries not saving
    • Changelog
      • v3.2.1
      • v3.2.0
      • v3.1.6
      • v3.1.5
      • v3.1.4
      • v3.1.3
      • v3.1.2
      • v3.1.1
      • v3.1.0
      • v3.0.8
      • v3.0.7
      • v3.0.6
      • v3.0.5
      • v3.0.4
      • v3.0.3
      • v3.0.2
      • v3.0.1
      • v3
      • v2.2.9
      • v2.2.8
      • v2.2.7
      • v2.2.6
      • v2.2.5
      • v2.2.4
      • v2.2.3
      • v.2.2.2
      • v2.2.1
      • v2.2.0
      • v2.1.2
      • v2.1.1
      • v2.1
      • v2.0.7
      • v2.0.6
      • v2.0.5
      • v2.0.4
      • v2.0.3
      • v2.0.2
      • v2.0.1
  • 📊Handling
    • Introduction
    • Installation
    • Exports
  • 🎮Pro Scoreboard
    • Introduction
    • Installation
    • Config & Customisation
  • Advanced Garages v1
    • QB Installation & Config
    • ESX Installation & Config
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Advanced Garages v3
  2. Integrations

RoadPhone

Last updated 1 year ago

Was this helpful?

This code was provided to us by the developer of RoadPhone. Please notify RoadPhone so we can work together to get this documentation updated.

Buy it here:

This integration is to ensure the Valet functionality works with JG Advanced Garages.


Replace the contents of roadphone/server/serverAPI/valet.lua with the following (make sure you select the correct framework)

QBCore.Functions.CreateCallback("roadphone:valet:getCars", function(source, cb)

    local xPlayer = QBCore.Functions.GetPlayer(source)

    if not xPlayer then
        return;
    end

    MySQL.Async.fetchAll("SELECT * FROM " .. Config.OwnedVehiclesTable .. " WHERE `citizenid` = @citizenid and type = @type and `impound` = @impound", {
        ['@impound'] = 0,
        ['@citizenid'] = xPlayer.PlayerData.citizenid,
        ['@type'] = "car"
    }, function(result)
        local cachedvehicles = {}

        for i = 1, #result do
            table.insert(cachedvehicles, {
                plate = result[i].plate,
                vehicle = result[i].vehicle, -- result[i].vehicle,
                type = 'car',
                hash = result[i].hash,
                garage = result[i].garage_id,
                stored = result[i].in_garage
            })

        end

        cb(cachedvehicles)

    end)

end)

QBCore.Functions.CreateCallback('roadphone:valet:loadVehicle', function(source, cb, plate)

    local valetCheck = valetServerSideCheck(plate)

    if valetCheck ~= false then
        cb(false, valetCheck)
        return;
    end

    MySQL.Async.fetchAll('SELECT * FROM ' .. Config.OwnedVehiclesTable .. ' WHERE `plate` = @plate', {
        ['@plate'] = plate
    }, function(vehicle)
        cb(vehicle)
    end)
end)

QBCore.Functions.CreateCallback('roadphone:valet:checkMoney', function(source, cb)
    local xPlayer = QBCore.Functions.GetPlayer(source)

    if not xPlayer then
        return;
    end

    if xPlayer.Functions.GetMoney('bank') > Config.ValetDeliveryPrice then
        xPlayer.Functions.RemoveMoney('bank', Config.ValetDeliveryPrice, 'Car delivered')

        local number = getNumberFromIdentifier(xPlayer.PlayerData.citizenid)

        TriggerEvent("roadphone:addBankTransfer", number, 0,  Lang:t('info.valet_car_delivered'), Config.ValetDeliveryPrice)

        TriggerClientEvent("roadphone:sendNotification", source, {
            apptitle = "APP_VALET_NAME",
            title = "APP_VALET_CAR_ONTHEWAY",
            img = "/public/img/Apps/valet.jpg"
        })

        discordLog("9807270", "Valet", xPlayer.PlayerData.name .. ' ' .. Lang:t('info.valet_car_delivered_2', { value = Config.ValetDeliveryPrice }), 'RoadPhone - Valet', nil, Cfg.ValetWebhook)
        cb(true)
        return;
    else
        TriggerClientEvent("roadphone:sendNotification", source, {
            apptitle = "APP_VALET_NAME",
            title = "APP_VALET_NOTENOUGHMONEY",
            img = "/public/img/Apps/valet.jpg"
        })

        cb(false)
        return;
    end

end)

RegisterServerEvent("roadphone:valetCarSetOutside")
AddEventHandler("roadphone:valetCarSetOutside", function(plate)
    MySQL.Async.execute('UPDATE '..Config.OwnedVehiclesTable..' SET `in_garage` = @in_garage WHERE `plate` = @plate', {
        ['@plate'] = plate,
        ['@in_garage'] = 0,
    })
end)
ESX.RegisterServerCallback("roadphone:valet:getCars", function(source, cb)

    local xPlayer = ESX.GetPlayerFromId(source)

    if not xPlayer then
        return;
    end

    MySQL.Async.fetchAll("SELECT * FROM " .. Config.OwnedVehiclesTable .. " WHERE `owner` = @identifier and type = @type and `impound` = @impound", {
        ['@impound'] = 0,
        ['@identifier'] = xPlayer.identifier,
        ['@type'] = "car"
    }, function(result)
        local cachedvehicles = {}

        for i = 1, #result do

            local Garage = result[i].garage_id
            local State = _U('valet_state_default')

            table.insert(cachedvehicles, {
                plate = result[i].plate,
                vehicle = json.decode(result[i].vehicle),
                garage = Garage,
                state = State
            })

        end

        cb(cachedvehicles)

    end)

end)

ESX.RegisterServerCallback('roadphone:valet:loadVehicle', function(source, cb, plate)

    local valetCheck = valetServerSideCheck(plate)

    if valetCheck ~= false then
        cb(false, valetCheck)
        return;
    end

    MySQL.Async.fetchAll('SELECT * FROM ' .. Config.OwnedVehiclesTable .. ' WHERE `plate` = @plate', {
        ['@plate'] = plate
    }, function(vehicle)
        cb(vehicle)
    end)
end)

ESX.RegisterServerCallback('roadphone:valet:checkMoney', function(source, cb)
    local xPlayer = ESX.GetPlayerFromId(source)

    if not xPlayer then
        return;
    end

    if xPlayer.getAccount('bank').money > Config.ValetDeliveryPrice then
        xPlayer.removeAccountMoney('bank', Config.ValetDeliveryPrice)

        local number = getNumberFromIdentifier(xPlayer.identifier)

        TriggerEvent("roadphone:addBankTransfer", number, 0,  _U('valet_car_delivered'), Config.ValetDeliveryPrice)

        TriggerClientEvent("roadphone:sendNotification", source, {
            apptitle = "APP_VALET_NAME",
            title = "APP_VALET_CAR_ONTHEWAY",
            img = "/public/img/Apps/valet.jpg"
        })

        discordLog("9807270", "Valet", xPlayer.getName() .. ' ' .. _U('valet_car_delivered_2', Config.ValetDeliveryPrice), 'RoadPhone - Valet', nil, Cfg.ValetWebhook)
        cb(true)
        return;
    else
        TriggerClientEvent("roadphone:sendNotification", source, {
            apptitle = "APP_VALET_NAME",
            title = "APP_VALET_NOTENOUGHMONEY",
            img = "/public/img/Apps/valet.jpg"
        })

        cb(false)
        return;
    end

end)

RegisterServerEvent("roadphone:valetCarSetOutside")
AddEventHandler("roadphone:valetCarSetOutside", function(plate)
    MySQL.Async.execute('UPDATE '..Config.OwnedVehiclesTable..' SET `in_garage` = @in_garage WHERE `plate` = @plate', {
      ['@plate'] = plate,
      ['@in_garage'] = 0,
    })
    return
end)

🚗
https://fivem.roadshop.org/