Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 全局變量
- local highestValue = 0
- -- 定義動物名稱列表
- local npcNames = {
- "Lvl1",
- "Rock",
- "Grass",
- "Water",
- "Ice",
- "Lightning",
- "Void",
- "Fire",
- "Worm"
- }
- -- 觸發造成傷害的事件
- local function causeDamageEvent(npcIndex)
- local npcName = npcNames[npcIndex]
- print("攻擊經驗",skill)
- if npcName then
- local args = {
- isLocalNPC = true,
- npcName = npcName
- }
- game:GetService("ReplicatedStorage").Events.DamageEvent:FireServer(args)
- end
- end
- -- 獲取技能的變化值
- local skill = game.Players.LocalPlayer.settingsstats.SelectedSkill.Value
- print("技能:", skill)
- game.Players.LocalPlayer.settingsstats.SelectedSkill:GetPropertyChangedSignal("Value"):Connect(function()
- local Newskill = game.Players.LocalPlayer.settingsstats.SelectedSkill.Value
- if Newskill ~= skill then
- print("已檢測到技能更換:", Newskill)
- skill = Newskill -- 更新 skill 變量為新技能值
- end
- print("新技能", skill)
- end)
- local function KillDamageEvent(npcIndex)
- local npcName = npcNames[npcIndex]
- print("技能經驗",skill)
- if npcName then
- local args = {
- [1] = "damage",
- [2] = {
- ["npcName"] = npcName, -- 使用單個 NPC 名稱而不是整個名稱列表
- ["SelectedSkill"] = skill,
- ["isLocalNPC"] = true
- }
- }
- game:GetService("ReplicatedStorage").Events.Skills.SkillEvent:FireServer(unpack(args))
- end
- end
- -- 初始化已執行的動作狀態
- local alreadyExecuted = {
- Below50 = false,
- Behigh50 = false,
- Behigh200 = false,
- Behigh450 = false,
- Behigh750 = false,
- Behigh1100 = false,
- Behigh1500 = false,
- Behigh1950 = false,
- Behigh2450 = false
- }
- -- 傳送角色到指定位置
- local function teleportTo(x, y, z)
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- humanoidRootPart.CFrame = CFrame.new(x, y, z)
- end
- -- 檢查動物經驗值範圍並執行相應操作
- local function checkAnimalExperience(animalName, animalValue)
- print(animalName, animalValue)
- print("舊值:",highestValue,"新值:",animalValue)
- if animalValue > highestValue then
- highestValue = animalValue -- 更新最高值
- print("舊值已更新:",highestValue)
- end
- if highestValue > 2450 then
- causeDamageEvent(9)
- KillDamageEvent(9)
- if not alreadyExecuted.Behigh2450 then
- wait(0.3)
- teleportTo(-112.44, 16, -1506.1)
- alreadyExecuted.Behigh2450 = true
- end
- elseif highestValue > 1950 then
- causeDamageEvent(8)
- KillDamageEvent(8)
- if not alreadyExecuted.Behigh1950 then
- wait(0.3)
- teleportTo(-149.4, 27.7, -1338.4)
- alreadyExecuted.Behigh1950 = true
- end
- elseif highestValue > 1500 then
- causeDamageEvent(7)
- KillDamageEvent(7)
- if not alreadyExecuted.Behigh1500 then
- wait(0.3)
- teleportTo(-129.1, 29.1, -1164.9)
- alreadyExecuted.Behigh1500 = true
- end
- elseif highestValue > 1100 then
- causeDamageEvent(6)
- KillDamageEvent(6)
- if not alreadyExecuted.Behigh1100 then
- wait(0.3)
- teleportTo(-127.3, 21, -994.7)
- alreadyExecuted.Behigh1100 = true
- end
- elseif highestValue > 750 then
- causeDamageEvent(5)
- KillDamageEvent(5)
- if not alreadyExecuted.Behigh750 then
- wait(0.3)
- teleportTo(-124.8, 14.65, -839.4)
- alreadyExecuted.Behigh750 = true
- end
- elseif highestValue > 450 then
- causeDamageEvent(4)
- KillDamageEvent(4)
- if not alreadyExecuted.Behigh450 then
- wait(0.3)
- teleportTo(-165.2, 20.59, -658.2)
- alreadyExecuted.Behigh450 = true
- end
- elseif highestValue > 200 then
- causeDamageEvent(3)
- KillDamageEvent(3)
- if not alreadyExecuted.Behigh200 then
- wait(0.3)
- teleportTo(-142, 16.2, -518)
- alreadyExecuted.Behigh200 = true
- end
- elseif highestValue > 50 then
- causeDamageEvent(2)
- KillDamageEvent(2)
- if not alreadyExecuted.Behigh50 then
- wait(0.3)
- teleportTo(-145, 25.47, -373.2)
- alreadyExecuted.Behigh50 = true
- end
- elseif highestValue < 50 then
- causeDamageEvent(1)
- KillDamageEvent(1)
- if not alreadyExecuted.Below50 then
- wait(0.3)
- teleportTo(-106.5, 8.86, -265.1)
- alreadyExecuted.Below50 = true
- end
- end
- end
- -- 監聽各動物經驗值變化的函數
- local function connectExpChangeSignal(animalName, expChangeFunction)
- game.Players.LocalPlayer.levelstats[animalName]:GetPropertyChangedSignal("Value"):Connect(expChangeFunction)
- print(animalName, "已註冊")
- for key, _ in pairs(alreadyExecuted) do
- alreadyExecuted[key] = false
- end
- end
- -- 註冊各動物經驗值變化事件
- connectExpChangeSignal("Dog", function()
- local newDogExp = game.Players.LocalPlayer.levelstats.Dog.Value
- checkAnimalExperience("Dog", newDogExp)
- end)
- connectExpChangeSignal("Cat", function()
- local newCatExp = game.Players.LocalPlayer.levelstats.Cat.Value
- checkAnimalExperience("Cat", newCatExp)
- end)
- connectExpChangeSignal("Bear", function()
- local newBearExp = game.Players.LocalPlayer.levelstats.Bear.Value
- checkAnimalExperience("Bear", newBearExp)
- end)
- connectExpChangeSignal("Human", function()
- local newHumanExp = game.Players.LocalPlayer.levelstats.Human.Value
- checkAnimalExperience("Human", newHumanExp)
- end)
- connectExpChangeSignal("Rabbit", function()
- local newRabbitExp = game.Players.LocalPlayer.levelstats.Rabbit.Value
- checkAnimalExperience("Rabbit", newRabbitExp)
- end)
- -- 初次檢查當前角色的動物經驗值範圍
- local currentAnimal = game.Players.LocalPlayer.animalFolderName.Value
- checkAnimalExperience(currentAnimal, game.Players.LocalPlayer.levelstats[currentAnimal].Value)
- -- 監聽角色切換事件
- game.Players.LocalPlayer.animalFolderName:GetPropertyChangedSignal("Value"):Connect(function()
- for key, _ in pairs(alreadyExecuted) do
- alreadyExecuted[key] = false
- end
- local newAnimalForm = game.Players.LocalPlayer.animalFolderName.Value
- print("當前腳色切換為:", newAnimalForm)
- highestValue = 0
- print("舊值:",highestValue)
- print("舊值:以清空")
- checkAnimalExperience(newAnimalForm, game.Players.LocalPlayer.levelstats[newAnimalForm].Value)
- end)
- -- 創建一個主界面 Frame
- local ScreenGui = Instance.new("ScreenGui")
- ScreenGui.Parent = game.CoreGui
- -- 創建一個 Frame 來容納 UI 元素
- local Frame = Instance.new("Frame")
- Frame.Size = UDim2.new(0, 250, 0, 50)
- Frame.Position = UDim2.new(0, 10, 0, 10)
- -- 調整位置到左上角
- Frame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
- Frame.BorderSizePixel = 0
- Frame.Active = true
- Frame.Draggable = true -- 允許拖動
- Frame.Parent = ScreenGui
- -- 創建關閉按鈕 (X)
- local CloseButton = Instance.new("TextButton")
- CloseButton.Size = UDim2.new(0, 20, 0, 20)
- CloseButton.Position = UDim2.new(0, 5, 0, 5) -- 放置在左上角
- CloseButton.BackgroundColor3 = Color3.fromRGB(255, 50, 50)
- CloseButton.TextColor3 = Color3.fromRGB(255, 255, 255)
- CloseButton.Text = "X"
- CloseButton.TextSize = 14
- CloseButton.Font = Enum.Font.SourceSansBold
- CloseButton.Parent = Frame
- -- 全局變量來表示腳本的運行狀態
- local isRunning = false
- -- 創建切換按鈕函數,確保使用當前動物名稱和經驗值
- local function createToggleButton(parent, labelText, buttonPosition, buttonAction)
- local label = Instance.new("TextLabel")
- label.Size = UDim2.new(0.6, 5, 0, 30)
- label.Position = UDim2.new(0, 5, 0, 10)
- label.BackgroundTransparency = 1
- label.TextColor3 = Color3.fromRGB(255, 255, 255)
- label.Text = labelText
- label.TextSize = 18
- label.Parent = parent
- local toggleButton = Instance.new("TextButton")
- toggleButton.Size = UDim2.new(0.3, 0, 0, 30)
- toggleButton.Position = UDim2.new(0, 175, 0, 10)
- toggleButton.BackgroundColor3 = Color3.fromRGB(100, 100, 100)
- toggleButton.TextColor3 = Color3.fromRGB(255, 255, 255)
- toggleButton.Text = "啟用"
- toggleButton.TextSize = 14
- toggleButton.Parent = parent
- toggleButton.MouseButton1Click:Connect(function()
- buttonAction(toggleButton)
- end)
- return toggleButton
- end
- -- 在 stopScript 函數中添加清理操作
- local function stopScript()
- isRunning = false
- highestValue = 0
- -- 重置已執行的狀態
- for key, _ in pairs(alreadyExecuted) do
- alreadyExecuted[key] = false
- end
- -- 其他清理操作
- print("腳本已停止")
- end
- -- 修正 createToggleButton 函數,確保使用當前動物名稱和經驗值
- local toggleButton = createToggleButton(Frame, "經驗一條龍", 40, function(button)
- isRunning = not isRunning
- local currentAnimal = game.Players.LocalPlayer.animalFolderName.Value
- local currentAnimalExp = game.Players.LocalPlayer.levelstats[currentAnimal].Value
- if isRunning then
- button.Text = "停止"
- print("腳本已啟用")
- while isRunning do
- checkAnimalExperience(currentAnimal, currentAnimalExp)
- wait(0.3)
- end
- else
- button.Text = "啟用"
- stopScript()
- end
- end)
- -- 關閉按鈕的點擊事件處理
- CloseButton.MouseButton1Click:Connect(function()
- ScreenGui:Destroy() -- 移除整個界面
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement