mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 02:08:55 +00:00
52 lines
1.3 KiB
Lua
52 lines
1.3 KiB
Lua
ESX = nil
|
|
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
|
local Vehicles = nil
|
|
|
|
RegisterServerEvent('esx_lscustom:buyMod')
|
|
AddEventHandler('esx_lscustom:buyMod', function(price)
|
|
local _source = source
|
|
local xPlayer = ESX.GetPlayerFromId(_source)
|
|
price = tonumber(price)
|
|
if price > xPlayer.getMoney() then
|
|
TriggerClientEvent('esx_lscustom:cancelInstallMod', _source)
|
|
TriggerClientEvent('esx:showNotification', _source, _U('not_enough_money'))
|
|
else
|
|
xPlayer.removeMoney(price)
|
|
TriggerClientEvent('esx_lscustom:installMod', _source)
|
|
TriggerClientEvent('esx:showNotification', _source, _U('purchased'))
|
|
end
|
|
end)
|
|
|
|
RegisterServerEvent('esx_lscustom:refreshOwnedVehicle')
|
|
AddEventHandler('esx_lscustom:refreshOwnedVehicle', function(myCar)
|
|
|
|
MySQL.Async.execute(
|
|
'UPDATE `owned_vehicles` SET `vehicle` = @vehicle WHERE `vehicle` LIKE "%' .. myCar['plate'] .. '%"',
|
|
{
|
|
['@vehicle'] = json.encode(myCar)
|
|
}
|
|
)
|
|
end)
|
|
|
|
ESX.RegisterServerCallback('esx_lscustom:getVehiclesPrices', function(source, cb)
|
|
|
|
if Vehicles == nil then
|
|
MySQL.Async.fetchAll(
|
|
'SELECT * FROM vehicles',
|
|
{},
|
|
function(result)
|
|
local vehicles = {}
|
|
for i=1, #result, 1 do
|
|
table.insert(vehicles,{
|
|
model = result[i].model,
|
|
price = result[i].price
|
|
})
|
|
end
|
|
Vehicles = vehicles
|
|
cb(Vehicles)
|
|
end
|
|
)
|
|
else
|
|
cb(Vehicles)
|
|
end
|
|
end) |