diff --git a/gamemode/modules/base/cl_jobmodels.lua b/gamemode/modules/base/cl_jobmodels.lua index 3a8b5d8e4..8dfb33ff7 100644 --- a/gamemode/modules/base/cl_jobmodels.lua +++ b/gamemode/modules/base/cl_jobmodels.lua @@ -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 = {} @@ -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) @@ -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 @@ -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)