epidemic.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. local Epidemic = {}
  2. Epidemic.code = 'epidemic'
  3. function Epidemic:init(map)
  4. self.timer = 5 * 60
  5. ctx.event:on(app.net.events.dead, function(_data)
  6. if _data.id == _data.kill then return end
  7. local p = ctx.players:get(_data.id)
  8. if p.team == purple then
  9. ctx.net:emit(app.net.events.class, {id = _data.id, class = p.class.id, team = orange})
  10. ctx.players:each(function(p)
  11. if p.team == orange then ctx.buffs:add(p, 'zombieboost') end
  12. end)
  13. end
  14. end)
  15. ctx.event:on(app.net.events.class, function(data) self:refresh() end)
  16. ctx.event:on(app.net.messages.leave, function(data) self:refresh() end)
  17. for i = #map.props, 1, -1 do
  18. local p = map.props[i]
  19. if (p.code == 'spawnroom' or p.code == 'teamwall') and p.team == purple then
  20. p:deactivate()
  21. table.remove(map.props, i)
  22. end
  23. end
  24. end
  25. function Epidemic:update()
  26. self.timer = timer.rot(self.timer, function()
  27. ctx.map:modExec('scoring', 'win', purple)
  28. end)
  29. ctx.players:each(function(p)
  30. if p.team == orange and not ctx.buffs:get(p, 'zombie') then ctx.buffs:add(p, 'zombie') end
  31. end)
  32. end
  33. function Epidemic:refresh()
  34. if tick < 10 / tickRate then return end
  35. local purples = 0
  36. ctx.players:each(function(p)
  37. if p.team == purple then purples = purples + 1 end
  38. end)
  39. if purples == 0 then
  40. ctx.map:modExec('scoring', 'win', orange)
  41. end
  42. end
  43. return Epidemic