Import vehicle name from database

hi my friends
I want to retrieve the name of the car from the database to appear in the car information

I did a name retrieval from config

But it’s tiring, there are more than 200 cars, so I want to retrieve them from the database

how can I do that

This is an explanation

in game
how
config.lua

Screenshot_1

client.lua


db
Screenshot_4

up up up

You want to have the config file to hold the model of the car and you want to get the name out of the database or you want to build an array of vehicle model and name from the database?

I want to fetch vehicle model and name from database without config

Screenshot_5

Take a look at this server callback in the current esx_garage, it would be a perfect starting point for modifying to build an array of vehicles for use in the manner you’re wanting to:

ESX.RegisterServerCallback('esx_vehicleshop:getVehiclesInGarage', function(source, cb, garage)
	local xPlayer  = ESX.GetPlayerFromId(source)

	MySQL.query('SELECT * FROM `user_parkings` WHERE `identifier` = @identifier AND garage = @garage',
	{
		['@identifier'] = xPlayer.identifier,
		['@garage']     = garage
	}, function(result)

		local vehicles = {}
		for i=1, #result, 1 do
			table.insert(vehicles, {
				zone    = result[i].zone,
				vehicle = json.decode(result[i].vehicle)
			})
		end

		cb(vehicles)

	end)
end)

my friend, thanks for your reply
I will put this in the server.lua file

What do I put in the clinet.lua file?

Just putting that in a server file won’t do anything helpful for you, you need to modify it to grab what you want. As for the client file, you would want to replace the config’s vehicle building portion with a client function that triggers this event to build the config array.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.