Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.26 KB | None | 0 0
  1. AddCSLuaFile("cl_init.lua")
  2. AddCSLuaFile("shared.lua")
  3.  
  4.  
  5. include('shared.lua')
  6. util.AddNetworkString("tankgame_sync")
  7. util.AddNetworkString("tankgame_upsync")
  8. util.AddNetworkString("tankgame_upload")
  9. util.AddNetworkString("tankgame_init")
  10. util.AddNetworkString("tankgame_projectile")
  11. util.AddNetworkString("tankgame_projectilespawn")
  12. util.AddNetworkString("tankgame_projectilespawn_cl")
  13.  
  14.  
  15.  
  16.  
  17.  
  18. function SetupTankGame()
  19. for k,v in pairs(ents.FindByClass("tankgame_manager"))do
  20. v:Remove()
  21. end
  22. for k,v in pairs(ents.FindByClass("info_target"))do
  23. if(string.find(v:GetName(),"tankgame_"))then
  24. MakeTankGame(v)
  25. print("Found tank game "..v:GetName())
  26. end
  27. end
  28.  
  29. end
  30. hook.Add("PostCleanupMap","PostCleanupMap_TankGame",SetupTankGame)
  31. hook.Add("InitPostEntity","InitPostEntity_TankGame",SetupTankGame)
  32.  
  33. function MakeTankGame(ent)
  34. timer.Simple(0.5,function()
  35. if(IsValid(ent))then
  36. local name = ent:GetName()
  37. print("preparing "..name)
  38. local p1 = ents.FindByName(name.."_p1")[1]
  39. local p2 = ents.FindByName(name.."_p2")[1]
  40. local p3 = ents.FindByName(name.."_p3")[1]
  41. local p4 = ents.FindByName(name.."_p4")[1]
  42. local p5 = ents.FindByName(name.."_p5")[1]
  43. local p6 = ents.FindByName(name.."_p6")[1]
  44. local p7 = ents.FindByName(name.."_p7")[1]
  45. local p8 = ents.FindByName(name.."_p8")[1]
  46. local screen = ents.FindByName(name.."_screen")[1]
  47.  
  48.  
  49. if(IsValid(p1) and IsValid(p2) and IsValid(p3) and IsValid(p4))then
  50. print(name.." successfully constructed")
  51. local mngr = ents.Create("tankgame_manager")
  52. mngr:SetPos(ent:GetPos() + Vector(0,0,0))
  53. mngr:SetAngles(ent:GetAngles())
  54. mngr:SetNWVector("ScreenPos",ent:GetPos())
  55. mngr:SetNWAngle("ScreenAng",ent:GetAngles())
  56. mngr:SetName(name)
  57. mngr:Spawn()
  58.  
  59. for i,v in pairs({p1,p2,p3,p4,p5,p6,p7,p8})do
  60. mngr["Seat"..i] = ents.Create("prop_vehicle_prisoner_pod")
  61. mngr["Seat"..i]:SetModel("models/nova/chair_office02.mdl")
  62. mngr["Seat"..i]:SetPos(v:GetPos() + v:GetAngles():Up()*-16 + v:GetAngles():Forward()*-32)
  63. mngr["Seat"..i]:SetAngles(v:GetAngles() + Angle(0,-90,0))
  64. mngr["Seat"..i].IsGameSeat = true
  65. mngr["Seat"..i]:Spawn()
  66. mngr["Seat"..i]:SetColor(mngr.TeamColors[0])
  67. mngr["Seat"..i]:SetNWEntity("SourceGame",mngr)
  68. mngr["Seat"..i]:GetPhysicsObject():EnableMotion(false)
  69. mngr:SetNWEntity("GameSeat"..i,mngr["Seat"..i])
  70.  
  71.  
  72. end
  73. else
  74. print(name.." Failed to construct")
  75. end
  76. end
  77. end)
  78.  
  79. end
  80.  
  81.  
  82. hook.Add("CanPlayerEnterVehicle", "TankGame_SeatEntry", function(ply, vehicle)
  83. if vehicle.IsGameSeat then return true end
  84.  
  85. end)
  86. TANKGAME_NET_LIST = TANKGAME_NET_LIST or {}
  87. net.Receive("tankgame_sync",function(len,ply)
  88. TANKGAME_NET_LIST = TANKGAME_NET_LIST or {}
  89. local ent = net.ReadEntity()
  90. local tank = net.ReadInt(16)
  91. local time = net.ReadFloat()
  92.  
  93. local data = net.ReadTable()
  94.  
  95. local delay = time - CurTime()
  96.  
  97. net.Start("tankgame_upsync")
  98. net.WriteEntity(ent)
  99. net.WriteInt(tank,16)
  100. net.WriteTable(data)
  101. net.Send(TANKGAME_NET_LIST)
  102.  
  103. end)
  104.  
  105. hook.Add("PlayerChangeLocation","tankgame_tracknetworkingresidents",function( ply, newloc, oldloc )
  106. TANKGAME_NET_LIST = TANKGAME_NET_LIST or {}
  107. local network_location = 0 //set this pls
  108. ply.bInArcade = ply.bInArcade or false
  109. local bInArcade = newloc == network_location
  110. if(bInArcade != ply.bInArcade)then //on the condition that a player starts or stops being in the arcade, rebuild the list of people in there
  111. ply.bInArcade = bInArcade
  112. local gaymers = {}
  113. for _,ply in pairs(player.GetAll())do
  114. if(ply.bInArcade)then
  115. table.insert(gaymers,ply)
  116. end
  117. end
  118. TANKGAME_NET_LIST = gaymers
  119. end
  120.  
  121. end)
  122.  
  123. net.Receive("tankgame_projectile",function(len,ply)
  124. local ent = net.ReadEntity()
  125. local tank = net.ReadInt(16)
  126.  
  127. ent:SetNWInt("Health"..tank,math.Clamp(ent:GetNWInt("Health"..tank)-1,0,10))
  128. if(ent:GetNWInt("Health"..tank) == 0)then
  129. //ent:SetNWEntity("Player"..tank,NULL)
  130. ent:HandleTankDeath(tank)
  131. end
  132.  
  133.  
  134. print(ent:GetNWInt("Health"..tank))
  135. print("ow, i got fuckin' hit man")
  136. --[[
  137. net.Start("tankgame_upsync")
  138. net.WriteEntity(ent)
  139. net.WriteInt(tank,16)
  140. net.WriteTable(data)
  141. net.Broadcast()
  142. ]]
  143. end)
  144. function ENT:HandleTankDeath(ind)
  145. local grps = {}
  146. local liv = -1
  147.  
  148. for i=1,self.TankAmount do
  149. if(IsValid(self:GetNWEntity("Player"..i)) and self:GetNWInt("Health"..i) > 0 and !table.HasValue(grps,self:GetNWInt("Team"..i)))then
  150. table.insert(grps,self:GetNWInt("Team"..i))
  151.  
  152. liv = self:GetNWInt("Team"..i)
  153. end
  154. end
  155. if(table.Count(grps) == 1)then
  156. for i=1,self.TankAmount do
  157. if(self:GetNWInt("Team"..i) == liv and IsValid(self:GetNWEntity("Player"..i)))then
  158. local ply = self:GetNWEntity("Player"..i)
  159. self.PrizeOutput = self.PrizeOutput or 2
  160. end
  161. end
  162. end
  163. if(table.Count(grps) <=1)then
  164. self:EndGame()
  165. end
  166.  
  167.  
  168. end
  169.  
  170. function ENT:EndGame()
  171. timer.Simple(0.5,function()
  172. if(IsValid(self))then
  173. self:SetNWBool("GameOn",self.GameStarted)
  174. for i=1,self.TankAmount do
  175.  
  176. if(IsValid(self:GetNWEntity("Player"..i)))then
  177. local ply = self:GetNWEntity("Player"..i)
  178. if(ply.ACV_Increase != nil)then
  179. ply:ACV_Increase("ACV_Tanks_Play_50",1)
  180. end
  181. end
  182. self:SetNWEntity("Player"..i,NULL)
  183. self:SetNWInt("Health"..i,0)
  184. self:SetNWInt("Mines"..i,0)
  185. self:SetNWInt("Team"..i,0)
  186. self["Seat"..i]:SetColor(self.TeamColors[0])
  187. end
  188.  
  189. self.GameStarted = false
  190. end
  191. end)
  192. end
  193.  
  194.  
  195. net.Receive("tankgame_projectilespawn",function(len,ply)
  196. local ent = net.ReadEntity()
  197. local tank = net.ReadInt(16)
  198. local ject = net.ReadTable()
  199.  
  200. net.Start("tankgame_projectilespawn_cl")
  201. net.WriteEntity(ent)
  202. net.WriteInt(tank,16)
  203. net.WriteTable(ject)
  204. net.Send(TANKGAME_NET_LIST)
  205.  
  206. end)
  207.  
  208.  
  209. function ENT:Think()
  210. local seats = 0
  211. for i=1,self.TankAmount do
  212. if(IsValid(self["Seat"..i]) and IsValid(self["Seat"..i]:GetDriver()))then
  213. seats = seats + 1
  214. end
  215. end
  216.  
  217. if(self.GameStarted and seats <= 1)then
  218. self:EndGame()
  219. end
  220. if(!self.GameStarted and seats > 1)then
  221. self:StartGame()
  222.  
  223. end
  224. end
  225.  
  226. function ENT:Initialize()
  227. self.Entity:SetModel("models/pyroteknik/redbutton/techbutton.mdl");
  228. self:SetSolid( SOLID_NONE )
  229.  
  230. self.GameStarted = false
  231. self:SetNWBool("GameOn",self.GameStarted)
  232. self:SetNWInt("GameMap",1)
  233. end
  234.  
  235. ENT.GamePrice = 5
  236. function ENT:StartGame()
  237. self.GameStarted = true
  238. local mode = 3
  239. local map = math.random(1,#self.Maps)
  240. local teams = {}
  241.  
  242. local players = {}
  243. for i=1,self.TankAmount do
  244. if(IsValid(self["Seat"..i]) and IsValid(self["Seat"..i]:GetDriver()))then
  245. local ply = self["Seat"..i]:GetDriver()
  246.  
  247. players[i] = ply
  248.  
  249.  
  250. end
  251. end
  252. self.PrizeOutput = table.Count(players)
  253. if(table.Count(players) == 2)then mode = 0 end
  254. if(table.Count(players) == 3)then mode = 0 end
  255. if(table.Count(players) == 4)then mode = 3 end
  256. if(table.Count(players) == 5)then mode = 0 end
  257. if(table.Count(players) == 6)then mode = 2 end
  258. if(table.Count(players) == 7)then mode = 0 end
  259. if(table.Count(players) == 8)then mode = 1 end
  260.  
  261. if(table.Count(players) > 0)then
  262. self:SetNWBool("GameOn",self.GameStarted)
  263. self:SetNWInt("GameMap",map)
  264. self:SetNWFloat("GameScale",self.MapSizes[map])
  265. local ateams = {1,2,3,4,5,6,7,8}
  266. local groups = 8
  267. if(mode == 1)then groups = 4 end
  268. if(mode == 2)then groups = 3 end
  269. if(mode == 3)then groups = 2 end
  270. local td = {}
  271. local tp = {}
  272. for i=1,groups do
  273. local sel = math.random(1,table.Count(ateams))
  274. tp[i] = ateams[sel]
  275. table.remove(ateams,sel)
  276. end
  277.  
  278. for i=1,groups do
  279. td[i] = td[i] or {tp[i],{}}
  280. end
  281. local ct = math.random(1,groups)
  282. for k,v in pairs(players)do
  283. table.insert(td[ct][2],k)
  284. ct = ct + 1
  285. if(ct > groups)then ct = 1 end
  286. end
  287.  
  288. for i=1,self.TankAmount do
  289. local teet = 0
  290. for _,v in pairs(td)do
  291. for _,x in pairs(v[2])do
  292. if(x == i)then
  293. teet = v[1]
  294. end
  295. end
  296. end
  297.  
  298. teams[i] = teet
  299. self:SetNWInt("Team"..i,teet)
  300. if(IsValid(self["Seat"..i]))then
  301. self["Seat"..i]:SetColor(self.TeamColors[teet])
  302. end
  303.  
  304. if(IsValid(self["Seat"..i]) and IsValid(players[i]))then
  305. self:SetNWEntity("Player"..i,players[i])
  306.  
  307.  
  308.  
  309. else
  310. self:SetNWEntity("Player"..i,NULL)
  311. end
  312. self:SetNWInt("Mines"..i,5)
  313. self:SetNWInt("Health"..i,4)
  314. end
  315. self.TeamSet = teams
  316. end
  317.  
  318. timer.Simple(0.5,function()
  319. if(IsValid(self))then
  320. net.Start("tankgame_init")
  321. net.WriteEntity(self)
  322. net.WriteTable(teams)
  323. net.Broadcast()
  324. end
  325. end)
  326. end
  327. concommand.Add("StartTankGame",function(ply,cmd,args)
  328. if(ply:IsSuperAdmin())then
  329. for k,v in pairs(ents.FindByClass("tankgame_manager"))do
  330. v:StartGame()
  331. end
  332. end
  333. end)
  334.  
  335.  
  336.  
  337.  
  338. function ENT:Use(user)
  339.  
  340. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement