Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PlayerConnect
- function whenLoaded(player)
- warn("Игрок", player, "подключился к игре!")
- script.Parent.Player.Value = player
- print(script.Parent.Player.Value)
- end
- game.Players.PlayerAdded:Connect(whenLoaded)
- --ZombieSpawn
- working = true
- local distance = 0
- while working do
- for _, player in pairs(game.Players:GetPlayers()) do
- distance = player:DistanceFromCharacter(script.Parent.Position)
- if (distance > 0) and (distance < 50) then
- working = false
- end
- end
- wait(1)
- end
- wait(2)
- D_num = script.Parent.Parent.Quantity
- while D_num.Value < 10 do
- if distance < 50 then
- local zombie = game.ServerStorage.Zombie:Clone()
- zombie.Parent = game.Workspace.NPC
- zombie:MoveTo(script.Parent.Position)
- D_num.Value += 1
- end
- local destination = game.Workspace.Data.Player.Value.Character.HumanoidRootPart.Position
- distance = (destination - script.Parent.Position).magnitude
- wait(5)
- end
- --SeekEnemy
- local npc = script.Parent --получаем модель НПС
- local humanoid = npc:WaitForChild("Humanoid") --получаем гуманоида из модели, с его помощью будем двигать НПС
- local rootPart = npc:WaitForChild("HumanoidRootPart") --получаем корневую деталь из модели, от неё будем брать позицию НПС
- local nearestPlayerPos = nil --создаем переменную для ближайшего игрока
- local shortestDistance = 100 -- Большое значение для сравнения
- local function getNearestPlayerPos() --функция, которая ищет позицию ближайшего игрока
- for _, player in ipairs(game.Players:GetPlayers()) do --перебираем всех игроков в игре
- local character = player.Character --получаем модель игрока
- if character and character:FindFirstChild("HumanoidRootPart") then --если модель найдена и имеет корневую деталь
- local characterRootPos = character.HumanoidRootPart.Position --Получаем позицию игрока
- local distance = (characterRootPos - rootPart.Position).Magnitude --считаем растояние между игроком и НПС
- if distance < shortestDistance then
- shortestDistance = distance --сохраняем новое ближайшее растояние
- end
- if distance < 50 then --если растояние меньше 50 и меньше предыдущего, запоминаем его
- nearestPlayerPos = characterRootPos --сохраняем игрока как ближайшего
- end
- end
- end
- return nearestPlayerPos --возвращаем позицию ближайшего игрока
- end
- while wait() do --запускаем бесконечный цикл
- local nearestPlayerPos = getNearestPlayerPos() --получаем ближайшего игрока
- if nearestPlayerPos then --если нашли ближайшего игрока
- humanoid:MoveTo(nearestPlayerPos) --двигаем НПС к ближайшему игроку
- end
- end
- --ZombieAttack
- local rarm = script.Parent:FindFirstChild("RightHand")
- local larm = script.Parent:FindFirstChild("LeftHand")
- local torso = script.Parent:FindFirstChild("UpperTorso")
- local Attack_Speed = script.Parent.Parent.AttackSpeed
- function dmg(hit)
- if hit.Parent ~= nil then
- local hum = hit.Parent:FindFirstChild("Humanoid")
- if hum ~= nil then
- hum.Health = hum.Health - 0.1
- end
- wait(Attack_Speed.Value)
- end
- end
- rarm.Touched:Connect(dmg)
- larm.Touched:Connect(dmg)
- torso.Touched:Connect(dmg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement