Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.80 KB | None | 0 0
  1. local ww2 = ww2 or {}
  2. local round = round or {}
  3. local flag = flag or {}
  4. util.AddNetworkString("ww2_upwinner")
  5. round.cfg = {}
  6. round.cfg.preparetime = 15
  7. round.cfg.godtime = 10
  8. round.cfg.respawntime = 15
  9. round.cfg.endingtime = 15
  10. round.cfg.defendtime = 9999
  11. round.winner = 0
  12.  
  13. function round.Setup()
  14. roundstared = false
  15. preparing = false
  16. end
  17.  
  18. function round.SpawnPlayers()
  19. for k, ply in pairs(player.GetAll()) do
  20. ply:SetFrags(0)
  21. ply:SetDeaths(0)
  22. ply.Killed = 0
  23. ply:StripWeapons()
  24. if ply:GetTeam() == 1 then
  25. ply:SetTeam(ply:GetTeam())
  26. ply:SetupSpawn()
  27. ply:GodEnable()
  28. ply:SetNoCollideWithTeammates(true)
  29. ply:SetPos(table.Random(ww2.getTeamSpawnes(ply:GetTeam())))
  30. ply:SetFreezed(true)
  31. elseif ply:GetTeam() == 2 then
  32. ply:SetTeam(ply:GetTeam())
  33. ply:SetupSpawn()
  34. ply:GodEnable()
  35. ply:SetNoCollideWithTeammates(true)
  36. ply:SetPos(table.Random(ww2.getTeamSpawnes(ply:GetTeam())))
  37. ply:SetFreezed(true)
  38. end
  39. end
  40. end
  41.  
  42. function round.DisablePlayersGod()
  43. for k, v in pairs(ww2.AlivePlayers()) do
  44. if v:HasGodMode() then
  45. v:GodDisable()
  46. v:SetNoCollideWithTeammates(false)
  47. end
  48.  
  49. end
  50. end
  51.  
  52. function round.ChangePlayerTeam()
  53. if #ww2.GetSovietPlayers() > #ww2.GetNaziPlayers() then
  54. local ply = table.Random(ww2.GetSovietPlayers())
  55. ply:SetWTeam(1)
  56. ply:SetWClass("newbie_rus", 1)
  57. elseif #ww2.GetNaziPlayers() > #ww2.GetSovietPlayers() then
  58. local ply = table.Random(ww2.GetNaziPlayers())
  59. ply:SetWTeam(2)
  60. ply:SetWClass("newbie_rus", 2)
  61. end
  62. end
  63.  
  64. function round.DoBalanceTeam()
  65. if #ww2.GetSovietPlayers() > #ww2.GetNaziPlayers() then
  66. for i = 1, #ww2.GetSovietPlayers() - #ww2.GetNaziPlayers() do
  67. round.ChangePlayerTeam()
  68. end
  69. elseif #ww2.GetNaziPlayers() > #ww2.GetSovietPlayers() then
  70. for i = 1, #ww2.GetNaziPlayers() - #ww2.GetSovietPlayers() do
  71. round.ChangePlayerTeam()
  72. end
  73. end
  74. end
  75.  
  76. function round.UnFreezeAll()
  77. for k, v in pairs(ww2.AlivePlayers()) do
  78. v:SetFreezed(false)
  79. end
  80. end
  81.  
  82. function round.Begin() -- инициализация раунда
  83. -- ресет тикетов
  84. ww2.ResetTickets()
  85. ww2.UpdateTickets()
  86. -- ресет спавнов
  87. ww2.ClearSpawnPos()
  88. ww2.CreateSpawnes()
  89. -- ресет флагов
  90. flag.ClearOldFlags()
  91. flag.OnRoundStart()
  92. -- обновляем инфу о флагах у игроков
  93. for k, v in pairs(player.GetAll()) do
  94. ww2.LoadFlags(v)
  95. end
  96. -- закрываем все клиентские меню у игроков
  97. ww2.CloseAllMenues()
  98. -- очищаем регдоллы по карте
  99. ww2.CleanUpRagdolls()
  100. -- ресетаем XP
  101. xp.ResetPerming()
  102. ----------------------------------
  103. timer.Remove("UpdatePrepTime")
  104. timer.Remove("WW2_round_prepare")
  105. timer.Remove("WW2_round_goddisable")
  106. timer.Remove("WW2_ticket")
  107. timer.Remove("UpdateRoundTime")
  108. timer.Remove("ww2_restartGAME")
  109. timer.Remove('UpdateRTime')
  110. ----------------------------------
  111. -- общая чистка карты (декали и т.д.)
  112. game.CleanUpMap()
  113. roundstared = false
  114. preparing = true
  115.  
  116. -- VAR
  117. SetGlobalString("DefeatType", "")
  118. SetGlobalInt("DUR_TIME", 0)
  119. SetGlobalBool("RoundStarted", false)
  120. --
  121.  
  122. -- ресетаем настройки раунда, балансируем команды и спавним игроков
  123. round.ShowupEnd(false)
  124. round.SetWinner(0)
  125. round.DoBalanceTeam()
  126. round.SpawnPlayers()
  127.  
  128. -- хз чё это, но если есть, значит так нужно.
  129. timer.Create("UpdatePrepTime", 0.1, round.cfg.preparetime * 10, function()
  130. SetGlobalInt("PREP_TIME", timer.TimeLeft("WW2_round_prepare"))
  131. end)
  132.  
  133. -- функция пушдефенда, работает только в пушдефенде
  134. onRoundStart()
  135.  
  136. -- старт раунда после подготовки
  137. timer.Create("WW2_round_prepare", round.cfg.preparetime, 1, function()
  138. round.UnFreezeAll()
  139. roundstared = true
  140. preparing = false
  141. if gm.GetCurGMIndex() == "capture" then
  142. ww2.InitTicketSystem()
  143. elseif gm.GetCurGMIndex() == "defende" then
  144. ww2.InitTicketDefend()
  145. end
  146. SetGlobalBool("RoundStarted", roundstared)
  147. timer.Create("WW2_round_goddisable", round.cfg.godtime, 1, function()
  148. round.DisablePlayersGod()
  149. end)
  150. if gm.GetCurGMIndex() == 'capture' then
  151. timer.Create("UpdateRoundTime", 1, 0, function()
  152. SetGlobalInt("DUR_TIME", GetGlobalInt("DUR_TIME") + 1)
  153. end)
  154. elseif gm.GetCurGMIndex() == 'defende' then
  155. timer.Create("UpdateRoundTime", round.cfg.defendtime, 1, function()
  156. round.SetWinType('defend')
  157. round.End('pushed')
  158. end)
  159. timer.Create("UpdateRTime", 0.1, 0, function()
  160. SetGlobalInt("DUR_TIME", timer.TimeLeft("UpdateRoundTime"))
  161. end)
  162. end
  163. end)
  164. end
  165.  
  166. function round.SetWinner(team)
  167. round.winner = team
  168. end
  169.  
  170. function round.GetWinner()
  171. return round.winner
  172. end
  173.  
  174. function round.UpdateWinner()
  175. net.Start("ww2_upwinner")
  176. net.WriteInt(round.GetWinner(), 5)
  177. net.Broadcast()
  178. end
  179.  
  180. function round.ShowupEnd(bShow)
  181. SetGlobalBool("Ending", bShow)
  182. end
  183.  
  184. function round.SetWinType(type)
  185. SetGlobalString("DefeatType", tostring(type))
  186. end
  187.  
  188. function round.End(reasontype)
  189. SetGlobalString("ReasonType", reasontype)
  190. ww2.CloseAllMenues() -- закрываем все менюшкии
  191. if reasontype == "tickets" then -- если раунд закончился по тикетам
  192. ww2.SetSpectatorsAll()
  193. ww2.FreezeAll()
  194. xp.permingXP()
  195. if ww2.GetTickets(1) > ww2.GetTickets(2) then
  196. SetGlobalBool("Ending", true)
  197. round.SetWinner(1)
  198. round.ShowupEnd(true)
  199. timer.Remove("WW2_ticket")
  200. timer.Stop("UpdateRoundTime")
  201. ww2.ResetTickets()
  202. timer.Create("ww2_restartGAME", round.cfg.endingtime, 1, function()
  203. round.Begin()
  204. ww2.UnFreezeAll()
  205. xp.ResetPerming()
  206. end)
  207. timer.Create("UpdateEndTime", 0.1, round.cfg.endingtime * 10, function()
  208. SetGlobalInt("END_TIME", timer.TimeLeft("ww2_restartGAME"))
  209. end)
  210. round.UpdateWinner()
  211. elseif ww2.GetTickets(2) > ww2.GetTickets(1) then
  212. SetGlobalBool("Ending", true)
  213. round.SetWinner(2)
  214. round.ShowupEnd(true)
  215. timer.Remove("WW2_ticket")
  216. timer.Stop("UpdateRoundTime")
  217. ww2.ResetTickets()
  218. timer.Create("ww2_restartGAME", round.cfg.endingtime, 1, function()
  219. round.Begin()
  220. ww2.UnFreezeAll()
  221. xp.ResetPerming()
  222. end)
  223. timer.Create("UpdateEndTime", 0.1, round.cfg.endingtime * 10, function()
  224. SetGlobalInt("END_TIME", timer.TimeLeft("ww2_restartGAME"))
  225. end)
  226. round.UpdateWinner()
  227. end
  228. elseif reasontype == "pushed" then
  229. if GetGlobalString("DefeatType") == "push" then
  230. ww2.SetSpectatorsAll()
  231. ww2.FreezeAll()
  232. xp.permingXP()
  233. SetGlobalBool("Ending", true)
  234. round.SetWinner(ww2.GetPushTeam())
  235. round.ShowupEnd(true)
  236. timer.Remove("WW2_ticket")
  237. timer.Stop("UpdateRoundTime")
  238. ww2.ResetTickets()
  239. timer.Create("ww2_restartGAME", round.cfg.endingtime, 1, function()
  240. round.Begin()
  241. ww2.UnFreezeAll()
  242. xp.ResetPerming()
  243. end)
  244. timer.Create("UpdateEndTime", 0.1, round.cfg.endingtime * 10, function()
  245. SetGlobalInt("END_TIME", timer.TimeLeft("ww2_restartGAME"))
  246. end)
  247. round.UpdateWinner()
  248. elseif GetGlobalString("DefeatType") == "defend" then
  249. ww2.SetSpectatorsAll()
  250. ww2.FreezeAll()
  251. xp.permingXP()
  252. SetGlobalBool("Ending", true)
  253. round.SetWinner(ww2.GetDefendTeam())
  254. round.ShowupEnd(true)
  255. timer.Remove("WW2_ticket")
  256. timer.Stop("UpdateRoundTime")
  257. ww2.ResetTickets()
  258. timer.Create("ww2_restartGAME", round.cfg.endingtime, 1, function()
  259. round.Begin()
  260. ww2.UnFreezeAll()
  261. xp.ResetPerming()
  262. end)
  263. timer.Create("UpdateEndTime", 0.1, round.cfg.endingtime * 10, function()
  264. SetGlobalInt("END_TIME", timer.TimeLeft("ww2_restartGAME"))
  265. end)
  266. round.UpdateWinner()
  267. end
  268. end
  269. team.AddScore(round.GetWinner(), 1)
  270. ww2.MapSelection()
  271. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement