Skip to content

Instantly share code, notes, and snippets.

@FiveEYZ
Created May 10, 2020 12:52
Show Gist options
  • Save FiveEYZ/00fdf51d8591f4cd580533afbf8fb3c8 to your computer and use it in GitHub Desktop.
Save FiveEYZ/00fdf51d8591f4cd580533afbf8fb3c8 to your computer and use it in GitHub Desktop.
ESX.RegisterServerCallback('esx_policejob:buyJobVehicle', function(source, cb, vehicleProps, type)
local xPlayer = ESX.GetPlayerFromId(source)
local price = getPriceFromHash(vehicleProps.model, xPlayer.job.grade_name, type)
-- vehicle model not found
if xPlayer.job.grade_name ~= 'boss' then
if price == 0 then
print(('esx_policejob: %s attempted to exploit the shop! (invalid vehicle model)'):format(xPlayer.identifier))
cb(false)
else
if xPlayer.getMoney() >= price then
xPlayer.removeMoney(price)
MySQL.Async.execute('INSERT INTO owned_vehicles (owner, vehicle, plate, type, job, `stored`) VALUES (@owner, @vehicle, @plate, @type, @job, @stored)', {
['@owner'] = xPlayer.identifier,
['@vehicle'] = json.encode(vehicleProps),
['@plate'] = vehicleProps.plate,
['@type'] = type,
['@job'] = xPlayer.job.name,
['@stored'] = true
}, function (rowsChanged)
cb(true)
end)
TriggerEvent('shorty_slocks:transferOwner', vehicleProps.plate, source)
else
cb(false)
end
end
else
if xPlayer.getMoney() >= price then
xPlayer.removeMoney(price)
MySQL.Async.execute('INSERT INTO owned_vehicles (owner, vehicle, plate, type, job, `stored`) VALUES (@owner, @vehicle, @plate, @type, @job, @stored)', {
['@owner'] = xPlayer.identifier,
['@vehicle'] = json.encode(vehicleProps),
['@plate'] = vehicleProps.plate,
['@type'] = type,
['@job'] = xPlayer.job.name,
['@stored'] = true
}, function (rowsChanged)
cb(true)
end)
TriggerEvent('shorty_slocks:transferOwner', vehicleProps.plate, source)
else
cb(false)
end
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment