Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game:GetService("Players").LocalPlayer;
- local stats = player:WaitForChild("值"):WaitForChild("统计");
- local killsValue = stats:WaitForChild("杀敌数");
- local playerGui = player:WaitForChild("PlayerGui");
- local screenGui = Instance.new("ScreenGui", playerGui);
- screenGui.IgnoreGuiInset = true;
- local kpsFrame = Instance.new("Frame", screenGui);
- kpsFrame.Size = UDim2.new(0, 200, 0, 150);
- kpsFrame.Position = UDim2.new(0, 10, 1, -160);
- kpsFrame.BackgroundColor3 = Color3.new(0, 0, 0);
- kpsFrame.BorderSizePixel = 2;
- kpsFrame.BorderColor3 = Color3.new(1, 1, 1);
- local unitButton = Instance.new("TextButton", kpsFrame);
- unitButton.Size = UDim2.new(0, 180, 0, 30);
- unitButton.Position = UDim2.new(0, 10, 0, 10);
- unitButton.BackgroundColor3 = Color3.new(0, 0, 0);
- unitButton.TextColor3 = Color3.new(1, 1, 1);
- unitButton.TextScaled = true;
- unitButton.Text = "切換單位";
- unitButton.BorderSizePixel = 2;
- unitButton.BorderColor3 = Color3.new(1, 1, 1);
- local kpsLabel = Instance.new("TextLabel", kpsFrame);
- kpsLabel.Size = UDim2.new(0, 180, 0, 45);
- kpsLabel.Position = UDim2.new(0, 10, 0, 50);
- kpsLabel.BackgroundColor3 = Color3.new(0, 0, 0);
- kpsLabel.TextColor3 = Color3.new(1, 1, 1);
- kpsLabel.TextScaled = true;
- kpsLabel.TextSize = 15;
- kpsLabel.Text = "0 ";
- kpsLabel.BorderSizePixel = 2;
- kpsLabel.BorderColor3 = Color3.new(1, 1, 1);
- local closeButton = Instance.new("TextButton", kpsFrame);
- closeButton.Size = UDim2.new(0, 180, 0, 30);
- closeButton.Position = UDim2.new(0, 10, 1, -40);
- closeButton.BackgroundColor3 = Color3.new(1, 0, 0);
- closeButton.TextColor3 = Color3.new(1, 1, 1);
- closeButton.TextScaled = true;
- closeButton.Text = "關閉並停止計算";
- closeButton.BorderSizePixel = 1;
- closeButton.MouseButton1Click:Connect(function()
- running = false;
- screenGui:Destroy();
- end);
- local previousKills = killsValue.Value;
- local previousTime = tick();
- local running = true;
- local units = {"秒擊殺","分鐘擊殺","小時擊殺","天擊殺"};
- local currentUnitIndex = 1;
- local kpsHistory = {};
- local function calculateKPS()
- local currentKills = killsValue.Value;
- local currentTime = tick();
- local timeDifference = currentTime - previousTime;
- if (timeDifference == 0) then
- timeDifference = 0.1;
- end
- local kpsValue = (currentKills - previousKills) / timeDifference;
- previousKills = currentKills;
- previousTime = currentTime;
- local kpsDisplay = 0;
- local unitLabel = "";
- table.insert(kpsHistory, kpsValue);
- if (#kpsHistory > 60) then
- table.remove(kpsHistory, 1);
- end
- local avgKPS = 0;
- for _, value in ipairs(kpsHistory) do
- avgKPS = avgKPS + value;
- end
- avgKPS = avgKPS / #kpsHistory;
- if (currentUnitIndex == 1) then
- kpsDisplay = math.floor(kpsValue);
- unitLabel = string.format("%d 擊殺/秒", kpsDisplay);
- elseif (currentUnitIndex == 2) then
- kpsDisplay = math.floor(avgKPS * 60);
- unitLabel = string.format("%d 擊殺/分鐘", kpsDisplay);
- elseif (currentUnitIndex == 3) then
- kpsDisplay = math.floor(avgKPS * 3600);
- if (kpsDisplay >= 1000) then
- kpsDisplay = math.floor(kpsDisplay / 1000);
- unitLabel = string.format("%d (k)擊殺/小時", kpsDisplay);
- else
- unitLabel = string.format("%d 擊殺/小時", kpsDisplay);
- end
- elseif (currentUnitIndex == 4) then
- kpsDisplay = math.floor(avgKPS * 86400);
- if (kpsDisplay >= 1000) then
- kpsDisplay = math.floor(kpsDisplay / 1000);
- unitLabel = string.format("%d (k)擊殺/天", kpsDisplay);
- else
- unitLabel = string.format("%d 擊殺/天", kpsDisplay);
- end
- end
- kpsLabel.Text = unitLabel;
- end
- task.spawn(function()
- while running do
- calculateKPS();
- task.wait(1);
- end
- end);
- unitButton.MouseButton1Click:Connect(function()
- currentUnitIndex = (currentUnitIndex % #units) + 1;
- end);
- local function enableDrag(frame)
- local dragging = false;
- local dragStart, startPos;
- frame.InputBegan:Connect(function(input)
- if ((input.UserInputType == Enum.UserInputType.MouseButton1) or (input.UserInputType == Enum.UserInputType.Touch)) then
- dragging = true;
- dragStart = input.Position;
- startPos = frame.Position;
- input.Changed:Connect(function()
- if (input.UserInputState == Enum.UserInputState.End) then
- dragging = false;
- end
- end);
- end
- end);
- frame.InputChanged:Connect(function(input)
- if (dragging and ((input.UserInputType == Enum.UserInputType.MouseMovement) or (input.UserInputType == Enum.UserInputType.Touch))) then
- local delta = input.Position - dragStart;
- frame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y);
- end
- end);
- end
- enableDrag(kpsFrame);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement