· 7 years ago · Feb 23, 2019, 04:56 AM
1local meta = FindMetaTable( "Player" )
2
3TeamTable = {}
4RegTable = {}
5RegRanks = {}
6
7local admintable = {
8 ["owner"] = true,
9 ["founder"] = true,
10 ["community manager"] = true,
11 ["staff manager"] = true,
12 ["server manager"] = true,
13
14 ["superadmin"] = true,
15 ["admin"] = true,
16 ["senior moderator"] = true,
17 ["moderator"] = true,
18 ["junior moderator"] = true,
19 ["trial moderator"] = true,
20
21 ["community event manager"] = true,
22 ["server event manager"] = true,
23 ["senior event master"] = true,
24 ["event master"] = true,
25 ["trial event master"] = true,
26 ["junior event master"] = true,
27
28 ["community developer"] = true,
29 ["developer"] = true,
30 ["senior developer"] = true,
31}
32
33function meta:IsAdmin()
34 if admintable[ string.lower( self:GetUserGroup() ) ] then return true end
35 return false
36end
37
38function CreateTeam( name, teamtbl )
39 if !istable( teamtbl ) then ErrorNoHalt( "Failed to create team, " .. ( name or "nil" ) ) return end
40
41 teamtbl.Weapons = teamtbl.Weapons or {}
42 teamtbl.Health = teamtbl.Health or 100
43 teamtbl.Clearance = teamtbl.Clearance or "Unassigned"
44 teamtbl.Colour = teamtbl.Colour or Color( 255, 255, 255 )
45 teamtbl.Side = teamtbl.Side or 0
46 teamtbl.Rank = teamtbl.Rank or 0
47 teamtbl.Model = teamtbl.Model or ""
48 teamtbl.Bodygroups = teamtbl.Bodygroups or ""
49 teamtbl.Regiment = teamtbl.Regiment or ""
50 teamtbl.Name = name
51
52 local count = table.Count( TeamTable )
53
54 teamtbl.Count = count
55
56 team.SetUp( count, name, teamtbl.Colour )
57 TeamTable[ count ] = teamtbl
58
59 local shouldteam = true
60 for k, v in pairs( RegTable ) do
61 if v.Regiment == teamtbl.Regiment then shouldteam = false break end
62 end
63 if shouldteam then
64 table.insert( RegTable, teamtbl )
65 end
66 RegRanks[ teamtbl.Regiment ] = RegRanks[ teamtbl.Regiment ] or {}
67 RegRanks[ teamtbl.Regiment ][ count ] = name
68 if type(teamtbl.Model) == "table" then
69 for _, v in pairs(teamtbl.Model) do util.PrecacheModel(v) end
70 else
71 util.PrecacheModel( teamtbl.Model )
72 end
73 util.PrecacheModel( "models/imperial_officer/officer.mdl" )
74 return count
75end
76
77if SERVER then
78 if ( !sql.TableExists( "jobdata" ) ) then
79 sql.Query( "CREATE TABLE IF NOT EXISTS jobdata ( steamid TEXT NOT NULL PRIMARY KEY, value TEXT );" )
80 end
81
82 function meta:GetJData( name, default )
83 name = string.format( "%s[%s]", self:SteamID64(), name )
84 local val = sql.QueryValue( "SELECT value FROM jobdata WHERE steamid = " .. sql.SQLStr( name ) .. " LIMIT 1" )
85 if ( val == nil ) then return default end
86 return val
87 end
88
89 function meta:SetJData( name, value )
90 name = string.format( "%s[%s]", self:SteamID64(), name )
91 sql.Query( "REPLACE INTO jobdata ( steamid, value ) VALUES ( " .. sql.SQLStr( name ) .. ", " .. sql.SQLStr( value ) .. " )" )
92 end
93
94 if !file.Exists( "spawns.txt", "DATA" ) then file.Write( "spawns.txt", util.TableToJSON( {} ) ) end
95
96 local spawnTable = util.JSONToTable( file.Read( "spawns.txt", "DATA" ) )
97
98 hook.Add( "PlayerSay", "SetSpawn", function( ply, text )
99
100 if !ply:IsSuperAdmin() then return end
101
102 text = string.Explode( " ", text )
103
104 if string.lower( text[ 1 ] ) == "!setspawn" or string.lower( text[ 1 ] ) == "/setspawn" then
105 if text[ 2 ] == nil then return "" end
106 local t = string.lower( table.concat( text, " ", 2 ) )
107 spawnTable[ game.GetMap() ] = spawnTable[ game.GetMap() ] or {}
108 spawnTable[ game.GetMap() ][ t ] = ply:GetPos()
109 file.Write( "spawns.txt", util.TableToJSON( spawnTable ) )
110 ply:PrintMessage( HUD_PRINTTALK, "[UPDATED SPAWN]" )
111 ply:PrintMessage( HUD_PRINTTALK, string.upper(t) )
112 return ""
113 end
114 end )
115
116 hook.Add( "PlayerSay", "DelSpawn", function( ply, text )
117
118 if !ply:IsSuperAdmin() then return end
119
120 text = string.Explode( " ", text )
121
122 if string.lower( text[ 1 ] ) == "!delspawn" or string.lower( text[ 1 ] ) == "/delspawn" then
123 if text[ 2 ] == nil then return "" end
124 local t = string.lower( table.concat( text, " ", 2 ) )
125 if string.lower(t) == "default" then
126 ply:PrintMessage( HUD_PRINTTALK, "[DEFAULT SPAWN CANNOT BE DELETED]" )
127 return ""
128 end
129 spawnTable[ game.GetMap() ] = spawnTable[ game.GetMap() ] or {}
130 spawnTable[ game.GetMap() ][ t ] = nil
131 file.Write( "spawns.txt", util.TableToJSON( spawnTable ) )
132 ply:PrintMessage( HUD_PRINTTALK, "[DELETED SPAWN]" )
133 ply:PrintMessage( HUD_PRINTTALK, string.upper(t) )
134 return ""
135 end
136 end )
137
138 function GM:PlayerInitialSpawn( ply )
139 if ply:GetJData( "job", nil ) ~= nil then
140 local job = ply:GetJData( "job", nil )
141 local tbl = TeamTable[ tonumber( job ) ]
142 ply:SetTeam( job )
143 ply:Spawn()
144 if type(tbl.Model) == "table" then
145 ply:SetModel( table.Random(tbl.Model) )
146 else
147 ply:SetModel( tbl.Model )
148 end
149 ply:SetBodyGroups(tbl.Bodygroups)
150 else
151 local tbl = TeamTable[ TEAM_ST_RECRUIT ]
152 ply:SetJData( "job", TEAM_ST_RECRUIT )
153 ply:SetTeam( TEAM_ST_RECRUIT )
154 if type(tbl.Model) == "table" then
155 ply:SetModel( table.Random(tbl.Model) )
156 else
157 ply:SetModel( tbl.Model )
158 end
159 end
160 end
161
162 function GM:PlayerSpawn( ply )
163 ply:SetRunSpeed( 240 )
164 ply:SetWalkSpeed( 160 )
165
166 if ply:IsAdmin() then
167 ply:Give("weapon_physgun")
168 ply:Give("gmod_tool")
169 end
170
171 if TeamTable[ ply:Team() ] then
172
173 local tbl = TeamTable[ ply:Team() ]
174
175 local tbl = TeamTable[ ply:Team() ]
176 if spawnTable[ game.GetMap() ] and spawnTable[ game.GetMap() ][ string.lower( tbl.Regiment ) ] then
177 ply:SetPos( spawnTable[ game.GetMap() ][ string.lower( tbl.Regiment ) ] )
178 elseif spawnTable[ game.GetMap() ] and spawnTable[ game.GetMap() ][ "default" ] then
179 ply:SetPos( spawnTable[ game.GetMap() ][ "default" ] )
180 end
181
182 end
183
184 if ply:GetJData( "job", nil ) ~= nil then
185 if tonumber(ply:GetJData( "job", nil )) ~= ply:Team() then
186
187 local tbl = TeamTable[ ply:Team() ]
188
189 if type(tbl.Model) == "table" then
190 ply:SetModel( table.Random(tbl.Model) )
191 else
192 ply:SetModel( tbl.Model )
193 end
194
195 ply:SetHealth(tbl.Health)
196 ply:SetMaxHealth(tbl.Health)
197
198 local weps = tbl.Weapons
199
200 for i = 1, #weps do
201 ply:Give( weps[ i ] )
202 end
203
204 else
205
206 local job = ply:GetJData( "job", nil )
207 local tbl = TeamTable[ tonumber( job ) ]
208
209 if type(tbl.Model) == "table" then
210 ply:SetModel( table.Random(tbl.Model) )
211 else
212 ply:SetModel( tbl.Model )
213 end
214
215 ply:SetHealth(tbl.Health)
216 ply:SetMaxHealth(tbl.Health)
217
218 local weps = tbl.Weapons
219
220 for i = 1, #weps do
221 ply:Give( weps[ i ] )
222 end
223
224 end
225
226 ply:Give( "weapon_empty_hands" )
227 ply:Give( "climb_swep2" )
228 ply:Give( "bkeycard" )
229
230 weps = ply:GetWeapons()
231
232 for i = 1, #weps do
233 if weps[ i ]:GetClass() == "tfa_swch_clonelauncher" then continue end
234 ply:GiveAmmo( 256, weps[ i ]:GetPrimaryAmmoType(), true )
235 end
236 end
237 end
238end