--Script made by Therealscroob/Crilly, this script's goal is to get a select set of sniper bots to target and kill meds and enemy --snipers threatening them. local function removeCallbacks(player, callbacks) if not IsValid(player) then return end for _, callbackId in pairs(callbacks) do player:RemoveCallback(callbackId) end end function MedHunterSniper(_, activator) local callbacks = {} local check local terminated = false local primary = activator:GetPlayerItemBySlot(0) local function terminate() if terminated then return end terminated = true timer.Stop(check) removeCallbacks(activator, callbacks) end local function checkLineOfSight(activator, caller) if not util.IsLagCompensationActive() then util.StartLagCompensation(activator) end --thanks mince for the local callerHead = Vector(caller:GetAbsOrigin()[1],caller:GetAbsOrigin()[2],caller:GetAbsOrigin()[3] + 60) local traceAngles = (callerHead - (activator:GetAbsOrigin() + Vector( 0, 0, activator["m_vecViewOffset[2]"] ))):ToAngles() traceAngles = Vector(traceAngles[1], traceAngles[2], 0) local TraceLineOfSight = { start = activator, -- Start position vector. Can also be set to entity, in this case the trace will start from entity eyes position distance = 10000, -- Used if endpos is nil angles = traceAngles, -- Used if endpos is nil mask = MASK_SOLID, -- Solid type mask, see MASK_* globals collisiongroup = COLLISION_GROUP_PLAYER, -- Pretend the trace to be fired by an entity belonging to this group. See COLLISION_GROUP_* globals } local lineOfSightTraceTable = util.Trace(TraceLineOfSight) --PrintTable(lineOfSightTraceTable) --print(lineOfSightTraceTable.HitPos) if lineOfSightTraceTable.Hit == true and lineOfSightTraceTable.HitWorld == false then --print("Enemy is in our line of sight") return true else --print("Enemy is not in our line of sight") return false end end local scanningDistance = 3000 activator:RunScriptCode("activator.SetMaxVisionRangeOverride(3000)", activator) check = timer.Create(0.015, function() --Find all players within 3000 units of the activator, filter for med targets and snipers local botLocation = activator:GetAbsOrigin() local sphereResults = ents.FindInSphere(botLocation, scanningDistance) local filteredSphereResults = {} local validTargetList = nil local lastEntry validTargetList = MEDICBUSTER_GetValidMeds() if #table.GetKeys(validTargetList) == 0 then print("Lowtiergod") activator:Suicide() return end if sphereResults then for _, entity in pairs(sphereResults) do if entity:GetClassname() == "entity_medigun_shield" and checkLineOfSight(activator, entity) == true then for _, player in pairs(validTargetList) do if player == entity.m_hOwnerEntity then table.insert(filteredSphereResults, entity) --print("Shield Detected") lastEntry = entity end end end if entity:IsPlayer() and entity.m_iTeamNum ~= activator.m_iTeamNum and entity:IsAlive() then for _, player in pairs(validTargetList) do if entity == player and checkLineOfSight(activator, entity) == true then table.insert(filteredSphereResults, entity) --print("Medic Detected") lastEntry = entity end end end end else return end if IsValid(lastEntry) == true and activator.m_hActiveWeapon == primary and activator:InCond(130) == false then timer.Simple(0.25, function() if not IsValid(lastEntry) then return end --print("Target!") activator:SetAttributeValue("move speed bonus", 0.0) activator:RunScriptCode("activator.SetMaxVisionRangeOverride(100)", activator) activator:RunScriptCode("activator.ClearAttentionFocus()", activator) scanningDistance = 0.1 local lastEntryHead = Vector(lastEntry:GetAbsOrigin()[1],lastEntry:GetAbsOrigin()[2],lastEntry:GetAbsOrigin()[3] + 60) local targetAngles = (lastEntryHead - (activator:GetAbsOrigin() + Vector( 0, 0, activator["m_vecViewOffset[2]"] ))):ToAngles() targetAngles = Vector(targetAngles[1], targetAngles[2], 0) activator:SnapEyeAngles(targetAngles) activator:RunScriptCode("activator.ClearAttentionFocus()", activator) --print("Snapping to target!") if lastEntry:GetClassname() == "entity_medigun_shield" then activator:RunScriptCode("activator.PressFireButton(0.01)",activator) --print("Forcing fire input on medshield!") end activator:RunScriptCode("activator.ClearAttentionFocus()", activator) --taken from the comments of build_ally_bot.lua end, 1) else activator:RunScriptCode("activator.SetMaxVisionRangeOverride(3000)", activator) activator:SetAttributeValue("move speed bonus", 1) scanningDistance = 3000 return end end, 0) callbacks.died = activator:AddCallback(ON_DEATH, function() terminate() end) callbacks.removed = activator:AddCallback(ON_REMOVE, function() terminate() end) callbacks.spawned = activator:AddCallback(ON_SPAWN, function() terminate() end) end