Advertisement
chen399d

一條龍經驗

Sep 12th, 2024 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.88 KB | Source Code | 0 0
  1. -- 全局變量
  2. local highestValue = 0
  3. -- 定義動物名稱列表
  4. local npcNames = {
  5.     "Lvl1",
  6.     "Rock",
  7.     "Grass",
  8.     "Water",
  9.     "Ice",
  10.     "Lightning",
  11.     "Void",
  12.     "Fire",
  13.     "Worm"
  14. }
  15.  
  16. -- 觸發造成傷害的事件
  17. local function causeDamageEvent(npcIndex)
  18.     local npcName = npcNames[npcIndex]
  19.     print("攻擊經驗",skill)
  20.     if npcName then
  21.         local args = {
  22.             isLocalNPC = true,
  23.             npcName = npcName
  24.         }
  25.         game:GetService("ReplicatedStorage").Events.DamageEvent:FireServer(args)
  26.     end
  27. end
  28.  
  29. -- 獲取技能的變化值
  30. local skill = game.Players.LocalPlayer.settingsstats.SelectedSkill.Value
  31. print("技能:", skill)
  32.  
  33. game.Players.LocalPlayer.settingsstats.SelectedSkill:GetPropertyChangedSignal("Value"):Connect(function()
  34.     local Newskill = game.Players.LocalPlayer.settingsstats.SelectedSkill.Value
  35.     if Newskill ~= skill then
  36.         print("已檢測到技能更換:", Newskill)
  37.         skill = Newskill  -- 更新 skill 變量為新技能值
  38.     end
  39.     print("新技能", skill)
  40. end)
  41.  
  42. local function KillDamageEvent(npcIndex)
  43.     local npcName = npcNames[npcIndex]
  44.     print("技能經驗",skill)
  45.     if npcName then
  46.         local args = {
  47.             [1] = "damage",
  48.             [2] = {
  49.                 ["npcName"] = npcName,  -- 使用單個 NPC 名稱而不是整個名稱列表
  50.                 ["SelectedSkill"] = skill,
  51.                 ["isLocalNPC"] = true
  52.             }
  53.         }
  54.         game:GetService("ReplicatedStorage").Events.Skills.SkillEvent:FireServer(unpack(args))
  55.     end
  56. end
  57.  
  58.  
  59.  
  60. -- 初始化已執行的動作狀態
  61. local alreadyExecuted = {
  62.     Below50 = false,
  63.     Behigh50 = false,
  64.     Behigh200 = false,
  65.     Behigh450 = false,
  66.     Behigh750 = false,
  67.     Behigh1100 = false,
  68.     Behigh1500 = false,
  69.     Behigh1950 = false,
  70.     Behigh2450 = false
  71. }
  72.  
  73. -- 傳送角色到指定位置
  74. local function teleportTo(x, y, z)
  75.     local player = game.Players.LocalPlayer
  76.     local character = player.Character or player.CharacterAdded:Wait()
  77.     local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  78.     humanoidRootPart.CFrame = CFrame.new(x, y, z)
  79. end
  80.  
  81. -- 檢查動物經驗值範圍並執行相應操作
  82. local function checkAnimalExperience(animalName, animalValue)
  83.     print(animalName, animalValue)
  84.     print("舊值:",highestValue,"新值:",animalValue)
  85.     if animalValue > highestValue then
  86.         highestValue = animalValue  -- 更新最高值
  87.         print("舊值已更新:",highestValue)
  88.     end
  89.     if highestValue > 2450 then
  90.         causeDamageEvent(9)
  91.         KillDamageEvent(9)
  92.         if not alreadyExecuted.Behigh2450 then
  93.             wait(0.3)
  94.             teleportTo(-112.44, 16, -1506.1)
  95.             alreadyExecuted.Behigh2450 = true
  96.         end
  97.     elseif highestValue > 1950 then
  98.         causeDamageEvent(8)
  99.         KillDamageEvent(8)
  100.         if not alreadyExecuted.Behigh1950 then
  101.             wait(0.3)
  102.             teleportTo(-149.4, 27.7, -1338.4)
  103.             alreadyExecuted.Behigh1950 = true
  104.         end
  105.     elseif highestValue > 1500 then
  106.         causeDamageEvent(7)
  107.         KillDamageEvent(7)
  108.         if not alreadyExecuted.Behigh1500 then
  109.             wait(0.3)
  110.             teleportTo(-129.1, 29.1, -1164.9)
  111.             alreadyExecuted.Behigh1500 = true
  112.         end
  113.     elseif highestValue > 1100 then
  114.         causeDamageEvent(6)
  115.         KillDamageEvent(6)
  116.         if not alreadyExecuted.Behigh1100 then
  117.             wait(0.3)
  118.             teleportTo(-127.3, 21, -994.7)
  119.             alreadyExecuted.Behigh1100 = true
  120.         end
  121.     elseif highestValue > 750 then
  122.         causeDamageEvent(5)
  123.         KillDamageEvent(5)
  124.         if not alreadyExecuted.Behigh750 then
  125.             wait(0.3)
  126.             teleportTo(-124.8, 14.65, -839.4)
  127.             alreadyExecuted.Behigh750 = true
  128.         end
  129.     elseif highestValue > 450 then
  130.         causeDamageEvent(4)
  131.         KillDamageEvent(4)
  132.         if not alreadyExecuted.Behigh450 then
  133.             wait(0.3)
  134.             teleportTo(-165.2, 20.59, -658.2)
  135.             alreadyExecuted.Behigh450 = true
  136.         end
  137.     elseif highestValue > 200 then
  138.         causeDamageEvent(3)
  139.         KillDamageEvent(3)
  140.         if not alreadyExecuted.Behigh200 then
  141.             wait(0.3)
  142.             teleportTo(-142, 16.2, -518)
  143.             alreadyExecuted.Behigh200 = true
  144.         end
  145.     elseif highestValue > 50 then
  146.         causeDamageEvent(2)
  147.         KillDamageEvent(2)
  148.         if not alreadyExecuted.Behigh50 then
  149.             wait(0.3)
  150.             teleportTo(-145, 25.47, -373.2)
  151.             alreadyExecuted.Behigh50 = true
  152.         end
  153.     elseif highestValue < 50 then
  154.         causeDamageEvent(1)
  155.         KillDamageEvent(1)
  156.         if not alreadyExecuted.Below50 then
  157.             wait(0.3)
  158.             teleportTo(-106.5, 8.86, -265.1)
  159.             alreadyExecuted.Below50 = true
  160.         end
  161.     end
  162. end
  163.  
  164. -- 監聽各動物經驗值變化的函數
  165. local function connectExpChangeSignal(animalName, expChangeFunction)
  166.     game.Players.LocalPlayer.levelstats[animalName]:GetPropertyChangedSignal("Value"):Connect(expChangeFunction)
  167.     print(animalName, "已註冊")
  168.     for key, _ in pairs(alreadyExecuted) do
  169.         alreadyExecuted[key] = false
  170.     end
  171. end
  172.  
  173. -- 註冊各動物經驗值變化事件
  174. connectExpChangeSignal("Dog", function()
  175.     local newDogExp = game.Players.LocalPlayer.levelstats.Dog.Value
  176.     checkAnimalExperience("Dog", newDogExp)
  177. end)
  178. connectExpChangeSignal("Cat", function()
  179.     local newCatExp = game.Players.LocalPlayer.levelstats.Cat.Value
  180.     checkAnimalExperience("Cat", newCatExp)
  181. end)
  182. connectExpChangeSignal("Bear", function()
  183.     local newBearExp = game.Players.LocalPlayer.levelstats.Bear.Value
  184.     checkAnimalExperience("Bear", newBearExp)
  185. end)
  186. connectExpChangeSignal("Human", function()
  187.     local newHumanExp = game.Players.LocalPlayer.levelstats.Human.Value
  188.     checkAnimalExperience("Human", newHumanExp)
  189. end)
  190. connectExpChangeSignal("Rabbit", function()
  191.     local newRabbitExp = game.Players.LocalPlayer.levelstats.Rabbit.Value
  192.     checkAnimalExperience("Rabbit", newRabbitExp)
  193. end)
  194.  
  195. -- 初次檢查當前角色的動物經驗值範圍
  196. local currentAnimal = game.Players.LocalPlayer.animalFolderName.Value
  197. checkAnimalExperience(currentAnimal, game.Players.LocalPlayer.levelstats[currentAnimal].Value)
  198.  
  199. -- 監聽角色切換事件
  200. game.Players.LocalPlayer.animalFolderName:GetPropertyChangedSignal("Value"):Connect(function()
  201.     for key, _ in pairs(alreadyExecuted) do
  202.         alreadyExecuted[key] = false
  203.     end
  204.     local newAnimalForm = game.Players.LocalPlayer.animalFolderName.Value
  205.     print("當前腳色切換為:", newAnimalForm)
  206.     highestValue = 0
  207.     print("舊值:",highestValue)
  208.     print("舊值:以清空")
  209.     checkAnimalExperience(newAnimalForm, game.Players.LocalPlayer.levelstats[newAnimalForm].Value)
  210. end)
  211.  
  212.  
  213. -- 創建一個主界面 Frame
  214. local ScreenGui = Instance.new("ScreenGui")
  215. ScreenGui.Parent = game.CoreGui
  216.  
  217. -- 創建一個 Frame 來容納 UI 元素
  218. local Frame = Instance.new("Frame")
  219. Frame.Size = UDim2.new(0, 250, 0, 50)
  220. Frame.Position = UDim2.new(0, 10, 0, 10)
  221.  -- 調整位置到左上角
  222. Frame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
  223. Frame.BorderSizePixel = 0
  224. Frame.Active = true
  225. Frame.Draggable = true  -- 允許拖動
  226. Frame.Parent = ScreenGui
  227.  
  228. -- 創建關閉按鈕 (X)
  229. local CloseButton = Instance.new("TextButton")
  230. CloseButton.Size = UDim2.new(0, 20, 0, 20)
  231. CloseButton.Position = UDim2.new(0, 5, 0, 5)  -- 放置在左上角
  232. CloseButton.BackgroundColor3 = Color3.fromRGB(255, 50, 50)
  233. CloseButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  234. CloseButton.Text = "X"
  235. CloseButton.TextSize = 14
  236. CloseButton.Font = Enum.Font.SourceSansBold
  237. CloseButton.Parent = Frame
  238.  
  239. -- 全局變量來表示腳本的運行狀態
  240. local isRunning = false
  241.  
  242. -- 創建切換按鈕函數,確保使用當前動物名稱和經驗值
  243. local function createToggleButton(parent, labelText, buttonPosition, buttonAction)
  244.     local label = Instance.new("TextLabel")
  245.     label.Size = UDim2.new(0.6, 5, 0, 30)
  246.     label.Position = UDim2.new(0, 5, 0, 10)
  247.     label.BackgroundTransparency = 1
  248.     label.TextColor3 = Color3.fromRGB(255, 255, 255)
  249.     label.Text = labelText
  250.     label.TextSize = 18
  251.     label.Parent = parent
  252.  
  253.     local toggleButton = Instance.new("TextButton")
  254.     toggleButton.Size = UDim2.new(0.3, 0, 0, 30)
  255.     toggleButton.Position = UDim2.new(0, 175, 0, 10)  
  256.     toggleButton.BackgroundColor3 = Color3.fromRGB(100, 100, 100)
  257.     toggleButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  258.     toggleButton.Text = "啟用"
  259.     toggleButton.TextSize = 14
  260.     toggleButton.Parent = parent
  261.  
  262.     toggleButton.MouseButton1Click:Connect(function()
  263.         buttonAction(toggleButton)
  264.     end)
  265.  
  266.     return toggleButton
  267. end
  268. -- 在 stopScript 函數中添加清理操作
  269. local function stopScript()
  270.     isRunning = false
  271.     highestValue = 0
  272.     -- 重置已執行的狀態
  273.     for key, _ in pairs(alreadyExecuted) do
  274.         alreadyExecuted[key] = false
  275.     end
  276.     -- 其他清理操作
  277.     print("腳本已停止")
  278. end
  279.  
  280.  
  281. -- 修正 createToggleButton 函數,確保使用當前動物名稱和經驗值
  282. local toggleButton = createToggleButton(Frame, "經驗一條龍", 40, function(button)
  283.     isRunning = not isRunning
  284.     local currentAnimal = game.Players.LocalPlayer.animalFolderName.Value
  285.     local currentAnimalExp = game.Players.LocalPlayer.levelstats[currentAnimal].Value
  286.     if isRunning then
  287.         button.Text = "停止"
  288.         print("腳本已啟用")
  289.         while isRunning do
  290.             checkAnimalExperience(currentAnimal, currentAnimalExp)
  291.             wait(0.3)
  292.         end
  293.     else
  294.         button.Text = "啟用"
  295.         stopScript()
  296.     end
  297. end)
  298.  
  299.  
  300.  
  301. -- 關閉按鈕的點擊事件處理
  302. CloseButton.MouseButton1Click:Connect(function()
  303.     ScreenGui:Destroy()  -- 移除整個界面
  304. end)
  305.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement