mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 18:28:52 +00:00
Completed server-sided code, and fixed serious caution flaws
This commit is contained in:
@@ -38,7 +38,7 @@ start esx_jobs
|
||||
### License
|
||||
esx_jobs - jobs
|
||||
|
||||
Copyright (C) 2015-2018 Jérémie N'gadi
|
||||
Copyright (C) 2015-2019 Jérémie N'gadi
|
||||
|
||||
This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.
|
||||
|
||||
|
||||
+18
-7
@@ -12,6 +12,15 @@ server_scripts {
|
||||
'locales/fr.lua',
|
||||
'locales/sv.lua',
|
||||
'config.lua',
|
||||
|
||||
'jobs/fisherman.lua',
|
||||
'jobs/fueler.lua',
|
||||
'jobs/lumberjack.lua',
|
||||
'jobs/miner.lua',
|
||||
'jobs/reporter.lua',
|
||||
'jobs/slaughterer.lua',
|
||||
'jobs/tailor.lua',
|
||||
|
||||
'server/main.lua'
|
||||
}
|
||||
|
||||
@@ -23,13 +32,15 @@ client_scripts {
|
||||
'locales/fr.lua',
|
||||
'locales/sv.lua',
|
||||
'config.lua',
|
||||
'client/jobs/fisherman.lua',
|
||||
'client/jobs/fueler.lua',
|
||||
'client/jobs/lumberjack.lua',
|
||||
'client/jobs/miner.lua',
|
||||
'client/jobs/reporter.lua',
|
||||
'client/jobs/slaughterer.lua',
|
||||
'client/jobs/tailor.lua',
|
||||
|
||||
'jobs/fisherman.lua',
|
||||
'jobs/fueler.lua',
|
||||
'jobs/lumberjack.lua',
|
||||
'jobs/miner.lua',
|
||||
'jobs/reporter.lua',
|
||||
'jobs/slaughterer.lua',
|
||||
'jobs/tailor.lua',
|
||||
|
||||
'client/main.lua'
|
||||
}
|
||||
|
||||
|
||||
+23
-26
@@ -1,5 +1,5 @@
|
||||
local menuIsShowed, hintIsShowed, hintToDisplay, hasAlreadyEnteredMarker, isInMarker, onDuty, vehicleObjInCaseofDrop, vehicleInCaseofDrop, vehicleMaxHealth
|
||||
local PlayerData, Blips, JobBlips, myPlate, spawner = {}, {}, {}, {}, 0
|
||||
local menuIsShowed, hintIsShowed, hintToDisplay, hasAlreadyEnteredMarker, isInMarker, vehicleObjInCaseofDrop, vehicleInCaseofDrop, vehicleMaxHealth
|
||||
local PlayerData, Blips, JobBlips, myPlate, onDuty, spawner = {}, {}, {}, {}, false, 0
|
||||
|
||||
ESX = nil
|
||||
|
||||
@@ -55,7 +55,7 @@ function OpenMenu()
|
||||
end)
|
||||
end
|
||||
|
||||
AddEventHandler('esx_jobs:action', function(job, zone)
|
||||
AddEventHandler('esx_jobs:action', function(job, zone, zoneIndex)
|
||||
menuIsShowed = true
|
||||
if zone.Type == 'cloakroom' then
|
||||
OpenMenu()
|
||||
@@ -65,7 +65,7 @@ AddEventHandler('esx_jobs:action', function(job, zone)
|
||||
local playerPed = PlayerPedId()
|
||||
|
||||
if IsPedOnFoot(playerPed) then
|
||||
TriggerServerEvent('esx_jobs:startWork', zone.Item)
|
||||
TriggerServerEvent('esx_jobs:startWork', zoneIndex)
|
||||
else
|
||||
ESX.ShowNotification(_U('foot_work'))
|
||||
end
|
||||
@@ -150,7 +150,7 @@ AddEventHandler('esx_jobs:action', function(job, zone)
|
||||
|
||||
hintToDisplay = nil
|
||||
hintIsShowed = false
|
||||
TriggerServerEvent('esx_jobs:startWork', zone.Item)
|
||||
TriggerServerEvent('esx_jobs:startWork', zoneIndex)
|
||||
end
|
||||
|
||||
--nextStep(zone.GPS)
|
||||
@@ -195,28 +195,25 @@ function deleteBlips()
|
||||
end
|
||||
|
||||
function refreshBlips()
|
||||
local zones = {}
|
||||
local blipInfo = {}
|
||||
|
||||
if PlayerData.job then
|
||||
for jobKey,jobValues in pairs(Config.Jobs) do
|
||||
local jobObject = Config.Jobs[PlayerData.job.name]
|
||||
|
||||
if jobKey == PlayerData.job.name then
|
||||
for zoneKey,zoneValues in pairs(jobValues.Zones) do
|
||||
if jobObject then
|
||||
for k,v in pairs(jobObject.Zones) do
|
||||
if v.Blip then
|
||||
local blip = AddBlipForCoord(v.Pos.x, v.Pos.y, v.Pos.z)
|
||||
|
||||
if zoneValues.Blip then
|
||||
local blip = AddBlipForCoord(zoneValues.Pos.x, zoneValues.Pos.y, zoneValues.Pos.z)
|
||||
SetBlipSprite (blip, jobValues.BlipInfos.Sprite)
|
||||
SetBlipScale (blip, 1.2)
|
||||
SetBlipCategory(blip, 3)
|
||||
SetBlipColour (blip, jobValues.BlipInfos.Color)
|
||||
SetBlipAsShortRange(blip, true)
|
||||
SetBlipSprite (blip, jobObject.BlipInfos.Sprite)
|
||||
SetBlipScale (blip, 1.2)
|
||||
SetBlipCategory(blip, 3)
|
||||
SetBlipColour (blip, jobObject.BlipInfos.Color)
|
||||
SetBlipAsShortRange(blip, true)
|
||||
|
||||
BeginTextCommandSetBlipName('STRING')
|
||||
AddTextComponentSubstringPlayerName(zoneValues.Name)
|
||||
EndTextCommandSetBlipName(blip)
|
||||
table.insert(JobBlips, blip)
|
||||
end
|
||||
BeginTextCommandSetBlipName('STRING')
|
||||
AddTextComponentSubstringPlayerName(v.Name)
|
||||
EndTextCommandSetBlipName(blip)
|
||||
|
||||
table.insert(JobBlips, blip)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -273,7 +270,7 @@ end)
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
local zones, currentZone, isInMarker = {}
|
||||
local zones, currentZone, currentZoneIndex, isInMarker = {}
|
||||
local letSleep, playerPed = true, PlayerPedId()
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
|
||||
@@ -293,14 +290,14 @@ Citizen.CreateThread(function()
|
||||
end
|
||||
|
||||
if distance < v.Size.x then
|
||||
letSleep, isInMarker, currentZone = false, true, v
|
||||
letSleep, isInMarker, currentZone, currentZoneIndex = false, true, v, k
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if IsControlJustReleased(0, 38) and not menuIsShowed and isInMarker then
|
||||
if onDuty or currentZone.Type == 'cloakroom' or PlayerData.job.name == 'reporter' then
|
||||
TriggerEvent('esx_jobs:action', PlayerData.job.name, currentZone)
|
||||
TriggerEvent('esx_jobs:action', PlayerData.job.name, currentZone, currentZoneIndex)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ Config.DrawDistance = 100.0
|
||||
Config.Locale = 'fr'
|
||||
Config.Jobs = {}
|
||||
|
||||
Config.MaxCaution = 10000 -- the max caution allowed
|
||||
|
||||
Config.PublicZones = {
|
||||
|
||||
EnterBuilding = {
|
||||
|
||||
@@ -51,7 +51,7 @@ Config.Jobs.fisherman = {
|
||||
{
|
||||
name = _U('fm_fish'),
|
||||
db_name= 'fish',
|
||||
time = 2000,
|
||||
time = 2,
|
||||
max = 100,
|
||||
add = 1,
|
||||
remove = 1,
|
||||
@@ -160,7 +160,7 @@ Config.Jobs.fisherman = {
|
||||
Item = {
|
||||
{
|
||||
name = _U('delivery'),
|
||||
time = 500,
|
||||
time = 0.5,
|
||||
remove = 1,
|
||||
max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua
|
||||
price = 11,
|
||||
@@ -42,7 +42,7 @@ Config.Jobs.fueler = {
|
||||
{
|
||||
name = _U('f_fuel'),
|
||||
db_name = 'petrol',
|
||||
time = 5000,
|
||||
time = 5,
|
||||
max = 24,
|
||||
add = 1,
|
||||
remove = 1,
|
||||
@@ -67,7 +67,7 @@ Config.Jobs.fueler = {
|
||||
{
|
||||
name = _U('f_fuel_refine'),
|
||||
db_name = 'petrol_raffin',
|
||||
time = 5000,
|
||||
time = 5,
|
||||
max = 24,
|
||||
add = 1,
|
||||
remove = 2,
|
||||
@@ -92,7 +92,7 @@ Config.Jobs.fueler = {
|
||||
{
|
||||
name = _U('f_gas'),
|
||||
db_name = 'essence',
|
||||
time = 5000,
|
||||
time = 5,
|
||||
max = 24,
|
||||
add = 2,
|
||||
remove = 1,
|
||||
@@ -158,7 +158,7 @@ Config.Jobs.fueler = {
|
||||
Item = {
|
||||
{
|
||||
name = _U('delivery'),
|
||||
time = 500,
|
||||
time = 0.5,
|
||||
remove = 1,
|
||||
max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua
|
||||
price = 61,
|
||||
@@ -41,7 +41,7 @@ Config.Jobs.lumberjack = {
|
||||
{
|
||||
name = _U('lj_wood'),
|
||||
db_name = 'wood',
|
||||
time = 3000,
|
||||
time = 3,
|
||||
max = 20,
|
||||
add = 1,
|
||||
remove = 1,
|
||||
@@ -65,7 +65,7 @@ Config.Jobs.lumberjack = {
|
||||
{
|
||||
name = _U('lj_cutwood'),
|
||||
db_name = 'cutted_wood',
|
||||
time = 5000,
|
||||
time = 5,
|
||||
max = 20,
|
||||
add = 1,
|
||||
remove = 1,
|
||||
@@ -89,7 +89,7 @@ Config.Jobs.lumberjack = {
|
||||
{
|
||||
name = _U('lj_planks'),
|
||||
db_name = 'packaged_plank',
|
||||
time = 4000,
|
||||
time = 4,
|
||||
max = 100,
|
||||
add = 5,
|
||||
remove = 1,
|
||||
@@ -152,7 +152,7 @@ Config.Jobs.lumberjack = {
|
||||
Item = {
|
||||
{
|
||||
name = _U('delivery'),
|
||||
time = 500,
|
||||
time = 0.5,
|
||||
remove = 1,
|
||||
max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua
|
||||
price = 13,
|
||||
@@ -42,7 +42,7 @@ Config.Jobs.miner = {
|
||||
{
|
||||
name = _U('m_rock'),
|
||||
db_name = 'stone',
|
||||
time = 3000,
|
||||
time = 3,
|
||||
max = 7,
|
||||
add = 1,
|
||||
remove = 1,
|
||||
@@ -67,7 +67,7 @@ Config.Jobs.miner = {
|
||||
{
|
||||
name = _U('m_washrock'),
|
||||
db_name = 'washed_stone',
|
||||
time = 5000,
|
||||
time = 5,
|
||||
max = 7,
|
||||
add = 1,
|
||||
remove = 1,
|
||||
@@ -92,7 +92,7 @@ Config.Jobs.miner = {
|
||||
{
|
||||
name = _U('m_copper'),
|
||||
db_name = 'copper',
|
||||
time = 4000,
|
||||
time = 4,
|
||||
max = 56,
|
||||
add = 8,
|
||||
remove = 1,
|
||||
@@ -179,7 +179,7 @@ Config.Jobs.miner = {
|
||||
Item = {
|
||||
{
|
||||
name = _U('delivery'),
|
||||
time = 500,
|
||||
time = 0.5,
|
||||
remove = 1,
|
||||
max = 56, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua
|
||||
price = 5,
|
||||
@@ -205,7 +205,7 @@ Config.Jobs.miner = {
|
||||
Item = {
|
||||
{
|
||||
name = _U('delivery'),
|
||||
time = 500,
|
||||
time = 0.5,
|
||||
remove = 1,
|
||||
max = 42, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua
|
||||
price = 9,
|
||||
@@ -231,7 +231,7 @@ Config.Jobs.miner = {
|
||||
Item = {
|
||||
{
|
||||
name = _U('delivery'),
|
||||
time = 500,
|
||||
time = 0.5,
|
||||
remove = 1,
|
||||
max = 21, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua
|
||||
price = 25,
|
||||
@@ -257,7 +257,7 @@ Config.Jobs.miner = {
|
||||
Item = {
|
||||
{
|
||||
name = _U('delivery'),
|
||||
time = 500,
|
||||
time = 0.5,
|
||||
remove = 1,
|
||||
max = 50, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua
|
||||
price = 250,
|
||||
@@ -40,7 +40,7 @@ Config.Jobs.slaughterer = {
|
||||
{
|
||||
name = _U('s_alive_chicken'),
|
||||
db_name = 'alive_chicken',
|
||||
time = 3000,
|
||||
time = 3,
|
||||
max = 20,
|
||||
add = 1,
|
||||
remove = 1,
|
||||
@@ -64,7 +64,7 @@ Config.Jobs.slaughterer = {
|
||||
{
|
||||
name = _U('s_slaughtered_chicken'),
|
||||
db_name = 'slaughtered_chicken',
|
||||
time = 5000,
|
||||
time = 5,
|
||||
max = 20,
|
||||
add = 1,
|
||||
remove = 1,
|
||||
@@ -88,7 +88,7 @@ Config.Jobs.slaughterer = {
|
||||
{
|
||||
name = _U('s_packagechicken'),
|
||||
db_name = 'packaged_chicken',
|
||||
time = 4000,
|
||||
time = 4,
|
||||
max = 100,
|
||||
add = 5,
|
||||
remove = 1,
|
||||
@@ -151,7 +151,7 @@ Config.Jobs.slaughterer = {
|
||||
Item = {
|
||||
{
|
||||
name = _U('delivery'),
|
||||
time = 500,
|
||||
time = 0.5,
|
||||
remove = 1,
|
||||
max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua
|
||||
price = 23,
|
||||
@@ -42,7 +42,7 @@ Config.Jobs.tailor = {
|
||||
{
|
||||
name = _U('dd_wool'),
|
||||
db_name = 'wool',
|
||||
time = 3000,
|
||||
time = 3,
|
||||
max = 40,
|
||||
add = 1,
|
||||
remove = 1,
|
||||
@@ -67,7 +67,7 @@ Config.Jobs.tailor = {
|
||||
{
|
||||
name = _U('dd_fabric'),
|
||||
db_name = 'fabric',
|
||||
time = 5000,
|
||||
time = 5,
|
||||
max = 80,
|
||||
add = 2,
|
||||
remove = 1,
|
||||
@@ -92,7 +92,7 @@ Config.Jobs.tailor = {
|
||||
{
|
||||
name = _U('dd_clothing'),
|
||||
db_name = 'clothe',
|
||||
time = 4000,
|
||||
time = 4,
|
||||
max = 40,
|
||||
add = 1,
|
||||
remove = 2,
|
||||
@@ -158,7 +158,7 @@ Config.Jobs.tailor = {
|
||||
Item = {
|
||||
{
|
||||
name = _U('delivery'),
|
||||
time = 500,
|
||||
time = 0.5,
|
||||
remove = 1,
|
||||
max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua
|
||||
price = 40,
|
||||
@@ -6,6 +6,7 @@ Locales['br'] = {
|
||||
['job_wear'] = 'colocar uniforme',
|
||||
['bank_deposit_returned'] = 'um depósito de segurança de ~g~$%s~s~ foi devolvido a você.',
|
||||
['bank_deposit_taken'] = 'um depósito de segurança de ~g~$%s~s~ foi tirado de você.',
|
||||
['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~',
|
||||
['foot_work'] = 'você deve estar a pé para poder trabalhar.',
|
||||
['next_point'] = 'vá para o próximo passo depois de completar este.',
|
||||
['not_your_vehicle'] = 'este não é o seu veículo ou você deve ser um motorista.',
|
||||
|
||||
@@ -6,6 +6,7 @@ Locales['en'] = {
|
||||
['job_wear'] = 'workers clothes',
|
||||
['bank_deposit_returned'] = 'a security deposit of ~g~$%s~s~ was returned to you.',
|
||||
['bank_deposit_taken'] = 'a security deposit of ~r~$%s~s~ was taken from you.',
|
||||
['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~',
|
||||
['foot_work'] = 'you have to be on foot to be able to work.',
|
||||
['next_point'] = 'go to the next step after completing this one.',
|
||||
['not_your_vehicle'] = 'you are not the driver of this vehicle.',
|
||||
|
||||
@@ -6,6 +6,7 @@ Locales['fi'] = {
|
||||
['job_wear'] = 'työvaatteet',
|
||||
['bank_deposit_returned'] = 'vakuuden summa ~g~€%s~s~ palautettiin sinulle.',
|
||||
['bank_deposit_taken'] = 'vakuuden summa ~r~€%s~s~ otettiin sinulta.',
|
||||
['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~',
|
||||
['foot_work'] = 'sinun täytyy olla jalan, jotta voit työskennellä',
|
||||
['next_point'] = 'mene seuraavaan pisteeseen kun olet valmis täällä',
|
||||
['not_your_vehicle'] = 'tämä ei ole sinun ajoneuvo tai et ole sen kuski',
|
||||
|
||||
@@ -6,6 +6,7 @@ Locales['fr'] = {
|
||||
['job_wear'] = 'tenue de travail',
|
||||
['bank_deposit_returned'] = 'une caution de ~g~$%s~s~ vous a été rendue.',
|
||||
['bank_deposit_taken'] = 'une caution de ~g~$%s~s~ vous a été prélevée.',
|
||||
['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~',
|
||||
['foot_work'] = 'vous devez être à pied pour pouvoir travailler.',
|
||||
['next_point'] = 'rendez-vous à la prochaine étape après avoir complété celle-ci.',
|
||||
['not_your_vehicle'] = 'ce n\'est pas votre véhicule ou vous devez être conducteur.',
|
||||
|
||||
@@ -6,6 +6,7 @@ Locales['sv'] = {
|
||||
['job_wear'] = 'arbetskläder',
|
||||
['bank_deposit_returned'] = 'en deposition på ~g~%s SEK~s~ har återvänts till dig.',
|
||||
['bank_deposit_taken'] = 'en deposition på ~r~%s SEK~s~ togs från dig.',
|
||||
['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~',
|
||||
['foot_work'] = 'du måste vara till fots för att kunna arbeta.',
|
||||
['next_point'] = 'gå till nästa steg efter att du har avslutat här.',
|
||||
['not_your_vehicle'] = 'det här är inte ditt fordon eller så måste du vara föraren.',
|
||||
|
||||
+107
-73
@@ -1,105 +1,139 @@
|
||||
local PlayersWorking = {}
|
||||
local playersWorking = {}
|
||||
|
||||
ESX = nil
|
||||
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
local function Work(source, item)
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(1000)
|
||||
local timeNow = os.clock()
|
||||
|
||||
SetTimeout(item[1].time, function()
|
||||
for playerId,data in pairs(playersWorking) do
|
||||
Citizen.Wait(10)
|
||||
local xPlayer = ESX.GetPlayerFromId(playerId)
|
||||
|
||||
if PlayersWorking[source] == true then
|
||||
-- is player still online?
|
||||
if xPlayer then
|
||||
local distance = #(xPlayer.getCoords(true) - data.zoneCoords)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
if xPlayer == nil then
|
||||
return
|
||||
end
|
||||
-- player still within zone limits?
|
||||
if distance <= data.zoneMaxDistance then
|
||||
-- calculate the elapsed time
|
||||
local timeElapsed = timeNow - data.time
|
||||
|
||||
for i=1, #item, 1 do
|
||||
local itemQtty = 0
|
||||
if item[i].name ~= _U('delivery') then
|
||||
itemQtty = xPlayer.getInventoryItem(item[i].db_name).count
|
||||
end
|
||||
if timeElapsed > data.jobItem[1].time then
|
||||
data.time = os.clock()
|
||||
|
||||
local requiredItemQtty = 0
|
||||
if item[1].requires ~= 'nothing' then
|
||||
requiredItemQtty = xPlayer.getInventoryItem(item[1].requires).count
|
||||
end
|
||||
for k,v in ipairs(data.jobItem) do
|
||||
local itemQtty, requiredItemQtty = 0, 0
|
||||
|
||||
if item[i].name ~= _U('delivery') and itemQtty >= item[i].max then
|
||||
xPlayer.showNotification(_U('max_limit', item[i].name))
|
||||
elseif item[i].requires ~= 'nothing' and requiredItemQtty <= 0 then
|
||||
xPlayer.showNotification(_U('not_enough', item[1].requires_name))
|
||||
else
|
||||
if item[i].name ~= _U('delivery') then
|
||||
-- Chances to drop the item
|
||||
if item[i].drop == 100 then
|
||||
xPlayer.addInventoryItem(item[i].db_name, item[i].add)
|
||||
else
|
||||
local chanceToDrop = math.random(100)
|
||||
if chanceToDrop <= item[i].drop then
|
||||
xPlayer.addInventoryItem(item[i].db_name, item[i].add)
|
||||
if v.name ~= _U('delivery') then
|
||||
itemQtty = xPlayer.getInventoryItem(v.db_name).count
|
||||
end
|
||||
|
||||
if data.jobItem[1].requires ~= 'nothing' then
|
||||
requiredItemQtty = xPlayer.getInventoryItem(data.jobItem[1].requires).count
|
||||
end
|
||||
|
||||
if v.name ~= _U('delivery') and itemQtty >= v.max then
|
||||
xPlayer.showNotification(_U('max_limit', v.name))
|
||||
playersWorking[playerId] = nil
|
||||
elseif v.requires ~= 'nothing' and requiredItemQtty <= 0 then
|
||||
xPlayer.showNotification(_U('not_enough', data.jobItem[1].requires_name))
|
||||
playersWorking[playerId] = nil
|
||||
else
|
||||
if v.name ~= _U('delivery') then
|
||||
-- chances to drop the item
|
||||
if v.drop == 100 then
|
||||
xPlayer.addInventoryItem(v.db_name, v.add)
|
||||
else
|
||||
local chanceToDrop = math.random(100)
|
||||
if chanceToDrop <= v.drop then
|
||||
xPlayer.addInventoryItem(v.db_name, v.add)
|
||||
end
|
||||
end
|
||||
else
|
||||
xPlayer.addMoney(v.price)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if data.jobItem[1].requires ~= 'nothing' then
|
||||
local itemToRemoveQtty = xPlayer.getInventoryItem(data.jobItem[1].requires).count
|
||||
if itemToRemoveQtty > 0 then
|
||||
xPlayer.removeInventoryItem(data.jobItem[1].requires, data.jobItem[1].remove)
|
||||
end
|
||||
end
|
||||
else
|
||||
xPlayer.addMoney(item[i].price)
|
||||
end
|
||||
else
|
||||
playersWorking[playerId] = nil
|
||||
end
|
||||
else
|
||||
playersWorking[playerId] = nil
|
||||
end
|
||||
|
||||
if item[1].requires ~= 'nothing' then
|
||||
local itemToRemoveQtty = xPlayer.getInventoryItem(item[1].requires).count
|
||||
if itemToRemoveQtty > 0 then
|
||||
xPlayer.removeInventoryItem(item[1].requires, item[1].remove)
|
||||
end
|
||||
end
|
||||
|
||||
Work(source, item)
|
||||
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_jobs:startWork')
|
||||
AddEventHandler('esx_jobs:startWork', function(item)
|
||||
if not PlayersWorking[source] then
|
||||
PlayersWorking[source] = true
|
||||
Work(source, item)
|
||||
else
|
||||
print(('esx_jobs: %s attempted to exploit the marker!'):format(GetPlayerIdentifiers(source)[1]))
|
||||
AddEventHandler('esx_jobs:startWork', function(zoneIndex)
|
||||
if not playersWorking[source] then
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
if xPlayer then
|
||||
local jobObject = Config.Jobs[xPlayer.job.name]
|
||||
|
||||
if jobObject then
|
||||
local jobZone = jobObject.Zones[zoneIndex]
|
||||
|
||||
if jobZone and jobZone.Item then
|
||||
playersWorking[source] = {
|
||||
jobItem = jobZone.Item,
|
||||
zoneCoords = vector3(jobZone.Pos.x, jobZone.Pos.y, jobZone.Pos.z),
|
||||
zoneMaxDistance = jobZone.Size.x,
|
||||
time = os.clock()
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_jobs:stopWork')
|
||||
AddEventHandler('esx_jobs:stopWork', function()
|
||||
PlayersWorking[source] = false
|
||||
if playersWorking[source] then
|
||||
playersWorking[source] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_jobs:caution')
|
||||
RegisterNetEvent('esx_jobs:caution')
|
||||
AddEventHandler('esx_jobs:caution', function(cautionType, cautionAmount, spawnPoint, vehicle)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
if cautionType == 'take' then
|
||||
TriggerEvent('esx_addonaccount:getAccount', 'caution', xPlayer.identifier, function(account)
|
||||
xPlayer.removeAccountMoney('bank', cautionAmount)
|
||||
account.addMoney(cautionAmount)
|
||||
end)
|
||||
|
||||
xPlayer.showNotification(_U('bank_deposit_taken', ESX.Math.GroupDigits(cautionAmount)))
|
||||
TriggerClientEvent('esx_jobs:spawnJobVehicle', source, spawnPoint, vehicle)
|
||||
elseif cautionType == 'give_back' then
|
||||
|
||||
if cautionAmount > 1 then
|
||||
print(('esx_jobs: %s is using cheat engine!'):format(xPlayer.identifier))
|
||||
return
|
||||
if cautionAmount <= Config.MaxCaution and cautionAmount > 0 then
|
||||
TriggerEvent('esx_addonaccount:getAccount', 'caution', xPlayer.identifier, function(account)
|
||||
if xPlayer.getAccount('bank').money >= cautionAmount then
|
||||
xPlayer.removeAccountMoney('bank', cautionAmount)
|
||||
account.addMoney(cautionAmount)
|
||||
xPlayer.showNotification(_U('bank_deposit_taken', ESX.Math.GroupDigits(cautionAmount)))
|
||||
TriggerClientEvent('esx_jobs:spawnJobVehicle', xPlayer.source, spawnPoint, vehicle)
|
||||
else
|
||||
xPlayer.showNotification(_U('caution_afford', ESX.Math.GroupDigits(cautionAmount)))
|
||||
end
|
||||
end)
|
||||
end
|
||||
elseif cautionType == 'give_back' then
|
||||
if cautionAmount <= 1 and cautionAmount > 0 then
|
||||
TriggerEvent('esx_addonaccount:getAccount', 'caution', xPlayer.identifier, function(account)
|
||||
local caution = account.money
|
||||
local toGive = ESX.Math.Round(caution * cautionAmount)
|
||||
|
||||
xPlayer.addAccountMoney('bank', toGive)
|
||||
account.removeMoney(toGive)
|
||||
TriggerClientEvent('esx:showNotification', source, _U('bank_deposit_returned', ESX.Math.GroupDigits(toGive)))
|
||||
end)
|
||||
end
|
||||
|
||||
TriggerEvent('esx_addonaccount:getAccount', 'caution', xPlayer.identifier, function(account)
|
||||
local caution = account.money
|
||||
local toGive = ESX.Math.Round(caution * cautionAmount)
|
||||
|
||||
xPlayer.addAccountMoney('bank', toGive)
|
||||
account.removeMoney(toGive)
|
||||
xPlayer.showNotification(_U('bank_deposit_returned', ESX.Math.GroupDigits(toGive)))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user