I want to send the vehicle variable from the client to the server callback, there I will verify if the person with the steam id owns the vehicle he is trying to open, if he does then all the license plates he owns will be saved in into an array and sent back to the client.
How to pass parameters from client to server callback?
#Client
function openmenuvehicle() local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) local vehicle = nil if IsPedInAnyVehicle(playerPed, false) then vehicle = GetVehiclePedIsIn(playerPed, false) else vehicle = getVehicleInDirection(3.0) if not DoesEntityExist(vehicle) then vehicle = GetClosestVehicle(coords, 3.0, 0, 70) end end if DoesEntityExist(vehicle) then local lockStatus = GetVehicleDoorLockStatus(vehicle) if lockStatus == 0 or lockStatus == 1 then local trunkpos = GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, "boot")) local distanceToTrunk = GetDistanceBetweenCoords(coords, trunkpos, 1) if distanceToTrunk <= 1.25 or (trunkpos.x + trunkpos.y + trunkpos.z) == 0.0 then ESX.TriggerServerCallback('esx_inventoryhud_trunk:getOwner', function(isOwner) print(isOwner) if isOwner then TriggerEvent( "mythic_progbar:client:progress", { name = "Open_Trunk", duration = Config.OpenTime, label = 'ABRINDO MALA', useWhileDead = false, canCancel = true, controlDisables = { disableMovement = true, disableCarMovement = true, disableMouse = false, disableCombat = true } }, function(status) if not status then currentVehicle = vehicle SetVehicleDoorOpen(vehicle, 5, false, false) local class = GetVehicleClass(vehicle) OpenCoffreInventoryMenu(GetVehicleNumberPlateText(vehicle), Config.VehicleLimit[class]) end end ) end end) else exports['okokNotify']:Alert("", "Aproxima-te da mala", 3000, 'error') end else exports['okokNotify']:Alert("", "Mala trancada", 3000, 'error') end else exports['okokNotify']:Alert("", "Sem veículos por perto", 3000, 'error') end end
#Service-Terminal
ESX.RegisterServerCallback("esx_inventoryhud_trunk:getOwner", function(source, cb, plate) local id = GetPlayerIdentifiers(source)[1] MySQL.Async.fetchAll("SELECT plate FROM owned_vehicles WHERE owner = @owner", {['@owner'] = id}, function(data) if data[1].owner == id then return cb(true) else return cb(false) end end) end)
All you need to do is add an additional parameter to the client's callback. If you define the board above like I did below, then ",board" will be fine.
For the server side, you just need cb(data).