· 6 years ago · Jun 16, 2019, 02:06 AM
1hook.Add("DatabaseInitialized", "DarkRP_PersistentJobs", function()
2 MySQLite.query([[
3 CREATE TABLE IF NOT EXISTS darkrp_persistentjobs(
4 uid BIGINT NOT NULL PRIMARY KEY,
5 job TINYINT UNSIGNED NOT NULL
6 );
7 ]])
8end)
9local initialSpawn = GM.PlayerInitialSpawn
10function GM:PlayerInitialSpawn(ply)
11 initialSpawn(self, ply)
12 MySQLite.query("SELECT job FROM darkrp_persistentjobs WHERE uid = " .. ply:UniqueID() .. ";", function(data)
13 if not IsValid(ply) then return end
14
15 local info = data and data[1] or {}
16 local teamIndex = info.job or self.DefaultTeam
17 ply:updateJob(team.GetName(teamIndex))
18 ply:SetTeam(teamIndex)
19
20 if not data then
21 MySQLite.query([[REPLACE INTO darkrp_persistentjobs VALUES(]] .. ply:UniqueID() .. [[, ]] .. teamIndex .. [[);]])
22 end
23 end)
24end
25hook.Add("OnPlayerChangedTeam", "DarkRP_PersistentJobs", function(ply, _, newTeam)
26 MySQLite.query([[UPDATE darkrp_persistentjobs SET job = ]] .. newTeam .. [[ WHERE uid = ]] .. ply:UniqueID())
27end)