diff --git a/README.md b/README.md index 6f27877a..ca7a1d38 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ git clone https://github.com/ESX-Org/esx_mecanojob [esx]/esx_mecanojob - Download https://github.com/ESX-Org/esx_mecanojob/archive/master.zip - Put it in the `[esx]` directory - ## Installation - Import `esx_mecanojob.sql` in your database - If you want player management you have to set `Config.EnablePlayerManagement` to `true` in `config.lua` diff --git a/client/main.lua b/client/main.lua index df823fc7..b3e58a14 100644 --- a/client/main.lua +++ b/client/main.lua @@ -16,7 +16,6 @@ local LastZone = nil local CurrentAction = nil local CurrentActionMsg = '' local CurrentActionData = {} -local OnJob = false local CurrentlyTowedVehicle = nil local Blips = {} local NPCOnJob = false @@ -36,375 +35,320 @@ Citizen.CreateThread(function() TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Citizen.Wait(0) end - + Citizen.Wait(5000) PlayerData = ESX.GetPlayerData() end) function SelectRandomTowable() + local index = GetRandomIntInRange(1, #Config.Towables) - local index = GetRandomIntInRange(1, #Config.Towables) - - for k,v in pairs(Config.Zones) do - if v.Pos.x == Config.Towables[index].x and v.Pos.y == Config.Towables[index].y and v.Pos.z == Config.Towables[index].z then - return k - end - end - + for k,v in pairs(Config.Zones) do + if v.Pos.x == Config.Towables[index].x and v.Pos.y == Config.Towables[index].y and v.Pos.z == Config.Towables[index].z then + return k + end + end end function StartNPCJob() + NPCOnJob = true - NPCOnJob = true + NPCTargetTowableZone = SelectRandomTowable() + local zone = Config.Zones[NPCTargetTowableZone] - NPCTargetTowableZone = SelectRandomTowable() - local zone = Config.Zones[NPCTargetTowableZone] + Blips['NPCTargetTowableZone'] = AddBlipForCoord(zone.Pos.x, zone.Pos.y, zone.Pos.z) + SetBlipRoute(Blips['NPCTargetTowableZone'], true) - Blips['NPCTargetTowableZone'] = AddBlipForCoord(zone.Pos.x, zone.Pos.y, zone.Pos.z) - SetBlipRoute(Blips['NPCTargetTowableZone'], true) - - ESX.ShowNotification(_U('drive_to_indicated')) + ESX.ShowNotification(_U('drive_to_indicated')) end function StopNPCJob(cancel) + if Blips['NPCTargetTowableZone'] ~= nil then + RemoveBlip(Blips['NPCTargetTowableZone']) + Blips['NPCTargetTowableZone'] = nil + end - if Blips['NPCTargetTowableZone'] ~= nil then - RemoveBlip(Blips['NPCTargetTowableZone']) - Blips['NPCTargetTowableZone'] = nil - end + if Blips['NPCDelivery'] ~= nil then + RemoveBlip(Blips['NPCDelivery']) + Blips['NPCDelivery'] = nil + end - if Blips['NPCDelivery'] ~= nil then - RemoveBlip(Blips['NPCDelivery']) - Blips['NPCDelivery'] = nil - end + Config.Zones.VehicleDelivery.Type = -1 + NPCOnJob = false + NPCTargetTowable = nil + NPCTargetTowableZone = nil + NPCHasSpawnedTowable = false + NPCHasBeenNextToTowable = false - Config.Zones.VehicleDelivery.Type = -1 - - NPCOnJob = false - NPCTargetTowable = nil - NPCTargetTowableZone = nil - NPCHasSpawnedTowable = false - NPCHasBeenNextToTowable = false - - if cancel then - ESX.ShowNotification(_U('mission_canceled')) - else - TriggerServerEvent('esx_mecanojob:onNPCJobCompleted') - end - + if cancel then + ESX.ShowNotification(_U('mission_canceled')) + else + --TriggerServerEvent('esx_mecanojob:onNPCJobCompleted') + end end function OpenMecanoActionsMenu() - local elements = { - {label = _U('vehicle_list'), value = 'vehicle_list'}, - {label = _U('work_wear'), value = 'cloakroom'}, - {label = _U('civ_wear'), value = 'cloakroom2'}, - {label = _U('deposit_stock'), value = 'put_stock'}, - {label = _U('withdraw_stock'), value = 'get_stock'} - } - if Config.EnablePlayerManagement and PlayerData.job ~= nil and PlayerData.job.grade_name == 'boss' then - table.insert(elements, {label = _U('boss_actions'), value = 'boss_actions'}) - end + local elements = { + {label = _U('vehicle_list'), value = 'vehicle_list'}, + {label = _U('work_wear'), value = 'cloakroom'}, + {label = _U('civ_wear'), value = 'cloakroom2'}, + {label = _U('deposit_stock'), value = 'put_stock'}, + {label = _U('withdraw_stock'), value = 'get_stock'} + } - ESX.UI.Menu.CloseAll() + if Config.EnablePlayerManagement and PlayerData.job ~= nil and PlayerData.job.grade_name == 'boss' then + table.insert(elements, {label = _U('boss_actions'), value = 'boss_actions'}) + end - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'mecano_actions', - { - title = _U('mechanic'), - align = 'top-left', - elements = elements - }, - function(data, menu) - if data.current.value == 'vehicle_list' then + ESX.UI.Menu.CloseAll() - if Config.EnableSocietyOwnedVehicles then + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'mecano_actions', { + title = _U('mechanic'), + align = 'top-left', + elements = elements + }, function(data, menu) + if data.current.value == 'vehicle_list' then - local elements = {} + if Config.EnableSocietyOwnedVehicles then - ESX.TriggerServerCallback('esx_society:getVehiclesInGarage', function(vehicles) + local elements = {} - for i=1, #vehicles, 1 do - table.insert(elements, {label = GetDisplayNameFromVehicleModel(vehicles[i].model) .. ' [' .. vehicles[i].plate .. ']', value = vehicles[i]}) - end + ESX.TriggerServerCallback('esx_society:getVehiclesInGarage', function(vehicles) + for i=1, #vehicles, 1 do + table.insert(elements, { + label = GetDisplayNameFromVehicleModel(vehicles[i].model) .. ' [' .. vehicles[i].plate .. ']', + value = vehicles[i] + }) + end - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'vehicle_spawner', - { - title = _U('service_vehicle'), - align = 'top-left', - elements = elements, - }, - function(data, menu) + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_spawner', { + title = _U('service_vehicle'), + align = 'top-left', + elements = elements + }, function(data, menu) + menu.close() + local vehicleProps = data.current.value - menu.close() + ESX.Game.SpawnVehicle(vehicleProps.model, Config.Zones.VehicleSpawnPoint.Pos, 270.0, function(vehicle) + ESX.Game.SetVehicleProperties(vehicle, vehicleProps) + local playerPed = PlayerPedId() + TaskWarpPedIntoVehicle(playerPed, vehicle, -1) + end) - local vehicleProps = data.current.value + TriggerServerEvent('esx_society:removeVehicleFromGarage', 'mecano', vehicleProps) + end, function(data, menu) + menu.close() + end) + end, 'mecano') - ESX.Game.SpawnVehicle(vehicleProps.model, Config.Zones.VehicleSpawnPoint.Pos, 270.0, function(vehicle) - ESX.Game.SetVehicleProperties(vehicle, vehicleProps) - local playerPed = GetPlayerPed(-1) - TaskWarpPedIntoVehicle(playerPed, vehicle, -1) - end) + else - TriggerServerEvent('esx_society:removeVehicleFromGarage', 'mecano', vehicleProps) + local elements = { + {label = _U('flat_bed'), value = 'flatbed'}, + {label = _U('tow_truck'), value = 'towtruck2'} + } - end, - function(data, menu) - menu.close() - end - ) + if Config.EnablePlayerManagement and PlayerData.job ~= nil and (PlayerData.job.grade_name == 'boss' or PlayerData.job.grade_name == 'chef' or PlayerData.job.grade_name == 'experimente') then + table.insert(elements, {label = 'SlamVan', value = 'slamvan3'}) + end - end, 'mecano') + ESX.UI.Menu.CloseAll() - else + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'spawn_vehicle', { + title = _U('service_vehicle'), + align = 'top-left', + elements = elements + }, function(data, menu) + if Config.MaxInService == -1 then + ESX.Game.SpawnVehicle(data.current.value, Config.Zones.VehicleSpawnPoint.Pos, 90.0, function(vehicle) + local playerPed = PlayerPedId() + TaskWarpPedIntoVehicle(playerPed, vehicle, -1) + end) + else + ESX.TriggerServerCallback('esx_service:enableService', function(canTakeService, maxInService, inServiceCount) + if canTakeService then + ESX.Game.SpawnVehicle(data.current.value, Config.Zones.VehicleSpawnPoint.Pos, 90.0, function(vehicle) + local playerPed = PlayerPedId() + TaskWarpPedIntoVehicle(playerPed, vehicle, -1) + end) + else + ESX.ShowNotification(_U('service_full') .. inServiceCount .. '/' .. maxInService) + end + end, 'mecano') + end - local elements = { - {label = _U('flat_bed'), value = 'flatbed'}, - {label = _U('tow_truck'), value = 'towtruck2'} - } + menu.close() + end, function(data, menu) + menu.close() + OpenMecanoActionsMenu() + end) - if Config.EnablePlayerManagement and PlayerData.job ~= nil and - (PlayerData.job.grade_name == 'boss' or PlayerData.job.grade_name == 'chef' or PlayerData.job.grade_name == 'experimente') then - table.insert(elements, {label = 'SlamVan', value = 'slamvan3'}) - end + end - ESX.UI.Menu.CloseAll() + elseif data.current.value == 'cloakroom' then - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'spawn_vehicle', - { - title = _U('service_vehicle'), - align = 'top-left', - elements = elements - }, - function(data, menu) - for i=1, #elements, 1 do - if Config.MaxInService == -1 then - ESX.Game.SpawnVehicle(data.current.value, Config.Zones.VehicleSpawnPoint.Pos, 90.0, function(vehicle) - local playerPed = GetPlayerPed(-1) - TaskWarpPedIntoVehicle(playerPed, vehicle, -1) - end) - break - else - ESX.TriggerServerCallback('esx_service:enableService', function(canTakeService, maxInService, inServiceCount) - if canTakeService then - ESX.Game.SpawnVehicle(data.current.value, Config.Zones.VehicleSpawnPoint.Pos, 90.0, function(vehicle) - local playerPed = GetPlayerPed(-1) - TaskWarpPedIntoVehicle(playerPed, vehicle, -1) - end) - else - ESX.ShowNotification(_U('service_full') .. inServiceCount .. '/' .. maxInService) - end - end, 'mecano') - break - end - end - menu.close() - end, - function(data, menu) - menu.close() - OpenMecanoActionsMenu() - end - ) + menu.close() + ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin) + if skin.sex == 0 then + TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_male) + else + TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_female) + end + end) - end - end + elseif data.current.value == 'cloakroom2' then - if data.current.value == 'cloakroom' then - menu.close() - ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin) + menu.close() + ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin) + TriggerEvent('skinchanger:loadSkin', skin) + end) - if skin.sex == 0 then - TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_male) - else - TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_female) - end + elseif data.current.value == 'put_stock' then + OpenPutStocksMenu() + elseif data.current.value == 'get_stock' then + OpenGetStocksMenu() + elseif data.current.value == 'boss_actions' then + TriggerEvent('esx_society:openBossMenu', 'mecano', function(data, menu) + menu.close() + end) + end - end) - end + end, function(data, menu) + menu.close() - if data.current.value == 'cloakroom2' then - menu.close() - ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin) - - TriggerEvent('skinchanger:loadSkin', skin) - - end) - end - - if data.current.value == 'put_stock' then - OpenPutStocksMenu() - end - - if data.current.value == 'get_stock' then - OpenGetStocksMenu() - end - - if data.current.value == 'boss_actions' then - TriggerEvent('esx_society:openBossMenu', 'mecano', function(data, menu) - menu.close() - end) - end - - end, - function(data, menu) - menu.close() - CurrentAction = 'mecano_actions_menu' - CurrentActionMsg = _U('open_actions') - CurrentActionData = {} - end - ) + CurrentAction = 'mecano_actions_menu' + CurrentActionMsg = _U('open_actions') + CurrentActionData = {} + end) end function OpenMecanoHarvestMenu() - if Config.EnablePlayerManagement and PlayerData.job ~= nil and PlayerData.job.grade_name ~= 'recrue' then - local elements = { - {label = _U('gas_can'), value = 'gaz_bottle'}, - {label = _U('repair_tools'), value = 'fix_tool'}, - {label = _U('body_work_tools'), value = 'caro_tool'} - } + if Config.EnablePlayerManagement and PlayerData.job ~= nil and PlayerData.job.grade_name ~= 'recrue' then - ESX.UI.Menu.CloseAll() + local elements = { + {label = _U('gas_can'), value = 'gaz_bottle'}, + {label = _U('repair_tools'), value = 'fix_tool'}, + {label = _U('body_work_tools'), value = 'caro_tool'} + } - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'mecano_harvest', - { - title = _U('harvest'), - align = 'top-left', - elements = elements - }, - function(data, menu) - if data.current.value == 'gaz_bottle' then - menu.close() - TriggerServerEvent('esx_mecanojob:startHarvest') - end + ESX.UI.Menu.CloseAll() - if data.current.value == 'fix_tool' then - menu.close() - TriggerServerEvent('esx_mecanojob:startHarvest2') - end + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'mecano_harvest', { + title = _U('harvest'), + align = 'top-left', + elements = elements + }, function(data, menu) - if data.current.value == 'caro_tool' then - menu.close() - TriggerServerEvent('esx_mecanojob:startHarvest3') - end + if data.current.value == 'gaz_bottle' then + menu.close() + TriggerServerEvent('esx_mecanojob:startHarvest') + elseif data.current.value == 'fix_tool' then + menu.close() + TriggerServerEvent('esx_mecanojob:startHarvest2') + elseif data.current.value == 'caro_tool' then + menu.close() + TriggerServerEvent('esx_mecanojob:startHarvest3') + end - end, - function(data, menu) - menu.close() - CurrentAction = 'mecano_harvest_menu' - CurrentActionMsg = _U('harvest_menu') - CurrentActionData = {} - end - ) - else - ESX.ShowNotification(_U('not_experienced_enough')) - end + end, function(data, menu) + menu.close() + CurrentAction = 'mecano_harvest_menu' + CurrentActionMsg = _U('harvest_menu') + CurrentActionData = {} + end) + + else + ESX.ShowNotification(_U('not_experienced_enough')) + end end function OpenMecanoCraftMenu() - if Config.EnablePlayerManagement and PlayerData.job ~= nil and PlayerData.job.grade_name ~= 'recrue' then + if Config.EnablePlayerManagement and PlayerData.job ~= nil and PlayerData.job.grade_name ~= 'recrue' then - local elements = { - {label = _U('blowtorch'), value = 'blow_pipe'}, - {label = _U('repair_kit'), value = 'fix_kit'}, - {label = _U('body_kit'), value = 'caro_kit'} - } + local elements = { + {label = _U('blowtorch'), value = 'blow_pipe'}, + {label = _U('repair_kit'), value = 'fix_kit'}, + {label = _U('body_kit'), value = 'caro_kit'} + } - ESX.UI.Menu.CloseAll() + ESX.UI.Menu.CloseAll() - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'mecano_craft', - { - title = _U('craft'), - align = 'top-left', - elements = elements - }, - function(data, menu) - if data.current.value == 'blow_pipe' then - menu.close() - TriggerServerEvent('esx_mecanojob:startCraft') - end + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'mecano_craft', { + title = _U('craft'), + align = 'top-left', + elements = elements + }, function(data, menu) + if data.current.value == 'blow_pipe' then + menu.close() + TriggerServerEvent('esx_mecanojob:startCraft') + elseif data.current.value == 'fix_kit' then + menu.close() + TriggerServerEvent('esx_mecanojob:startCraft2') + elseif data.current.value == 'caro_kit' then + menu.close() + TriggerServerEvent('esx_mecanojob:startCraft3') + end - if data.current.value == 'fix_kit' then - menu.close() - TriggerServerEvent('esx_mecanojob:startCraft2') - end + end, function(data, menu) + menu.close() - if data.current.value == 'caro_kit' then - menu.close() - TriggerServerEvent('esx_mecanojob:startCraft3') - end + CurrentAction = 'mecano_craft_menu' + CurrentActionMsg = _U('craft_menu') + CurrentActionData = {} + end) - end, - function(data, menu) - menu.close() - CurrentAction = 'mecano_craft_menu' - CurrentActionMsg = _U('craft_menu') - CurrentActionData = {} - end - ) - else - ESX.ShowNotification(_U('not_experienced_enough')) - end + else + ESX.ShowNotification(_U('not_experienced_enough')) + end end function OpenMobileMecanoActionsMenu() - ESX.UI.Menu.CloseAll() + ESX.UI.Menu.CloseAll() - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'mobile_mecano_actions', - { - title = _U('mechanic'), - align = 'top-left', - elements = { - {label = _U('billing'), value = 'billing'}, - {label = _U('hijack'), value = 'hijack_vehicle'}, - {label = _U('repair'), value = 'fix_vehicle'}, - {label = _U('clean'), value = 'clean_vehicle'}, - {label = _U('imp_veh'), value = 'del_vehicle'}, - {label = _U('flat_bed'), value = 'dep_vehicle'}, - {label = _U('place_objects'), value = 'object_spawner'} - } - }, - function(data, menu) - if IsBusy then return end + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'mobile_mecano_actions', { + title = _U('mechanic'), + align = 'top-left', + elements = { + {label = _U('billing'), value = 'billing'}, + {label = _U('hijack'), value = 'hijack_vehicle'}, + {label = _U('repair'), value = 'fix_vehicle'}, + {label = _U('clean'), value = 'clean_vehicle'}, + {label = _U('imp_veh'), value = 'del_vehicle'}, + {label = _U('flat_bed'), value = 'dep_vehicle'}, + {label = _U('place_objects'), value = 'object_spawner'} + } + }, function(data, menu) + if IsBusy then return end - if data.current.value == 'billing' then - ESX.UI.Menu.Open( - 'dialog', GetCurrentResourceName(), 'billing', - { - title = _U('invoice_amount') - }, - function(data, menu) - local amount = tonumber(data.value) - if amount == nil or amount < 0 then - ESX.ShowNotification(_U('amount_invalid')) - else - - local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() - if closestPlayer == -1 or closestDistance > 3.0 then - ESX.ShowNotification(_U('no_players_nearby')) - else + if data.current.value == 'billing' then + + ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'billing', { + title = _U('invoice_amount') + }, function(data, menu) + local amount = tonumber(data.value) + + if amount == nil or amount < 0 then + ESX.ShowNotification(_U('amount_invalid')) + else + local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() + if closestPlayer == -1 or closestDistance > 3.0 then + ESX.ShowNotification(_U('no_players_nearby')) + else + menu.close() + TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(closestPlayer), 'society_mecano', _U('mechanic'), amount) + end + end + end, function(data, menu) menu.close() - TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(closestPlayer), 'society_mecano', _U('mechanic'), amount) - end - end - end, - function(data, menu) - menu.close() - end - ) - end + end) - if data.current.value == 'hijack_vehicle' then + elseif data.current.value == 'hijack_vehicle' then - local playerPed = GetPlayerPed(-1) + local playerPed = PlayerPedId() local vehicle = ESX.Game.GetVehicleInDirection() local coords = GetEntityCoords(playerPed) @@ -432,7 +376,7 @@ function OpenMobileMecanoActionsMenu() elseif data.current.value == 'fix_vehicle' then - local playerPed = GetPlayerPed(-1) + local playerPed = PlayerPedId() local vehicle = ESX.Game.GetVehicleInDirection() local coords = GetEntityCoords(playerPed) @@ -462,7 +406,7 @@ function OpenMobileMecanoActionsMenu() elseif data.current.value == 'clean_vehicle' then - local playerPed = GetPlayerPed(-1) + local playerPed = PlayerPedId() local vehicle = ESX.Game.GetVehicleInDirection() local coords = GetEntityCoords(playerPed) @@ -487,588 +431,529 @@ function OpenMobileMecanoActionsMenu() ESX.ShowNotification(_U('no_vehicle_nearby')) end - elseif data.current.value == 'del_vehicle' then + elseif data.current.value == 'del_vehicle' then - local ped = GetPlayerPed(-1) + local ped = PlayerPedId() - if DoesEntityExist(ped) and not IsEntityDead(ped) then - local pos = GetEntityCoords( ped ) + if DoesEntityExist(ped) and not IsEntityDead(ped) then + local pos = GetEntityCoords( ped ) - if IsPedSittingInAnyVehicle(ped) then - local vehicle = GetVehiclePedIsIn( ped, false ) + if IsPedSittingInAnyVehicle(ped) then + local vehicle = GetVehiclePedIsIn( ped, false ) - if GetPedInVehicleSeat(vehicle, -1) == ped then - ESX.ShowNotification(_U('vehicle_impounded')) - ESX.Game.DeleteVehicle(vehicle) - else - ESX.ShowNotification(_U('must_seat_driver')) - end - else - local vehicle = ESX.Game.GetVehicleInDirection() + if GetPedInVehicleSeat(vehicle, -1) == ped then + ESX.ShowNotification(_U('vehicle_impounded')) + ESX.Game.DeleteVehicle(vehicle) + else + ESX.ShowNotification(_U('must_seat_driver')) + end + else + local vehicle = ESX.Game.GetVehicleInDirection() - if DoesEntityExist(vehicle) then - ESX.ShowNotification(_U('vehicle_impounded')) - ESX.Game.DeleteVehicle(vehicle) - else - ESX.ShowNotification(_U('must_near')) - end - end - end - end + if DoesEntityExist(vehicle) then + ESX.ShowNotification(_U('vehicle_impounded')) + ESX.Game.DeleteVehicle(vehicle) + else + ESX.ShowNotification(_U('must_near')) + end + end + end - if data.current.value == 'dep_vehicle' then + elseif data.current.value == 'dep_vehicle' then - local playerped = GetPlayerPed(-1) - local vehicle = GetVehiclePedIsIn(playerped, true) + local playerPed = PlayerPedId() + local vehicle = GetVehiclePedIsIn(playerPed, true) - local towmodel = GetHashKey('flatbed') - local isVehicleTow = IsVehicleModel(vehicle, towmodel) + local towmodel = GetHashKey('flatbed') + local isVehicleTow = IsVehicleModel(vehicle, towmodel) - if isVehicleTow then - local targetVehicle = ESX.Game.GetVehicleInDirection() + if isVehicleTow then + local targetVehicle = ESX.Game.GetVehicleInDirection() - if CurrentlyTowedVehicle == nil then - if targetVehicle ~= 0 then - if not IsPedInAnyVehicle(playerped, true) then - if vehicle ~= targetVehicle then - AttachEntityToEntity(targetVehicle, vehicle, 20, -0.5, -5.0, 1.0, 0.0, 0.0, 0.0, false, false, false, false, 20, true) - CurrentlyTowedVehicle = targetVehicle - ESX.ShowNotification(_U('vehicle_success_attached')) + if CurrentlyTowedVehicle == nil then + if targetVehicle ~= 0 then + if not IsPedInAnyVehicle(playerPed, true) then + if vehicle ~= targetVehicle then + AttachEntityToEntity(targetVehicle, vehicle, 20, -0.5, -5.0, 1.0, 0.0, 0.0, 0.0, false, false, false, false, 20, true) + CurrentlyTowedVehicle = targetVehicle + ESX.ShowNotification(_U('vehicle_success_attached')) - if NPCOnJob then + if NPCOnJob then + if NPCTargetTowable == targetVehicle then + ESX.ShowNotification(_U('please_drop_off')) + Config.Zones.VehicleDelivery.Type = 1 - if NPCTargetTowable == targetVehicle then - ESX.ShowNotification(_U('please_drop_off')) + if Blips['NPCTargetTowableZone'] ~= nil then + RemoveBlip(Blips['NPCTargetTowableZone']) + Blips['NPCTargetTowableZone'] = nil + end - Config.Zones.VehicleDelivery.Type = 1 + Blips['NPCDelivery'] = AddBlipForCoord(Config.Zones.VehicleDelivery.Pos.x, Config.Zones.VehicleDelivery.Pos.y, Config.Zones.VehicleDelivery.Pos.z) + SetBlipRoute(Blips['NPCDelivery'], true) + end + end + else + ESX.ShowNotification(_U('cant_attach_own_tt')) + end + end + else + ESX.ShowNotification(_U('no_veh_att')) + end + else - if Blips['NPCTargetTowableZone'] ~= nil then - RemoveBlip(Blips['NPCTargetTowableZone']) - Blips['NPCTargetTowableZone'] = nil - end + AttachEntityToEntity(CurrentlyTowedVehicle, vehicle, 20, -0.5, -12.0, 1.0, 0.0, 0.0, 0.0, false, false, false, false, 20, true) + DetachEntity(CurrentlyTowedVehicle, true, true) - Blips['NPCDelivery'] = AddBlipForCoord(Config.Zones.VehicleDelivery.Pos.x, Config.Zones.VehicleDelivery.Pos.y, Config.Zones.VehicleDelivery.Pos.z) + if NPCOnJob then + if NPCTargetDeleterZone then - SetBlipRoute(Blips['NPCDelivery'], true) + if CurrentlyTowedVehicle == NPCTargetTowable then + ESX.Game.DeleteVehicle(NPCTargetTowable) + TriggerServerEvent('esx_mecanojob:onNPCJobMissionCompleted') + StopNPCJob() + NPCTargetDeleterZone = false + else + ESX.ShowNotification(_U('not_right_veh')) + end - end + else + ESX.ShowNotification(_U('not_right_place')) + end + end - end + CurrentlyTowedVehicle = nil + ESX.ShowNotification(_U('veh_det_succ')) - else - ESX.ShowNotification(_U('cant_attach_own_tt')) - end - end - else - ESX.ShowNotification(_U('no_veh_att')) - end - else + end + else + ESX.ShowNotification(_U('imp_flatbed')) + end - AttachEntityToEntity(CurrentlyTowedVehicle, vehicle, 20, -0.5, -12.0, 1.0, 0.0, 0.0, 0.0, false, false, false, false, 20, true) - DetachEntity(CurrentlyTowedVehicle, true, true) + elseif data.current.value == 'object_spawner' then - if NPCOnJob then - - if NPCTargetDeleterZone then - - if CurrentlyTowedVehicle == NPCTargetTowable then - ESX.Game.DeleteVehicle(NPCTargetTowable) - TriggerServerEvent('esx_mecanojob:onNPCJobMissionCompleted') - StopNPCJob() - NPCTargetDeleterZone = false - - else - ESX.ShowNotification(_U('not_right_veh')) - end - - else - ESX.ShowNotification(_U('not_right_place')) - end - - end - - CurrentlyTowedVehicle = nil - - ESX.ShowNotification(_U('veh_det_succ')) - end - else - ESX.ShowNotification(_U('imp_flatbed')) - end - end - - if data.current.value == 'object_spawner' then - local playerPed = GetPlayerPed(-1) + local playerPed = PlayerPedId() if IsPedSittingInAnyVehicle(playerPed) then ESX.ShowNotification(_U('inside_vehicle')) return end - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'mobile_mecano_actions_spawn', - { - title = _U('objects'), - align = 'top-left', - elements = { - {label = _U('roadcone'), value = 'prop_roadcone02a'}, - {label = _U('toolbox'), value = 'prop_toolchest_01'}, - }, - }, - function(data2, menu2) + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'mobile_mecano_actions_spawn', { + title = _U('objects'), + align = 'top-left', + elements = { + {label = _U('roadcone'), value = 'prop_roadcone02a'}, + {label = _U('toolbox'), value = 'prop_toolchest_01'} + } + }, function(data2, menu2) + local model = data2.current.value + local coords = GetEntityCoords(playerPed) + local forward = GetEntityForwardVector(playerPed) + local x, y, z = table.unpack(coords + forward * 1.0) - local model = data2.current.value - local coords = GetEntityCoords(playerPed) - local forward = GetEntityForwardVector(playerPed) - local x, y, z = table.unpack(coords + forward * 1.0) + if model == 'prop_roadcone02a' then + z = z - 2.0 + elseif model == 'prop_toolchest_01' then + z = z - 2.0 + end - if model == 'prop_roadcone02a' then - z = z - 2.0 - elseif model == 'prop_toolchest_01' then - z = z - 2.0 - end + ESX.Game.SpawnObject(model, { + x = x, + y = y, + z = z + }, function(obj) + SetEntityHeading(obj, GetEntityHeading(playerPed)) + PlaceObjectOnGroundProperly(obj) + end) - ESX.Game.SpawnObject(model, { - x = x, - y = y, - z = z - }, function(obj) - SetEntityHeading(obj, GetEntityHeading(playerPed)) - PlaceObjectOnGroundProperly(obj) - end) + end, function(data2, menu2) + menu2.close() + end) - end, - function(data2, menu2) - menu2.close() - end - ) + end - end - - end, - function(data, menu) - menu.close() - end - ) + end, function(data, menu) + menu.close() + end) end function OpenGetStocksMenu() - ESX.TriggerServerCallback('esx_mecanojob:getStockItems', function(items) - local elements = {} + ESX.TriggerServerCallback('esx_mecanojob:getStockItems', function(items) - for i=1, #items, 1 do - table.insert(elements, {label = 'x' .. items[i].count .. ' ' .. items[i].label, value = items[i].name}) - end + local elements = {} - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'stocks_menu', - { - title = _U('mechanic_stock'), - align = 'top-left', - elements = elements - }, - function(data, menu) + for i=1, #items, 1 do + table.insert(elements, { + label = 'x' .. items[i].count .. ' ' .. items[i].label, + value = items[i].name + }) + end - local itemName = data.current.value + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'stocks_menu', + { + title = _U('mechanic_stock'), + align = 'top-left', + elements = elements + }, function(data, menu) - ESX.UI.Menu.Open( - 'dialog', GetCurrentResourceName(), 'stocks_menu_get_item_count', - { - title = _U('quantity') - }, - function(data2, menu2) + local itemName = data.current.value - local count = tonumber(data2.value) + ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'stocks_menu_get_item_count', { + title = _U('quantity') + }, function(data2, menu2) + local count = tonumber(data2.value) - if count == nil then - ESX.ShowNotification(_U('invalid_quantity')) - else - menu2.close() - menu.close() - TriggerServerEvent('esx_mecanojob:getStockItem', itemName, count) + if count == nil then + ESX.ShowNotification(_U('invalid_quantity')) + else + menu2.close() + menu.close() + TriggerServerEvent('esx_mecanojob:getStockItem', itemName, count) - Citizen.Wait(1000) - OpenGetStocksMenu() - end + Citizen.Wait(1000) + OpenGetStocksMenu() + end + end, function(data2, menu2) + menu2.close() + end) - end, - function(data2, menu2) - menu2.close() - end - ) + end, function(data, menu) + menu.close() + end) - end, - function(data, menu) - menu.close() - end - ) - - end) + end) end function OpenPutStocksMenu() -ESX.TriggerServerCallback('esx_mecanojob:getPlayerInventory', function(inventory) + ESX.TriggerServerCallback('esx_mecanojob:getPlayerInventory', function(inventory) + local elements = {} - local elements = {} + for i=1, #inventory.items, 1 do + local item = inventory.items[i] - for i=1, #inventory.items, 1 do + if item.count > 0 then + table.insert(elements, { + label = item.label .. ' x' .. item.count, + type = 'item_standard', + value = item.name + }) + end + end - local item = inventory.items[i] + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'stocks_menu', { + title = _U('inventory'), + align = 'top-left', + elements = elements + }, function(data, menu) - if item.count > 0 then - table.insert(elements, {label = item.label .. ' x' .. item.count, type = 'item_standard', value = item.name}) - end + local itemName = data.current.value - end + ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'stocks_menu_put_item_count', { + title = _U('quantity') + }, function(data2, menu2) + local count = tonumber(data2.value) - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'stocks_menu', - { - title = _U('inventory'), - align = 'top-left', - elements = elements - }, - function(data, menu) + if count == nil then + ESX.ShowNotification(_U('invalid_quantity')) + else + menu2.close() + menu.close() + TriggerServerEvent('esx_mecanojob:putStockItems', itemName, count) - local itemName = data.current.value + Citizen.Wait(1000) + OpenPutStocksMenu() + end + end, function(data2, menu2) + menu2.close() + end) + end, function(data, menu) + menu.close() + end) - ESX.UI.Menu.Open( - 'dialog', GetCurrentResourceName(), 'stocks_menu_put_item_count', - { - title = _U('quantity') - }, - function(data2, menu2) - - local count = tonumber(data2.value) - - if count == nil then - ESX.ShowNotification(_U('invalid_quantity')) - else - menu2.close() - menu.close() - TriggerServerEvent('esx_mecanojob:putStockItems', itemName, count) - - Citizen.Wait(1000) - OpenPutStocksMenu() - end - - end, - function(data2, menu2) - menu2.close() - end - ) - - end, - function(data, menu) - menu.close() - end - ) - - end) + end) end RegisterNetEvent('esx_mecanojob:onHijack') AddEventHandler('esx_mecanojob:onHijack', function() - local playerPed = GetPlayerPed(-1) - local coords = GetEntityCoords(playerPed) + local playerPed = PlayerPedId() + local coords = GetEntityCoords(playerPed) - if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then + if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then + local vehicle = nil - local vehicle = nil + if IsPedInAnyVehicle(playerPed, false) then + vehicle = GetVehiclePedIsIn(playerPed, false) + else + vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71) + end - if IsPedInAnyVehicle(playerPed, false) then - vehicle = GetVehiclePedIsIn(playerPed, false) - else - vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71) - end + local chance = math.random(100) + local alarm = math.random(100) - local crochete = math.random(100) - local alarm = math.random(100) + if DoesEntityExist(vehicle) then + if alarm <= 33 then + SetVehicleAlarm(vehicle, true) + StartVehicleAlarm(vehicle) + end - if DoesEntityExist(vehicle) then - if alarm <= 33 then - SetVehicleAlarm(vehicle, true) - StartVehicleAlarm(vehicle) - end - TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_WELDING", 0, true) - Citizen.CreateThread(function() - Citizen.Wait(10000) - if crochete <= 66 then - SetVehicleDoorsLocked(vehicle, 1) - SetVehicleDoorsLockedForAllPlayers(vehicle, false) - ClearPedTasksImmediately(playerPed) - ESX.ShowNotification(_U('veh_unlocked')) - else - ESX.ShowNotification(_U('hijack_failed')) - ClearPedTasksImmediately(playerPed) - end - end) - end + TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_WELDING", 0, true) - end + Citizen.CreateThread(function() + Citizen.Wait(10000) + if chance <= 66 then + SetVehicleDoorsLocked(vehicle, 1) + SetVehicleDoorsLockedForAllPlayers(vehicle, false) + ClearPedTasksImmediately(playerPed) + ESX.ShowNotification(_U('veh_unlocked')) + else + ESX.ShowNotification(_U('hijack_failed')) + ClearPedTasksImmediately(playerPed) + end + end) + + end + end end) RegisterNetEvent('esx_mecanojob:onCarokit') AddEventHandler('esx_mecanojob:onCarokit', function() - local playerPed = GetPlayerPed(-1) - local coords = GetEntityCoords(playerPed) + local playerPed = PlayerPedId() + local coords = GetEntityCoords(playerPed) - if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then + if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then + local vehicle = nil - local vehicle = nil + if IsPedInAnyVehicle(playerPed, false) then + vehicle = GetVehiclePedIsIn(playerPed, false) + else + vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71) + end - if IsPedInAnyVehicle(playerPed, false) then - vehicle = GetVehiclePedIsIn(playerPed, false) - else - vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71) - end - - if DoesEntityExist(vehicle) then - TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_HAMMERING", 0, true) - Citizen.CreateThread(function() - Citizen.Wait(10000) - SetVehicleFixed(vehicle) - SetVehicleDeformationFixed(vehicle) - ClearPedTasksImmediately(playerPed) - ESX.ShowNotification(_U('body_repaired')) - end) - end - end + if DoesEntityExist(vehicle) then + TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_HAMMERING", 0, true) + Citizen.CreateThread(function() + Citizen.Wait(10000) + SetVehicleFixed(vehicle) + SetVehicleDeformationFixed(vehicle) + ClearPedTasksImmediately(playerPed) + ESX.ShowNotification(_U('body_repaired')) + end) + end + end end) RegisterNetEvent('esx_mecanojob:onFixkit') AddEventHandler('esx_mecanojob:onFixkit', function() - local playerPed = GetPlayerPed(-1) - local coords = GetEntityCoords(playerPed) + local playerPed = PlayerPedId() + local coords = GetEntityCoords(playerPed) - if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then + if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then + local vehicle = nil - local vehicle = nil + if IsPedInAnyVehicle(playerPed, false) then + vehicle = GetVehiclePedIsIn(playerPed, false) + else + vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71) + end - if IsPedInAnyVehicle(playerPed, false) then - vehicle = GetVehiclePedIsIn(playerPed, false) - else - vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71) - end - - if DoesEntityExist(vehicle) then - TaskStartScenarioInPlace(playerPed, "PROP_HUMAN_BUM_BIN", 0, true) - Citizen.CreateThread(function() - Citizen.Wait(20000) - SetVehicleFixed(vehicle) - SetVehicleDeformationFixed(vehicle) - SetVehicleUndriveable(vehicle, false) - ClearPedTasksImmediately(playerPed) - ESX.ShowNotification(_U('veh_repaired')) - end) - end - end + if DoesEntityExist(vehicle) then + TaskStartScenarioInPlace(playerPed, "PROP_HUMAN_BUM_BIN", 0, true) + Citizen.CreateThread(function() + Citizen.Wait(20000) + SetVehicleFixed(vehicle) + SetVehicleDeformationFixed(vehicle) + SetVehicleUndriveable(vehicle, false) + ClearPedTasksImmediately(playerPed) + ESX.ShowNotification(_U('veh_repaired')) + end) + end + end end) RegisterNetEvent('esx:playerLoaded') AddEventHandler('esx:playerLoaded', function(xPlayer) - PlayerData = xPlayer + PlayerData = xPlayer end) RegisterNetEvent('esx:setJob') AddEventHandler('esx:setJob', function(job) - PlayerData.job = job + PlayerData.job = job end) AddEventHandler('esx_mecanojob:hasEnteredMarker', function(zone) + if zone == NPCJobTargetTowable then - if zone == NPCJobTargetTowable then + elseif zone =='VehicleDelivery' then + NPCTargetDeleterZone = true + elseif zone == 'MecanoActions' then + CurrentAction = 'mecano_actions_menu' + CurrentActionMsg = _U('open_actions') + CurrentActionData = {} + elseif zone == 'Garage' then + CurrentAction = 'mecano_harvest_menu' + CurrentActionMsg = _U('harvest_menu') + CurrentActionData = {} + elseif zone == 'Craft' then + CurrentAction = 'mecano_craft_menu' + CurrentActionMsg = _U('craft_menu') + CurrentActionData = {} + elseif zone == 'VehicleDeleter' then + local playerPed = PlayerPedId() - end - - if zone =='VehicleDelivery' then - NPCTargetDeleterZone = true - end - - if zone == 'MecanoActions' then - CurrentAction = 'mecano_actions_menu' - CurrentActionMsg = _U('open_actions') - CurrentActionData = {} - end - - if zone == 'Garage' then - CurrentAction = 'mecano_harvest_menu' - CurrentActionMsg = _U('harvest_menu') - CurrentActionData = {} - end - - if zone == 'Craft' then - CurrentAction = 'mecano_craft_menu' - CurrentActionMsg = _U('craft_menu') - CurrentActionData = {} - end - - if zone == 'VehicleDeleter' then - - local playerPed = GetPlayerPed(-1) - - if IsPedInAnyVehicle(playerPed, false) then - - local vehicle = GetVehiclePedIsIn(playerPed, false) - - CurrentAction = 'delete_vehicle' - CurrentActionMsg = _U('veh_stored') - CurrentActionData = {vehicle = vehicle} - end - end + if IsPedInAnyVehicle(playerPed, false) then + local vehicle = GetVehiclePedIsIn(playerPed, false) + CurrentAction = 'delete_vehicle' + CurrentActionMsg = _U('veh_stored') + CurrentActionData = {vehicle = vehicle} + end + end end) AddEventHandler('esx_mecanojob:hasExitedMarker', function(zone) + if zone =='VehicleDelivery' then + NPCTargetDeleterZone = false + elseif zone == 'Craft' then + TriggerServerEvent('esx_mecanojob:stopCraft') + TriggerServerEvent('esx_mecanojob:stopCraft2') + TriggerServerEvent('esx_mecanojob:stopCraft3') + elseif zone == 'Garage' then + TriggerServerEvent('esx_mecanojob:stopHarvest') + TriggerServerEvent('esx_mecanojob:stopHarvest2') + TriggerServerEvent('esx_mecanojob:stopHarvest3') + end - if zone =='VehicleDelivery' then - NPCTargetDeleterZone = false - end - - if zone == 'Craft' then - TriggerServerEvent('esx_mecanojob:stopCraft') - TriggerServerEvent('esx_mecanojob:stopCraft2') - TriggerServerEvent('esx_mecanojob:stopCraft3') - end - - if zone == 'Garage' then - TriggerServerEvent('esx_mecanojob:stopHarvest') - TriggerServerEvent('esx_mecanojob:stopHarvest2') - TriggerServerEvent('esx_mecanojob:stopHarvest3') - end - - CurrentAction = nil - ESX.UI.Menu.CloseAll() + CurrentAction = nil + ESX.UI.Menu.CloseAll() end) AddEventHandler('esx_mecanojob:hasEnteredEntityZone', function(entity) + local playerPed = PlayerPedId() - local playerPed = GetPlayerPed(-1) - - if PlayerData.job ~= nil and PlayerData.job.name == 'mecano' and not IsPedInAnyVehicle(playerPed, false) then - CurrentAction = 'remove_entity' - CurrentActionMsg = _U('press_remove_obj') - CurrentActionData = {entity = entity} - end - + if PlayerData.job ~= nil and PlayerData.job.name == 'mecano' and not IsPedInAnyVehicle(playerPed, false) then + CurrentAction = 'remove_entity' + CurrentActionMsg = _U('press_remove_obj') + CurrentActionData = {entity = entity} + end end) AddEventHandler('esx_mecanojob:hasExitedEntityZone', function(entity) - - if CurrentAction == 'remove_entity' then - CurrentAction = nil - end - + if CurrentAction == 'remove_entity' then + CurrentAction = nil + end end) RegisterNetEvent('esx_phone:loaded') AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts) - local specialContact = { - name = _U('mechanic'), - number = 'mecano', - base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAAAA4BJREFUWIXtll9oU3cUx7/nJA02aSSlFouWMnXVB0ejU3wcRteHjv1puoc9rA978cUi2IqgRYWIZkMwrahUGfgkFMEZUdg6C+u21z1o3fbgqigVi7NzUtNcmsac40Npltz7S3rvUHzxQODec87vfD+/e0/O/QFv7Q0beV3QeXqmgV74/7H7fZJvuLwv8q/Xeux1gUrNBpN/nmtavdaqDqBK8VT2RDyV2VHmF1lvLERSBtCVynzYmcp+A9WqT9kcVKX4gHUehF0CEVY+1jYTTIwvt7YSIQnCTvsSUYz6gX5uDt7MP7KOKuQAgxmqQ+neUA+I1B1AiXi5X6ZAvKrabirmVYFwAMRT2RMg7F9SyKspvk73hfrtbkMPyIhA5FVqi0iBiEZMMQdAui/8E4GPv0oAJkpc6Q3+6goAAGpWBxNQmTLFmgL3jSJNgQdGv4pMts2EKm7ICJB/aG0xNdz74VEk13UYCx1/twPR8JjDT8wttyLZtkoAxSb8ZDCz0gdfKxWkFURf2v9qTYH7SK7rQIDn0P3nA0ehixvfwZwE0X9vBE/mW8piohhl1WH18UQBhYnre8N/L8b8xQvlx4ACbB4NnzaeRYDnKm0EALCMLXy84hwuTCXL/ExoB1E7qcK/8NCLIq5HcTT0i6u8TYbXUM1cAyyveVq8Xls7XhYrvY/4n3gC8C+dsmAzL1YUiyfWxvHzsy/w/dNd+KjhW2yvv/RfXr7x9QDcmo1he2RBiCCI1Q8jVj9szPNixVfgz+UiIGyDSrcoRu2J16d3I6e1VYvNSQjXpnucAcEPUOkGYZs/l4uUhowt/3kqu1UIv9n90fAY9jT3YBlbRvFTD4fw++wHjhiTRL/bG75t0jI2ITcHb5om4Xgmhv57xpGOg3d/NIqryOR7z+r+MC6qBJB/ZB2t9Om1D5lFm843G/3E3HI7Yh1xDRAfzLQr5EClBf/HBHK462TG2J0OABXeyWDPZ8VqxmBWYscpyghwtTd4EKpDTjCZdCNmzFM9k+4LHXIFACJN94Z6FiFEpKDQw9HndWsEuhnADVMhAUaYJBp9XrcGQKJ4qFE9k+6r2+MG3k5N8VQ22TVglbX2ZwOzX2VvNKr91zmY6S7N6zqZicVT2WNLyVSehESaBhxnOALfMeYX+K/S2yv7wmMAlvwyuR7FxQUyf0fgc/jztfkJr7XeGgC8BJJgWNV8ImT+AAAAAElFTkSuQmCC' - } - TriggerEvent('esx_phone:addSpecialContact', specialContact.name, specialContact.number, specialContact.base64Icon) + local specialContact = { + name = _U('mechanic'), + number = 'mecano', + base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAAAA4BJREFUWIXtll9oU3cUx7/nJA02aSSlFouWMnXVB0ejU3wcRteHjv1puoc9rA978cUi2IqgRYWIZkMwrahUGfgkFMEZUdg6C+u21z1o3fbgqigVi7NzUtNcmsac40Npltz7S3rvUHzxQODec87vfD+/e0/O/QFv7Q0beV3QeXqmgV74/7H7fZJvuLwv8q/Xeux1gUrNBpN/nmtavdaqDqBK8VT2RDyV2VHmF1lvLERSBtCVynzYmcp+A9WqT9kcVKX4gHUehF0CEVY+1jYTTIwvt7YSIQnCTvsSUYz6gX5uDt7MP7KOKuQAgxmqQ+neUA+I1B1AiXi5X6ZAvKrabirmVYFwAMRT2RMg7F9SyKspvk73hfrtbkMPyIhA5FVqi0iBiEZMMQdAui/8E4GPv0oAJkpc6Q3+6goAAGpWBxNQmTLFmgL3jSJNgQdGv4pMts2EKm7ICJB/aG0xNdz74VEk13UYCx1/twPR8JjDT8wttyLZtkoAxSb8ZDCz0gdfKxWkFURf2v9qTYH7SK7rQIDn0P3nA0ehixvfwZwE0X9vBE/mW8piohhl1WH18UQBhYnre8N/L8b8xQvlx4ACbB4NnzaeRYDnKm0EALCMLXy84hwuTCXL/ExoB1E7qcK/8NCLIq5HcTT0i6u8TYbXUM1cAyyveVq8Xls7XhYrvY/4n3gC8C+dsmAzL1YUiyfWxvHzsy/w/dNd+KjhW2yvv/RfXr7x9QDcmo1he2RBiCCI1Q8jVj9szPNixVfgz+UiIGyDSrcoRu2J16d3I6e1VYvNSQjXpnucAcEPUOkGYZs/l4uUhowt/3kqu1UIv9n90fAY9jT3YBlbRvFTD4fw++wHjhiTRL/bG75t0jI2ITcHb5om4Xgmhv57xpGOg3d/NIqryOR7z+r+MC6qBJB/ZB2t9Om1D5lFm843G/3E3HI7Yh1xDRAfzLQr5EClBf/HBHK462TG2J0OABXeyWDPZ8VqxmBWYscpyghwtTd4EKpDTjCZdCNmzFM9k+4LHXIFACJN94Z6FiFEpKDQw9HndWsEuhnADVMhAUaYJBp9XrcGQKJ4qFE9k+6r2+MG3k5N8VQ22TVglbX2ZwOzX2VvNKr91zmY6S7N6zqZicVT2WNLyVSehESaBhxnOALfMeYX+K/S2yv7wmMAlvwyuR7FxQUyf0fgc/jztfkJr7XeGgC8BJJgWNV8ImT+AAAAAElFTkSuQmCC' + } + + TriggerEvent('esx_phone:addSpecialContact', specialContact.name, specialContact.number, specialContact.base64Icon) end) -- Pop NPC mission vehicle when inside area Citizen.CreateThread(function() - while true do + while true do - Wait(0) + Citizen.Wait(10) - if NPCTargetTowableZone ~= nil and not NPCHasSpawnedTowable then + if NPCTargetTowableZone ~= nil and not NPCHasSpawnedTowable then + local coords = GetEntityCoords(PlayerPedId()) + local zone = Config.Zones[NPCTargetTowableZone] - local coords = GetEntityCoords(GetPlayerPed(-1)) - local zone = Config.Zones[NPCTargetTowableZone] + if GetDistanceBetweenCoords(coords, zone.Pos.x, zone.Pos.y, zone.Pos.z, true) < Config.NPCSpawnDistance then + local model = Config.Vehicles[GetRandomIntInRange(1, #Config.Vehicles)] - if GetDistanceBetweenCoords(coords, zone.Pos.x, zone.Pos.y, zone.Pos.z, true) < Config.NPCSpawnDistance then + ESX.Game.SpawnVehicle(model, zone.Pos, 0, function(vehicle) + NPCTargetTowable = vehicle + end) - local model = Config.Vehicles[GetRandomIntInRange(1, #Config.Vehicles)] + NPCHasSpawnedTowable = true + end + end - ESX.Game.SpawnVehicle(model, zone.Pos, 0, function(vehicle) - NPCTargetTowable = vehicle - end) + if NPCTargetTowableZone ~= nil and NPCHasSpawnedTowable and not NPCHasBeenNextToTowable then + local coords = GetEntityCoords(PlayerPedId()) + local zone = Config.Zones[NPCTargetTowableZone] - NPCHasSpawnedTowable = true + if GetDistanceBetweenCoords(coords, zone.Pos.x, zone.Pos.y, zone.Pos.z, true) < Config.NPCNextToDistance then + ESX.ShowNotification(_U('please_tow')) + NPCHasBeenNextToTowable = true + end + end - end - - end - - if NPCTargetTowableZone ~= nil and NPCHasSpawnedTowable and not NPCHasBeenNextToTowable then - - local coords = GetEntityCoords(GetPlayerPed(-1)) - local zone = Config.Zones[NPCTargetTowableZone] - - if(GetDistanceBetweenCoords(coords, zone.Pos.x, zone.Pos.y, zone.Pos.z, true) < Config.NPCNextToDistance) then - ESX.ShowNotification(_U('please_tow')) - NPCHasBeenNextToTowable = true - end - - end - - end + end end) -- Create Blips Citizen.CreateThread(function() - local blip = AddBlipForCoord(Config.Zones.MecanoActions.Pos.x, Config.Zones.MecanoActions.Pos.y, Config.Zones.MecanoActions.Pos.z) - SetBlipSprite (blip, 446) - SetBlipDisplay(blip, 4) - SetBlipScale (blip, 1.8) - SetBlipColour (blip, 5) - SetBlipAsShortRange(blip, true) - BeginTextCommandSetBlipName("STRING") - AddTextComponentString(_U('mechanic')) - EndTextCommandSetBlipName(blip) + local blip = AddBlipForCoord(Config.Zones.MecanoActions.Pos.x, Config.Zones.MecanoActions.Pos.y, Config.Zones.MecanoActions.Pos.z) + + SetBlipSprite (blip, 446) + SetBlipDisplay(blip, 4) + SetBlipScale (blip, 1.8) + SetBlipColour (blip, 5) + SetBlipAsShortRange(blip, true) + + BeginTextCommandSetBlipName("STRING") + AddTextComponentString(_U('mechanic')) + EndTextCommandSetBlipName(blip) end) -- Display markers Citizen.CreateThread(function() - while true do - Wait(0) - if PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then + while true do + Citizen.Wait(0) + if PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then + local coords = GetEntityCoords(PlayerPedId()) - local coords = GetEntityCoords(GetPlayerPed(-1)) - - for k,v in pairs(Config.Zones) do - if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then - DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false) - end - end - end - end + for k,v in pairs(Config.Zones) do + if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then + DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false) + end + end + end + end end) -- Enter / Exit marker events Citizen.CreateThread(function() - while true do - Wait(0) - if PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then - local coords = GetEntityCoords(GetPlayerPed(-1)) - local isInMarker = false - local currentZone = nil - for k,v in pairs(Config.Zones) do - if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then - isInMarker = true - currentZone = k - end - end - if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then - HasAlreadyEnteredMarker = true - LastZone = currentZone - TriggerEvent('esx_mecanojob:hasEnteredMarker', currentZone) - end - if not isInMarker and HasAlreadyEnteredMarker then - HasAlreadyEnteredMarker = false - TriggerEvent('esx_mecanojob:hasExitedMarker', LastZone) - end - end - end + while true do + Citizen.Wait(10) + + if PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then + + local coords = GetEntityCoords(PlayerPedId()) + local isInMarker = false + local currentZone = nil + + for k,v in pairs(Config.Zones) do + if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then + isInMarker = true + currentZone = k + end + end + + if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then + HasAlreadyEnteredMarker = true + LastZone = currentZone + TriggerEvent('esx_mecanojob:hasEnteredMarker', currentZone) + end + + if not isInMarker and HasAlreadyEnteredMarker then + HasAlreadyEnteredMarker = false + TriggerEvent('esx_mecanojob:hasExitedMarker', LastZone) + end + + end + end end) Citizen.CreateThread(function() @@ -1080,18 +965,18 @@ Citizen.CreateThread(function() while true do Citizen.Wait(500) - local playerPed = GetPlayerPed(-1) + local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) local closestDistance = -1 local closestEntity = nil for i=1, #trackedEntities, 1 do - local object = GetClosestObjectOfType(coords.x, coords.y, coords.z, 3.0, GetHashKey(trackedEntities[i]), false, false, false) + local object = GetClosestObjectOfType(coords.x, coords.y, coords.z, 3.0, GetHashKey(trackedEntities[i]), false, false, false) if DoesEntityExist(object) then local objCoords = GetEntityCoords(object) - local distance = GetDistanceBetweenCoords(coords.x, coords.y, coords.z, objCoords.x, objCoords.y, objCoords.z, true) + local distance = GetDistanceBetweenCoords(coords.x, coords.y, coords.z, objCoords.x, objCoords.y, objCoords.z, true) if closestDistance == -1 or closestDistance > distance then closestDistance = distance @@ -1116,89 +1001,79 @@ end) -- Key Controls Citizen.CreateThread(function() - while true do - Citizen.Wait(0) + while true do + Citizen.Wait(10) - if CurrentAction ~= nil then + if CurrentAction ~= nil then + ESX.ShowHelpNotification(CurrentActionMsg) - SetTextComponentFormat('STRING') - AddTextComponentString(CurrentActionMsg) - DisplayHelpTextFromStringLabel(0, 0, 1, -1) + if IsControlJustReleased(0, Keys['E']) and PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then - if IsControlJustReleased(0, Keys['E']) and PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then + if CurrentAction == 'mecano_actions_menu' then + OpenMecanoActionsMenu() + elseif CurrentAction == 'mecano_harvest_menu' then + OpenMecanoHarvestMenu() + elseif CurrentAction == 'mecano_craft_menu' then + OpenMecanoCraftMenu() + elseif CurrentAction == 'delete_vehicle' then - if CurrentAction == 'mecano_actions_menu' then - OpenMecanoActionsMenu() - end + if Config.EnableSocietyOwnedVehicles then - if CurrentAction == 'mecano_harvest_menu' then - OpenMecanoHarvestMenu() - end + local vehicleProps = ESX.Game.GetVehicleProperties(CurrentActionData.vehicle) + TriggerServerEvent('esx_society:putVehicleInGarage', 'mecano', vehicleProps) - if CurrentAction == 'mecano_craft_menu' then - OpenMecanoCraftMenu() - end + else - if CurrentAction == 'delete_vehicle' then + if + GetEntityModel(vehicle) == GetHashKey('flatbed') or + GetEntityModel(vehicle) == GetHashKey('towtruck2') or + GetEntityModel(vehicle) == GetHashKey('slamvan3') + then + TriggerServerEvent('esx_service:disableService', 'mecano') + end - if Config.EnableSocietyOwnedVehicles then + end - local vehicleProps = ESX.Game.GetVehicleProperties(CurrentActionData.vehicle) - TriggerServerEvent('esx_society:putVehicleInGarage', 'mecano', vehicleProps) + ESX.Game.DeleteVehicle(CurrentActionData.vehicle) + end - else + elseif CurrentAction == 'remove_entity' then + DeleteEntity(CurrentActionData.entity) + end - if - GetEntityModel(vehicle) == GetHashKey('flatbed') or - GetEntityModel(vehicle) == GetHashKey('towtruck2') or - GetEntityModel(vehicle) == GetHashKey('slamvan3') - then - TriggerServerEvent('esx_service:disableService', 'mecano') - end + CurrentAction = nil + end - end + if IsControlJustReleased(0, Keys['F6']) and not IsDead and PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then + OpenMobileMecanoActionsMenu() + end - ESX.Game.DeleteVehicle(CurrentActionData.vehicle) - end + if IsControlJustReleased(0, Keys['DELETE']) and not IsDead and PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then - if CurrentAction == 'remove_entity' then - DeleteEntity(CurrentActionData.entity) - end + if NPCOnJob then - CurrentAction = nil - end - end + if GetGameTimer() - NPCLastCancel > 5 * 60000 then + StopNPCJob(true) + NPCLastCancel = GetGameTimer() + else + ESX.ShowNotification(_U('wait_five')) + end - if IsControlJustReleased(0, Keys['F6']) and not IsDead and PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then - OpenMobileMecanoActionsMenu() - end + else - if IsControlJustReleased(0, Keys['DELETE']) and not IsDead and PlayerData.job ~= nil and PlayerData.job.name == 'mecano' then + local playerPed = PlayerPedId() - if NPCOnJob then + if IsPedInAnyVehicle(playerPed, false) and IsVehicleModel(GetVehiclePedIsIn(playerPed, false), GetHashKey("flatbed")) then + StartNPCJob() + else + ESX.ShowNotification(_U('must_in_flatbed')) + end - if GetGameTimer() - NPCLastCancel > 5 * 60000 then - StopNPCJob(true) - NPCLastCancel = GetGameTimer() - else - ESX.ShowNotification(_U('wait_five')) - end + end - else + end - local playerPed = GetPlayerPed(-1) - - if IsPedInAnyVehicle(playerPed, false) and IsVehicleModel(GetVehiclePedIsIn(playerPed, false), GetHashKey("flatbed")) then - StartNPCJob() - else - ESX.ShowNotification(_U('must_in_flatbed')) - end - - end - - end - - end + end end) AddEventHandler('esx:onPlayerDeath', function() @@ -1207,4 +1082,4 @@ end) AddEventHandler('playerSpawned', function(spawn) IsDead = false -end) \ No newline at end of file +end) diff --git a/config.lua b/config.lua index f9932363..1a580b14 100644 --- a/config.lua +++ b/config.lua @@ -8,105 +8,107 @@ Config.NPCNextToDistance = 25.0 Config.NPCJobEarnings = { min = 15, max = 40 } Config.Locale = 'fr' +Config.Vehicles = { + 'adder', + 'asea', + 'asterope', + 'banshee', + 'buffalo' +} + Config.Zones = { - MecanoActions = { - Pos = { x = -342.291, y = -133.370, z = 38.009 }, - Size = { x = 1.5, y = 1.5, z = 1.0 }, - Color = { r = 204, g = 204, b = 0 }, - Type = 1, - }, - Garage = { - Pos = { x = -97.5797576904297, y = 6496.11376953125, z = 30.4909038543701 }, - Size = { x = 1.5, y = 1.5, z = 1.0 }, - Color = { r = 204, g = 204, b = 0 }, - Type = 1, - }, + MecanoActions = { + Pos = { x = -342.291, y = -133.370, z = 38.009 }, + Size = { x = 1.5, y = 1.5, z = 1.0 }, + Color = { r = 204, g = 204, b = 0 }, + Type = 1, + }, - Craft = { - Pos = { x = -323.140, y = -129.882, z = 37.999 }, - Size = { x = 1.5, y = 1.5, z = 1.0 }, - Color = { r = 204, g = 204, b = 0 }, - Type = 1, - }, + Garage = { + Pos = { x = -97.5797576904297, y = 6496.11376953125, z = 30.4909038543701 }, + Size = { x = 1.5, y = 1.5, z = 1.0 }, + Color = { r = 204, g = 204, b = 0 }, + Type = 1, + }, - VehicleSpawnPoint = { - Pos = { x = -366.354, y = -110.766, z = 37.696 }, - Size = { x = 1.5, y = 1.5, z = 1.0 }, - Type = -1, - }, + Craft = { + Pos = { x = -323.140, y = -129.882, z = 37.999 }, + Size = { x = 1.5, y = 1.5, z = 1.0 }, + Color = { r = 204, g = 204, b = 0 }, + Type = 1, + }, - VehicleDeleter = { - Pos = { x = -386.899, y = -105.675, z = 37.683 }, - Size = { x = 3.0, y = 3.0, z = 1.0 }, - Color = { r = 204, g = 204, b = 0 }, - Type = 1, - }, + VehicleSpawnPoint = { + Pos = { x = -366.354, y = -110.766, z = 37.696 }, + Size = { x = 1.5, y = 1.5, z = 1.0 }, + Type = -1, + }, + + VehicleDeleter = { + Pos = { x = -386.899, y = -105.675, z = 37.683 }, + Size = { x = 3.0, y = 3.0, z = 1.0 }, + Color = { r = 204, g = 204, b = 0 }, + Type = 1, + }, + + VehicleDelivery = { + Pos = { x = -382.925, y = -133.748, z = 37.685 }, + Size = { x = 20.0, y = 20.0, z = 3.0 }, + Color = { r = 204, g = 204, b = 0 }, + Type = -1, + } - VehicleDelivery = { - Pos = { x = -382.925, y = -133.748, z = 37.685 }, - Size = { x = 20.0, y = 20.0, z = 3.0 }, - Color = { r = 204, g = 204, b = 0 }, - Type = -1, - }, } Config.Towables = { - { ['x'] = -2480.8720703125, ['y'] = -211.96409606934, ['z'] = 17.397672653198 }, - { ['x'] = -2723.392578125, ['y'] = 13.207388877869, ['z'] = 15.12806892395 }, - { ['x'] = -3169.6235351563, ['y'] = 976.18127441406, ['z'] = 15.038360595703 }, - { ['x'] = -3139.7568359375, ['y'] = 1078.7182617188, ['z'] = 20.189767837524 }, - { ['x'] = -1656.9357910156, ['y'] = -246.16479492188, ['z'] = 54.510955810547 }, - { ['x'] = -1586.6560058594, ['y'] = -647.56115722656, ['z'] = 29.441320419312 }, - { ['x'] = -1036.1470947266, ['y'] = -491.05856323242, ['z'] = 36.214912414551 }, - { ['x'] = -1029.1884765625, ['y'] = -475.53167724609, ['z'] = 36.416831970215 }, - { ['x'] = 75.212287902832, ['y'] = 164.8522644043, ['z'] = 104.69123077393 }, - { ['x'] = -534.60491943359, ['y'] = -756.71801757813, ['z'] = 31.599143981934 }, - { ['x'] = 487.24212646484, ['y'] = -30.827201843262, ['z'] = 88.856712341309 }, - { ['x'] = -772.20111083984, ['y'] = -1281.8114013672, ['z'] = 4.5642876625061 }, - { ['x'] = -663.84173583984, ['y'] = -1206.9936523438, ['z'] = 10.171216011047 }, - { ['x'] = 719.12451171875, ['y'] = -767.77545166016, ['z'] = 24.892364501953 }, - { ['x'] = -970.95465087891, ['y'] = -2410.4453125, ['z'] = 13.344270706177 }, - { ['x'] = -1067.5234375, ['y'] = -2571.4064941406, ['z'] = 13.211874008179 }, - { ['x'] = -619.23968505859, ['y'] = -2207.2927246094, ['z'] = 5.5659561157227 }, - { ['x'] = 1192.0831298828, ['y'] = -1336.9086914063, ['z'] = 35.106426239014 }, - { ['x'] = -432.81033325195, ['y'] = -2166.0505371094, ['z'] = 9.8885231018066 }, - { ['x'] = -451.82403564453, ['y'] = -2269.34765625, ['z'] = 7.1719741821289 }, - { ['x'] = 939.26702880859, ['y'] = -2197.5390625, ['z'] = 30.546691894531 }, - { ['x'] = -556.11486816406, ['y'] = -1794.7312011719, ['z'] = 22.043060302734 }, - { ['x'] = 591.73504638672, ['y'] = -2628.2197265625, ['z'] = 5.5735430717468 }, - { ['x'] = 1654.515625, ['y'] = -2535.8325195313, ['z'] = 74.491394042969 }, - { ['x'] = 1642.6146240234, ['y'] = -2413.3159179688, ['z'] = 93.139915466309 }, - { ['x'] = 1371.3223876953, ['y'] = -2549.525390625, ['z'] = 47.575256347656 }, - { ['x'] = 383.83779907227, ['y'] = -1652.8695068359, ['z'] = 37.278503417969 }, - { ['x'] = 27.219129562378, ['y'] = -1030.8818359375, ['z'] = 29.414621353149 }, - { ['x'] = 229.26435852051, ['y'] = -365.91101074219, ['z'] = 43.750762939453 }, - { ['x'] = -85.809432983398, ['y'] = -51.665500640869, ['z'] = 61.10591506958 }, - { ['x'] = -4.5967531204224, ['y'] = -670.27124023438, ['z'] = 31.85863494873 }, - { ['x'] = -111.89884185791, ['y'] = 91.96940612793, ['z'] = 71.080169677734 }, - { ['x'] = -314.26129150391, ['y'] = -698.23309326172, ['z'] = 32.545776367188 }, - { ['x'] = -366.90979003906, ['y'] = 115.53963470459, ['z'] = 65.575706481934 }, - { ['x'] = -592.06726074219, ['y'] = 138.20733642578, ['z'] = 60.074813842773 }, - { ['x'] = -1613.8572998047, ['y'] = 18.759860992432, ['z'] = 61.799819946289 }, - { ['x'] = -1709.7995605469, ['y'] = 55.105819702148, ['z'] = 65.706237792969 }, - { ['x'] = -521.88830566406, ['y'] = -266.7805480957, ['z'] = 34.940990447998 }, - { ['x'] = -451.08666992188, ['y'] = -333.52026367188, ['z'] = 34.021533966064 }, - { ['x'] = 322.36480712891, ['y'] = -1900.4990234375, ['z'] = 25.773607254028 }, + { ['x'] = -2480.8720703125, ['y'] = -211.96409606934, ['z'] = 17.397672653198 }, + { ['x'] = -2723.392578125, ['y'] = 13.207388877869, ['z'] = 15.12806892395 }, + { ['x'] = -3169.6235351563, ['y'] = 976.18127441406, ['z'] = 15.038360595703 }, + { ['x'] = -3139.7568359375, ['y'] = 1078.7182617188, ['z'] = 20.189767837524 }, + { ['x'] = -1656.9357910156, ['y'] = -246.16479492188, ['z'] = 54.510955810547 }, + { ['x'] = -1586.6560058594, ['y'] = -647.56115722656, ['z'] = 29.441320419312 }, + { ['x'] = -1036.1470947266, ['y'] = -491.05856323242, ['z'] = 36.214912414551 }, + { ['x'] = -1029.1884765625, ['y'] = -475.53167724609, ['z'] = 36.416831970215 }, + { ['x'] = 75.212287902832, ['y'] = 164.8522644043, ['z'] = 104.69123077393 }, + { ['x'] = -534.60491943359, ['y'] = -756.71801757813, ['z'] = 31.599143981934 }, + { ['x'] = 487.24212646484, ['y'] = -30.827201843262, ['z'] = 88.856712341309 }, + { ['x'] = -772.20111083984, ['y'] = -1281.8114013672, ['z'] = 4.5642876625061 }, + { ['x'] = -663.84173583984, ['y'] = -1206.9936523438, ['z'] = 10.171216011047 }, + { ['x'] = 719.12451171875, ['y'] = -767.77545166016, ['z'] = 24.892364501953 }, + { ['x'] = -970.95465087891, ['y'] = -2410.4453125, ['z'] = 13.344270706177 }, + { ['x'] = -1067.5234375, ['y'] = -2571.4064941406, ['z'] = 13.211874008179 }, + { ['x'] = -619.23968505859, ['y'] = -2207.2927246094, ['z'] = 5.5659561157227 }, + { ['x'] = 1192.0831298828, ['y'] = -1336.9086914063, ['z'] = 35.106426239014 }, + { ['x'] = -432.81033325195, ['y'] = -2166.0505371094, ['z'] = 9.8885231018066 }, + { ['x'] = -451.82403564453, ['y'] = -2269.34765625, ['z'] = 7.1719741821289 }, + { ['x'] = 939.26702880859, ['y'] = -2197.5390625, ['z'] = 30.546691894531 }, + { ['x'] = -556.11486816406, ['y'] = -1794.7312011719, ['z'] = 22.043060302734 }, + { ['x'] = 591.73504638672, ['y'] = -2628.2197265625, ['z'] = 5.5735430717468 }, + { ['x'] = 1654.515625, ['y'] = -2535.8325195313, ['z'] = 74.491394042969 }, + { ['x'] = 1642.6146240234, ['y'] = -2413.3159179688, ['z'] = 93.139915466309 }, + { ['x'] = 1371.3223876953, ['y'] = -2549.525390625, ['z'] = 47.575256347656 }, + { ['x'] = 383.83779907227, ['y'] = -1652.8695068359, ['z'] = 37.278503417969 }, + { ['x'] = 27.219129562378, ['y'] = -1030.8818359375, ['z'] = 29.414621353149 }, + { ['x'] = 229.26435852051, ['y'] = -365.91101074219, ['z'] = 43.750762939453 }, + { ['x'] = -85.809432983398, ['y'] = -51.665500640869, ['z'] = 61.10591506958 }, + { ['x'] = -4.5967531204224, ['y'] = -670.27124023438, ['z'] = 31.85863494873 }, + { ['x'] = -111.89884185791, ['y'] = 91.96940612793, ['z'] = 71.080169677734 }, + { ['x'] = -314.26129150391, ['y'] = -698.23309326172, ['z'] = 32.545776367188 }, + { ['x'] = -366.90979003906, ['y'] = 115.53963470459, ['z'] = 65.575706481934 }, + { ['x'] = -592.06726074219, ['y'] = 138.20733642578, ['z'] = 60.074813842773 }, + { ['x'] = -1613.8572998047, ['y'] = 18.759860992432, ['z'] = 61.799819946289 }, + { ['x'] = -1709.7995605469, ['y'] = 55.105819702148, ['z'] = 65.706237792969 }, + { ['x'] = -521.88830566406, ['y'] = -266.7805480957, ['z'] = 34.940990447998 }, + { ['x'] = -451.08666992188, ['y'] = -333.52026367188, ['z'] = 34.021533966064 }, + { ['x'] = 322.36480712891, ['y'] = -1900.4990234375, ['z'] = 25.773607254028 } } for i=1, #Config.Towables, 1 do - Config.Zones['Towable' .. i] = { - Pos = Config.Towables[i], - Size = { x = 1.5, y = 1.5, z = 1.0 }, - Color = { r = 204, g = 204, b = 0 }, - Type = -1 - } + Config.Zones['Towable' .. i] = { + Pos = Config.Towables[i], + Size = { x = 1.5, y = 1.5, z = 1.0 }, + Color = { r = 204, g = 204, b = 0 }, + Type = -1 + } end - -Config.Vehicles = { - 'adder', - 'asea', - 'asterope', - 'banshee', - 'buffalo' -} diff --git a/server/main.lua b/server/main.lua index 890bdd75..ce4baf68 100644 --- a/server/main.lua +++ b/server/main.lua @@ -9,262 +9,251 @@ PlayersCrafting3 = {} TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) if Config.MaxInService ~= -1 then - TriggerEvent('esx_service:activateService', 'mecano', Config.MaxInService) + TriggerEvent('esx_service:activateService', 'mecano', Config.MaxInService) end TriggerEvent('esx_phone:registerNumber', 'mecano', _U('mechanic_customer'), true, true) TriggerEvent('esx_society:registerSociety', 'mecano', 'Mecano', 'society_mecano', 'society_mecano', 'society_mecano', {type = 'private'}) local function Harvest(source) + SetTimeout(4000, function() - SetTimeout(4000, function() + if PlayersHarvesting[source] == true then + local xPlayer = ESX.GetPlayerFromId(source) + local GazBottleQuantity = xPlayer.getInventoryItem('gazbottle').count - if PlayersHarvesting[source] == true then + if GazBottleQuantity >= 5 then + TriggerClientEvent('esx:showNotification', source, _U('you_do_not_room')) + else + xPlayer.addInventoryItem('gazbottle', 1) + Harvest(source) + end + end - local xPlayer = ESX.GetPlayerFromId(source) - local GazBottleQuantity = xPlayer.getInventoryItem('gazbottle').count - - if GazBottleQuantity >= 5 then - TriggerClientEvent('esx:showNotification', source, _U('you_do_not_room')) - else - xPlayer.addInventoryItem('gazbottle', 1) - Harvest(source) - end - end - end) + end) end RegisterServerEvent('esx_mecanojob:startHarvest') AddEventHandler('esx_mecanojob:startHarvest', function() - local _source = source - PlayersHarvesting[_source] = true - TriggerClientEvent('esx:showNotification', _source, _U('recovery_gas_can')) - Harvest(source) + local _source = source + PlayersHarvesting[_source] = true + TriggerClientEvent('esx:showNotification', _source, _U('recovery_gas_can')) + Harvest(source) end) RegisterServerEvent('esx_mecanojob:stopHarvest') AddEventHandler('esx_mecanojob:stopHarvest', function() - local _source = source - PlayersHarvesting[_source] = false + local _source = source + PlayersHarvesting[_source] = false end) local function Harvest2(source) + SetTimeout(4000, function() - SetTimeout(4000, function() + if PlayersHarvesting2[source] == true then + local xPlayer = ESX.GetPlayerFromId(source) + local FixToolQuantity = xPlayer.getInventoryItem('fixtool').count - if PlayersHarvesting2[source] == true then + if FixToolQuantity >= 5 then + TriggerClientEvent('esx:showNotification', source, _U('you_do_not_room')) + else + xPlayer.addInventoryItem('fixtool', 1) + Harvest2(source) + end + end - local xPlayer = ESX.GetPlayerFromId(source) - local FixToolQuantity = xPlayer.getInventoryItem('fixtool').count - if FixToolQuantity >= 5 then - TriggerClientEvent('esx:showNotification', source, _U('you_do_not_room')) - else - xPlayer.addInventoryItem('fixtool', 1) - Harvest2(source) - end - end - end) + end) end RegisterServerEvent('esx_mecanojob:startHarvest2') AddEventHandler('esx_mecanojob:startHarvest2', function() - local _source = source - PlayersHarvesting2[_source] = true - TriggerClientEvent('esx:showNotification', _source, _U('recovery_repair_tools')) - Harvest2(_source) + local _source = source + PlayersHarvesting2[_source] = true + TriggerClientEvent('esx:showNotification', _source, _U('recovery_repair_tools')) + Harvest2(_source) end) RegisterServerEvent('esx_mecanojob:stopHarvest2') AddEventHandler('esx_mecanojob:stopHarvest2', function() - local _source = source - PlayersHarvesting2[_source] = false + local _source = source + PlayersHarvesting2[_source] = false end) local function Harvest3(source) + SetTimeout(4000, function() - SetTimeout(4000, function() + if PlayersHarvesting3[source] == true then + local xPlayer = ESX.GetPlayerFromId(source) + local CaroToolQuantity = xPlayer.getInventoryItem('carotool').count + if CaroToolQuantity >= 5 then + TriggerClientEvent('esx:showNotification', source, _U('you_do_not_room')) + else + xPlayer.addInventoryItem('carotool', 1) + Harvest3(source) + end + end - if PlayersHarvesting3[source] == true then - - local xPlayer = ESX.GetPlayerFromId(source) - local CaroToolQuantity = xPlayer.getInventoryItem('carotool').count - if CaroToolQuantity >= 5 then - TriggerClientEvent('esx:showNotification', source, _U('you_do_not_room')) - else - xPlayer.addInventoryItem('carotool', 1) - Harvest3(source) - end - end - end) + end) end RegisterServerEvent('esx_mecanojob:startHarvest3') AddEventHandler('esx_mecanojob:startHarvest3', function() - local _source = source - PlayersHarvesting3[_source] = true - TriggerClientEvent('esx:showNotification', _source, _U('recovery_body_tools')) - Harvest3(_source) + local _source = source + PlayersHarvesting3[_source] = true + TriggerClientEvent('esx:showNotification', _source, _U('recovery_body_tools')) + Harvest3(_source) end) RegisterServerEvent('esx_mecanojob:stopHarvest3') AddEventHandler('esx_mecanojob:stopHarvest3', function() - local _source = source - PlayersHarvesting3[_source] = false + local _source = source + PlayersHarvesting3[_source] = false end) local function Craft(source) + SetTimeout(4000, function() - SetTimeout(4000, function() + if PlayersCrafting[source] == true then + local xPlayer = ESX.GetPlayerFromId(source) + local GazBottleQuantity = xPlayer.getInventoryItem('gazbottle').count - if PlayersCrafting[source] == true then + if GazBottleQuantity <= 0 then + TriggerClientEvent('esx:showNotification', source, _U('not_enough_gas_can')) + else + xPlayer.removeInventoryItem('gazbottle', 1) + xPlayer.addInventoryItem('blowpipe', 1) + Craft(source) + end + end - local xPlayer = ESX.GetPlayerFromId(source) - local GazBottleQuantity = xPlayer.getInventoryItem('gazbottle').count - - if GazBottleQuantity <= 0 then - TriggerClientEvent('esx:showNotification', source, _U('not_enough_gas_can')) - else - xPlayer.removeInventoryItem('gazbottle', 1) - xPlayer.addInventoryItem('blowpipe', 1) - Craft(source) - end - end - end) + end) end RegisterServerEvent('esx_mecanojob:startCraft') AddEventHandler('esx_mecanojob:startCraft', function() - local _source = source - PlayersCrafting[_source] = true - TriggerClientEvent('esx:showNotification', _source, _U('assembling_blowtorch')) - Craft(_source) + local _source = source + PlayersCrafting[_source] = true + TriggerClientEvent('esx:showNotification', _source, _U('assembling_blowtorch')) + Craft(_source) end) RegisterServerEvent('esx_mecanojob:stopCraft') AddEventHandler('esx_mecanojob:stopCraft', function() - local _source = source - PlayersCrafting[_source] = false + local _source = source + PlayersCrafting[_source] = false end) local function Craft2(source) + SetTimeout(4000, function() - SetTimeout(4000, function() + if PlayersCrafting2[source] == true then + local xPlayer = ESX.GetPlayerFromId(source) + local FixToolQuantity = xPlayer.getInventoryItem('fixtool').count - if PlayersCrafting2[source] == true then + if FixToolQuantity <= 0 then + TriggerClientEvent('esx:showNotification', source, _U('not_enough_repair_tools')) + else + xPlayer.removeInventoryItem('fixtool', 1) + xPlayer.addInventoryItem('fixkit', 1) + Craft2(source) + end + end - local xPlayer = ESX.GetPlayerFromId(source) - local FixToolQuantity = xPlayer.getInventoryItem('fixtool').count - if FixToolQuantity <= 0 then - TriggerClientEvent('esx:showNotification', source, _U('not_enough_repair_tools')) - else - xPlayer.removeInventoryItem('fixtool', 1) - xPlayer.addInventoryItem('fixkit', 1) - Craft2(source) - end - end - end) + end) end RegisterServerEvent('esx_mecanojob:startCraft2') AddEventHandler('esx_mecanojob:startCraft2', function() - local _source = source - PlayersCrafting2[_source] = true - TriggerClientEvent('esx:showNotification', _source, _U('assembling_repair_kit')) - Craft2(_source) + local _source = source + PlayersCrafting2[_source] = true + TriggerClientEvent('esx:showNotification', _source, _U('assembling_repair_kit')) + Craft2(_source) end) RegisterServerEvent('esx_mecanojob:stopCraft2') AddEventHandler('esx_mecanojob:stopCraft2', function() - local _source = source - PlayersCrafting2[_source] = false + local _source = source + PlayersCrafting2[_source] = false end) local function Craft3(source) + SetTimeout(4000, function() - SetTimeout(4000, function() + if PlayersCrafting3[source] == true then + local xPlayer = ESX.GetPlayerFromId(source) + local CaroToolQuantity = xPlayer.getInventoryItem('carotool').count - if PlayersCrafting3[source] == true then + if CaroToolQuantity <= 0 then + TriggerClientEvent('esx:showNotification', source, _U('not_enough_body_tools')) + else + xPlayer.removeInventoryItem('carotool', 1) + xPlayer.addInventoryItem('carokit', 1) + Craft3(source) + end + end - local xPlayer = ESX.GetPlayerFromId(source) - local CaroToolQuantity = xPlayer.getInventoryItem('carotool').count - if CaroToolQuantity <= 0 then - TriggerClientEvent('esx:showNotification', source, _U('not_enough_body_tools')) - else - xPlayer.removeInventoryItem('carotool', 1) - xPlayer.addInventoryItem('carokit', 1) - Craft3(source) - end - end - end) + end) end RegisterServerEvent('esx_mecanojob:startCraft3') AddEventHandler('esx_mecanojob:startCraft3', function() - local _source = source - PlayersCrafting3[_source] = true - TriggerClientEvent('esx:showNotification', _source, _U('assembling_body_kit')) - Craft3(_source) + local _source = source + PlayersCrafting3[_source] = true + TriggerClientEvent('esx:showNotification', _source, _U('assembling_body_kit')) + Craft3(_source) end) RegisterServerEvent('esx_mecanojob:stopCraft3') AddEventHandler('esx_mecanojob:stopCraft3', function() - local _source = source - PlayersCrafting3[_source] = false + local _source = source + PlayersCrafting3[_source] = false end) RegisterServerEvent('esx_mecanojob:onNPCJobMissionCompleted') AddEventHandler('esx_mecanojob:onNPCJobMissionCompleted', function() + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + local total = math.random(Config.NPCJobEarnings.min, Config.NPCJobEarnings.max); - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - local total = math.random(Config.NPCJobEarnings.min, Config.NPCJobEarnings.max); + if xPlayer.job.grade >= 3 then + total = total * 2 + end - if xPlayer.job.grade >= 3 then - total = total * 2 - end - - TriggerEvent('esx_addonaccount:getSharedAccount', 'society_mecano', function(account) - account.addMoney(total) - end) - - TriggerClientEvent("esx:showNotification", _source, _U('your_comp_earned').. total) + TriggerEvent('esx_addonaccount:getSharedAccount', 'society_mecano', function(account) + account.addMoney(total) + end) + TriggerClientEvent("esx:showNotification", _source, _U('your_comp_earned').. total) end) ESX.RegisterUsableItem('blowpipe', function(source) + local _source = source + local xPlayer = ESX.GetPlayerFromId(source) - local _source = source - local xPlayer = ESX.GetPlayerFromId(source) - - xPlayer.removeInventoryItem('blowpipe', 1) - - TriggerClientEvent('esx_mecanojob:onHijack', _source) - TriggerClientEvent('esx:showNotification', _source, _U('you_used_blowtorch')) + xPlayer.removeInventoryItem('blowpipe', 1) + TriggerClientEvent('esx_mecanojob:onHijack', _source) + TriggerClientEvent('esx:showNotification', _source, _U('you_used_blowtorch')) end) ESX.RegisterUsableItem('fixkit', function(source) + local _source = source + local xPlayer = ESX.GetPlayerFromId(source) - local _source = source - local xPlayer = ESX.GetPlayerFromId(source) - - xPlayer.removeInventoryItem('fixkit', 1) - - TriggerClientEvent('esx_mecanojob:onFixkit', _source) - TriggerClientEvent('esx:showNotification', _source, _U('you_used_repair_kit')) + xPlayer.removeInventoryItem('fixkit', 1) + TriggerClientEvent('esx_mecanojob:onFixkit', _source) + TriggerClientEvent('esx:showNotification', _source, _U('you_used_repair_kit')) end) ESX.RegisterUsableItem('carokit', function(source) + local _source = source + local xPlayer = ESX.GetPlayerFromId(source) - local _source = source - local xPlayer = ESX.GetPlayerFromId(source) - - xPlayer.removeInventoryItem('carokit', 1) - - TriggerClientEvent('esx_mecanojob:onCarokit', _source) - TriggerClientEvent('esx:showNotification', _source, _U('you_used_body_kit')) + xPlayer.removeInventoryItem('carokit', 1) + TriggerClientEvent('esx_mecanojob:onCarokit', _source) + TriggerClientEvent('esx:showNotification', _source, _U('you_used_body_kit')) end) RegisterServerEvent('esx_mecanojob:getStockItem') @@ -274,10 +263,10 @@ AddEventHandler('esx_mecanojob:getStockItem', function(itemName, count) TriggerEvent('esx_addoninventory:getSharedInventory', 'society_mecano', function(inventory) local item = inventory.getItem(itemName) local sourceItem = xPlayer.getInventoryItem(itemName) - + -- is there enough in the society? if count > 0 and item.count >= count then - + -- can the player carry the said amount of x item? if sourceItem.limit ~= -1 and (sourceItem.count + count) > sourceItem.limit then TriggerClientEvent('esx:showNotification', xPlayer.source, _U('player_cannot_hold')) @@ -293,43 +282,33 @@ AddEventHandler('esx_mecanojob:getStockItem', function(itemName, count) end) ESX.RegisterServerCallback('esx_mecanojob:getStockItems', function(source, cb) - - TriggerEvent('esx_addoninventory:getSharedInventory', 'society_mecano', function(inventory) - cb(inventory.items) - end) - + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_mecano', function(inventory) + cb(inventory.items) + end) end) RegisterServerEvent('esx_mecanojob:putStockItems') AddEventHandler('esx_mecanojob:putStockItems', function(itemName, count) + local xPlayer = ESX.GetPlayerFromId(source) - local xPlayer = ESX.GetPlayerFromId(source) + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_mecano', function(inventory) + local item = inventory.getItem(itemName) + local playerItemCount = xPlayer.getInventoryItem(itemName).count - TriggerEvent('esx_addoninventory:getSharedInventory', 'society_mecano', function(inventory) - - local item = inventory.getItem(itemName) - local playerItemCount = xPlayer.getInventoryItem(itemName).count - - if item.count >= 0 and count <= playerItemCount then - xPlayer.removeInventoryItem(itemName, count) - inventory.addItem(itemName, count) - else - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_quantity')) - end - - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', count, item.label)) - - end) + if item.count >= 0 and count <= playerItemCount then + xPlayer.removeInventoryItem(itemName, count) + inventory.addItem(itemName, count) + else + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_quantity')) + end + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', count, item.label)) + end) end) ESX.RegisterServerCallback('esx_mecanojob:getPlayerInventory', function(source, cb) + local xPlayer = ESX.GetPlayerFromId(source) + local items = xPlayer.inventory - local xPlayer = ESX.GetPlayerFromId(source) - local items = xPlayer.inventory - - cb({ - items = items - }) - + cb({items = items}) end)