Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local vu = game:GetService("VirtualUser")
- local runService = game:GetService("RunService")
- -- Funzione per trovare l'NPC più vicino
- function getClosestNPC()
- local character = player.Character
- if not character then return nil end
- local hrp = character:FindFirstChild("HumanoidRootPart")
- if not hrp then return nil end
- local closestNPC = nil
- local shortestDistance = math.huge
- for _, npc in pairs(workspace.Enemies:GetChildren()) do
- if npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
- local distance = (hrp.Position - npc.HumanoidRootPart.Position).Magnitude
- if distance < shortestDistance then
- shortestDistance = distance
- closestNPC = npc
- end
- end
- end
- return closestNPC
- end
- -- Funzione per attivare l'attacco della spada
- function useSwordAttack()
- local character = player.Character
- if not character then return end
- local humanoid = character:FindFirstChild("Humanoid")
- if not humanoid then return end
- -- Verifica se l'abilità della spada è disponibile e la usa
- -- Supponiamo che l'abilità della spada sia una funzione dell'oggetto spada
- local sword = character:FindFirstChildOfClass("Tool") -- Assume che la spada sia un Tool
- if sword and sword:IsA("Tool") then
- -- Usa la spada (simulazione dell'attacco)
- sword:Activate() -- Questo invoca l'abilità della spada automaticamente
- end
- end
- -- Funzione per controllare se il giocatore è in acqua
- function isInWater()
- local character = player.Character
- if not character then return false end
- local hrp = character:FindFirstChild("HumanoidRootPart")
- if not hrp then return false end
- return hrp.Position.Y < 5 -- Se è sotto l'altezza 5, è considerato in acqua
- end
- -- Funzione per teletrasportare il giocatore al nemico più vicino
- function teleportToEnemy()
- local target = getClosestNPC()
- if target then
- local character = player.Character
- if not character then return end
- local hrp = character:FindFirstChild("HumanoidRootPart")
- if not hrp then return end
- hrp.CFrame = target.HumanoidRootPart.CFrame + Vector3.new(0, 5, 0) -- Teletrasporto sopra il nemico
- end
- end
- -- Auto-click (clicca ogni 10ms)
- spawn(function()
- while true do
- vu:Button1Down(Vector2.new(0, 0)) -- Simula il click
- task.wait(0.01) -- Aspetta 10ms
- end
- end)
- -- Movimento automatico con gestione dell'acqua e salto
- local function startMovement()
- runService.RenderStepped:Connect(function()
- local character = player.Character
- if not character then return end
- local humanoid = character:FindFirstChild("Humanoid")
- local hrp = character:FindFirstChild("HumanoidRootPart")
- if not humanoid or not hrp then return end
- -- Se il giocatore è in acqua, teletrasportalo
- if isInWater() then
- teleportToEnemy()
- end
- local target = getClosestNPC()
- if target then
- local enemyPosition = target.HumanoidRootPart.Position
- -- Spostati verso il nemico
- if (hrp.Position - enemyPosition).Magnitude > 5 then
- humanoid:MoveTo(enemyPosition)
- end
- -- Se il nemico è vicino, usa la spada
- if (hrp.Position - enemyPosition).Magnitude <= 5 then
- useSwordAttack() -- Usa l'attacco della spada quando è vicino
- end
- -- Se il nemico è in alto, salta
- if enemyPosition.Y - hrp.Position.Y > 3 then
- humanoid.Jump = true
- end
- end
- end)
- end
- -- Funzione per rilevare la morte e refreshare il personaggio
- local function detectDeath()
- player.CharacterAdded:Connect(function(character)
- task.wait(1) -- Aspetta 1 secondo dopo la morte
- local humanoid = character:WaitForChild("Humanoid")
- local hrp = character:WaitForChild("HumanoidRootPart")
- -- Dopo il respawn, premi automaticamente "3"
- task.wait(2) -- Aspetta 2 secondi per assicurarsi che il personaggio sia caricato
- end)
- end
- -- Avvia le funzioni principali
- startMovement()
- detectDeath()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement