Skip to content

Commit

Permalink
Isolate PreferredJobModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Be1zebub authored Sep 13, 2024
1 parent 8762674 commit d39acb5
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions gamemode/modules/base/cl_jobmodels.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sql.Query([[CREATE TABLE IF NOT EXISTS darkp_playermodels(
model VARCHAR(140) NOT NULL
);]])

sql.Query("ALTER TABLE darkp_playermodels ADD COLUMN IF NOT EXISTS server VARCHAR(21);")

local preferredModels = {}


Expand All @@ -14,7 +16,7 @@ function DarkRP.setPreferredJobModel(teamNr, model)
local job = RPExtraTeams[teamNr]
if not job then return end
preferredModels[job.command] = model
sql.Query(string.format([[REPLACE INTO darkp_playermodels VALUES(%s, %s);]], sql.SQLStr(job.command), sql.SQLStr(model)))
sql.Query(string.format([[REPLACE INTO darkp_playermodels VALUES(%s, %s, %s);]], sql.SQLStr(job.command), sql.SQLStr(model), sql.SQLStr(game.GetIPAddress())))

net.Start("DarkRP_preferredjobmodel")
net.WriteUInt(teamNr, 8)
Expand All @@ -31,7 +33,7 @@ end
--[[---------------------------------------------------------------------------
Load the preferred models
---------------------------------------------------------------------------]]
local function sendModels() -- run after the jobs have loaded
local function sendModels()
net.Start("DarkRP_preferredjobmodels")
for _, job in pairs(RPExtraTeams) do
if not preferredModels[job.command] then net.WriteBit(false) continue end
Expand All @@ -42,11 +44,22 @@ local function sendModels() -- run after the jobs have loaded
net.SendToServer()
end

do
local models = sql.Query([[SELECT jobcmd, model FROM darkp_playermodels;]])
local function jobHasModel(job, model)
return istable(job.model) and table.HasValue(job.model, model) or job.model == model
end

timer.Simple(0, function()
-- run after the jobs have loaded
local models = sql.Query([[SELECT jobcmd, model, server FROM darkp_playermodels;]])

for _, v in ipairs(models or {}) do
if v.server and v.server ~= game.GetIPAddress() then continue end

local job = DarkRP.getJobByCommand(v.jobcmd)
if job == nil or jobHasModel(job, v.model) == false then continue end

preferredModels[v.jobcmd] = v.model
end

timer.Simple(0, sendModels)
end
sendModels()
end)

0 comments on commit d39acb5

Please sign in to comment.