Try Insert column, help me pl

help

#1

Hi everybody, I tryed change the esx_vehicleshop. I want to add vehicleName column to owned_vehicles table.
So, if i buy a car, that have to add a car name to vehicleName column. But i can’t. Help me please.

RegisterServerEvent('esx_vehicleshop:setVehicleOwnedPlayerId')
AddEventHandler('esx_vehicleshop:setVehicleOwnedPlayerId', function (playerId, vehicleProps)
  local xPlayer = ESX.GetPlayerFromId(playerId)

  MySQL.Async.execute(
    'INSERT INTO owned_vehicles (vehicle, owner) VALUES (@vehicle, @owner)',
    {
      ['@vehicle'] = json.encode(vehicleProps),
      ['@owner']   = xPlayer.identifier,
    },
    function (rowsChanged)
      TriggerClientEvent('esx:showNotification', playerId, _U('vehicle_belongs', vehicleProps.plate))
    end
  )
end)

I want to add it here.


#2

What exactly can’t you do?

Do you not know where to add it in that code?
Do you not know how to add a new column to a table in your database?


#3

Yes, but it doesn’t work
I create a column " model" in the owned_vehicles
add in the code this:
local hashVehicule = v.vehicle.model
local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
[’@model’] = vehicleName,
But it nothing. What is the right way?

RegisterServerEvent('esx_vehicleshop:setVehicleOwned')
AddEventHandler('esx_vehicleshop:setVehicleOwned', function (vehicleProps)
 local _source = source
 local xPlayer = ESX.GetPlayerFromId(source)
 local hashVehicule = v.vehicle.model
 local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
 
 MySQL.Async.execute(
   'INSERT INTO owned_vehicles (vehicle, owner, model) VALUES (@vehicle, @owner, @model)',
   {
     ['@vehicle'] = json.encode(vehicleProps),
     ['@owner']   = xPlayer.identifier,
     ['@model'] = vehicleName,
   },
   function (rowsChanged)
     TriggerClientEvent('esx:showNotification', _source, _U('vehicle').. vehicleProps.plate .. _('belongs'))
   end
 )
end)

RegisterServerEvent('esx_vehicleshop:setVehicleOwnedPlayerId')
AddEventHandler('esx_vehicleshop:setVehicleOwnedPlayerId', function (playerId, vehicleProps)
 local xPlayer = ESX.GetPlayerFromId(playerId)
 local hashVehicule = v.vehicle.model
 local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
 
 MySQL.Async.execute(
   'INSERT INTO owned_vehicles (vehicle, owner, model) VALUES (@vehicle, @owner, @model)',
   {
     ['@vehicle'] = json.encode(vehicleProps),
     ['@owner']   = xPlayer.identifier,
     ['@model'] = vehicleName
   },
   function (rowsChanged)
     TriggerClientEvent('esx:showNotification', playerId, _U('vehicle') .. vehicleProps.plate .. _('belongs'))
   end
 )
end)

RegisterServerEvent('esx_vehshopprice:buy')
AddEventHandler('esx_vehshopprice:buy', function ()
	local mysource = source
   local price = 4000
   local xPlayer  = ESX.GetPlayerFromId(source)
   

   	if(xPlayer.getMoney() >= price) then
   			xPlayer.removeMoney((price))
   			TriggerClientEvent('esx_vehicleshop:openPersonnalVehicleMenudva', mysource)
   				else
   		TriggerClientEvent('esx:showNotification', mysource, ('У вас нету денег'))
   	end
   	

end)


RegisterServerEvent('esx_vehicleshop:setVehicleOwnedSociety')
AddEventHandler('esx_vehicleshop:setVehicleOwnedSociety', function (society, vehicleProps)
 local _source = source
 local xPlayer = ESX.GetPlayerFromId(source)
 local hashVehicule = v.vehicle.model
 local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
 
 MySQL.Async.execute(
   'INSERT INTO owned_vehicles (vehicle, owner, model) VALUES (@vehicle, @owner, @model)',
   {
     ['@vehicle'] = json.encode(vehicleProps),
     ['@owner']   = 'society:' .. society,
     ['@model'] = vehicleName
   },
   function (rowsChanged)

   end
 )
end)

#4

what is wrong? (20 charters)


#5

where does v.vehicle.model come from? And is it actually a hash?


#6

That’s from esx_eden_garage


#7

may be this one from vehicle shop would be right?

local vehicleData = vehiclesByCategory[data.current.name][data.current.value + 1]