Advertisement
chen399d

每秒金幣數

Dec 3rd, 2024 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. local player = game:GetService("Players").LocalPlayer;
  2. local currency = player:WaitForChild("值"):WaitForChild("货币"):WaitForChild("金币");
  3. local playerGui = player:WaitForChild("PlayerGui");
  4. local screenGui = Instance.new("ScreenGui", playerGui);
  5. screenGui.IgnoreGuiInset = true;
  6. local gpsFrame = Instance.new("Frame", screenGui);
  7. gpsFrame.Size = UDim2.new(0, 200, 0, 150);
  8. gpsFrame.Position = UDim2.new(0, 220, 1, -160);
  9. gpsFrame.BackgroundColor3 = Color3.new(0, 0, 0);
  10. gpsFrame.BorderSizePixel = 2;
  11. gpsFrame.BorderColor3 = Color3.new(1, 1, 1);
  12. local unitButton = Instance.new("TextButton", gpsFrame);
  13. unitButton.Size = UDim2.new(0, 180, 0, 30);
  14. unitButton.Position = UDim2.new(0, 10, 0, 10);
  15. unitButton.BackgroundColor3 = Color3.new(0, 0, 0);
  16. unitButton.TextColor3 = Color3.new(1, 1, 1);
  17. unitButton.TextScaled = true;
  18. unitButton.Text = "切換單位";
  19. unitButton.BorderSizePixel = 2;
  20. unitButton.BorderColor3 = Color3.new(1, 1, 1);
  21. local gpsLabel = Instance.new("TextLabel", gpsFrame);
  22. gpsLabel.Size = UDim2.new(0, 180, 0, 45);
  23. gpsLabel.Position = UDim2.new(0, 10, 0, 50);
  24. gpsLabel.BackgroundColor3 = Color3.new(0, 0, 0);
  25. gpsLabel.TextColor3 = Color3.new(1, 1, 1);
  26. gpsLabel.TextScaled = true;
  27. gpsLabel.TextSize = 20;
  28. gpsLabel.Text = "0 ";
  29. gpsLabel.BorderSizePixel = 2;
  30. gpsLabel.BorderColor3 = Color3.new(1, 1, 1);
  31. local closeButton = Instance.new("TextButton", gpsFrame);
  32. closeButton.Size = UDim2.new(0, 180, 0, 30);
  33. closeButton.Position = UDim2.new(0, 10, 1, -40);
  34. closeButton.BackgroundColor3 = Color3.new(1, 0, 0);
  35. closeButton.TextColor3 = Color3.new(1, 1, 1);
  36. closeButton.TextScaled = true;
  37. closeButton.Text = "關閉並停止計算";
  38. closeButton.BorderSizePixel = 1;
  39. closeButton.MouseButton1Click:Connect(function()
  40.     running = false;
  41.     screenGui:Destroy();
  42. end);
  43. local previousGold = currency.Value;
  44. local previousTime = tick();
  45. local running = true;
  46. local units = {"秒金幣","分鐘金幣","小時金幣","天金幣"};
  47. local currentUnitIndex = 1;
  48. local gpsHistory = {};
  49. local function calculateGPS()
  50.     local currentGold = currency.Value;
  51.     local currentTime = tick();
  52.     local timeDifference = currentTime - previousTime;
  53.     if (timeDifference == 0) then
  54.         timeDifference = 0.1;
  55.     end
  56.     local gpsValue = (currentGold - previousGold) / timeDifference;
  57.     previousGold = currentGold;
  58.     previousTime = currentTime;
  59.     local gpsDisplay = 0;
  60.     local unitLabel = "";
  61.     table.insert(gpsHistory, gpsValue);
  62.     if (#gpsHistory > 60) then
  63.         table.remove(gpsHistory, 1);
  64.     end
  65.     local avgGPS = 0;
  66.     for _, value in ipairs(gpsHistory) do
  67.         avgGPS = avgGPS + value;
  68.     end
  69.     avgGPS = avgGPS / #gpsHistory;
  70.     if (currentUnitIndex == 1) then
  71.         gpsDisplay = math.floor(gpsValue);
  72.         unitLabel = string.format("%d 金幣/秒", gpsDisplay);
  73.     elseif (currentUnitIndex == 2) then
  74.         gpsDisplay = math.floor(avgGPS * 60);
  75.         unitLabel = string.format("%d 金幣/分鐘", gpsDisplay);
  76.     elseif (currentUnitIndex == 3) then
  77.         gpsDisplay = math.floor(avgGPS * 3600);
  78.         if (gpsDisplay >= 1000) then
  79.             gpsDisplay = math.floor(gpsDisplay / 1000);
  80.             unitLabel = string.format("%d (k)金幣/小時", gpsDisplay);
  81.         else
  82.             unitLabel = string.format("%d 金幣/小時", gpsDisplay);
  83.         end
  84.     elseif (currentUnitIndex == 4) then
  85.         gpsDisplay = math.floor(avgGPS * 86400);
  86.         if (gpsDisplay >= 1000) then
  87.             gpsDisplay = math.floor(gpsDisplay / 1000);
  88.             unitLabel = string.format("%d (k)金幣/天", gpsDisplay);
  89.         else
  90.             unitLabel = string.format("%d 金幣/天", gpsDisplay);
  91.         end
  92.     end
  93.     gpsLabel.Text = unitLabel;
  94. end
  95. task.spawn(function()
  96.     while running do
  97.         calculateGPS();
  98.         task.wait(1);
  99.     end
  100. end);
  101. unitButton.MouseButton1Click:Connect(function()
  102.     currentUnitIndex = (currentUnitIndex % #units) + 1;
  103. end);
  104. local function enableDrag(frame)
  105.     local dragging = false;
  106.     local dragStart, startPos;
  107.     frame.InputBegan:Connect(function(input)
  108.         if ((input.UserInputType == Enum.UserInputType.MouseButton1) or (input.UserInputType == Enum.UserInputType.Touch)) then
  109.             dragging = true;
  110.             dragStart = input.Position;
  111.             startPos = frame.Position;
  112.             input.Changed:Connect(function()
  113.                 if (input.UserInputState == Enum.UserInputState.End) then
  114.                     dragging = false;
  115.                 end
  116.             end);
  117.         end
  118.     end);
  119.     frame.InputChanged:Connect(function(input)
  120.         if (dragging and ((input.UserInputType == Enum.UserInputType.MouseMovement) or (input.UserInputType == Enum.UserInputType.Touch))) then
  121.             local delta = input.Position - dragStart;
  122.             frame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y);
  123.         end
  124.     end);
  125. end
  126. enableDrag(gpsFrame);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement