-- ========================================================================= -- MERCENARY SQUAD MANAGER v2 (NATIVE WAVESPAWN INTEGRATION) -- Покупка отряда в станции улучшений -> $BuySquad -> включается скрытый WaveSpawn "Merc_" -- ========================================================================= local SQUAD_BUY_COOLDOWN = 0.0 local next_squad_time = 0 -- per_buy : сколько ботов выходит за 1 покупку (должно совпадать со SpawnCount в .pop) -- max_active : лимит одновременно живых (должен совпадать с MaxActive в .pop) local SQUADS = { trio_soldiers = { per_buy = 3, max_active = 6, title = "Banner Squad (3x Soldier)" }, solo_heavy = { per_buy = 1, max_active = 2, title = "Heavy Terminator" }, solo_medic = { per_buy = 1, max_active = 3, title = "Medic Guardian" }, } local pending_spawns = {} -- куплено, но ещё не вышло из спавна local alive_count = {} -- сейчас живы for id, _ in pairs(SQUADS) do pending_spawns[id] = 0 alive_count[id] = 0 end -- Поиск контроллера волн local function GetPopulatorInterface() local pop_interface = ents.FindByClass("point_populator_interface") if pop_interface and pop_interface:IsValid() then return pop_interface end pop_interface = ents.FindByName("pop_interface") if pop_interface and pop_interface:IsValid() then return pop_interface end return nil end local function Tell(player, msg) if player and player:IsValid() then player:AcceptInput("$DisplayTextChat", msg) end 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 -- В одной среде с build_ally_bot_modified.lua хуки могут конфликтовать: -- запоминаем предыдущий OnWaveInit (если он есть) и вызываем его первым. local previous_OnWaveInit = OnWaveInit function OnWaveInit() if previous_OnWaveInit then previous_OnWaveInit() end next_squad_time = 0 for id, _ in pairs(SQUADS) do pending_spawns[id] = 0 alive_count[id] = 0 end local shop = ents.FindByName("red_merc_upgrade_station") if shop and shop:IsValid() then shop:AcceptInput("Enable") end end -- Вызывается из апгрейда: "popscript,$BuySquad,,0" function BuySquad(squad_id, activator) local cur_time = CurTime() if cur_time < next_squad_time then Tell(activator, "{red}Base communications are overloaded! Please wait...") return end local squad = SQUADS[squad_id] if not squad then return end local pop_interface = GetPopulatorInterface() if not pop_interface then Tell(activator, "{red}ERROR: populator interface not found on the map!") return end next_squad_time = cur_time + SQUAD_BUY_COOLDOWN pending_spawns[squad_id] = pending_spawns[squad_id] + squad.per_buy pop_interface:AcceptInput("$ResumeWavespawn", "Merc_" .. squad_id) local who = "Someone" if activator and activator:IsValid() then who = activator.m_szNetname or who end -- Если слотов не хватает, отряд встанет в очередь и выйдет, когда погибнут предыдущие if alive_count[squad_id] + squad.per_buy > squad.max_active then Tell(activator, "{red}[SHOP] Mercenary limit reached. Reinforcements are queued and will deploy when slots free up.") else Tell(activator, "{blue}[SHOP] Elite mercenaries have been deployed!") end Broadcast("{blue}[RADIO] " .. who .. " called in: " .. squad.title) end -- Встроенный хук Sigsegv: срабатывает на каждого бота из WaveSpawn function OnWaveSpawnBot(bot, wave, tags) if not tags then return end local prefix = "merc_" for _, tag in ipairs(tags) do if string.sub(tag, 1, string.len(prefix)) == prefix then local squad_id = string.sub(tag, string.len(prefix) + 1) if SQUADS[squad_id] and pending_spawns[squad_id] > 0 then if bot and bot:IsValid() then bot:AddCond(TF_COND_SPEED_BOOST, 5.0) -- ускорение на старте -- учёт живых наёмников (нужен для сообщения про очередь) alive_count[squad_id] = alive_count[squad_id] + 1 local cb cb = bot:AddCallback(ON_DEATH, function() alive_count[squad_id] = math.max(0, alive_count[squad_id] - 1) bot:RemoveCallback(cb) end) end pending_spawns[squad_id] = pending_spawns[squad_id] - 1 -- Все купленные вышли: ставим WaveSpawn обратно на паузу if pending_spawns[squad_id] <= 0 then timer.Simple(0.02, function() local pop_interface = GetPopulatorInterface() if pop_interface then pop_interface:AcceptInput("$PauseWavespawn", "Merc_" .. squad_id) end end) end end break end end end