Skip to content

Commit

Permalink
Fix Job Requirement Config Option
Browse files Browse the repository at this point in the history
Script wasn't properly populating the job into the shared object, or into the cityhall. Newest update now allows for the auto-population of both on startup.
  • Loading branch information
DonHulieo committed Sep 18, 2023
1 parent 89129f2 commit dc83bfc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Warehousing script for QBCore
- Can be used for a specific job (set in the config) or for anyone as an activity
- Can be configured for multiple warehouses (set in the config) ~ Supports 3 warehouses by default and Ultrunz's Warehouse
- Earn Bonus Money for completing the job without damaging the pallets
- A percantage of money earned through deliveries is sent to the business society
- A percentage of money earned through deliveries is sent to the business society

## Installation

Expand All @@ -27,6 +27,33 @@ Warehousing script for QBCore

- **Note:** If RequiresJob is set to true, the job can be set in the config, if set to false, the job is not required.

### When using the Job Requirement

- You don't need to add the job to your qb-core config, as it will be added automatically
- Find the following code in qb-cityhall/server/main.lua, in the 'qb-cityhall:server:ApplyJob' Event

```lua
if QBCore.Shared.QBJobsStatus then
exports["qb-jobs"]:submitApplication(data, "Jobs")
else
local JobInfo = QBCore.Shared.Jobs[job]
Player.Functions.SetJob(data.job, 0)
TriggerClientEvent('QBCore:Notify', data.src, Lang:t('info.new_job', { job = JobInfo.label }))
end
```

- Replace it with the following code

```lua
if QBCore.Shared.QBJobsStatus then
exports["qb-jobs"]:submitApplication(data, "Jobs")
else
local JobInfo = QBCore.Shared.Jobs[job] or availableJobs[job]
Player.Functions.SetJob(data.job, 0)
TriggerClientEvent('QBCore:Notify', data.src, Lang:t('info.new_job', { job = JobInfo.label }))
end
```

## Job Locations

- For the Warehouse used in the preview:
Expand Down
7 changes: 5 additions & 2 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ local function getUsersCurrentWarehouse()
for current = 1, #Config.Locations do
if Config.Locations[current].inUse and Config.Locations[current].user == identifier then return current end
end
return nil
end

---@param location number
Expand Down Expand Up @@ -535,7 +534,11 @@ end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
for id, warehouse in pairs(Config.Locations) do
if Config.RequiresJob then
if JobInfo.name == Config.Job then
local function getK()
for k in pairs(Config.Job) do return k end
end
local tableName = getK()
if JobInfo.name == tableName then
PlayerData.job = JobInfo
if Config.Blips then
createBlip(warehouse['Start'].coords, warehouse['Blips'].label, warehouse['Blips'].sprite, warehouse['Blips'].color, warehouse['Blips'].scale)
Expand Down
6 changes: 4 additions & 2 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Config.PalletMarkers = { -- Pallet markers | https://docs.fivem.net/docs/game-re

Config.FuelSystem = 'LegacyFuel' -- Fuel system your server is using

Config.RequiresJob = false -- Enable if you want to require a job to an order
Config.RequiresJob = true -- Enable if you want to require a job to an order
Config.IsManaged = true -- Enable if you want to use the QB-Cityhall job management system
Config.Job = {
['logistics'] = {
label = 'Warehouse Logistics',
Expand All @@ -36,7 +37,8 @@ Config.Job = {
},
['3'] = {
name = 'Owner',
pay = 750
pay = 750,
isboss = true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ game 'gta5'

author 'DonHulieo'
description 'Warehousing Job for QBCore'
version '1.1.9'
version '1.2.0'

shared_scripts {'config.lua'}

Expand Down
7 changes: 6 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ QBCore.Functions.CreateCallback('don-forklift:server:GetLocations', function(sou
end)

if Config.RequiresJob then
QBCore.Functions.AddJobs(Config.Job['logistics'])
local function getK()
for k in pairs(Config.Job) do return k end
end
local tableName = getK()
QBCore.Functions.AddJob(tableName, Config.Job[tableName])
exports['qb-cityhall']:AddCityJob(tableName, {label = Config.Job[tableName].label, isManaged = Config.IsManaged})
end

-------------------------------- THREADS --------------------------------
Expand Down

0 comments on commit dc83bfc

Please sign in to comment.