-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKaitun_AV.lua
365 lines (310 loc) · 12.4 KB
/
Kaitun_AV.lua
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
local unitIdMap = {
Itochi = 10,
Agony = 15,
Goi = 12,
["Grim Wow"] = 14,
["Cha-In"] = 22,
["Song Jinwu"] = 21,
Aligator = 32,
Sanjo = 43,
Roku = 41,
Vogita = 45,
Noruto = 40,
Luffo = 39,
Jon = 38,
Kinnua = 31,
Pickleo = 34,
Kinaru = 13
}
local function waitForSeconds(seconds)
local endTime = tick() + seconds
while tick() < endTime do
task.wait(0.1)
end
end
local function extractNumber(value)
return tonumber(string.match(value:gsub("[^%d]", ""), "%d+")) or 0
end
local function savePositionsToFile(positions)
local jsonData = json:JSONEncode(positions)
writefile(getgenv().SettingFarm.PositionFile, jsonData)
end
local function loadPositionsFromFile()
if isfile(getgenv().SettingFarm.PositionFile) then
local jsonData = readfile(getgenv().SettingFarm.PositionFile)
return json:JSONDecode(jsonData)
else
return {}
end
end
local function getNextPosition(startPos, currentPos, stepSize, endPos)
local nextZ = currentPos.Z - stepSize
local nextX = currentPos.X
if nextZ < endPos.Z then
nextZ = startPos.Z -- reset Z về giá trị ban đầu
nextX = currentPos.X - stepSize -- chuyển sang cột tiếp theo, giảm X
end
-- Nếu vượt quá giới hạn X, trả về nil để dừng quá trình đặt unit
if nextX < endPos.X then
return nil
end
return Vector3.new(nextX, startPos.Y, nextZ)
end
local function isPositionOccupied(newPos, stepSize)
for _, unit in pairs(workspace.Units:GetChildren()) do
local unitPos = unit.PrimaryPart.Position
if math.abs(unitPos.X - newPos.X) < stepSize and math.abs(unitPos.Z - newPos.Z) < stepSize then
return true
end
end
return false
end
local function FarmGem()
local player = game.Players.LocalPlayer
local unitFolder = player:WaitForChild("PlayerGui"):WaitForChild("Hotbar"):WaitForChild("Main"):WaitForChild("Units")
local argsSkip = { [1] = "Skip" }
game:GetService("ReplicatedStorage").Networking.SkipWaveEvent:FireServer(unpack(argsSkip))
wait(2)
local startPos = Vector3.new(140.06515502929688, 8.752506256103516, 123.34211730957031)
local endPos = Vector3.new(129.9888153076172, 8.752506256103516, 117.63985443115234)
local stepSize = 2
local currentPos = startPos
local pendingPositions = {}
while true do
local yenValueLabel = player:WaitForChild("PlayerGui"):WaitForChild("Hotbar"):WaitForChild("Main"):WaitForChild("Yen")
local yenValue = extractNumber(yenValueLabel.Text)
local anyPlaced = false
local enoughMoney = false
for i = 1, 6 do
local unitSlot = unitFolder:FindFirstChild(tostring(i))
if unitSlot and unitSlot:FindFirstChild("UnitTemplate") then
local unitName = unitSlot.UnitTemplate.Holder.Main.UnitName.Text
local unitId = unitIdMap[unitName]
local placementText = unitSlot.UnitTemplate.Holder.Main.MaxPlacement.Text
local maxPlacement = extractNumber(string.match(placementText, "/(%d+)"))
local currentPlacement = extractNumber(string.match(placementText, "(%d+)/"))
if currentPlacement < maxPlacement then
local price = extractNumber(unitSlot.UnitTemplate.Holder.Main.Price.Text)
if #pendingPositions > 0 then
local savedPos = table.remove(pendingPositions, 1)
if yenValue >= price then
local argsRender = {
[1] = "Render",
[2] = {
[1] = unitName,
[2] = unitId,
[3] = savedPos,
[4] = 0
}
}
game:GetService("ReplicatedStorage").Networking.UnitEvent:FireServer(unpack(argsRender))
wait(2)
anyPlaced = true
yenValue = yenValue - price
else
table.insert(pendingPositions, savedPos)
end
end
if yenValue >= price then
while currentPos do
if not isPositionOccupied(currentPos, stepSize) then
local argsRender = {
[1] = "Render",
[2] = {
[1] = unitName,
[2] = unitId,
[3] = currentPos,
[4] = 0
}
}
game:GetService("ReplicatedStorage").Networking.UnitEvent:FireServer(unpack(argsRender))
wait(2)
anyPlaced = true
yenValue = yenValue - price
currentPos = getNextPosition(startPos, currentPos, stepSize, endPos)
enoughMoney = true
break
else
currentPos = getNextPosition(startPos, currentPos, stepSize, endPos)
end
end
else
if currentPos then
table.insert(pendingPositions, currentPos)
currentPos = getNextPosition(startPos, currentPos, stepSize, endPos)
end
end
end
end
end
if not enoughMoney then
print("Không đủ yen để đặt unit, tạm dừng...")
wait(5)
end
if not anyPlaced and #pendingPositions == 0 and not currentPos then
print("Hoàn thành việc đặt tất cả các units.")
break
end
end
-- Tự động nâng cấp tất cả các units sau khi đặt xong
while true do
local anyUpgraded = false
for _, unit in pairs(workspace.Units:GetChildren()) do
local unitId = unit.Name
local argsUpgrade = {
[1] = "Upgrade",
[2] = unitId
}
local upgradeResponse = game:GetService("ReplicatedStorage").Networking.UnitEvent:FireServer(unpack(argsUpgrade))
wait(2)
-- Kiểm tra phản hồi xem có nâng cấp thành công không
if upgradeResponse and upgradeResponse.Success then
anyUpgraded = true
end
end
end
end
local function sendDialogueEvent(args)
game:GetService("ReplicatedStorage").Networking.State.DialogueEvent:FireServer(unpack(args))
end
local function enterCodes(codes)
for _, code in pairs(getgenv().SettingFarm.Codes) do
local codeArgs = { [1] = code }
game:GetService("ReplicatedStorage").Networking.CodesEvent:FireServer(unpack(codeArgs))
waitForSeconds(2)
end
end
local function selectUnit(unitName)
local selectArgs = { [1] = "Select", [2] = unitName }
game:GetService("ReplicatedStorage").Networking.Units.UnitSelectionEvent:FireServer(unpack(selectArgs))
end
local function equipUnit(fileName)
local equipArgs = { [1] = "Equip", [2] = fileName }
game:GetService("ReplicatedStorage").Networking.Units.EquipEvent:FireServer(unpack(equipArgs))
print("Unit equipment request sent: " .. fileName)
end
local function claimTutorial()
local tutorial = {
[1] = "ClaimTutorial",
[2] = "SummonTutorial"
}
game:GetService("ReplicatedStorage").Networking.ClientListeners.TutorialEvent:FireServer(unpack(tutorial))
end
local function findUnit(unitName, unitFolder)
for _, unitFile in pairs(unitFolder:GetChildren()) do
local fileName = unitFile.Name
if not (fileName:sub(1, 2) == "Ui" or fileName == "UIPadding" or fileName == "UICorner" or fileName == "UIGridLayout") then
local unitHolder = unitFile:FindFirstChild("Holder")
if unitHolder then
local unitMain = unitHolder:FindFirstChild("Main")
if unitMain then
local unitNameObj = unitMain:FindFirstChild("UnitName")
if unitNameObj and unitNameObj.Text == unitName then
return fileName
end
end
end
end
end
return nil
end
local function equipUnits(targetUnits, backupUnits)
local player = game.Players.LocalPlayer
local unitFolder = player:WaitForChild("PlayerGui"):WaitForChild("Windows"):WaitForChild("Units"):WaitForChild("Holder"):WaitForChild("Main"):WaitForChild("Units")
local unitsToEquip = {}
for _, targetUnit in pairs(targetUnits) do
local unitFileName = findUnit(targetUnit, unitFolder)
if unitFileName then
table.insert(unitsToEquip, unitFileName)
else
for _, backupUnit in pairs(backupUnits) do
local backupFileName = findUnit(backupUnit, unitFolder)
if backupFileName then
table.insert(unitsToEquip, backupFileName)
table.remove(backupUnits, table.find(backupUnits, backupUnit))
break
end
end
end
end
for _, unitFileName in pairs(unitsToEquip) do
equipUnit(unitFileName)
waitForSeconds(2)
end
return #unitsToEquip == #targetUnits
end
local function performLobbyActions()
local enterArgs = {
[1] = "Enter",
[2] = workspace.MainLobby.Lobby.Lobby
}
game:GetService("ReplicatedStorage").Networking.LobbyEvent:FireServer(unpack(enterArgs))
waitForSeconds(2)
local confirmArgs = {
[1] = "Confirm",
[2] = {
[1] = "Story",
[2] = "Stage1",
[3] = "Act1",
[4] = "Normal",
[5] = 4,
[6] = 0,
[7] = false
}
}
game:GetService("ReplicatedStorage").Networking.LobbyEvent:FireServer(unpack(confirmArgs))
waitForSeconds(2)
local startArgs = {
[1] = "Start",
[2] = workspace.MainLobby.Lobby.Lobby
}
game:GetService("ReplicatedStorage").Networking.LobbyEvent:FireServer(unpack(startArgs))
end
local targetPlaceId = 16146832113
local function runFarmGem()
if game.PlaceId ~= targetPlaceId then
FarmGem()
return
end
end
local function main()
if game.PlaceId ~= targetPlaceId then
print("Script only runs in Anime Vanguard Game ID: " .. targetPlaceId)
return
end
sendDialogueEvent({
[1] = "Interact",
[2] = { "StarterUnitDialogue", 1, "Okay!" }
})
waitForSeconds(1)
sendDialogueEvent({
[1] = "Interact",
[2] = { "StarterUnitDialogue", 2, "Yeah!" }
})
waitForSeconds(1)
sendDialogueEvent({
[1] = "Interact",
[2] = { "StarterUnitDialogue", 3, "Yeah!" }
})
waitForSeconds(1)
selectUnit("Luffo")
waitForSeconds(1)
enterCodes(getgenv().SettingFarm.Codes)
game:GetService("ReplicatedStorage").Networking.Settings.SettingsEvent:FireServer("Toggle", "SkipSummonAnimation")
game:GetService("ReplicatedStorage").Networking.Settings.SettingsEvent:FireServer("Toggle", "AutoSkipWaves")
for i = 1, 6 do
game:GetService("ReplicatedStorage").Networking.Units.SummonEvent:FireServer("SummonTen", "Special")
waitForSeconds(1)
end
claimTutorial()
if getgenv().SettingFarm.Equipment.Enable then
local success = equipUnits(getgenv().SettingFarm.Equipment.Units, getgenv().SettingFarm.Equipment.BackupUnits)
if success then
performLobbyActions()
else
print("Cannot equip enough units from main and backup list.")
end
end
end
main()
runFarmGem()