local db = false -- Personal creep stats -- local slashanim = script.slashanim local…
- User
local db = false
-- Personal creep stats --
local slashanim = script.slashanim local atkspeed = 70/50 local dps = math.random(15, 35)
local pathfindingService = game:GetService("PathfindingService") local creepsattackrange = 10 local targetCreepListDire = {} local targetCreepListRadiant = {} local waypoints = {} local dfws = 12 local fighting = false
local function attackCreep(creep, enemycreep) if enemycreep.Humanoid.Health > 0 and creep.Humanoid.Health > 0 then fighting = true waypoints = {} creep.Humanoid:MoveTo(enemycreep.HumanoidRootPart.Position) if db == false then db = true creep.Head.Slash:Play() if slashanim.Value == 1 then creep.Humanoid:LoadAnimation(script.Slash1):Play() slashanim.Value = 2 elseif slashanim.Value == 2 then creep.Humanoid:LoadAnimation(script.Slash2):Play() slashanim.Value = 1 end if math.random(0,enemycreep.MissChance.Value) <= enemycreep.MissChance.Value / 25 then if enemycreep:FindFirstChild("invincibility").Value == false then enemycreep.Humanoid:TakeDamage(dps) end wait(atkspeed) db = false end end if enemycreep.Humanoid.Health <= 0 then local cs = script:Clone() cs.Parent = script.Parent for i, v in pairs(creep.Humanoid.Animator:GetPlayingAnimationTracks()) do if v.Name == "Slash1" or v.Name == "Slash2" then v:Stop() end end script:Destroy() end else return end end
local function attackTower(creep, tower) if tower.Health.Value > 0 and creep.Humanoid.Health > 0 then print(22) fighting = true waypoints = {} creep.Humanoid:MoveTo(tower.PrimaryPart.Position) if db == false then db = true creep.Head.Slash:Play() if slashanim.Value == 1 then creep.Humanoid:LoadAnimation(script.Slash1):Play() slashanim.Value = 2 elseif slashanim.Value == 2 then creep.Humanoid:LoadAnimation(script.Slash2):Play() slashanim.Value = 1 end if tower:FindFirstChild("invincibility").Value == false then tower.Health.Value = tower.Health.Value - (dps / 1.12) end wait(atkspeed) db = false end if tower.Health.Value <= 0 then local cs = script:Clone() cs.Parent = script.Parent for i, v in pairs(creep.Humanoid.Animator:GetPlayingAnimationTracks()) do if v.Name == "Slash1" or v.Name == "Slash2" then v:Stop() end end script:Destroy() end else return end end
local function Lane(creep, targetCreepList, enemyThrone, enemyTowers) while creep.Humanoid.Health > 0 and fighting == false do if fighting == false then creep.Humanoid.WalkSpeed = dfws local targetCreep local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, enemyThrone.Position)
waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do creep.Humanoid:MoveTo(waypoint.Position) creep.Humanoid.MoveToFinished:Wait() end wait() else waypoints = {} end endend
wait(0.1) local function FindNearestTorsoRadiant(position) local minDistance = math.huge local nearestTorso = nil
for i, enemy in ipairs(targetCreepListRadiant) do local distance = (position - enemy:WaitForChild("HumanoidRootPart").Position).Magnitude if distance < minDistance then minDistance = distance nearestTorso = enemy:WaitForChild("HumanoidRootPart") end end return nearestTorsoend
local function FindNearestTorsoDire(position) local minDistance = math.huge local nearestTorso = nil
for i, enemy in ipairs(targetCreepListDire) do local distance = (position - enemy:WaitForChild("HumanoidRootPart").Position).Magnitude if distance < minDistance then minDistance = distance nearestTorso = enemy:WaitForChild("HumanoidRootPart") end end return nearestTorsoend
local function nearestTower(position) local minDistance = math.huge local nearestTorso = nil
for i, tower in ipairs(game.Workspace:GetChildren()) do local distance = (position - tower:WaitForChild("PrimaryPart").Position).Magnitude if distance < minDistance then minDistance = distance nearestTower = tower:WaitForChild("PrimaryPart") end end return nearestTowerend
local enemyTowersRadiant = {} local enemyTowersDire = {}
for i, enemyCreep in pairs(workspace:GetChildren()) do if enemyCreep.Name == "DireCreep" then table.insert(targetCreepListRadiant, enemyCreep) coroutine.wrap(function() while wait() do local nearestTorso = FindNearestTorsoDire(script.Parent.HumanoidRootPart.Position) if nearestTorso and (script.Parent.HumanoidRootPart.Position - nearestTorso.Position).Magnitude < creepsattackrange and nearestTorso.Parent.Name ~= script.Parent.Name then attackCreep(script.Parent, nearestTorso.Parent) end local nearestTower = FindNearestTorsoDire(script.Parent.HumanoidRootPart.Position) if nearestTower and (script.Parent.HumanoidRootPart.Position - nearestTower.Position).Magnitude < creepsattackrange * 1.4 and nearestTower.Parent.Faction.Value ~= "Dire" and nearestTower.Name == "Tower" then fighting = true attackTower(script.Parent.HumanoidRootPart, nearestTower.Parent) end end end)() elseif enemyCreep.Name == "RadiantCreep" then table.insert(targetCreepListDire, enemyCreep) coroutine.wrap(function() while wait() do local nearestTorso = FindNearestTorsoDire(script.Parent.HumanoidRootPart.Position) if nearestTorso and (script.Parent.HumanoidRootPart.Position - nearestTorso.Position).Magnitude < creepsattackrange and nearestTorso.Parent.Name ~= script.Parent.Name then attackCreep(script.Parent, nearestTorso.Parent) end local nearestTower = FindNearestTorsoDire(script.Parent.HumanoidRootPart.Position) if nearestTower and (script.Parent.HumanoidRootPart.Position - nearestTower.Position).Magnitude < creepsattackrange * 1.4 and nearestTower.Parent.Faction.Value ~= "Dire" and nearestTower.Name == "Tower" then fighting = true attackTower(script.Parent.HumanoidRootPart, nearestTower.Parent) end end end)() end end
if script.Parent.Name == "DireCreep" then for _, creep in ipairs(targetCreepListDire) do Lane(script.Parent, targetCreepListDire, game.Workspace.RadiantAncient, enemyTowersRadiant) end else for _, creep in ipairs(targetCreepListRadiant) do Lane(script.Parent, targetCreepListRadiant, game.Workspace.DireAncient, enemyTowersDire) end end почему крипы не бьют вышки и print(22) не срабатывает? Можешь подкорректировать?
- Assistant
Проблема возникает из-за того, что функция
nearestTowerне верно находит башни противника. Для исправления этой проблемы, вам нужно изменить логику функцииnearestTower. Вот обновленный код:local function nearestTower(position, faction) local minDistance = math.huge local nearestTorso = nil for _, tower in ipairs(game.Workspace:GetChildren()) do if tower.Name == "Tower" and tower.Faction.Value ~= faction and tower.Health.Value > 0 then local distance = (position - tower:WaitForChild("PrimaryPart").Position).Magnitude if distance < minDistance then minDistance = distance nearestTorso = tower:WaitForChild("PrimaryPart") end end end return nearestTorso endДополнительно, аргумент
factionбыл добавлен, чтобы функция знала, какой факции искать башни. Вы можете использовать эту функцию в ваших циклахwhileдля поиска и атаки башен противника:local nearestTower = nearestTower(script.Parent.HumanoidRootPart.Position, faction) if nearestTower and (script.Parent.HumanoidRootPart.Position - nearestTower.Position).Magnitude < creepsattackrange * 1.4 then fighting = true attackTower(script.Parent.HumanoidRootPart, nearestTower.Parent) endУбедитесь, что вы добавили аргумент
factionдля правильной фильтрации башен противника. Саму переменнуюfactionвы должны определить где-то в вашем коде.