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