Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. if CLIENT then
  2. function BTK.TeamsMenu()
  3. local frame = vgui.Create()
  4. end
  5.  
  6. --Client can stop here
  7. return
  8. end
  9.  
  10.  
  11. if SERVER then
  12.  
  13. BTK.ActiveTeams = {}
  14.  
  15. local Team = {
  16. Name = "base",
  17. FormalName = "Base Team",
  18.  
  19. WalkSpeed = 400, -- How fast to move when not running
  20. RunSpeed = 600, -- How fast to move when running
  21. CrouchedWalkSpeed = 0.3, -- Multiply move speed by this when crouching
  22. DuckSpeed = 0.3, -- How fast to go from not ducking, to ducking
  23. UnDuckSpeed = 0.3, -- How fast to go from ducking, to not ducking
  24. JumpPower = 200, -- How powerful our jump should be
  25. CanUseFlashlight = true, -- Can we use the flashlight
  26. MaxHealth = 100, -- Max health we can have
  27. StartHealth = 100, -- How much health we start with
  28. StartArmor = 0, -- How much armour we start with
  29. DropWeaponOnDie = false, -- Do we drop our weapon when we die
  30. TeammateNoCollide = true, -- Do we collide with teammates or run straight through them
  31. AvoidPlayers = true, -- Automatically swerves around other players
  32. UseVMHands = true, -- Uses viewmodel hands
  33. Model = nil, -- Team Player Model
  34. Members = {},
  35. isJoinable = true,
  36. TeamColor = nil,
  37. Index = 0,
  38.  
  39. --Hooks
  40. PlayerSpawn = function( self, ply )
  41.  
  42. end,
  43.  
  44. PlayerLoadout = function( self, ply )
  45. print("This is being called!")
  46.  
  47. ply:RemoveAllAmmo()
  48. ply:StripWeapons()
  49.  
  50. for _,v in pairs(BTK.DefaultLoadout) do
  51. ply:Give(v)
  52. end
  53.  
  54. return true
  55. end,
  56.  
  57. --This isn't working right... I'll try again later. For some reason, the models are T-posing instead of animating.
  58. PlayerSetModel = function( self, ply )
  59. local cl_playermodel = ply:GetInfo( "cl_playermodel" )
  60. local modelname = self.Model or player_manager.TranslatePlayerModel( cl_playermodel )
  61. --util.PrecacheModel( modelname )
  62. ply:SetModel( modelname )
  63. if self.TeamColor then
  64. ply:SetPlayerColor(self.TeamColor)
  65. end
  66. end,
  67.  
  68. --Meta-Methods
  69. GetFormalName = function(self)
  70. return self.FormalName
  71. end,
  72.  
  73. GetName = function(self)
  74. return self.Name
  75. end,
  76.  
  77. GetMembers = function(self)
  78. return self.Members
  79. end,
  80.  
  81. GetMemberByName = function(self, name)
  82. for _, v in pairs(self.Members) do
  83. if v:GetNick() == name then
  84. return v
  85. end
  86. end
  87.  
  88. print("Player not found: " .. name)
  89. return nil
  90. end,
  91.  
  92. --This needs to be called for all players disconnecting.
  93. RemoveMember = function(self, ply)
  94. if not ply:GetNWBool("is_in_team") then
  95. print("Player was not in a team to begin with!")
  96. return
  97. end
  98. for k,v in pairs(self.Members) do
  99. if ply:SteamID() == v then
  100. table.remove(self.Members, k)
  101. --Player may have already disconnected so there is no point in doing this if they are gone
  102. if ply:IsValid() then
  103. ply:SetNWString("team", "")
  104. ply:SetNWBool("is_in_team", false)
  105. end
  106. print(ply:Nick() .. " has left " .. self.FormalName)
  107. --This function should not return in-case there are duplicate copies of the same player for some reason.
  108. end
  109. end
  110. end,
  111.  
  112. AddMember = function(self, ply)
  113. table.insert(self.Members, ply:SteamID())
  114. ply:SetNWString("team", self.Name)
  115. ply:SetNWBool("is_in_team", true)
  116.  
  117. print(ply:Nick() .. " joined " .. self.FormalName)
  118. end,
  119.  
  120. GetIndex = function(self)
  121. return self.Index
  122. end
  123. }
  124.  
  125. Team.__index = Team
  126.  
  127. --Team gloabl functions--
  128.  
  129. --This function will create and return a team object
  130. function BTK.CreateTeam( index, name, teamColor, isJoinable, team_model )
  131.  
  132. team_model = team_model or nil
  133.  
  134. local team = {
  135. FormalName = name,
  136. Name = string.Replace(string.lower(name), " ", ""),
  137. TeamColor = teamColor,
  138. IsJoinable = isJoinable,
  139. Model = team_model,
  140. Index = index
  141. }
  142.  
  143. setmetatable(team, Team)
  144.  
  145. table.insert(BTK.ActiveTeams, team)
  146.  
  147. return team
  148. end
  149.  
  150. function BTK.GetTeams()
  151. return BTK.ActiveTeams
  152. end
  153.  
  154. function BTK.GetTeamsNames()
  155. local temp = {}
  156. for _,v in pairs(BTK.ActiveTeams) do
  157. table.insert(temp, v:GetName())
  158. end
  159. return temp
  160. end
  161.  
  162. function BTK.GetTeamsFormalNames()
  163. local temp = {}
  164. for _,v in pairs(BTK.ActiveTeams) do
  165. table.insert(temp, v:GetFormalName())
  166. end
  167. return temp
  168. end
  169.  
  170. function BTK.GetTeam( name )
  171. for _, v in pairs(BTK.ActiveTeams) do
  172. if v:GetName() == name then
  173. return v
  174. end
  175. end
  176.  
  177. print("No team found by: " .. name)
  178. return nil
  179. end
  180.  
  181. function BTK.DestroyTeam( name )
  182. local t = BTK.GetTeam( name )
  183. if not t then
  184. print("Team " .. name .. " can't be destroyed because it does not exist.")
  185. return
  186. end
  187.  
  188. local members = t:GetMembers()
  189. for _,v in pairs(members) do
  190. t:RemoveMember(v)
  191. end
  192.  
  193. table.remove(BTK.ActiveTeams, t:GetIndex())
  194. end
  195.  
  196. --Team Player Functions--
  197.  
  198. local playerMeta = FindMetaTable("Player")
  199.  
  200. function playerMeta:IsInTeam()
  201. return self:GetNWBool("is_in_team")
  202. end
  203.  
  204. function playerMeta:GetTeam()
  205. return BTK.GetTeam(self:GetNWString("team"))
  206. end
  207.  
  208. function playerMeta:GetTeamName()
  209. return self:GetNWString("team")
  210. end
  211.  
  212. function playerMeta:LeaveTeam()
  213. local t = self:GetTeam()
  214. if not t then
  215. print("Unable to leave team! Oh no!")
  216. return
  217. end
  218. t:RemoveMember(self)
  219. end
  220.  
  221. ---Base Teams--
  222.  
  223. BTK.CreateTeam( 1, "Civilians", Color(0,5,3,255), true )
  224. BTK.CreateTeam( 2, "EGI Guard", BTK.EGI_Guard_Color, true, BTK.EGI_Guard_Model)
  225. BTK.CreateTeam( 3, "Revolutionaries", BTK.Revolutionary_Color, true, BTK.Revolutionary_Model )
  226.  
  227. --Console Command
  228.  
  229. concommand.Add("join_team", function(ply, cmd, args, argStr)
  230.  
  231. if args[1] == ply:GetTeamName() then
  232. ply:ChatPrint("You are already in that team!")
  233. return
  234. end
  235.  
  236. if ply:IsInTeam() then
  237. ply:LeaveTeam()
  238. end
  239.  
  240. local t = BTK.GetTeam( args[1], false )
  241. if not t then
  242. ply:ChatPrint("Team " .. args[1] .. " is not a valid team.")
  243. return
  244. end
  245.  
  246. t:AddMember(ply)
  247. ply:ChatPrint("You have joined " .. t:GetFormalName() .. "!")
  248. ply:Kill()
  249. end)
  250.  
  251.  
  252. function GM:PlayerLoadout(ply)
  253. local t = ply:GetTeam()
  254. if not t then return end
  255.  
  256. t:PlayerLoadout(ply)
  257. end
  258.  
  259. function GM:PlayerSetModel(ply)
  260. local t = ply:GetTeam()
  261. if not t then return end
  262.  
  263. t:PlayerSetModel(ply)
  264. end
  265.  
  266. hook.Add("PlayerInitialSpawn", "team.PlayerInitialSpawn", function(ply)
  267. local t = BTK.GetTeam(BTK.StartTeam)
  268. if not t then return end
  269.  
  270. t:AddMember(ply)
  271. end)
  272.  
  273. hook.Add("PlayerDisconnected", "team.PlayerDisconnected", function(ply)
  274. if ply:IsInTeam() then
  275. ply:LeaveTeam()
  276. end
  277. end)
  278. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement