local BOTS_VARIANTS = { heavy = { Display = "Lvl.I Mecha-Heavy", Class = "Heavyweapons", Model = "models/bots/heavy/bot_heavy.mdl", MaxClip = 200, DefaultAttributes = { ["damage force reduction"] = 0.7, ["airblast vulnerability multiplier"] = 0.7, }, Tiers = { [2] = { Display = "Lvl.II Mecha-Heavy", Model = "models/bots/heavy/bot_heavy.mdl", Scale = 1.1, HealthIncrease = 1000, Items = { "TF_WEAPON_MINIGUN" }, Attributes = { ["damage bonus"] = 1.1, ["fire rate bonus"] = 0.9, }, }, [3] = { Display = "Lvl.III Mecha-Heavy", Model = "models/bots/heavy/bot_heavy.mdl", Scale = 1.2, HealthIncrease = 2000, Items = { "TF_WEAPON_MINIGUN" }, Attributes = { ["damage bonus"] = 1.25, ["fire rate bonus"] = 0.8, ["move speed bonus"] = 0.9, }, }, [4] = { Display = "Lvl.IV Mecha-Heavy", Model = "models/bots/heavy/bot_heavy.mdl", Scale = 1.3, HealthIncrease = 3500, Items = { "TF_WEAPON_MINIGUN" }, Attributes = { ["damage bonus"] = 1.4, ["fire rate bonus"] = 0.75, ["move speed bonus"] = 0.8, }, }, [5] = { Display = "Lvl.V Mecha-Heavy", Model = "models/bots/heavy/bot_heavy.mdl", Scale = 1.4, HealthIncrease = 5000, Items = { "TF_WEAPON_MINIGUN" }, MiniBoss = true, Attributes = { ["damage bonus"] = 1.5, ["fire rate bonus"] = 0.7, ["attack projectiles"] = 1.0, -- Дефлектор ["move speed bonus"] = 0.75, }, }, [6] = { Display = "Lvl.VI Giant Mecha-Heavy", Model = "models/bots/heavy_boss/bot_heavy_boss.mdl", Scale = 1.5, HealthIncrease = 8000, Items = { "TF_WEAPON_MINIGUN" }, MiniBoss = true, Attributes = { ["damage bonus"] = 1.5, ["fire rate bonus"] = 0.65, ["attack projectiles"] = 1.0, ["damage force reduction"] = 0.5, ["airblast vulnerability multiplier"] = 0.5, ["override footstep sound set"] = 2, ["dmg taken from crit reduced"] = 0.6, ["dmg taken from fire reduced"] = 0.6, ["dmg taken from blast reduced"] = 0.6, ["move speed bonus"] = 0.6, }, }, [7] = { Display = "Lvl.VII Giant Mecha-Heavy", Model = "models/bots/heavy_boss/bot_heavy_boss.mdl", Scale = 1.6, HealthIncrease = 12000, Items = { "TF_WEAPON_MINIGUN" }, MiniBoss = true, Attributes = { ["damage bonus"] = 1.5, ["fire rate bonus"] = 0.6, ["attack projectiles"] = 2.0, ["move speed bonus"] = 0.6, ["health regen"] = 45, ["dmg taken from crit reduced"] = 0.6, ["dmg taken from fire reduced"] = 0.6, ["dmg taken from blast reduced"] = 0.6, ["override footstep sound set"] = 2, }, }, [8] = { Display = "Lvl.VIII Boss Terminator", Model = "models/bots/heavy_boss/bot_heavy_boss.mdl", Scale = 1.7, HealthIncrease = 18000, Items = { "TF_WEAPON_MINIGUN" }, MiniBoss = true, Attributes = { ["damage bonus"] = 2.2, ["fire rate bonus"] = 0.5, ["attack projectiles"] = 2.0, ["move speed bonus"] = 0.55, ["health regen"] = 100, ["damage force reduction"] = 0.3, ["airblast vulnerability multiplier"] = 0.3, ["override footstep sound set"] = 2, ["dmg taken from crit reduced"] = 0.4, ["dmg taken from fire reduced"] = 0.4, ["dmg taken from blast reduced"] = 0.4, }, }, [9] = { Display = "Lvl.IX Boss Terminator", Model = "models/bots/heavy_boss/bot_heavy_boss.mdl", Scale = 1.8, HealthIncrease = 25000, Items = { "TF_WEAPON_MINIGUN" }, MiniBoss = true, Attributes = { ["damage bonus"] = 2.5, ["fire rate bonus"] = 0.45, ["attack projectiles"] = 2.0, ["minigun spinup time decreased"] = 0.3, ["move speed bonus"] = 0.5, ["health regen"] = 150, ["damage force reduction"] = 0.2, ["airblast vulnerability multiplier"] = 0.2, ["dmg taken from crit reduced"] = 0.35, ["dmg taken from fire reduced"] = 0.35, ["dmg taken from blast reduced"] = 0.35, ["override footstep sound set"] = 2 }, }, [10] = { Display = "OMEGA BOSS TERMINATOR", Model = "models/bots/heavy_boss/bot_heavy_boss.mdl", Scale = 1.9, HealthIncrease = 35000, Items = { "TF_WEAPON_MINIGUN" }, MiniBoss = true, Attributes = { ["damage bonus"] = 3.0, ["fire rate bonus"] = 0.4, ["attack projectiles"] = 2.0, ["move speed bonus"] = 0.5, ["health regen"] = 250, ["damage force reduction"] = 0.1, ["airblast vulnerability multiplier"] = 0.1, ["dmg taken from crit reduced"] = 0.35, ["dmg taken from fire reduced"] = 0.35, ["dmg taken from blast reduced"] = 0.35, ["minigun spinup time decreased"] = 0.1, ["override footstep sound set"] = 2 }, }, }, }, } local SPEED_BOOST_DISTANCE = 400 local BOTS_ATTRIBUTES = { ["collect currency on kill"] = 1, ["ammo regen"] = 10, ["crit mod disabled"] = 0, ["cannot be sapped"] = 1, ["is suicide counter"] = 1, ["health regen"] = 1, } local BOTS_WRANGLED_ATTRIBUTES = { ["fire rate bonus HIDDEN"] = 0.7, ["Reload time increased"] = 0.9, ["SET BONUS: move speed set bonus"] = 1.3, } local REPLICATE_CONDS = { TF_COND_CRITBOOSTED_USER_BUFF, TF_COND_INVULNERABLE_USER_BUFF, } local SENTRY_FIRERATE_REPLICATE_ATTR = "halloween fire rate bonus" local SENTRY_FIRERATE_REPLICATE_MULT = 1 local BOT_SETUP_VSCRIPT = "activator.SetDifficulty(3); activator.SetMaxVisionRangeOverride(100000); activator.AddBotAttribute(16)" local BOT_DISABLE_VISION_VSCRIPT = "activator.SetDifficulty(0); activator.SetMaxVisionRangeOverride(0.1)" local BOT_ENABLE_VISION_VSCRIPT = "activator.SetDifficulty(3); activator.SetMaxVisionRangeOverride(100000)" local BOT_CLEAR_RESTRICTIONS_VSCRIPT = "activator.ClearAllWeaponRestrictions()" local BOT_ATTACK_VSCRIPT = "activator.PressFireButton(0.1)" local activeBots = {} local activeBuiltBots = {} local activeBuiltBotsOwner = {} local lingeringBuiltBots = {} local inWave = false local companionMode = {} -- [owner handle] = "follow" | "attack" (chat: !attack / !follow / !heavy) function OnWaveInit() inWave = false companionMode = {} for _, bot in pairs(activeBuiltBots) do bot:Suicide() bot.m_iTeamNum = 1 end activeBuiltBots = {} end function OnWaveStart() inWave = true for _, bot in pairs(activeBuiltBots) do bot:ResetFakeSendProp("m_iTeamNum") bot.m_iTeamNum = 2 bot:SetAttributeValue("not solid to players", nil) bot:SetAttributeValue("ignored by enemy sentries", nil) bot:SetAttributeValue("ignored by bots", nil) bot:SetAttributeValue("damage bonus HIDDEN", nil) bot:SetAttributeValue("wet immunity", nil) end end local function checkOnHit(parent, damageinfo) local attacker = damageinfo.Attacker if not attacker then return end local handle = attacker:GetHandleIndex() local owner = activeBuiltBotsOwner[handle] if not owner or parent == owner then return end damageinfo.Attacker = owner return true end ents.AddCreateCallback("tank_boss", function(tank) tank:AddCallback(ON_DAMAGE_RECEIVED_PRE, function(_, damageinfo) return checkOnHit(tank, damageinfo) end) end) local function addGlobalCallbacks(player) player:AddCallback(ON_DAMAGE_RECEIVED_PRE, function(_, damageinfo) local isBot = activeBots[player:GetHandleIndex()] if isBot and not inWave then damageinfo.Damage = 0 damageinfo.Inflictor = nil damageinfo.Weapon = nil return true end return checkOnHit(player, damageinfo) end) player:AddCallback(ON_SPAWN, function() if player:IsRealPlayer() then return end timer.Simple(0.1, function() if inWave then return end local owner = activeBuiltBots[player:GetHandleIndex()] if not owner then return end if player.m_iTeamNum == owner.m_iTeamNum then player:Suicide() end end) end) end function OnPlayerConnected(player) addGlobalCallbacks(player) end local function removeCallbacks(player, callbacks) if not IsValid(player) then return end for _, callbackId in pairs(callbacks) do player:RemoveCallback(callbackId) end end local function getEyeAngles(player) local pitch = player["m_angEyeAngles[0]"] local yaw = player["m_angEyeAngles[1]"] return Vector(pitch, yaw, 0) end local function getCursorPos(player, bot) local eyeAngles = getEyeAngles(player) util.StartLagCompensation(player) local DefaultTraceInfo = { start = player, distance = 100000, angles = eyeAngles, mask = MASK_SHOT, collisiongroup = COLLISION_GROUP_PLAYER, filter = { player, bot }, } local okTrace, trace = pcall(util.Trace, DefaultTraceInfo) util.FinishLagCompensation(player) if not okTrace or not trace then return player:GetAbsOrigin() end return trace.HitPos end local function getMaxClip(bot) local clipBonusMult = bot:GetAttributeValueByClass("mult_clipsize", 1) local clipBonusAtomic = bot:GetAttributeValueByClass("mult_clipsize_upgrade_atomic", 0) return (4 * clipBonusMult) + clipBonusAtomic end local function applyName(bot, name, owner) local displayName = name .. " (" .. owner.m_szNetname .. ")" bot.m_szNetname = displayName bot:SetFakeClientConVar("name", displayName) end local function applyUniversalData(bot, data) if data.Model then bot:SetCustomModelWithClassAnimations(data.Model) end if data.Scale then local vscript = ("activator.SetScaleOverride(%s)"):format(tostring(data.Scale)) bot:RunScriptCode(vscript, bot) end if data.Items then for _, itemName in pairs(data.Items) do bot:GiveItem(itemName) end end if data.Attributes then for name, value in pairs(data.Attributes) do bot:SetAttributeValue(name, value) end end if data.MiniBoss then bot.m_bIsMiniBoss = 1 else bot.m_bIsMiniBoss = 0 end if data.Display then applyName(bot, data.Display, activeBuiltBotsOwner[bot:GetHandleIndex()]) end end local function applyMaxHealthUpgrade(owner, bot) local pda = owner:GetPlayerItemBySlot(LOADOUT_POSITION_PDA) local healthBonusMult = pda:GetAttributeValue("engy building health bonus") or 1 local extraHealth = 200 * (healthBonusMult - 1) local curMaxHealthBuff = bot:GetAttributeValue("hidden maxhealth non buffed") or 0 bot:SetAttributeValue("hidden maxhealth non buffed", curMaxHealthBuff + extraHealth) end local function applyDefaultData(owner, bot, class) local data = BOTS_VARIANTS[class] if data.DefaultAttributes then for name, value in pairs(data.DefaultAttributes) do bot:SetAttributeValue(name, value) end end bot:SwitchClassInPlace(data.Class) bot:SetAttributeValue("hidden maxhealth non buffed", nil) applyUniversalData(bot, data) applyMaxHealthUpgrade(owner, bot) end local function applyTierData(bot, data) applyUniversalData(bot, data) if data.HealthIncrease then bot:SetAttributeValue("hidden maxhealth non buffed", data.HealthIncrease) local owner = activeBuiltBotsOwner[bot:GetHandleIndex()] local sentry = Entity(tonumber(owner.BuiltBotSentry)) sentry.m_iMaxHealth = owner.m_iMaxHealth + data.HealthIncrease sentry.m_iHealth = sentry.m_iHealth + data.HealthIncrease end if data.Conds then for _, id in pairs(data.Conds) do bot:AddCond(id) end end bot:RefillAmmo() end local function removePreviousTier(bot, class, previousTier) local data = BOTS_VARIANTS[class].Tiers[previousTier] if data.Conds then for _, id in pairs(data.Conds) do bot:RemoveCond(id) end end if data.Items then for _, itemName in pairs(data.Items) do bot:RemoveItem(itemName) end end if data.Attributes then for name, _ in pairs(data.Attributes) do bot:SetAttributeValue(name, nil) end end end local function getCurBotTier(owner) return owner:GetPlayerItemBySlot(2):GetAttributeValue("throwable fire speed") end local function applyBotTier(owner, bot, class, tier) if tier > 2 then removePreviousTier(bot, class, tier - 1) end local tierData = BOTS_VARIANTS[class].Tiers[tier] applyTierData(bot, tierData) applyMaxHealthUpgrade(owner, bot) end local function setupBot(bot, owner, handle, building) local callbacks = {} local botHandle = bot:GetHandleIndex() applyName(bot, "Mecha-Heavy", owner) bot.m_iTeamNum = owner.m_iTeamNum bot.m_iszClassIcon = "" for name, value in pairs(BOTS_ATTRIBUTES) do bot:SetAttributeValue(name, value) end owner.BuiltBotHandle = tostring(botHandle) owner.BuiltBotSentry = tostring(building:GetHandleIndex()) activeBots[botHandle] = true activeBuiltBots[handle] = bot lingeringBuiltBots[botHandle] = true activeBuiltBotsOwner[botHandle] = owner callbacks.damaged = bot:AddCallback(ON_DAMAGE_RECEIVED_POST, function() building.m_iHealth = bot.m_iHealth end) callbacks.died = bot:AddCallback(ON_DEATH, function() for name, _ in pairs(bot:GetAllAttributeValues()) do bot:SetAttributeValue(name, nil) end owner.BuiltBotHandle = false owner.BuiltBotSentry = false activeBots[botHandle] = nil activeBuiltBots[handle] = nil activeBuiltBotsOwner[botHandle] = nil companionMode[handle] = nil bot:ResetFakeSendProp("m_iTeamNum") bot.m_iTeamNum = 1 removeCallbacks(bot, callbacks) if IsValid(building) then building:Remove() end end) return callbacks end local function findFreeBot() local chosen for _, bot in pairs(ents.GetAllPlayers()) do if not bot:IsRealPlayer() and not bot:IsAlive() and (bot.m_iTeamNum == 1 or bot.m_iTeamNum == 0) and bot:GetPlayerName() ~= "Demo-Bot" then chosen = bot break end end return chosen end function TierPurchase(tier, activator) tier = tier + 1 print("purchasing tier", tier) local botHandle = activator.BuiltBotHandle local bot = botHandle and Entity(tonumber(botHandle)) if tier <= 1 then if bot then bot:Suicide() end return end if not bot then return end applyBotTier(activator, bot, "heavy", tier) end local function startBotConstruction(owner, building, bot) if not inWave then building.m_iHealth = building.m_iMaxHealth return end building.m_bBuilding = 1 bot.m_iHealth = 1 local botTier = getCurBotTier(owner) or 1 local healthIncrement = 2 if botTier >= 10 then healthIncrement = 4 end bot:AddCond(TF_COND_MVM_BOT_STUN_RADIOWAVE, 50000) local constructionTimer constructionTimer = timer.Create(0, function() if not IsValid(building) then timer.Stop(constructionTimer) return end building.m_bBuilding = 1 bot.m_iHealth = bot.m_iHealth + healthIncrement building.m_iHealth = bot.m_iHealth local percent = building.m_iHealth / building.m_iMaxHealth building.m_flPercentageConstructed = percent building.m_bBuilding = 1 if percent >= 1 then timer.Stop(constructionTimer) bot:RemoveCond(TF_COND_STUNNED) building.m_bBuilding = 0 return end end, 0) end function SentrySpawned(_, building) if not IsValid(building) then print("building was destroyed before logic could register lol") return end local owner = building.m_hBuilder local handle = owner:GetHandleIndex() local origin = building:GetAbsOrigin() local newBuilding = ents.CreateWithKeys("obj_sentrygun", { defaultupgrade = 0, team = owner.m_iTeamNum, SolidToPlayer = 0, }, true) newBuilding.m_bBuilding = 1 building:Remove() newBuilding:SetBuilder(owner, owner, owner) newBuilding:SetAbsOrigin(Vector(0, 0, -10000)) newBuilding:Disable() if activeBuiltBots[handle] and activeBuiltBots[handle]:IsAlive() then newBuilding:Remove() return end local botSpawn = findFreeBot() if not botSpawn then owner:Print(PRINT_TARGET_CENTER, "GLOBAL BOT LIMIT REACHED") newBuilding:Remove() return end local callbacks = setupBot(botSpawn, owner, handle, newBuilding) timer.Simple(0, function() if not IsValid(newBuilding) then botSpawn:Suicide() return end botSpawn:SetAbsOrigin(origin) botSpawn:SwitchClassInPlace("Heavyweapons") local botTier = getCurBotTier(owner) if botTier and botTier > 1 then applyBotTier(owner, botSpawn, "heavy", botTier) else applyDefaultData(owner, botSpawn, "heavy") end --------------------------------------------------------- -- ВАЖНО: ИЗЫМАЕМ ВЕСЬ МЕТАЛЛ ИНЖЕНЕРА В КАЧЕСТВЕ "ПЛАТЫ" ЗА БОССА --------------------------------------------------------- -- Массивные пропы читаются строкой "name[i]" (как m_angEyeAngles[0] выше). TF_AMMO_METAL = 3. local okMetal, metalConsumed = pcall(function() return owner["m_iAmmo[3]"] end) if okMetal and metalConsumed and metalConsumed > 0 then pcall(function() owner["m_iAmmo[3]"] = 0 end) owner:Print(PRINT_TARGET_CENTER, "MECHA-COMPANION DEPLOYED!\nConsumed " .. metalConsumed .. " metal for power core.\nSay !attack to send it out, !follow to call it back.") end --------------------------------------------------------- botSpawn:RunScriptCode(BOT_SETUP_VSCRIPT, botSpawn, botSpawn) botSpawn:RunScriptCode(BOT_CLEAR_RESTRICTIONS_VSCRIPT, botSpawn, botSpawn) newBuilding.m_iMaxHealth = botSpawn.m_iHealth local teleParticle = ents.CreateWithKeys("info_particle_system", { effect_name = botSpawn.m_iTeamNum == TEAM_RED and "teleportedin_red" or "teleportedin_blue", start_active = 1, flag_as_weather = 0, }, true, true) teleParticle:SetAbsOrigin(botSpawn:GetAbsOrigin()) teleParticle:Start() timer.Simple(1, function () teleParticle:Remove() end) startBotConstruction(owner, newBuilding, botSpawn) newBuilding:AddCallback(ON_REMOVE, function() if not activeBuiltBots[handle] then return end botSpawn:Suicide() end) if not inWave then botSpawn:SetFakeSendProp("m_iTeamNum", 2) botSpawn.m_iTeamNum = 1 botSpawn:SetAttributeValue("not solid to players", 1) botSpawn:SetAttributeValue("ignored by enemy sentries", 1) botSpawn:SetAttributeValue("ignored by bots", 1) botSpawn:SetAttributeValue("damage bonus HIDDEN", 0.0001) botSpawn:SetAttributeValue("wet immunity", 1) end local spawnedCallback spawnedCallback = botSpawn:AddCallback(ON_SPAWN, function() if IsValid(newBuilding) then newBuilding:Remove() end botSpawn:ResetFakeSendProp("m_iTeamNum") lingeringBuiltBots[handle] = nil botSpawn:RemoveCallback(spawnedCallback) spawnedCallback = nil end) local cursorPos = Vector(0, 0, 0) local lastWrangled = false local logicLoop logicLoop = timer.Create(0.2, function() if not activeBuiltBots[handle] then timer.Stop(logicLoop) return end if not owner:IsAlive() then return end if owner:InCond(TF_COND_TAUNTING) then botSpawn["$Taunt"](botSpawn) end for _, cond in pairs(REPLICATE_CONDS) do if owner:InCond(cond) then botSpawn:AddCond(cond, 0.25, owner) end end local pda = owner:GetPlayerItemBySlot(LOADOUT_POSITION_PDA) local ownerFireRateUpgrade = pda:GetAttributeValue("engy sentry fire rate increased") if ownerFireRateUpgrade then botSpawn:SetAttributeValue(SENTRY_FIRERATE_REPLICATE_ATTR, ownerFireRateUpgrade * SENTRY_FIRERATE_REPLICATE_MULT) else botSpawn:SetAttributeValue(SENTRY_FIRERATE_REPLICATE_ATTR, nil) end local botWeapon = botSpawn.m_hActiveWeapon if not botWeapon or not IsValid(botWeapon) then return end local botWeaponClip = botWeapon.m_iClip1 -- Фикс бага с отсутствием обоймы (clip = -1) у пулеметов Хеви if botWeaponClip and botWeaponClip >= 0 then local maxClip = getMaxClip(botSpawn) local clipCalcMult = 150 / maxClip newBuilding.m_iAmmoShells = botWeaponClip * clipCalcMult end local ownerWeapon = owner.m_hActiveWeapon if ownerWeapon and ownerWeapon.m_iClassname == "tf_weapon_laser_pointer" then if not lastWrangled then botSpawn:RunScriptCode(BOT_DISABLE_VISION_VSCRIPT, botSpawn) botSpawn:AddCond(TF_COND_ENERGY_BUFF) botSpawn:AddCond(TF_COND_MEDIGUN_UBER_BULLET_RESIST) botSpawn:AddCond(TF_COND_MEDIGUN_UBER_BLAST_RESIST) botSpawn:AddCond(TF_COND_MEDIGUN_UBER_FIRE_RESIST) for name, value in pairs(BOTS_WRANGLED_ATTRIBUTES) do botSpawn:SetAttributeValue(name, value) end lastWrangled = true end botSpawn:RunScriptCode("activator.ClearAttentionFocus()", botSpawn) local altFireHeld = owner.m_nButtons & IN_ATTACK2 ~= 0 local attackHeld = owner.m_nButtons & IN_ATTACK ~= 0 cursorPos = getCursorPos(owner, botSpawn) if attackHeld then botSpawn:RunScriptCode(BOT_ATTACK_VSCRIPT, botSpawn) end if altFireHeld then local interruptAction = ("interrupt_action -pos %s %s %s -distance 1 -duration 0.1"):format( cursorPos[1], cursorPos[2], cursorPos[3] ) botSpawn:BotCommand(interruptAction) botSpawn:RunScriptCode(BOT_ENABLE_VISION_VSCRIPT, botSpawn) else botSpawn:RunScriptCode(BOT_DISABLE_VISION_VSCRIPT, botSpawn) end return end if lastWrangled then for name, _ in pairs(BOTS_WRANGLED_ATTRIBUTES) do botSpawn:SetAttributeValue(name, nil) end botSpawn:RunScriptCode(BOT_ENABLE_VISION_VSCRIPT, botSpawn) botSpawn:RemoveCond(TF_COND_ENERGY_BUFF) botSpawn:RemoveCond(TF_COND_MEDIGUN_UBER_BULLET_RESIST) botSpawn:RemoveCond(TF_COND_MEDIGUN_UBER_BLAST_RESIST) botSpawn:RemoveCond(TF_COND_MEDIGUN_UBER_FIRE_RESIST) lastWrangled = false end -- ATTACK mode: the heavy hunts enemies on its own instead of staying next to the engineer if companionMode[handle] == "attack" then botSpawn:RunScriptCode(BOT_ENABLE_VISION_VSCRIPT, botSpawn) pcall(function() botSpawn:BotCommand("interrupt_action -switch_action Mobber -duration 0.4") end) return end local pos = owner:GetAbsOrigin() local distance = pos:Distance(botSpawn:GetAbsOrigin()) if distance >= SPEED_BOOST_DISTANCE then botSpawn:AddCond(TF_COND_SPEED_BOOST, 1) end local stringStart = "interrupt_action -switch_action Default" if distance <= 150 then botSpawn:BotCommand(stringStart .. " -duration 0.1") return end local interruptAction = ("%s -pos %s %s %s -duration 0.1"):format(stringStart, pos[1], pos[2], pos[3]) botSpawn:BotCommand(interruptAction) end, 0) local wranglerLogic wranglerLogic = timer.Create(0, function() if not activeBuiltBots[handle] then timer.Stop(wranglerLogic) return end if not owner.m_hActiveWeapon then return end if owner.m_hActiveWeapon.m_iClassname == "tf_weapon_laser_pointer" then local altFireHeld = owner.m_nButtons & IN_ATTACK2 ~= 0 cursorPos = getCursorPos(owner, botSpawn) if not altFireHeld then local targetAngles = (cursorPos - (botSpawn:GetAbsOrigin() + Vector(0, 0, botSpawn["m_vecViewOffset[2]"]))):ToAngles() targetAngles = Vector(targetAngles[1], targetAngles[2], 0) botSpawn:SnapEyeAngles(targetAngles) end return end end, 0) end) end AddEventCallback("player_used_powerup_bottle", function(eventTable) local netId = eventTable.player local canteenType = eventTable.type local AMMO_CANTEEN = 4 local player = ents.GetAllPlayers()[netId] local bot = activeBuiltBots[player:GetHandleIndex()] if not bot then return end if canteenType == AMMO_CANTEEN then local botWeapon = bot.m_hActiveWeapon local botWeaponClip = botWeapon.m_iClip1 if botWeaponClip and botWeaponClip >= 0 then local maxClip = getMaxClip(bot) botWeapon.m_iClip1 = maxClip end end end) AddEventCallback("player_death", function(eventTable) local attacker = eventTable.attacker local player = ents.GetPlayerByUserId(attacker) if not player or not player:IsValid() then return end local attackerBot = activeBuiltBots[player:GetHandleIndex()] if not attackerBot then return end local isBotKill = false local inflictor = Entity(eventTable.inflictor_entindex) if not inflictor or not IsValid(attackerBot) then return end if inflictor == attackerBot.m_hActiveWeapon then isBotKill = true elseif inflictor.m_hLauncher then local weaponOwner = inflictor.m_hLauncher.m_hOwnerEntity if weaponOwner == attackerBot then isBotKill = true end end if not isBotKill then return end local victim = Entity(eventTable.victim_entindex) local killAddition = 1 if victim.m_bIsMiniBoss ~= 0 then killAddition = 5 end local sentryId = tonumber(player.BuiltBotSentry) local sentry = sentryId and Entity(sentryId) if sentry and IsValid(sentry) then sentry.m_iKills = sentry.m_iKills + killAddition end end) -- Chat commands: send the Mecha-Heavy out to attack, or call it back to the engineer AddEventCallback("player_say", function(ev) local text = string.lower(string.gsub(ev.text or "", "^%s*(.-)%s*$", "%1")) local mode if text == "!attack" or text == "!a" or text == "!heavy attack" then mode = "attack" elseif text == "!follow" or text == "!f" or text == "!heavy follow" or text == "!stay" then mode = "follow" elseif text == "!heavy" then mode = "toggle" end if not mode then return end local player = ents.GetPlayerByUserId(ev.userid) if not player or not player:IsValid() then return end local h = player:GetHandleIndex() if not activeBuiltBots[h] then player:Print(PRINT_TARGET_CENTER, "You have no Mecha-Heavy right now.") return end if mode == "toggle" then if companionMode[h] == "attack" then mode = "follow" else mode = "attack" end end companionMode[h] = mode if mode == "attack" then player:Print(PRINT_TARGET_CENTER, "Mecha-Heavy: ATTACK\n(say !follow to call it back)") else player:Print(PRINT_TARGET_CENTER, "Mecha-Heavy: FOLLOW") end end)