Advertisement
chen399d

每秒殺敵數

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