Could anyone help me to write a command that would give me two specific values from one row?
(One value, “plate” from separate collum)
and
I need to fetch 2 values from my database to my server script. In this case “modEngine” (value “-1”) and “model” (value “-1213539927”)
How is that possible? I’ve never done this complex fetching before…
Something like:
MySQL.Sync.fetchAll(“SELECT * FROM owned_vehicles WHERE owner=@plate AND FROM vehicle WHERE modEngine=@modEngine” AND model=“model”,{[’@plate ‘] = plate, [’@modEngine’] = modEngine}, [’@model’] = model}, function(modEngineValue)
You are just going to have to return the whole row based on the plate number then decode the vehicle data because its JSON data in a string.
MySQL.Async.fetchAll("SELECT * FROM owned_vehicle WHERE owner = @plate", {
["@plate"] = "PLATEHERE"
}, function(results)
if results[1] ~= nil then
local vehicleData = json.decode(results[1].vehicle)
local engineMod = vehicleData.modEngine
print(engineMod)
end
end)
I doubt that MySQL can search through stringified JSON.
RegisterNetEvent("upgradescript:UpgradeValue")
RegisterNetEvent('upgradescript:RetrievePlate', function(plate, model)
local ped = GetPlayerPed(-1)
local VehPedIsIn = GetVehiclePedIsIn(ped, false)
local VehPlate = GetVehicleNumberPlateText(VehPedIsIn)
local modValue = nil
-- New event to bring the value to this file from the server (called from the server, of course)
AddEventHandler("upgradescript:UpgradeValue", function(engineMod, model)
modValue = engineMod
modelHash = model
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1000)
-- Now, to tell the script condition if it's player's vehicle and what mod does it have
if IsPedInVehicle(ped, VehPedIsIn, false) then
-- checking if player is sitting in vehicle from SQL database (any vehicle from server's DB, even from other players)
VehPlate(VehPedIsIn)
AddEventHandler('upgradescript:RetrievePlate', function(plate, model)
if plate == nil then
if modelhash = '-216150906' and modValue == 0 or 1 or 2 or 3 then -- 16challenger as example
SetVehicleEnginePowerMultiplier(VehPedIsIn, 100)
end
end
end
end
end)
server
RegisterServerEvent('upgradescript:UpgradeValue')
RegisterServerEvent('upgradescript:RetrievePlate', function(plate)
AddEventHandler('upgradescript:UpgradeValue', function (vehicle)
MySQL.Async.fetchAll("SELECT * FROM owned_vehicle WHERE owner = @plate", {["@plate"] = "PLATEHERE"}, function(results)
if results[1] ~= nil then
local vehicleData = json.decode(results[1].vehicle)
local engineMod = vehicleData.modEngine
local model = vehicleData.model
print(engineMod)
print(model)
TriggerClientEvent('upgradescript:UpgradeValue', engineMod, model)
end
end)
end)
AddEventHandler('upgradescript:RetrievePlate', function(plate)
MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE @plate = plate', {['@plate'] = plate}, function(result)
local retrivedInfo = {plate = plate}
if result[1] then
MySQL.Async.fetchAll('SELECT * FROM vehicles WHERE plate = @plate', {['@plate'] = result[1].owner}, function(results)
-- how to tell to the script we want to look for engineMod and model values based on license plate??
if results[1] ~= nil then
local vehicleData = json.decode(results[1].vehicle)
local engineMod = vehicleData.modEngine
local model = vehicleData.model
end
end)
end
end)
end)