RP script for LSC engine boost

Hi!

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)


values edit.png1153x115 13.4 KB

I will appreciate any help in this! It’s very important for me !:slight_smile:(https://forum.cfx.re/images/emoji/twitter/slight_smile.png?v=6)

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.

Yes, I was a bit afraid it won’t be that easy :joy:

Gonna try it tomorrow! Thank you!!

I think I am getting really lost here. Could you, please, take a look on it?

__resource

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

server_scripts {
'@mysql-async/lib/MySQL.lua',
'server_main.lua'
}

client_scripts {
'client_main.lua'
}

client

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)

Cant really help right now.