Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

local pathfindingService = game:GetService("PathfindingService") local creepsattackrange…

  1. 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 dps и скорость атаки 1 удар в 5 секунд. Если крип убил крипа из противоположной фракции то скрипт перезапускается

  2. Assistant

    Чтобы добавить функционал, который начнет драку между встречающимися крипами и перезапустит скрипт после смерти одного из крипов, нужно внести следующие изменения:

    1. В функции startFight добавьте код, который будет обрабатывать драку между крипами:
    local function startFight(creep, targetCreepList, enemyThrone, creepsattackrange)
        coroutine.wrap(function()
            while creep.Humanoid.Health > 0 do
                -- Остальной код ...
                
                if targetCreep then
                    local startHealth = creep.Humanoid.Health
                    local targetHealth = targetCreep.Humanoid.Health
    
                    while targetCreep and targetCreep.Humanoid.Health > 0 and creep.Humanoid.Health > 0 do
                        -- Атака крипов
                        targetCreep.Humanoid:TakeDamage(creepsattackrange)
    
                        wait(5) -- Задержка между атаками
                    end
    
                    if not targetCreep or targetCreep.Humanoid.Health <= 0 then
                        -- Если враждебный крип убит скриптом, перезапускаем скрипт
                        startFight(creep, targetCreepList, enemyThrone, creepsattackrange)
                    elseif creep.Humanoid.Health <= 0 then
                        -- Если крип смертельно ранен, остановить его
                        creep.Humanoid:MoveTo(creep.Humanoid.RootPart.Position)
                    end
    
                    break
                end
                
                -- Остальной код ...
            end
        end)()
    end
    
    1. В основной части скрипта, после завершения функции startFight, добавьте код для перезапуска скрипта:
    if not targetCreep or targetCreep.Humanoid.Health <= 0 then
        -- Если враждебный крип убит скриптом, перезапускаем скрипт
        startFight(creep, targetCreepList, enemyThrone, creepsattackrange)
    end
    

    Теперь, когда встречаются два крипа, они начнут драку и, если один из них умрет, скрипт будет перезапущен.