-- ========================================================================= -- THE CARRIER INFECTION: story script -- -- THE INFECTION HAPPENS ONCE (wave 1). From wave 2 on the world is already infected: red-eyed robots, ghouls and -- hostages walk out without any new ceasefire or glitch. -- -- WAVE 1 Normal wave. After enough robots die and the Carrier appears it gets infected: -- a short ceasefire, the upgrade stations "glitch" out and a stranger on the radio replaces the announcer. -- Some robots are NOT infected (they use existing robot templates): they appear on the blue base, -- wait 15-30 s, get moved out to one of EXIT_POINTS and switch to RED. -- Once a player is within ~10 m they call for help (and get an uber). -- Stand next to one for 5 s (a Scout frees them instantly) and they come back online with -- Voodoo-Cursed Soul skin. Ghouls start pouring out. Only infected robots can carry the bomb. -- After all attackers are dead a scared engineer walks out ("Don't shoot!") and starts talking. -- WAVE 2 Defend Robot Engineer Mk II while he builds the new base (spawn + upgrade station + reinforcements). -- WAVE 3+ He keeps a sentry and dispenser at the new base and respawns while players live. -- -- Old red spawn: ghouls come out of it after wave 1; players who spawn there are rerouted to the new base. -- No money from infected robots or ghouls: the only income is rescued robots. -- ========================================================================= local VOODOO_ITEM = "Voodoo-Cursed Soul (Armory)" -- same as in the .pop local CFG = { KILLS = { 73, 82, 64, 93, 88, 91 }, -- infected-robot kills before the Carrier infects (per wave) DEFECTORS = { 4, 6, 8, 10, 12, 14 }, -- small not-infected robots per wave GIANT_HOSTAGES = { 1, 1, 2, 2, 3, 3 }, -- giant hostages per wave BOSS_DELAY = 25, -- boss hostage walks out this long after the Carrier is destroyed (wave 2+) TANK_MAX_WAIT = 60, DEBUG = true, -- chat/console hints when a wave looks stuck RESCUE_AFTER = 5, -- HUD enemy counter at 0 for this long, wave still running -> resume the hidden spawners so they can finish FALLBACK_AFTER = 75, -- same, but when the counter cannot be read: no hostile bots and no Carrier for this long SOFT_WAIT = 12, -- seconds the soft close gets before a hard jump is considered JUMP_OFFSET = 0, -- JumpToWave parameter = current wave + this (0 if the input is 0-based). The script re-checks and retries with +1 by itself VOTE_PASS = 0.6, -- !stuck: 60% yes needed (40% no kills the vote) VOTE_TIME = 30, -- seconds a vote lasts VOTE_COOLDOWN = 60, -- seconds before the next vote after a failed one VOTE_MIN_AGE = 45, -- a vote can start only when the wave has been running this long FORCE_STOP = true, -- last resort 15 s later: ask the populator to stop the wave's stages (tries $StopWavespawn) INFECT_TIME = 10, -- ceasefire seconds GHOULS_DELAY = 6, EXIT_DELAY = { 15, 30 }, -- seconds on the blue base before moving out and switching to RED EXIT_POINTS = { { x = 1786, y = -149, z = -350 }, { x = 1573, y = 2189, z = -360 }, { x = -197, y = 1683, z = -449 }, { x = 1607, y = 2469, z = -134 }, { x = 203, y = 2977, z = -134 }, }, CALL_RADIUS = 525, -- ~10 m: robots start calling for help RESCUE_RADIUS = 300, -- ~5.7 m: stand this close to free one RESCUE_TIME = 5.0, -- seconds (Scout: instant) CALL_TIMEOUT = 45, -- seconds after the first call, then the robot self-destructs DORMANT_MAX = 150, -- seconds nobody came near REWARD_SMALL = 100, -- credits to EVERY player, wherever they are REWARD_GIANT = 200, REWARD_BOSS = 500, REPEAT_DELAY = 25, -- waves 2+: the world is already infected; hostages start walking out this long after the wave starts PLEA_FIRST = { 25, 40 }, PLEA_INTERVAL = { 55, 100 }, MAX_HELPERS = 5, BUILD_TIME = 100, -- seconds the engineer needs for the new base (counts only while he is alive) REINFORCEMENT_INTERVAL = 45, -- seconds between allied robots dispatched from the new base ENGINEER_RESPAWN = 15, OLD_BASE = { x = -1680, y = 1068, z = -130 }, OLD_BASE_RADIUS = 800, NEW_SPAWN = { x = 1582, y = 937, z = -143 }, NEW_STATION = { x = 1396, y = 881, z = -143 }, TELEPORTER = { x = 1386, y = 1059, z = -143 }, SENTRY = { x = 1536, y = 658, z = -139 }, DISPENSER = { x = 1422, y = 806, z = -143 }, WAYPOINT1 = { x = 1575, y = -1678, z = -533 }, -- keep-out zones: around the ghoul spawn points (your coordinates). Small on purpose: far from the bomb path FORBIDDEN_ZONES = { { x = -1492, y = 634, z = -99 }, { x = -1138, y = 2671, z = -62 }, { x = -1593, y = 1118, z = -104 }, { x = -1264, y = 2203, z = -62 }, }, FORBIDDEN_RADIUS = 350, STATION_BACK = 60, -- the station model is moved this far back (away from the new spawn) TELEPORTER_BACK = 40, } local SPAWNERS = { defector = { "Defectors_a", "Defectors_b" }, defector_giant = { "Defectors_giant" }, defector_boss = { "Defector_boss" }, eng = { "Eng_ally" }, reinforce = { "Base_Reinforcements" } } local COND_REPROG = TF_COND_REPROGRAMMED or 43 local COND_INVULN = TF_COND_INVULNERABLE_USER_BUFF local COND_CRIT = TF_COND_CRITBOOSTED_USER_BUFF local UNK = "{red}[???]" local ENG = "{blue}[Robot Engineer Mk II]" local CALL_LINES = { "{blue}[BLU-%02d] ...I'm not one of them anymore. Please. Don't shoot.", "{blue}[BLU-%02d] There's a voice in my head. It says you're the enemy. Stay close, it gets quieter.", "{blue}[BLU-%02d] I walked out on my own. Stand next to me... please.", "{blue}[BLU-%02d] They hollowed us out. Help me before they come back.", "{blue}[BLU-%02d] My core is burning. I can still hear you. Don't leave.", } local DEATH_LINES = { [1] = "{red}[RESPAWN] Clone #%d deployed. Memory: %s. All systems nominal.", [4] = "{red}[RESPAWN] Clone #%d deployed. Memory: %s. Minor discrepancies detected.", [8] = "{red}[RESPAWN] Clone #%d deployed. Memory: %s. Do you remember the first one?", [12] = "{red}[RESPAWN] Clone #%d deployed. Memory: %s. Don't look behind you.", [18] = "{red}[RESPAWN] Clone #%d deployed. Memory: %s. You are not you.", } local WAVE_LINES = { [3] = "Turret and dispenser are up. Don't worry about me: as long as we're alive I can rebuild and come back to you.", [4] = "More giants are coming off the Carriers. Keep the dispenser alive, it's the only one I've got.", [5] = "The spellcasters are the worst. I'm recalibrating the turret. Stay close to the upgrade station.", [6] = "This is the last Carrier. Whatever is inside it... it knows my name.", } -- ------------------------------------------------------------------------- -- State -- ------------------------------------------------------------------------- local generation = 0 local in_wave = false local infected = false local kills, kill_goal = 0, 99 local warned = {} local tank_seen_at = nil local waves_started = 0 local def_counter = 0 -- story state lives across waves local story = { phase = 0, base_ready = false, guard_running = false, forbidden_running = false, new_spawn = nil } -- phase: 0 normal, 1 glitch (stations off), 2 engineer met (old spawn lost), 3 building, 4 base ready local pending = { defector = 0, defector_giant = 0, defector_boss = 0, eng = 0, reinforce = 0 } local last_spawn = { defector = 0, defector_giant = 0, defector_boss = 0, eng = 0 } local defectors = {} -- [handle] = { bot, stage, born, exit_at, call_since, prog, giant } local special = {} -- [handle] = true for ghouls and defectors local deaths = {} local eng = nil -- current allied engineer bot local build_progress = 0 local wave_started_at = 0 local last_redirect = {} local reinforcement_running = false local StartReinforcementLoop math.randomseed(math.floor(CurTime() * 1000)) local function RandRange(r) return r[1] + math.random() * (r[2] - r[1]) end local function V(t, dz) return Vector(t.x, t.y, t.z + (dz or 0)) end -- floor height under a point (trace straight down); nil if the trace fails or looks wrong local function FloorZ(x, y, z) local ok, hit = pcall(function() local tr = util.Trace({ start = Vector(x, y, z + 40), distance = 700, angles = Vector(90, 0, 0), mask = MASK_PLAYERSOLID or MASK_SHOT, collisiongroup = COLLISION_GROUP_PLAYER, filter = {}, }) return tr.HitPos end) if ok and hit and hit.z <= z + 45 and hit.z >= z - 650 then return hit.z end return nil end local function GetPopulatorInterface() local pi = ents.FindByClass("point_populator_interface") if pi and pi:IsValid() then return pi end pi = ents.FindByName("pop_interface") if pi and pi:IsValid() then return pi end return nil end local function Broadcast(msg) for _, p in pairs(ents.GetAllPlayers()) do if p:IsValid() and p:IsRealPlayer() then p:AcceptInput("$DisplayTextChat", msg) end end end local function Center(msg) for _, p in pairs(ents.GetAllPlayers()) do if p:IsValid() and p:IsRealPlayer() then p:Print(PRINT_TARGET_CENTER, msg) end end end local function Speaker() if story.phase >= 2 then return ENG else return UNK end end local function Say(msg) Broadcast(Speaker() .. " " .. msg) end local function Dist2(a, b) local dx, dy, dz = a.x - b.x, a.y - b.y, a.z - b.z return dx * dx + dy * dy + dz * dz end local function FindAll(class) local res = {} local ok = pcall(function() for _, e in pairs(ents.FindAllByClass(class)) do res[#res + 1] = e end end) if ok and #res > 0 then return res end pcall(function() local prev = nil for _ = 1, 24 do local e if prev then e = ents.FindByClass(class, prev) else e = ents.FindByClass(class) end if not e or not e:IsValid() or (prev and e:GetHandleIndex() == prev:GetHandleIndex()) then break end res[#res + 1] = e prev = e end end) return res end local function GetWaveNumber() local n pcall(function() local res = ents.FindByClass("tf_objective_resource") if res and res:IsValid() then n = res.m_nMannVsMachineWaveCount end end) if n and n > 0 then return n end return math.max(1, waves_started) end local function ByWave(t) return t[math.min(GetWaveNumber(), #t)] end local function RedPlayers() local t = {} for _, p in pairs(ents.GetAllPlayers()) do if p:IsValid() and p:IsRealPlayer() and p:IsAlive() and p.m_iTeamNum == 2 then t[#t + 1] = p end end return t end local function IsScout(p) local c pcall(function() c = p.m_iClass end) if not c then pcall(function() c = p:GetPlayerClass() end) end return c == 1 end local function AllRedPlayers() local t = {} for _, p in pairs(ents.GetAllPlayers()) do if p:IsValid() and p:IsRealPlayer() and p.m_iTeamNum == 2 then t[#t + 1] = p end end return t end local function IsMiniBoss(p) local mb = p.m_bIsMiniBoss return mb ~= nil and mb ~= false and mb ~= 0 end local function GiveCash(p, amount) if pcall(function() p:AddCurrency(amount) end) then return true end return pcall(function() p.m_nCurrency = (p.m_nCurrency or 0) + amount end) end local ForceNextWave -- defined below local function Teleport(bot, pos) timer.Simple(0.2, function() if IsValid(bot) and bot:IsAlive() then bot:SetAbsOrigin(pos) end end) end local function FlipToRed(bot) bot:AddCond(COND_REPROG) timer.Simple(0.6, function() if IsValid(bot) and bot:IsAlive() and bot.m_iTeamNum ~= 2 then -- Сначала убираем возможную подмену сетевого свойства, -- затем задаём настоящую команду RED. pcall(function() bot:ResetFakeSendProp("m_iTeamNum") end) bot.m_iTeamNum = 2 end end) end -- the wave is over: whatever blue is still walking dies (vanilla does this too) local function KillHostiles(reason) local n = 0 for _, p in pairs(ents.GetAllPlayers()) do if p:IsValid() and not p:IsRealPlayer() and p:IsAlive() and p.m_iTeamNum == 3 then pcall(function() p:RemoveCond(COND_INVULN) end) p:Suicide() n = n + 1 end end print("[infection] killed " .. n .. " hostile bots (" .. reason .. ")") end local function SetSpawners(names, resume) local pi = GetPopulatorInterface() if not pi then return false end for _, nm in ipairs(names) do pi:AcceptInput(resume and "$ResumeWavespawn" or "$PauseWavespawn", nm) end return true end local function Summon(key, n) if not SetSpawners(SPAWNERS[key], true) then return false end pending[key] = pending[key] + n last_spawn[key] = CurTime() local gen = generation timer.Simple(10, function() if gen ~= generation then return end if pending[key] > 0 and CurTime() - last_spawn[key] >= 9.5 then pending[key] = 0 SetSpawners(SPAWNERS[key], false) end end) return true end StartReinforcementLoop = function(gen) if reinforcement_running or not story.base_ready then return end reinforcement_running = true local function tick() timer.Simple(CFG.REINFORCEMENT_INTERVAL, function() if gen ~= generation or not in_wave or not story.base_ready then reinforcement_running = false return end if pending.reinforce <= 0 then Summon("reinforce", 1) end tick() end) end tick() end local function IsHostileBot(p) return p:IsValid() and not p:IsRealPlayer() and p:IsAlive() and p.m_iTeamNum == 3 and not special[p:GetHandleIndex()] end local function CountHelpers() local c = 0 for _, d in pairs(defectors) do if d.stage ~= "online" then c = c + 1 end end return c end -- ------------------------------------------------------------------------- -- Upgrade stations: the old ones "glitch" out after the Carrier infection -- ------------------------------------------------------------------------- local function StationGuard() if story.guard_running then return end story.guard_running = true local function tick() timer.Simple(2, function() -- Станции больше не отключаются скриптом: периодически принудительно -- включаем их, чтобы триггеры улучшений не оставались в состоянии Disabled. for _, st in ipairs(FindAll("func_upgradestation")) do pcall(function() st:AcceptInput("Enable") end) end tick() end) end tick() end -- ------------------------------------------------------------------------- -- Old spawn is overrun: reroute players and keep them out of the old base -- ------------------------------------------------------------------------- local function ToNewBase(p) local n = CFG.NEW_SPAWN p:SetAbsOrigin(Vector(n.x + math.random(-120, 120), n.y + math.random(-120, 120), n.z + 8)) end local function ForbiddenZone() if story.forbidden_running then return end story.forbidden_running = true local r2 = CFG.FORBIDDEN_RADIUS * CFG.FORBIDDEN_RADIUS local function tick() timer.Simple(1, function() if story.phase >= 2 then for _, p in ipairs(RedPlayers()) do local pos = p:GetAbsOrigin() for _, zone in ipairs(CFG.FORBIDDEN_ZONES) do if Dist2(pos, zone) <= r2 then ToNewBase(p) local h = p:GetHandleIndex() if not last_redirect[h] or CurTime() - last_redirect[h] > 10 then last_redirect[h] = CurTime() p:AcceptInput("$DisplayTextChat", "{red}[SYSTEM] Ghouls are coming out here. You were rerouted to the new base.") end break end end end end tick() end) end tick() end -- ------------------------------------------------------------------------- -- New base: spawn, station, teleporter, reinforcements -- ------------------------------------------------------------------------- local function BaseReady() if story.base_ready then return end story.base_ready = true story.phase = 4 pcall(function() local fz = FloorZ(CFG.NEW_SPAWN.x, CFG.NEW_SPAWN.y, CFG.NEW_SPAWN.z) local s = ents.CreateWithKeys("info_player_teamspawn", { TeamNum = 2, origin = CFG.NEW_SPAWN.x .. " " .. CFG.NEW_SPAWN.y .. " " .. (fz and (fz + 4) or CFG.NEW_SPAWN.z), angles = "0 180 0", }, true) if s and s:IsValid() then story.new_spawn = s for _, old in ipairs(FindAll("info_player_teamspawn")) do if old:GetHandleIndex() ~= s:GetHandleIndex() and old.m_iTeamNum == 2 then pcall(function() old:AcceptInput("Disable") end) end end end end) pcall(function() local st = ents.FindByName("new_upgrade_station") if st and st:IsValid() then st:AcceptInput("Enable") end end) -- models: on the real floor (trace), moved a bit back (away from the spawn), and SOLID (vphysics collision) local function Back(pt, back) local dx, dy = pt.x - CFG.NEW_SPAWN.x, pt.y - CFG.NEW_SPAWN.y local len = math.sqrt(dx * dx + dy * dy) if len < 1 then return pt.x, pt.y end return pt.x + dx / len * back, pt.y + dy / len * back end pcall(function() local x, y = Back(CFG.NEW_STATION, CFG.STATION_BACK) local z = FloorZ(x, y, CFG.NEW_STATION.z) or (CFG.NEW_STATION.z - 60) ents.CreateWithKeys("prop_dynamic", { model = "models/props_mvm/mvm_upgrade_center.mdl", origin = x .. " " .. y .. " " .. z, skin = 0, solid = 6, }, true) end) pcall(function() local x, y = Back(CFG.TELEPORTER, CFG.TELEPORTER_BACK) local z = FloorZ(x, y, CFG.TELEPORTER.z) or (CFG.TELEPORTER.z - 60) ents.CreateWithKeys("prop_dynamic", { model = "models/buildables/teleporter.mdl", origin = x .. " " .. y .. " " .. z, skin = 1, solid = 6, }, true) ents.CreateWithKeys("info_particle_system", { effect_name = "teleporter_blue_entrance", start_active = 1, origin = x .. " " .. y .. " " .. (z + 10), }, true) end) Broadcast(ENG .. " Done! The new spawn is online. The upgrade station is up too.") timer.Simple(5, function() Broadcast(ENG .. " Fair warning: I'm not sure how reliable it is. There may be defects. Respawns will take longer than usual, for one.") end) timer.Simple(11, function() Broadcast(ENG .. " I can also order reinforcements from carriers the infection hasn't reached yet. Use the upgrade station for that.") end) timer.Simple(17, function() Broadcast(ENG .. " Don't look at me like I'm swindling you. They're sold at cost, and I'm hauling them in from the far end of these lands.") end) Center("NEW BASE ONLINE") if in_wave and StartReinforcementLoop then StartReinforcementLoop(generation) end end local function BuildStructures() if not IsValid(eng) then return end local team = 2 pcall(function() local s = ents.CreateWithKeys("obj_sentrygun", { defaultupgrade = 1, team = team }, true) s:SetBuilder(eng, eng, eng) s:SetAbsOrigin(V(CFG.SENTRY)) end) pcall(function() local d = ents.CreateWithKeys("obj_dispenser", { defaultupgrade = 1, team = team }, true) d:SetBuilder(eng, eng, eng) d:SetAbsOrigin(V(CFG.DISPENSER)) end) end local function BuildTick(gen) timer.Simple(1, function() if gen ~= generation or not in_wave or story.base_ready then return end if IsValid(eng) and eng:IsAlive() then build_progress = build_progress + 1 local pct = math.floor(build_progress / CFG.BUILD_TIME * 100) if build_progress % 10 == 0 then Center("Construction: " .. pct .. "%") end if pct >= 25 and not story.said25 then story.said25 = true; Broadcast(ENG .. " Foundations are down. Keep them off me!") end if pct >= 50 and not story.said50 then story.said50 = true; Broadcast(ENG .. " Halfway. The wiring is the hard part.") end if pct >= 75 and not story.said75 then story.said75 = true; Broadcast(ENG .. " Almost there. Don't let anything near the generator!") end if build_progress >= CFG.BUILD_TIME then BaseReady() return end end BuildTick(gen) end) end local function RegisterEngineer(bot) eng = bot local h = bot:GetHandleIndex() local n = CFG.NEW_SPAWN Teleport(bot, Vector(n.x - 60, n.y + 90, n.z + 8)) local cb cb = bot:AddCallback(ON_DEATH, function() bot:RemoveCallback(cb) if eng and eng:IsValid() and eng:GetHandleIndex() == h then eng = nil end if in_wave then Broadcast(ENG .. " ...systems failing... rebooting...") timer.Simple(CFG.ENGINEER_RESPAWN, function() if in_wave and not IsValid(eng) then Summon("eng", 1) timer.Simple(4, function() Broadcast(ENG .. " I'm back. As long as you're alive, I can rebuild.") end) end end) end end) end -- ------------------------------------------------------------------------- -- Engineer intro: end of wave 1 -- ------------------------------------------------------------------------- local function EngineerIntro(bot) local gen = generation local function alive() return gen == generation and IsValid(bot) and bot:IsAlive() end bot:AddCond(COND_INVULN, 400) story.phase = math.max(story.phase, 1) Broadcast(ENG .. " Don't shoot! I'm coming out! Please, I'm not with them!") timer.Simple(6, function() if not alive() then return end bot:SetAbsOrigin(V(CFG.WAYPOINT1, 8)) FlipToRed(bot) timer.Simple(1, function() if IsValid(bot) and bot:IsAlive() then bot:AddCond(COND_INVULN, 120) end end) Center("A robot engineer is walking out of the blue base...") end) local lines = { { 11, "...Thank you. I'm Robot Engineer Mark II. I was built to keep the Carrier running." }, { 17, "That was me on the radio. The announcer died when the Carrier did. I patched into the old speakers." }, { 23, "The upgrade stations went down with it. And your old spawn is next: the clones are coming out of it now." }, { 29, "East of here I can raise a new base: a spawn, an upgrade station, the works. I need time, and I need you to keep me alive." }, { 35, "The robots you pull out of the Carrier's grip carry what's left of the company's money. That is your only income now." }, { 41, "A Scout is fast enough to free them instantly. Everyone else, give each robot five seconds." }, { 47, "Meet me at the site. Wave two: hold the line while I build." }, } for _, l in ipairs(lines) do timer.Simple(l[1], function() if gen ~= generation then return end if l[1] == 23 then story.phase = 2 end Broadcast(ENG .. " " .. l[2]) end) end timer.Simple(54, function() if gen ~= generation then return end story.phase = math.max(story.phase, 2) if IsValid(bot) and bot:IsAlive() then bot:SetAbsOrigin(V(CFG.NEW_SPAWN, 8)) timer.Simple(3, function() if IsValid(bot) and bot:IsAlive() then bot:Suicide() end -- ends the wave KillHostiles("wave 1 is over") -- if the wave does not close on its own, move on to wave 2 ourselves timer.Simple(8, function() if gen == generation and in_wave then ForceNextWave("the engineer left", false) end end) end) end end) end -- ------------------------------------------------------------------------- -- Not-infected robots: wait on the blue base -> move out -> RED -> call -> online -- ------------------------------------------------------------------------- -- A hostage must not be touched by anybody: invulnerable, and ignored by enemy bots and enemy sentries -- (otherwise the ghouls waste their time on an immortal robot instead of coming for the players). -- Same attribute names as the Mecha-Heavy construction in build_ally_bot_modified_oswald.lua. local function ApplyHostageState(bot) bot:AddCond(COND_INVULN, 9999) pcall(function() bot:SetAttributeValue("ignored by bots", 1) bot:SetAttributeValue("ignored by enemy sentries", 1) end) end local function ClearHostageState(bot) pcall(function() bot:SetAttributeValue("ignored by bots", nil) bot:SetAttributeValue("ignored by enemy sentries", nil) end) end local function RegisterDefector(bot, kind) local h = bot:GetHandleIndex() def_counter = def_counter + 1 defectors[h] = { bot = bot, stage = "exit", born = CurTime(), exit_at = CurTime() + RandRange(CFG.EXIT_DELAY), prog = 0, call_since = 0, kind = kind, id = def_counter, max_health = bot.m_iMaxHealth or bot.m_iHealth } ApplyHostageState(bot) -- uber + invisible to enemy bots from the very first moment, until rescued print("[infection] hostage #" .. def_counter .. " (" .. kind .. ") spawned") local cb cb = bot:AddCallback(ON_DEATH, function() bot:RemoveCallback(cb) timer.Simple(1, function() defectors[h] = nil; special[h] = nil end) end) end local function MoveOut(d) local bot = d.bot local pt = CFG.EXIT_POINTS[math.random(#CFG.EXIT_POINTS)] bot:SetAbsOrigin(Vector(pt.x + math.random(-80, 80), pt.y + math.random(-80, 80), pt.z + 8)) FlipToRed(bot) -- the team flip can clear conditions and attributes: put them back ApplyHostageState(bot) timer.Simple(1, function() if IsValid(bot) and bot:IsAlive() and d.stage ~= "online" then ApplyHostageState(bot) end end) d.stage = "dormant" d.dormant_since = CurTime() end local function StartCalling(d, near) d.stage = "calling" d.call_since = CurTime() Broadcast(string.format(CALL_LINES[math.random(#CALL_LINES)], d.id)) for _, p in ipairs(near) do p:Print(PRINT_TARGET_CENTER, "A robot is calling for help! Stand close to it (Scout: instant, others: 5 s).") end end local function GoOnline(d, rescuers) local bot = d.bot -- Giant templates can have custom max HP; ClearAllBotAttributes may recalculate it. local rescuedMaxHealth = d.max_health or bot.m_iMaxHealth or bot.m_iHealth d.stage = "online" -- Спасённый робот обязан остаться на RED и не учитываться как -- живой противник BLU при проверке завершения волны. if IsValid(bot) and bot:IsAlive() then pcall(function() bot:ResetFakeSendProp("m_iTeamNum") end) bot.m_iTeamNum = 2 end bot:RemoveCond(COND_INVULN) ClearHostageState(bot) pcall(function() bot:RunScriptCode("activator.ClearAllBotAttributes(); activator.SetDifficulty(3)", bot) end) pcall(function() bot:GiveItem(VOODOO_ITEM) end) -- Restore the original template health after attribute/team recalculation. if rescuedMaxHealth and rescuedMaxHealth > 0 then bot.m_iMaxHealth = rescuedMaxHealth bot.m_iHealth = rescuedMaxHealth timer.Simple(0.15, function() if IsValid(bot) and bot:IsAlive() then bot.m_iMaxHealth = rescuedMaxHealth bot.m_iHealth = rescuedMaxHealth end end) timer.Simple(0.6, function() if IsValid(bot) and bot:IsAlive() then bot.m_iMaxHealth = rescuedMaxHealth bot.m_iHealth = rescuedMaxHealth end end) else bot.m_iHealth = bot.m_iMaxHealth end bot:AddCond(COND_CRIT, 5) local reward = CFG.REWARD_SMALL if d.kind == "giant" then reward = CFG.REWARD_GIANT elseif d.kind == "boss" then reward = CFG.REWARD_BOSS end for _, p in ipairs(AllRedPlayers()) do -- everyone gets paid, wherever they are GiveCash(p, reward) p:Print(PRINT_TARGET_CENTER, "Robot rescued! +" .. reward .. " credits") end print("[infection] hostage #" .. d.id .. " rescued, paid " .. reward) Broadcast("{blue}[BLU] ...systems restored. We are with you. Hold the line.") end local function DefectorTick(gen) timer.Simple(0.5, function() if gen ~= generation or not in_wave then return end local reds = RedPlayers() local c2 = CFG.CALL_RADIUS * CFG.CALL_RADIUS local r2 = CFG.RESCUE_RADIUS * CFG.RESCUE_RADIUS for h, d in pairs(defectors) do local bot = d.bot if IsValid(bot) and bot:IsAlive() then if d.stage == "exit" then if CurTime() >= d.exit_at then MoveOut(d) end end -- stand still while waiting and while being rescued (same stop command the Mecha-Heavy uses next to its engineer) if d.stage == "dormant" or d.stage == "calling" then pcall(function() bot:BotCommand("interrupt_action -switch_action Default -duration 0.7") end) end if d.stage == "exit" then -- (handled above) elseif d.stage == "dormant" then local cp = bot:GetAbsOrigin() local near = {} for _, p in ipairs(reds) do if Dist2(p:GetAbsOrigin(), cp) <= c2 then near[#near + 1] = p end end if #near > 0 then StartCalling(d, near) elseif CurTime() - d.dormant_since >= CFG.DORMANT_MAX then bot:RemoveCond(COND_INVULN) bot:Suicide() end elseif d.stage == "calling" then local cp = bot:GetAbsOrigin() local close, scout = {}, false for _, p in ipairs(reds) do if Dist2(p:GetAbsOrigin(), cp) <= r2 then close[#close + 1] = p if IsScout(p) then scout = true end end end if #close > 0 then d.prog = d.prog + 0.5 local pct = math.min(100, math.floor(d.prog / CFG.RESCUE_TIME * 100)) for _, p in ipairs(close) do p:Print(PRINT_TARGET_CENTER, "Robot recovering: " .. pct .. "%") end if scout or d.prog >= CFG.RESCUE_TIME then GoOnline(d, close) end else d.prog = math.max(0, d.prog - 0.25) end if d.stage == "calling" and CurTime() - d.call_since >= CFG.CALL_TIMEOUT then Broadcast("{red}[RED-SYSTEM] Signal leak contained. Source shut down.") bot:RemoveCond(COND_INVULN) bot:Suicide() end end end end DefectorTick(gen) end) end local function PleaTick(gen, delay) timer.Simple(delay, function() if gen ~= generation or not in_wave then return end if CountHelpers() < CFG.MAX_HELPERS then Summon("defector", 1) end PleaTick(gen, RandRange(CFG.PLEA_INTERVAL)) end) end -- ------------------------------------------------------------------------- -- Carrier infection -- ------------------------------------------------------------------------- -- Boss hostage: walks out some time after the Carrier is destroyed (wave 2+) local function BossHostageWatch(gen) local seen, done = false, false local function tick() timer.Simple(2, function() if gen ~= generation or not in_wave or done then return end local tank = ents.FindByClass("tank_boss") if tank and tank:IsValid() then seen = true elseif seen then done = true if GetWaveNumber() >= 2 then timer.Simple(CFG.BOSS_DELAY, function() if gen ~= generation or not in_wave then return end Summon("defector_boss", 1) Say("Something big is walking out of the Carrier's base. It isn't shooting. Get to it before they do.") end) end return end tick() end) end tick() end local function Infect() if infected then return end infected = true local gen = generation local first = story.phase < 1 local steps = 5 Center("[ THE CARRIER IS BEING INFECTED ]") Broadcast("{red}[SYSTEM] Robot losses exceeded safe limits. The Carrier is losing signal. Ceasefire in effect.") for _, p in pairs(ents.GetAllPlayers()) do if p:IsValid() and p:IsAlive() then p:AddCond(COND_INVULN, CFG.INFECT_TIME) end end for i = 1, steps do timer.Simple(CFG.INFECT_TIME * i / (steps + 1), function() if gen ~= generation then return end Center("CARRIER INFECTION: " .. math.floor(i / steps * 100) .. "%") end) end if first then story.phase = 1 StationGuard() timer.Simple(3, function() if gen ~= generation then return end Broadcast(UNK .. " ...can anyone hear me? The announcer is gone. I'm patching in through the old radio.") end) timer.Simple(6, function() if gen ~= generation then return end Broadcast("{red}[SYSTEM] WARNING: upgrade station signal unstable. Upgrade services remain available.") Broadcast(UNK .. " The Carrier is interfering with the station network. Keep moving; the upgrade systems are still online.") end) end timer.Simple(CFG.INFECT_TIME, function() if gen ~= generation or not in_wave then return end Broadcast("{red}[SYSTEM] The Carrier has been captured. Hostile clones online.") Center("Some robots are walking out of their base and do not shoot!") Summon("defector", ByWave(CFG.DEFECTORS)) Summon("defector_giant", ByWave(CFG.GIANT_HOSTAGES)) DefectorTick(gen) BossHostageWatch(gen) PleaTick(gen, RandRange(CFG.PLEA_FIRST)) timer.Simple(4, function() if gen == generation then Say("Some robots aren't infected. Give them 15 or 20 seconds to get out, then get close to them. They'll call for help.") end end) end) timer.Simple(CFG.INFECT_TIME + CFG.GHOULS_DELAY, function() if gen ~= generation or not in_wave then return end -- the ghouls are now fixed wave content (see the .pop), they just start to come out Broadcast("{red}[SYSTEM] Ghouls detected. They are not robots. They are copies.") end) end -- Waves 2+: the Carrier was infected once, in wave 1, and stays that way. No ceasefire, no glitch, no countdown: -- the hostages just start walking out a bit after the wave starts, and the periodic pleas continue. local function PostInfection(gen) timer.Simple(CFG.REPEAT_DELAY, function() if gen ~= generation or not in_wave then return end Summon("defector", ByWave(CFG.DEFECTORS)) Summon("defector_giant", ByWave(CFG.GIANT_HOSTAGES)) DefectorTick(gen) PleaTick(gen, RandRange(CFG.PLEA_FIRST)) BossHostageWatch(gen) timer.Simple(4, function() if gen == generation then Say("More of them are slipping out of the Carrier's base. Find the ones that don't shoot.") end end) end) end local function Watch(gen) timer.Simple(1, function() if gen ~= generation or not in_wave or infected then return end local tank = ents.FindByClass("tank_boss") if tank and tank:IsValid() then if not tank_seen_at then tank_seen_at = CurTime() end if kills >= kill_goal or CurTime() - tank_seen_at >= CFG.TANK_MAX_WAIT then Infect() return end elseif tank_seen_at then Infect() return end Watch(gen) end) end -- ------------------------------------------------------------------------- -- Hooks (chained so other scripts keep theirs) -- ------------------------------------------------------------------------- -- Failsafe: the intro engineer is a normal (non-support) bot, so the wave cannot end while he lives. -- If the cutscene did not finish for any reason, kill him after 100 s. local intro_seen = {} local function EngineerFailsafe() local function tick() timer.Simple(5, function() for _, p in pairs(ents.GetAllPlayers()) do if p:IsValid() and not p:IsRealPlayer() and p:IsAlive() and p.m_iTeamNum == 3 and p.m_szNetname == "Robot Engineer Mk II" then local h = p:GetHandleIndex() intro_seen[h] = intro_seen[h] or CurTime() if CurTime() - intro_seen[h] > 100 then print("[infection] failsafe: killing stuck intro engineer") p:RemoveCond(COND_INVULN) p:Suicide() intro_seen[h] = nil end else intro_seen[p:IsValid() and p:GetHandleIndex() or 0] = nil end end tick() end) end tick() end EngineerFailsafe() -- Wave completion rescue. -- Vanilla finishes a wave only after EVERY WaveSpawn, support ones included, reached the DONE state. -- Our hidden spawners (mercenaries, hostages, engineer) start disabled and get paused, so they may never get -- there and the wave hangs with an empty panel. When the HUD says "0 enemies left" we resume them once and let -- the populator finish them. local HIDDEN_SPAWNERS = { "Merc_trio_soldiers", "Merc_solo_heavy", "Merc_solo_medic", "Defectors_a", "Defectors_b", "Defectors_giant", "Defector_boss", "Eng_ally" } local function HudEnemies() local n pcall(function() local res = ents.FindByClass("tf_objective_resource") if res and res:IsValid() then n = res.m_nMannVsMachineWaveEnemyCount end end) return n end local function WaveEndRescue(reason) print("[infection] wave end rescue (" .. reason .. "), wave " .. tostring(GetWaveNumber())) local pi = GetPopulatorInterface() if not pi then return end for _, nm in ipairs(HIDDEN_SPAWNERS) do pi:AcceptInput("$ResumeWavespawn", nm) end if CFG.DEBUG then Broadcast("{red}[DEBUG] Wave looks finished but did not end: resuming hidden spawners. If it stays stuck, type !stuck to start a skip vote.") end end local function StuckMonitor(gen) local empty_since, rescued, stopped = nil, false, false local function tick() timer.Simple(3, function() if gen ~= generation or not in_wave then return end local age = CurTime() - wave_started_at local hud = HudEnemies() local empty, need = false, CFG.RESCUE_AFTER if hud ~= nil then empty = (hud == 0) else local hostile = 0 for _, p in pairs(ents.GetAllPlayers()) do if p:IsValid() and not p:IsRealPlayer() and p:IsAlive() and p.m_iTeamNum == 3 then hostile = hostile + 1 end end local tank = false pcall(function() local t = ents.FindByClass("tank_boss"); tank = (t ~= nil and t:IsValid()) end) empty, need = (hostile == 0 and not tank), CFG.FALLBACK_AFTER end if age > 40 and empty then empty_since = empty_since or CurTime() local waited = CurTime() - empty_since if not rescued and waited >= need then rescued = true WaveEndRescue(hud ~= nil and "enemy counter is 0" or "no hostile bots") elseif rescued and not stopped and CFG.FORCE_STOP and waited >= need + 15 then stopped = true local pi = GetPopulatorInterface() if pi then for _, letter in ipairs({ "A", "B", "T", "G", "F", "E", "X" }) do pi:AcceptInput("$StopWavespawn", "W" .. GetWaveNumber() .. letter) end for _, nm in ipairs(HIDDEN_SPAWNERS) do pi:AcceptInput("$StopWavespawn", nm) end end print("[infection] sent $StopWavespawn, HUD enemies: " .. tostring(hud)) if CFG.DEBUG then Broadcast("{red}[DEBUG] Still not ended. HUD enemy counter: " .. tostring(hud) .. ". Tell me which wave-panel icon is lit.") end end else empty_since = nil end tick() end) end tick() end -- ------------------------------------------------------------------------- -- Forced transition to the next wave + the !stuck vote -- ------------------------------------------------------------------------- local function CurrentWaveNumber() local n pcall(function() local res = ents.FindByClass("tf_objective_resource") if res and res:IsValid() then n = res.m_nMannVsMachineWaveCount end end) return n end local jumping = false -- JumpToWave respawns everyone at the base. We remember where each living RED player stood and put them back. local jump_snapshot = {} local jump_restore_until = 0 local function RestoreAfterJump(p) local h = p:GetHandleIndex() local snap = jump_snapshot[h] if not snap then return end jump_snapshot[h] = nil timer.Simple(0.3, function() if IsValid(p) and p:IsAlive() then p:SetAbsOrigin(Vector(snap.x, snap.y, snap.z + 4)) end end) end -- fallback in case no respawn event arrives: anyone thrown far away from their remembered spot is put back local function RestoreWatch() local function tick() timer.Simple(0.5, function() if CurTime() > jump_restore_until or next(jump_snapshot) == nil then jump_snapshot = {} return end for _, p in ipairs(RedPlayers()) do local snap = jump_snapshot[p:GetHandleIndex()] if snap and Dist2(p:GetAbsOrigin(), snap) > 1500 * 1500 then RestoreAfterJump(p) end end tick() end) end tick() end -- HARD skip: JumpToWave. Besides respawning everybody at the base it RESETS the players' upgrades, -- so it is used only as a last resort (and only after a vote). local function JumpHard(w) local pi = GetPopulatorInterface() if not pi then print("[infection] JumpHard: no populator interface") jumping = false return end Broadcast("{red}[SYSTEM] The wave would not close. Forcing a jump (this resets upgrades).") jump_snapshot = {} for _, p in ipairs(RedPlayers()) do local o = p:GetAbsOrigin() jump_snapshot[p:GetHandleIndex()] = { x = o.x, y = o.y, z = o.z } end jump_restore_until = CurTime() + 25 RestoreWatch() pi:AcceptInput("JumpToWave", tostring(w + CFG.JUMP_OFFSET)) -- the map is rebuilt by the jump, so the old populator handle may be invalid: fetch a fresh one timer.Simple(6, function() local pi2 = GetPopulatorInterface() local now = CurrentWaveNumber() if pi2 and pi2:IsValid() and now ~= nil and now <= w and CFG.JUMP_OFFSET == 0 then print("[infection] still wave " .. tostring(now) .. ", retrying JumpToWave with " .. tostring(w + 1)) pi2:AcceptInput("JumpToWave", tostring(w + 1)) end timer.Simple(8, function() jumping = false end) end) end -- Forced transition. Step 1 (soft, upgrades are kept): resume the hidden spawners and ask the populator to stop -- the wave's stages, so the wave can close the normal way. Step 2 (only if allow_jump): JumpToWave. ForceNextWave = function(reason, allow_jump) if jumping then return end local pi = GetPopulatorInterface() if not pi then print("[infection] ForceNextWave: no populator interface") return end jumping = true local gen = generation local w = CurrentWaveNumber() or GetWaveNumber() print("[infection] closing the wave (" .. reason .. "), current wave " .. tostring(w)) Broadcast("{red}[SYSTEM] Closing the wave (" .. reason .. ")...") for _, nm in ipairs(HIDDEN_SPAWNERS) do pi:AcceptInput("$ResumeWavespawn", nm) end for _, letter in ipairs({ "A", "B", "T", "G", "F", "E", "X" }) do pi:AcceptInput("$StopWavespawn", "W" .. w .. letter) end for _, nm in ipairs(HIDDEN_SPAWNERS) do pi:AcceptInput("$StopWavespawn", nm) end KillHostiles("closing the wave") timer.Simple(CFG.SOFT_WAIT, function() if gen ~= generation or not in_wave then jumping = false return end -- the wave closed by itself if allow_jump then JumpHard(w) else Broadcast("{red}[SYSTEM] The wave did not close. Type !stuck to start a skip vote (a hard skip resets upgrades).") jumping = false end end) end local vote = nil local vote_blocked_until = 0 local function VoteTally() local y, n = 0, 0 for _ in pairs(vote.yes) do y = y + 1 end for _ in pairs(vote.no) do n = n + 1 end return y, n end local function EndVote(passed, why) local v = vote vote = nil if passed then Broadcast("{blue}[VOTE] Passed (" .. why .. "). Moving on.") ForceNextWave("vote", true) else vote_blocked_until = CurTime() + CFG.VOTE_COOLDOWN Broadcast("{red}[VOTE] Failed (" .. why .. ").") end end local function EvaluateVote(final) if not vote then return end local y, n = VoteTally() local elig = math.max(1, #AllRedPlayers()) local need = math.ceil(CFG.VOTE_PASS * elig) local max_no = math.floor((1 - CFG.VOTE_PASS) * elig) if y >= need then EndVote(true, y .. " of " .. elig .. " voted yes") elseif n > max_no then EndVote(false, n .. " voted no, 60% can no longer be reached") elseif final then local total = y + n if total >= math.ceil(elig / 2) and total > 0 and y / total >= CFG.VOTE_PASS then EndVote(true, y .. " yes / " .. n .. " no") else EndVote(false, y .. " yes / " .. n .. " no, not enough support") end end end local function StartVote(starter) if not in_wave then starter:AcceptInput("$DisplayTextChat", "{red}[VOTE] No wave is running.") return end if CurTime() - wave_started_at < CFG.VOTE_MIN_AGE then starter:AcceptInput("$DisplayTextChat", "{red}[VOTE] Too early: the wave has just started.") return end if CurTime() < vote_blocked_until then starter:AcceptInput("$DisplayTextChat", "{red}[VOTE] Wait a bit before the next vote.") return end local gen = generation vote = { yes = {}, no = {}, gen = gen } vote.yes[starter:GetHandleIndex()] = true Broadcast("{blue}[VOTE] " .. (starter.m_szNetname or "Someone") .. " wants to skip to the next wave. Warning: if the wave cannot be closed softly, the skip resets upgrades. Type !yes or !no (" .. math.floor(CFG.VOTE_PASS * 100) .. "% yes needed, " .. CFG.VOTE_TIME .. " s).") timer.Simple(CFG.VOTE_TIME, function() if vote and vote.gen == gen then EvaluateVote(true) end end) EvaluateVote(false) end local function CastVote(player, yes) if not vote then player:AcceptInput("$DisplayTextChat", "{red}[VOTE] There is no vote right now. Type !stuck to start one.") return end local h = player:GetHandleIndex() vote.yes[h], vote.no[h] = nil, nil if yes then vote.yes[h] = true else vote.no[h] = true end local y, n = VoteTally() Broadcast("{blue}[VOTE] yes " .. y .. " / no " .. n) EvaluateVote(false) end AddEventCallback("player_say", function(ev) local text = string.lower(string.gsub(ev.text or "", "^%s*(.-)%s*$", "%1")) if text ~= "!stuck" and text ~= "!yes" and text ~= "!y" and text ~= "!no" and text ~= "!n" then return end local player = ents.GetPlayerByUserId(ev.userid) if not player or not player:IsValid() or not player:IsRealPlayer() or player.m_iTeamNum ~= 2 then return end if text == "!stuck" then if vote then CastVote(player, true) else StartVote(player) end elseif text == "!yes" or text == "!y" then CastVote(player, true) else CastVote(player, false) end end) local previous_OnWaveInit = OnWaveInit function OnWaveInit() if previous_OnWaveInit then previous_OnWaveInit() end generation = generation + 1 vote = nil in_wave, infected = false, false kills, warned, tank_seen_at, def_counter = 0, {}, nil, 0 defectors, special, eng = {}, {}, nil reinforcement_running = false pending.defector, pending.defector_giant, pending.defector_boss, pending.eng, pending.reinforce = 0, 0, 0, 0, 0 if GetWaveNumber() >= 3 and not story.base_ready and story.phase >= 2 then BaseReady() end end local previous_OnWaveStart = OnWaveStart function OnWaveStart() if previous_OnWaveStart then previous_OnWaveStart() end waves_started = waves_started + 1 in_wave = true wave_started_at = CurTime() print("[infection] wave start, number " .. tostring(GetWaveNumber())) StuckMonitor(generation) local wave = GetWaveNumber() kill_goal = ByWave(CFG.KILLS) if wave == 1 then Watch(generation) -- the one and only infection else infected = true -- already infected: nothing to trigger PostInfection(generation) end if story.phase >= 1 then StationGuard() end if story.phase >= 2 then ForbiddenZone() end if story.base_ready then StartReinforcementLoop(generation) end if wave >= 2 and story.phase >= 2 then Summon("eng", 1) local gen = generation if wave == 2 and not story.base_ready then story.phase = 3 build_progress = 0 story.said25, story.said50, story.said75 = false, false, false timer.Simple(4, function() if gen ~= generation then return end Broadcast(ENG .. " I'm at the site. Starting construction: keep the ghouls off me!") end) BuildTick(gen) elseif wave >= 3 then timer.Simple(5, function() if gen ~= generation then return end BuildStructures() if WAVE_LINES[wave] then Broadcast(ENG .. " " .. WAVE_LINES[wave]) end end) end end end local previous_OnWaveSpawnBot = OnWaveSpawnBot function OnWaveSpawnBot(bot, wave, tags) if previous_OnWaveSpawnBot then previous_OnWaveSpawnBot(bot, wave, tags) end if not bot or not bot:IsValid() then return end special[bot:GetHandleIndex()] = nil if not tags then return end local set = {} for _, tag in ipairs(tags) do set[tag] = true end if set.ghoul then special[bot:GetHandleIndex()] = true end if set.base_reinforcement then local h = bot:GetHandleIndex() special[h] = true FlipToRed(bot) if pending.reinforce > 0 then pending.reinforce = pending.reinforce - 1 last_spawn.reinforce = CurTime() if pending.reinforce <= 0 then timer.Simple(0.02, function() SetSpawners(SPAWNERS.reinforce, false) end) end end end if set.defector then special[bot:GetHandleIndex()] = true local kind, key = "small", "defector" if set.defector_boss then kind, key = "boss", "defector_boss" elseif set.defector_giant then kind, key = "giant", "defector_giant" end RegisterDefector(bot, kind) if pending[key] > 0 then pending[key] = pending[key] - 1 last_spawn[key] = CurTime() if pending[key] <= 0 then timer.Simple(0.02, function() SetSpawners(SPAWNERS[key], false) end) end end end if set.eng_intro then special[bot:GetHandleIndex()] = true EngineerIntro(bot) end if set.eng_ally then special[bot:GetHandleIndex()] = true RegisterEngineer(bot) if pending.eng > 0 then pending.eng = pending.eng - 1 end timer.Simple(0.02, function() SetSpawners(SPAWNERS.eng, false) end) end end -- ------------------------------------------------------------------------- -- Game events -- ------------------------------------------------------------------------- AddEventCallback("player_death", function(ev) local victim = Entity(ev.victim_entindex) if not IsValid(victim) then return end local h = victim:GetHandleIndex() local d = defectors[h] if d then -- Rescued robots join RED while alive, but must leave the active teams on death. if d.stage == "online" then timer.Simple(0.05, function() if IsValid(victim) and not victim:IsRealPlayer() then pcall(function() victim:ResetFakeSendProp("m_iTeamNum") end) victim.m_iTeamNum = 1 -- TF2 spectator team end end) elseif d.stage ~= "exit" and in_wave then Broadcast("{red}[RED-SYSTEM] Defector eliminated. Leak contained.") end return end if not victim:IsRealPlayer() and victim.m_iTeamNum == 3 and not special[h] and not infected then kills = kills + 1 for _, frac in ipairs({ 0.5, 0.8 }) do if not warned[frac] and kills >= kill_goal * frac then warned[frac] = true Broadcast("{red}[SYSTEM] Robot losses are climbing. The Carrier is unstable.") end end return end if victim:IsRealPlayer() and victim.m_iTeamNum == 2 then local uid = ev.userid deaths[uid] = (deaths[uid] or 0) + 1 local n = deaths[uid] local line = DEATH_LINES[n] if line then local memory = math.max(0, 100 - n * 4) .. "%" victim:AcceptInput("$DisplayTextChat", string.format(line, n + 1, memory)) end end end) -- After wave 1 the old spawn is overrun: whoever spawns there is rerouted to the new base. -- Right after a forced wave jump players are put back where they stood instead. AddEventCallback("player_spawn", function(ev) local p = ents.GetPlayerByUserId(ev.userid) if not p or not p:IsValid() or not p:IsRealPlayer() or p.m_iTeamNum ~= 2 then return end if CurTime() < jump_restore_until and jump_snapshot[p:GetHandleIndex()] then RestoreAfterJump(p) return end if story.phase < 2 then return end timer.Simple(0.2, function() if not IsValid(p) or not p:IsAlive() then return end if CurTime() < jump_restore_until then return end if Dist2(p:GetAbsOrigin(), CFG.NEW_SPAWN) > 700 * 700 then ToNewBase(p) end end) end)