-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.lua
More file actions
127 lines (102 loc) · 3.7 KB
/
Copy pathClient.lua
File metadata and controls
127 lines (102 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
if game.GameId ~= 10200395747 then return end
local HttpService = game:GetService("HttpService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local GuiService = game:GetService("GuiService")
local WS_URL = "ws://127.0.0.1:8765"
local WebSocketConnection = nil
local function SendMessage(MessageData)
if not WebSocketConnection then
return false, nil
end
local Success, Error = pcall(function()
local JSON = HttpService:JSONEncode(MessageData)
WebSocketConnection:Send(JSON)
end)
if not Success then
warn("Failed to send message:", Error)
return false, nil
end
return true, nil
end
local function EstablishConnection()
local Success, Connection = pcall(function()
return WebSocket.connect(WS_URL)
end)
if Success and Connection then
WebSocketConnection = Connection
Connection.OnMessage:Connect(function(Message)
print("Received:", Message)
end)
Connection.OnClose:Connect(function()
WebSocketConnection = nil
end)
return true
else
warn("Failed to connect:", Connection)
return false
end
end
local function Terminate()
return SendMessage({action = "kill"})
end
local Connected = EstablishConnection()
if not Connected then
warn("WebSocket connection failed. Aborting script execution.")
return
end
local function GetRootPart()
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
if not Character or not Character.Parent then
Character = LocalPlayer.CharacterAdded:Wait()
end
local RootPart = Character:WaitForChild("HumanoidRootPart", 5)
if not RootPart then
Character = LocalPlayer.CharacterAdded:Wait()
RootPart = Character:WaitForChild("HumanoidRootPart")
end
return RootPart
end
local function MoveToPosition(TargetCFrame)
local RootPart = GetRootPart()
if not RootPart then return end
local Distance = (RootPart.Position - TargetCFrame.Position).Magnitude
local TweenInfoData = TweenInfo.new(Distance / 35, Enum.EasingStyle.Linear)
local Tween = TweenService:Create(RootPart, TweenInfoData, {CFrame = TargetCFrame})
Tween:Play()
Tween.Completed:Wait()
end
local function SendTamePacket(TargetPart)
local RemoteEvent = game.ReplicatedStorage:WaitForChild("SharedModules"):WaitForChild("Packet"):WaitForChild("RemoteEvent")
local PacketID = RemoteEvent:GetAttribute("WildPetTame") or 77
local TameBuffer = buffer.create(2)
buffer.writeu16(TameBuffer, 0, PacketID)
RemoteEvent:FireServer(TameBuffer, {[1] = TargetPart})
end
local function HandlePet(PetObject)
local PrimaryPart = PetObject:IsA("Model") and (PetObject.PrimaryPart or PetObject:FindFirstChildWhichIsA("BasePart")) or PetObject
if PrimaryPart then
MoveToPosition(PrimaryPart.CFrame * CFrame.new(0, 3, 0))
SendTamePacket(PetObject)
task.wait(1)
end
end
GuiService.ErrorMessageChanged:Connect(function()
local ErrorType = GuiService:GetErrorType()
if ErrorType == Enum.ConnectionError.DisconnectErrors then
task.wait(1)
Terminate()
end
end)
task.wait(30)
local WildPetReference = workspace.Map:WaitForChild("WildPetRef")
repeat task.wait(0.5) until #WildPetReference:GetChildren() > 0
local Pets = WildPetReference:GetChildren()
local RemainingPets = #Pets
for _, Pet in ipairs(Pets) do
HandlePet(Pet)
RemainingPets -= 1
end
repeat task.wait(0.1) until RemainingPets <= 0
Terminate()