[ESX] RP car upgrade script

Hi,

I want to create a script that would be checking if bought car has engine upgrade stored in database. If so, script would apply little engine power modifier, based on category of vehicles in DB (like Tuners D for Vehicle shop or based only on particular car model, that would be hash, as this is how cars are stored in owned_vehicles)

I’ve tried to come up with solution, but was unsuccessful so far, could anyone give a minute to this and correct me, fill the gaps or give me general advice, please?

client

ESX	= nil

Citizen.CreateThread(function ()
while ESX == nil do
	TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
	Citizen.Wait(0)
end
end)

local xPlayer 		= ESX.GetPlayerFromId(source)
local _source 		= source
local VehPedIsIn	= GetVehiclePedIsIn(xPlayer, false)
local VehPlate		= GetVehicleNumberPlateText(VehPedIsIn)
local modValue		=	nil
local modelHash		=	nil
local TunersD		=	




    -- New event to bring the value to this file from the server (called from the server, of course)
RegisterNetEvent("esx_upgradescript:UpgradeValue")
AddEventHandler("esx_upgradescript:UpgradeValue", function(engineMod, model)
local modValue	=	engineMod
local 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(xPlayer, VehPedIsIn, false) then
		--	checking if player is sitting in vehicle from SQL database (any vehicle from server's DB, even 
from other players)
		GetPlate(VehPlate)
			if VehPlate == nil then
				if	modelhash = '-707080126' and modValue	== 0 or 1 or 2 or 3 then
				SetVehicleEnginePowerMultiplier(VehPedIsIn, 100)
				end
			end
	end
end
end)

function GetPlate(plate)

ESX.TriggerServerCallback('esx_upgradescript:RetrievePlate', function(plate)

	if plate = nil then		--how to tell other servercallback to get me vehicle data from certain vehicle/plate??

	ESX.TriggerServerCallback('esx_upgradescript:ModelUpgradeValues', function(model, upgrade)
		
	end)

end)

end

server

ESX              = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)


ESX.RegisterServerCallback('esx_upgradescript:RetrievePlate', function(source, cb, 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)

Every response will be appreciated :slight_smile:

Anyone? Any help appreciated!

1 Like

Have you made any progression with the script? The concept sounds very good to me and I’d love to use a script like that in my server!