local TRAP_TEST_VECTOR = Vector(-1560, 2, -123) local TRAP_MIN_DISTANCE = 500 local TRAP_FIRE_COOLDOWN = 0.6 local TF_COND_IN_COMBAT = 12 function VectorToString(vec) local new = vec[1] .. " " .. vec[2] .. " " .. vec[3] return new end function GetViewHeight(player) local result = player.m_vecViewOffset[3] return result end function GetCamera(player) local origin = player:GetAbsOrigin() local height = GetViewHeight(player) local result = origin + Vector(0, 0, height) return result end function GetEyeAngles(player) return Vector(player.m_angEyeAngles[1], player.m_angEyeAngles[2], player.m_angEyeAngles[3]) end function GetStickyCount(player) local count = 0 for _, pipe in pairs(ents.FindAllByClass("tf_projectile_pipe_remote")) do if pipe.m_hThrower ~= nil and pipe.m_hThrower == player then count = count + 1 end end return count end function GetMaxStickyCount(player) local result = player:GetAttributeValueByClass("add_max_pipebombs", 0) + 8 return result end function Delay(seconds) local globaltime = CurTime() local newtime = globaltime + seconds return newtime end function GetTrapPositionCount(occupied) local count = 0 for _, target in pairs(ents.FindAllByClass("info_target")) do if string.find(target:GetName(), "trap_point") then if occupied == nil or occupied ~= nil and occupied == true and target.bOccupied ~= nil and target.bOccupied == 1 then count = count + 1 end end end return count end function GetGoodTrapPosition(player) player.iTrapDistances = {} player.hAvailableTraps = {} for _, target in pairs(ents.FindAllByClass("info_target")) do if string.find(target:GetName(), "trap_point") then if target.bOccupied == nil then target.bOccupied = 0 end end if GetTrapPositionCount() < GetTrapPositionCount(true) or target.bOccupied == 0 then local vecOrg = target:GetAbsOrigin() local iDist = vecOrg:Distance(player:GetAbsOrigin()) table.insert(player.hAvailableTraps, target) table.insert(player.iTrapDistances, iDist) end end table.sort(player.iTrapDistances) local hChosen for _, i in pairs(player.hAvailableTraps) do local vecPos = i:GetAbsOrigin() if vecPos:Distance(player:GetAbsOrigin()) == player.iTrapDistances[1] then hChosen = i break end end if hChosen == nil then hChosen = ents.FindByName("trap_point1") end return hChosen end ---- function OnPlayerConnected(player) player.bUseTrapBehavior = 0 player.flNextStickyFireTime = -1 player.vecTrapPosition = Vector(0,0,0) player.hOccupiedTrapPoint = nil player.iTrapDistances = {} player.hAvailableTraps = {} player:AddCallback(ON_DAMAGE_RECEIVED_PRE, function(_, damageinfo) local attacker = damageinfo.Attacker if attacker ~= nil and attacker.m_iTeamNum ~= player.m_iTeamNum then player:AddCond(TF_COND_IN_COMBAT, 5) player:BotCommand("stop interrupt action") end end) player:AddCallback(ON_SPAWN, function() player.bUseTrapBehavior = 0 player:AddCond(TF_COND_IN_COMBAT, 3) end) end timer.Create(0.045, function() for _, player in pairs(ents.GetAllPlayers()) do if player.bUseTrapBehavior == 1 and player:IsBot() and player:IsAlive() then StickyBehaviorLoop(player) end end end, 0) function StickyBehaviorLoop(player) if GetStickyCount(player) >= GetMaxStickyCount(player) then player:WeaponSwitchSlot(LOADOUT_POSITION_PRIMARY) player:AddCond(TF_COND_IN_COMBAT, 0.2) return false end local count = 0 if GetStickyCount(player) == 0 and player.hOccupiedTrapPoint ~= nil then for _, others in pairs(ents.GetAllPlayers()) do if others.hOccupiedTrapPoint == player.hOccupiedTrapPoint and others.hOccupiedTrapPoint ~= nil then count = count + 1 end end end if count == 0 and player.hOccupiedTrapPoint ~= nil then player.hOccupiedTrapPoint.bOccupied = 0 player.hOccupiedTrapPoint = nil end if not player:InCond(TF_COND_IN_COMBAT) then local hTrapPosition = GetGoodTrapPosition(player) local vecTrapOrigin = hTrapPosition:GetAbsOrigin() local szAction = ("interrupt_action -pos %s -looksposent %s -duration 0.1 -distance %s"):format(VectorToString(vecTrapOrigin), hTrapPosition:GetName(), TRAP_MIN_DISTANCE) -- print(szAction) -- player:SetFakeClientConVar("name", hTrapPosition:GetName()) player:WeaponSwitchSlot(LOADOUT_POSITION_SECONDARY) player:AcceptInput("$botcommand", szAction) if GetCamera(player):Distance(vecTrapOrigin) <= TRAP_MIN_DISTANCE and GetStickyCount(player) < GetMaxStickyCount(player) then player:RunScriptCode("self.PressFireButton(0.005)") hTrapPosition.bOccupied = 1 player.hOccupiedTrapPoint = hTrapPosition end else player:WeaponSwitchSlot(LOADOUT_POSITION_PRIMARY) player:BotCommand("stop interrupt action") end if GetStickyCount(player) == GetMaxStickyCount(player) then player:AddCond(TF_COND_IN_COMBAT, 0.2) end end --test function lua(_, activator) activator:TakeDamage({ Damage = 5000, DamageCustom = 46, DamageType = 2048 | DMG_BLAST, Attacker = activator, Inflictor = activator, }) timer.Simple(0.015, function() activator:SetTeam(1) for _, player in pairs(ents.GetAllPlayers()) do player.bUseTrapBehavior = 1 end end) end