Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions [SQL]/legacy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -235,27 +235,28 @@ INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES
CREATE TABLE `jobs` (
`name` varchar(50) NOT NULL,
`label` varchar(50) DEFAULT NULL,
`type` varchar(50) NOT NULL DEFAULT 'civ',
`whitelisted` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB;

--
-- Dumping data for table `jobs`
--

INSERT INTO `jobs` (`name`, `label`, `whitelisted`) VALUES
('ambulance', 'EMS', 0),
('cardealer', 'Cardealer', 0),
('fisherman', 'Fisherman', 0),
('fueler', 'Fueler', 0),
('lumberjack', 'Lumberjack', 0),
('mechanic', 'Mechanic', 0),
('miner', 'Miner', 0),
('police', 'LSPD', 0),
('reporter', 'Reporter', 0),
('slaughterer', 'Butcher', 0),
('tailor', 'Tailor', 0),
('taxi', 'Taxi', 0),
('unemployed', 'Unemployed', 0);
INSERT INTO `jobs` (`name`, `label`, `type`, `whitelisted`) VALUES
('ambulance', 'EMS', 'ems', 0),
('cardealer', 'Cardealer', 'civ', 0),
('fisherman', 'Fisherman', 'civ', 0),
('fueler', 'Fueler', 'civ', 0),
('lumberjack', 'Lumberjack', 'civ', 0),
('mechanic', 'Mechanic', 'mechanic', 0),
('miner', 'Miner', 'civ', 0),
('police', 'LSPD', 'leo', 0),
('reporter', 'Reporter', 'civ', 0),
('slaughterer', 'Butcher', 'civ', 0),
('tailor', 'Tailor', 'civ', 0),
('taxi', 'Taxi', 'civ', 0),
('unemployed', 'Unemployed', 'civ', 0);

-- --------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions [core]/es_extended/server/classes/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ function CreateExtendedPlayer(playerId, identifier, ssn, group, accounts, invent
id = jobObject.id,
name = jobObject.name,
label = jobObject.label,
type = jobObject.type,
onDuty = onDuty,

grade = tonumber(grade) or 0,
Expand Down
25 changes: 22 additions & 3 deletions [core]/es_extended/server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ function ESX.RefreshJobs()

if not Jobs then
-- Fallback data, if no jobs exist
ESX.Jobs["unemployed"] = { name = "unemployed", label = "Unemployed", whitelisted = false, grades = { ["0"] = { grade = 0, name = "unemployed", label = "Unemployed", salary = 200, skin_male = {}, skin_female = {} } } }
ESX.Jobs["unemployed"] = { name = "unemployed", label = "Unemployed", type = "civ", whitelisted = false, grades = { ["0"] = { grade = 0, name = "unemployed", label = "Unemployed", salary = 200, skin_male = {}, skin_female = {} } } }
else
ESX.Jobs = Jobs
end
Expand Down Expand Up @@ -628,13 +628,32 @@ function ESX.GetItemLabel(item)
end
end

---@param jobType string|string[]?
---@return table
function ESX.GetJobs()
function ESX.GetJobs(jobType)
while not Core.JobsLoaded do
Citizen.Wait(200)
end

return ESX.Jobs
if not jobType then
return ESX.Jobs
end

jobType = type(jobType) == "string" and { jobType } or jobType

local jobTypeLookup = {}
for i = 1, #jobType do
jobTypeLookup[jobType[i]] = true
end

local filteredJobs = {}
for jobName, jobObject in pairs(ESX.Jobs) do
if jobTypeLookup[jobObject.type] then
filteredJobs[jobName] = jobObject
end
end

return filteredJobs
end

---@return table
Expand Down
1 change: 1 addition & 0 deletions [core]/es_extended/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function loadESXPlayer(identifier, playerId, isNew)
id = jobObject.id,
name = jobObject.name,
label = jobObject.label,
type = jobObject.type,

grade = tonumber(grade),
grade_name = gradeObject.name,
Expand Down
35 changes: 35 additions & 0 deletions [core]/es_extended/server/migration/v1.13.5/jobType/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
local esxVersion = "v1.13.5"

Core.Migrations = Core.Migrations or {}
Core.Migrations[esxVersion] = Core.Migrations[esxVersion] or {}

if GetResourceKvpInt(("esx_migration:%s"):format(esxVersion)) == 1 then
return
end

---@return boolean restartRequired
Core.Migrations[esxVersion].jobTypes = function()
print("^4[esx_migration:v1.13.5:jobTypes]^7 Adding job type column to jobs table.")

local col = MySQL.scalar.await([[
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'jobs'
AND COLUMN_NAME = 'type'
]])

if col == 0 then
print("^4[esx_migration:v1.13.5:jobTypes]^7 Column not found, altering jobs table.")
MySQL.update.await([[
ALTER TABLE `jobs`
ADD COLUMN `type` VARCHAR(50) NOT NULL DEFAULT 'civ' AFTER `label`
]])
else
print("^4[esx_migration:v1.13.5:jobTypes]^7 Column already exists, migration not needed.")
return false
end

print("^4[esx_migration:v1.13.5:jobTypes]^7 Migration complete.")
return true
end
15 changes: 10 additions & 5 deletions [core]/es_extended/server/modules/createJob.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ local function doesJobAndGradesExist(name, grades)
return true
end

local function generateNewJobTable(name, label, grades)
local job = { name = name, label = label, grades = {} }
local function generateNewJobTable(name, label, grades, jobType)
local job = { name = name, label = label, type = jobType, grades = {} }
for _, v in pairs(grades) do
job.grades[tostring(v.grade)] = { job_name = name, grade = v.grade, name = v.name, label = v.label, salary = v.salary, skin_male = v.skin_male or '{}', skin_female = v.skin_female or '{}' }
end
Expand All @@ -42,7 +42,8 @@ end
--- @param name string
--- @param label string
--- @param grades table
function ESX.CreateJob(name, label, grades)
--- @param jobType string
function ESX.CreateJob(name, label, grades, jobType)
local currentResourceName = GetInvokingResource()
local success = false

Expand All @@ -61,6 +62,10 @@ function ESX.CreateJob(name, label, grades)
return success
end

if type(jobType) ~= "string" then
jobType = "civ"
end

local currentJobExist = doesJobAndGradesExist(name, grades)

if currentJobExist then
Expand All @@ -69,7 +74,7 @@ function ESX.CreateJob(name, label, grades)
end

local queries = {
{ query = 'INSERT INTO jobs (name, label) VALUES (?, ?)', values = { name, label } }
{ query = 'INSERT INTO `jobs` (`name`, `label`, `type`) VALUES (?, ?, ?)', values = { name, label, jobType } }
}

for _, grade in pairs(grades) do
Expand All @@ -86,7 +91,7 @@ function ESX.CreateJob(name, label, grades)
return success
end

ESX.Jobs[name] = generateNewJobTable(name, label, grades)
ESX.Jobs[name] = generateNewJobTable(name, label, grades, jobType)

notify("SUCCESS", currentResourceName, 'Job created successfully: `%s`', name)

Expand Down
Loading