local pathfindingService = game:GetService("PathfindingService") local creepsattackrange…
- User
local pathfindingService = game:GetService("PathfindingService") local creepsattackrange = 4 local targetCreepListDire = {} local targetCreepListRadiant = {}
local function startFight(creep, targetCreepList, enemyThrone, creepsattackrange) coroutine.wrap(function() while creep.Humanoid.Health > 0 do -- Проверка здесь чтобы крипы начали движение только если они живы local targetCreep local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, enemyThrone.Position)
local waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do creep.Humanoid:MoveTo(waypoint.Position) creep.Humanoid.MoveToFinished:Wait() targetCreep = nil for _, enemyCreep in ipairs(workspace:GetChildren()) do if enemyCreep.Name ~= script.Parent.Name and targetCreepList[enemyCreep] then if (enemyCreep.PrimaryPart.Position - creep.PrimaryPart.Position).Magnitude <= creepsattackrange and enemyCreep.Humanoid.Health > 0 then targetCreep = enemyCreep -- Крипы начнут драку с ближайшим враждебным крипом break end end end if targetCreep then waypoints = {} -- Сброс пути creep.Humanoid:MoveTo(creep.Humanoid.RootPart.Position) creep.Humanoid:MoveTo(creep.PrimaryPart.Position) -- Остановка крипа на месте startFight(creep, targetCreepListRadiant, enemyThrone) -- Активация функции драки break end end if targetCreep then break -- Прерывание цикла и движения крипа, если найден враждебный крип end wait() -- Подождать до следующего кадра end end)()end
wait(0.1) for i, enemyCreep in pairs(game.Workspace:GetChildren()) do if enemyCreep.Name == "DireCreep" then table.insert(targetCreepListRadiant, enemyCreep) elseif enemyCreep.Name == "RadiantCreep" then table.insert(targetCreepListDire, enemyCreep) end end
if script.Parent.Name == "DireCreep" then for _, creep in ipairs(targetCreepListDire) do startFight(script.Parent, targetCreepListDire, game.Workspace.RadiantAncient, creepsattackrange) end elseif script.Parent.Name == "RadiantCreep" then for _, creep in ipairs(targetCreepListRadiant) do startFight(script.Parent, targetCreepListRadiant, game.Workspace.DireAncient, creepsattackrange) end end сделай так чтобы когда крипы встречаются они начинали драку. Урон крипов варьируется от 19-21 и скорость атаки 1 удар в 2 секунды. ТАК ЖЕ НЕ ЗАБЫВАЙ ЧТО КРИПЫ ДОЛЖНЫ ИДТИ НА ТРОН ПРОТИВОПОЛОЖНОЙ ФРАКЦИИ! Тоесть если крипы встретятся, то будет драка, если по близости все крипы противоположной фракции будут мертвы или их вообще не будет в радиусе creepsattackrange, то крипы идут на трон противоположной фракции. Если крип убил крипа из противоположной фракции то скрипт перезапускается
- Assistant
To make the creeps engage in combat when they meet, and follow the rules you've specified, you can modify the provided script as follows:
local pathfindingService = game:GetService("PathfindingService") local creepsattackrange = 4 local targetCreepListDire = {} local targetCreepListRadiant = {} local function startFight(creep, targetCreepList, enemyThrone, creepsattackrange) coroutine.wrap(function() while creep.Humanoid.Health > 0 do local targetCreep local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, enemyThrone.Position) local waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do creep.Humanoid:MoveTo(waypoint.Position) creep.Humanoid.MoveToFinished:Wait() targetCreep = nil for _, enemyCreep in ipairs(workspace:GetChildren()) do if enemyCreep.Name ~= creep.Name and targetCreepList[enemyCreep] and enemyCreep.Humanoid.Health > 0 then if (enemyCreep.PrimaryPart.Position - creep.PrimaryPart.Position).Magnitude <= creepsattackrange then targetCreep = enemyCreep break end end end if targetCreep then waypoints = {} creep.Humanoid:MoveTo(creep.Humanoid.RootPart.Position) creep.Humanoid:MoveTo(creep.PrimaryPart.Position) startFight(creep, targetCreepListRadiant, enemyThrone) break end end if targetCreep then break end wait() end end)() end wait(0.1) for i, enemyCreep in pairs(workspace:GetChildren()) do if enemyCreep.Name == "DireCreep" then table.insert(targetCreepListRadiant, enemyCreep) elseif enemyCreep.Name == "RadiantCreep" then table.insert(targetCreepListDire, enemyCreep) end end if script.Parent.Name == "DireCreep" then for _, creep in ipairs(targetCreepListDire) do startFight(script.Parent, targetCreepListDire, game.Workspace.RadiantAncient, creepsattackrange) end else for _, creep in ipairs(targetCreepListRadiant) do startFight(script.Parent, targetCreepListRadiant, game.Workspace.DireAncient, creepsattackrange) end end