Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function PlayerHasHurtABot(ply)
- if ply:IsBot() then
- timer.Create(ply:EntIndex().."_Update", 0, 0, function()
- ply:SetVelocity( (ply:GetAimVector() * 30 ) )
- end)
- end
- end
- hook.Add( "PlayerHurt", "BotHasBeenHurtHopeThisWorks", PlayerHasHurtABot )
- function GetRidOfDaTimerOnSpawn(ply)
- if ply:IsBot() then
- timer.Create( "PleaseWork2", 0, 1, function()
- if(timer.Exists(ply:EntIndex().."_Update")) then timer.Destroy(ply:EntIndex().."_Update")
- end
- end)
- end
- end
- hook.Add( "PlayerSpawn", "MakeTheBotNotGoPsycho", GetRidOfDaTimerOnSpawn )
- --Rudimentary Bot combat script by BFG9000
- --This is crap don't use this in a serious context pls
- --Sorting function taken from Sanic NPC by Xyxen
- if SERVER then
- local function IsValidBotTarget(ent)
- if (!ent:IsValid()) then return false end
- return ((ent:IsPlayer() and ent:Alive()) or
- (ent:IsNPC() and ent:Health() > 0))
- end
- local function GetNearestBotTargetFromTable(table, bot)
- local maxAcquireDist = 10000
- local maxAcquireDistSqr = math.pow(maxAcquireDist, 2)
- //local acquirableEntities = ents.FindInSphere(self:GetPos(), maxAcquireDist)
- local target = nil
- for _, ent in pairs(table) do
- if (not IsValidBotTarget(ent)) then continue end
- local distSqr = ent:GetPos():DistToSqr(bot:GetPos())
- if distSqr < maxAcquireDistSqr then
- target = ent
- maxAcquireDistSqr = distSqr
- end
- end
- return target
- end
- local function BotSetTarget(bot)
- bot.PotentialTargets = ents.FindInSphere(bot:GetPos(), 9001)
- //for k,v in pairs(bot.PotentialTargets) do if not v:IsPlayer() then table.remove(bot.PotentialTargets, k) end end
- bot.ViableTargets = {}
- for k,v in pairs(bot.PotentialTargets) do if IsValidBotTarget(v) then if bot:Visible(v) then table.ForceInsert(bot.ViableTargets, v) end end end
- table.RemoveByValue(bot.ViableTargets, bot)
- bot.CurrentTarget = GetNearestBotTargetFromTable(bot.ViableTargets, bot)
- //bot.CurrentTarget = bot.ViableTargets[1]
- if IsValid(bot.CurrentTarget) then
- if bot.CurrentTarget:IsPlayer() then
- if !bot.CurrentTarget:Alive() then
- bot.CurrentTarget = table.Random(bot.ViableTargets)
- end
- elseif bot.CurrentTarget:IsNPC() then
- if not (bot.CurrentTarget:Health() < 1) then
- bot.CurrentTarget = table.Random(bot.ViableTargets)
- end
- end
- end
- //print(bot.CurrentTarget)
- end
- local NextTarget = CurTime()
- local TargetUpdateRate = 4
- local function BotTargetThink()
- if NextTarget <= CurTime() then
- NextTarget = CurTime() + TargetUpdateRate
- for id, bot in pairs(player.GetBots()) do
- BotSetTarget(bot)
- end
- //NextTarget = CurTime() + TargetUpdateRate
- end
- end
- hook.Add("Think", "BFG Bot Targeting", BotTargetThink)
- local NextThink = CurTime()
- local ThinkRate = .1
- local function BotThink()
- //if NextThink <= CurTime() then
- NextThink = CurTime() + ThinkRate
- for id, bot in pairs(player.GetBots()) do
- if IsValid(bot.CurrentTarget) and (bot.CurrentTarget != self and bot.CurrentTarget != nil) then
- bot.TargetAimDir = ((bot.CurrentTarget:GetPos() + Vector(0,0,35)) - (bot:GetPos() + Vector(0,0,35))):Angle() - bot:GetPunchAngle()
- //bot:SetEyeAngles( bot.TargetAimDir ) --aimbot
- bot:SetEyeAngles( BFGApproach3DAngles( bot:EyeAngles(), bot.TargetAimDir, (bot.TargetAimDir.yaw - bot:EyeAngles().yaw)/6.5))
- //print(bot.TargetAimDir)
- else
- //bot:SetEyeAngles( Angle( 30,30,30) )
- end
- end
- //end
- end
- hook.Add("Think", "BFG Bot Thinking", BotThink)
- local function UpdateBotTarget(victim, inflictor, attacker)
- if attacker:IsNPC() or not (attacker:IsPlayer()) then return end
- if attacker:IsBot() then
- //print(attacker:Nick() .. ": Tango Down!")
- if not IsValid(attacker.CurrentTarget) then return end
- if not attacker.CurrentTarget == victim then return end
- BotSetTarget(attacker)
- //print("New target acquired")
- end
- end
- hook.Add("PlayerDeath", "BFG_UpdateBotTargets", UpdateBotTarget)
- end --IF SERVER THEN
- function BFGApproach3DAngles( CurrentAng, TargetAng, Rate )
- local pitch = math.ApproachAngle( CurrentAng.pitch, TargetAng.pitch, Rate)
- local yaw = math.ApproachAngle( CurrentAng.yaw, TargetAng.yaw, Rate)
- local roll = math.ApproachAngle( CurrentAng.roll, TargetAng.roll, Rate)
- return Angle(pitch, yaw, roll)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement