mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 02:08:55 +00:00
New helicopter system, Config re-write
This commit is contained in:
@@ -110,6 +110,84 @@ ESX.RegisterServerCallback('esx_ambulancejob:getItemAmount', function(source, cb
|
||||
cb(quantity)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_ambulancejob:buyJobVehicle', function(source, cb, vehicleProps)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local price = getPriceFromHash(vehicleProps.model, xPlayer.job.grade_name, 'heli')
|
||||
|
||||
-- vehicle model not found
|
||||
if price == 0 then
|
||||
print(('esx_ambulancejob: %s attempted to exploit the shop! (invalid vehicle model)'):format(xPlayer.identifier))
|
||||
cb(false)
|
||||
end
|
||||
|
||||
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'] = 'helicopter',
|
||||
['@job'] = xPlayer.job.name,
|
||||
['@stored'] = true
|
||||
}, function (rowsChanged)
|
||||
cb(true)
|
||||
end)
|
||||
else
|
||||
cb(false)
|
||||
end
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_ambulancejob:storeNearbyVehicle', function(source, cb, nearbyVehicles)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local foundPlate, foundNum
|
||||
|
||||
for k,v in ipairs(nearbyVehicles) do
|
||||
local result = MySQL.Sync.fetchAll('SELECT plate FROM owned_vehicles WHERE owner = @owner AND plate = @plate AND job = @job', {
|
||||
['@owner'] = xPlayer.identifier,
|
||||
['@plate'] = v.plate,
|
||||
['@job'] = xPlayer.job.name
|
||||
})
|
||||
|
||||
if result[1] then
|
||||
foundPlate, foundNum = result[1].plate, k
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not foundPlate then
|
||||
cb(false)
|
||||
else
|
||||
MySQL.Async.execute('UPDATE owned_vehicles SET stored = true WHERE owner = @owner AND plate = @plate AND job = @job', {
|
||||
['@owner'] = xPlayer.identifier,
|
||||
['@plate'] = foundPlate,
|
||||
['@job'] = xPlayer.job.name
|
||||
}, function (rowsChanged)
|
||||
if rowsChanged == 0 then
|
||||
print(('esx_ambulancejob: %s has exploited the garage!'):format(xPlayer.identifier))
|
||||
cb(false)
|
||||
else
|
||||
cb(true, foundNum)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
function getPriceFromHash(hashKey, jobGrade, type)
|
||||
if type == 'heli' then
|
||||
local vehicles = Config.AuthorizedHelicopters[jobGrade]
|
||||
|
||||
for k,v in ipairs(vehicles) do
|
||||
if GetHashKey(v.model) == hashKey then
|
||||
return v.price
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
RegisterServerEvent('esx_ambulancejob:removeItem')
|
||||
AddEventHandler('esx_ambulancejob:removeItem', function(item)
|
||||
local _source = source
|
||||
|
||||
Reference in New Issue
Block a user