-
Notifications
You must be signed in to change notification settings - Fork 0
/
DropStuffGrind.ahk
1478 lines (1339 loc) · 80.5 KB
/
DropStuffGrind.ahk
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; HATCH & GRIND
; ----------------------------------------------------------------------------------------
; AutoHotKey 2.0 Macro For Pet Simulator 99 (PS99) by waktool
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; DIRECTIVES & CONFIGURATIONS
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
#Requires AutoHotKey v2.0
#SingleInstance Force
CoordMode "Mouse", "Window"
CoordMode "Pixel", "Window"
SetMouseDelay 10
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; GLOBAL VARIABLES
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
global MACRO_TITLE := "Drop Stuff & Grind"
global MACRO_VERSION := "0.3.1"
global SETTINGS_INI := A_ScriptDir "\Settings.ini"
global ONE_SECOND := 1000
global FIRST_ZONE := 210
global BEST_ZONE := 214
global SHOW_OCR_OUTLINE := getSetting("ShowOcrOutline", "Settings")
global DARK_MODE := getSetting("DarkMode", "Settings")
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; LIBRARIES
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; Third-party Libraries:
#Include <OCR>
#Include <Pin>
#Include <JXON>
#Include <DarkMode>
; Macro Related Libraries:
#Include "%A_ScriptDir%\Modules"
#Include "Coords.ahk"
#Include "Delays.ahk"
#Include "Movement.ahk"
#Include "Timers.ahk"
#Include "Zones.ahk"
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; TIMERS
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
SetTimer updateFlagTimer, ONE_SECOND
SetTimer updateSprinklerTimer, ONE_SECOND
SetTimer updateFruitTimer, ONE_SECOND
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; MACRO START
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
runMacro()
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; FUNCTIONS & PROCEDURES
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; ---------------------------------------------------------------------------------
; runMacro Function
; Description: Completes initial tasks, shows the main GUI, activates Roblox, and enters a loop to perform various game actions.
; Operation:
; - Completes initialization tasks including activating Roblox, setting the application icon, initializing the Roblox window, changing to fullscreen, and setting hotkeys.
; - Shows the main GUI.
; - Activates the Roblox window.
; - Enters an infinite loop to:
; - Check for disconnection and reconnect if necessary.
; - Claim free gifts if they are ready.
; - Teleport to the first zone and then to the best zone.
; - Toggle the auto farm setting.
; - Move to the center of the best zone and toggle auto farm again.
; - Repeatedly use items and abilities in a nested loop.
; Dependencies:
; - completeInitialisationTasks: Function to complete initial tasks.
; - showMainGui: Function to show the main GUI.
; - activateRoblox: Function to activate the Roblox window.
; - checkForDisconnection: Function to check for disconnection and reconnect if necessary.
; - claimFreeGifts: Function to claim free gifts if they are ready.
; - teleportToZone: Function to teleport to a specified zone.
; - clickAutoFarmButton: Function to toggle the auto farm setting.
; - moveToCentreOfTheBestZone: Function to move to the center of the best zone.
; - useFlag, useSprinkler, eatFruit, useUltimate, dropItem: Functions to use items and abilities.
; - getSetting: Function to retrieve specific settings from the INI file.
; Return: None; the function performs various game actions in a loop.
; ---------------------------------------------------------------------------------
runMacro() {
completeInitialisationTasks() ; Complete initial tasks.
showMainGui() ; Show the main GUI.
activateRoblox() ; Activate the Roblox window.
checkForDisconnection() ; Check for disconnection and reconnect if necessary.
teleportToZone(FIRST_ZONE) ; Teleport to the first zone.
teleportToZone(BEST_ZONE) ; Teleport to the best zone.
clickAutoFarmButton() ; Click the auto farm button.
moveToCentreOfTheBestZone() ; Move to the center of the best zone.
clickAutoFarmButton() ; Click the auto farm button again.
Loop {
checkForDisconnection() ; Check for disconnection and reconnect if necessary.
claimFreeGifts() ; Claim free gifts if they are ready.
useFlag() ; Use the flag.
useSprinkler() ; Use the sprinkler.
eatFruit() ; Eat fruit items to gain boosts.
useUltimate() ; Use the ultimate ability.
dropItem(getSetting("ItemToDrop", "Settings")) ; Drop the specified item.
}
}
; ---------------------------------------------------------------------------------
; showMainGui Function
; Description: Initializes the main GUI with "AlwaysOnTop" property, sets its title and font, adds a ListView and buttons, and handles events and dark mode settings.
; Operation:
; - Creates the main GUI and sets it to always stay on top.
; - Sets the title and font for the GUI.
; - Adds a ListView to display flag, sprinkler, fruit, and action status.
; - Adds buttons for pausing the macro and accessing the wiki.
; - Displays the GUI and positions it at the top-right of the screen.
; - Attaches event handlers to the buttons for pausing the macro and opening the wiki.
; - Applies dark mode settings if enabled.
; Dependencies:
; - Gui: AHK command to create a new GUI.
; - AddListView: AHK command to add a ListView to the GUI.
; - AddButton: AHK command to add a button to the GUI.
; - Show, GetPos, Move: AHK commands to display, position, and move the GUI.
; - OnEvent: AHK command to attach an event handler to a GUI control.
; - SetWindowAttribute, SetWindowTheme: Functions to apply dark mode settings.
; Return: None; the function initializes and displays the main GUI.
; ---------------------------------------------------------------------------------
showMainGui() {
global guiMain := Gui("+AlwaysOnTop") ; Create the main GUI with "AlwaysOnTop" property.
guiMain.Title := MACRO_TITLE " " MACRO_VERSION ; Set the GUI title.
guiMain.SetFont(, "Segoe UI") ; Set the GUI font.
; Add a ListView to display flag, sprinkler, fruit, and action status.
global lvCurrent := guiMain.AddListView("Section r1 w400", ["Flag", "Sprinkler", "Fruit", "Action", "Time"])
lvCurrent.Add(, "0", "0", "0", "-") ; Add a default row to the ListView.
lvCurrent.ModifyCol(1, 60) ; Set the width of the first column.
lvCurrent.ModifyCol(2, 60) ; Set the width of the second column.
lvCurrent.ModifyCol(3, 60) ; Set the width of the third column.
lvCurrent.ModifyCol(4, 150) ; Set the width of the fourth column.
lvCurrent.ModifyCol(5, 60) ; Set the width of the fifth column.
; Add buttons for pausing the macro and accessing the wiki.
btnPause := guiMain.AddButton("xs", "⏸ &Pause")
btnHelp := guiMain.AddButton("yp", "🌐 &Wiki")
guiMain.Show() ; Display the GUI.
guiMain.GetPos(,, &Width,) ; Get the current width of the GUI.
guiMain.Move(A_ScreenWidth - Width + 8, 0) ; Move the GUI to the top-right corner of the screen.
; Attach event handlers to the buttons.
btnPause.OnEvent("Click", pauseMacro) ; Attach the pause event handler to the pause button.
btnHelp.OnEvent("Click", openWiki) ; Attach the wiki event handler to the help button.
; Apply dark mode settings if enabled.
if (DARK_MODE == "true") {
SetWindowAttribute(guiMain)
SetWindowTheme(guiMain)
}
}
; ---------------------------------------------------------------------------------
; pauseMacro Function
; Description: Pauses the macro indefinitely until it is resumed.
; Operation:
; - Uses the Pause command with the -1 parameter to pause the script indefinitely.
; Dependencies: None.
; Return: None; the function pauses the macro and waits for a resume action.
; ---------------------------------------------------------------------------------
pauseMacro(*) {
Pause -1 ; Pause the macro indefinitely until resumed.
}
; ---------------------------------------------------------------------------------
; exitMacro Function
; Description: Exits the macro execution.
; Operation:
; - Uses the ExitApp command to terminate the script.
; Dependencies: None.
; Return: None; the function terminates the script execution.
; ---------------------------------------------------------------------------------
exitMacro(*) {
ExitApp ; Exit the macro.
}
; ---------------------------------------------------------------------------------
; openWiki Function
; Description: Opens the help text file in Notepad.
; Operation:
; - Uses the Run command to open the specified URL in the default web browser.
; Dependencies: None.
; Return: None; the function opens the URL in the web browser.
; ---------------------------------------------------------------------------------
openWiki(*) {
Run "https://github.com/waktool/DropStuffGrind/wiki" ; Open the help text file URL.
}
; ---------------------------------------------------------------------------------
; setCurrentAction Function
; Description: Updates the current action displayed in the GUI.
; Operation:
; - Modifies the text of the first row in the ListView to display the provided action.
; Dependencies:
; - lvCurrent: A global variable representing the ListView control to be updated.
; Return: None; the function updates the ListView with the new action.
; ---------------------------------------------------------------------------------
setCurrentAction(currentAction) {
lvCurrent.Modify(1, , , , , currentAction) ; Update the ListView with the provided action.
}
; ---------------------------------------------------------------------------------
; setCurrentTime Function
; Description: Updates the current time displayed in the GUI ListView.
; Operation:
; - Modifies the text of the time column in the first row of the ListView with the provided new time.
; Dependencies:
; - lvCurrent: Global ListView object representing the current status.
; - Modify: AHK command to modify a ListView row.
; Return: None; the function updates the current time in the ListView.
; ---------------------------------------------------------------------------------
setCurrentTime(newTime) {
lvCurrent.Modify(1, , , , , , newTime) ; Modify the text of the time column in the first row with the new time.
}
; ---------------------------------------------------------------------------------
; setFlagTimer Function
; Description: Updates the flag timer displayed in the GUI.
; Operation:
; - Modifies the text of the first row in the ListView to display the provided time.
; Dependencies:
; - lvCurrent: A global variable representing the ListView control to be updated.
; Return: None; the function updates the ListView with the new time.
; ---------------------------------------------------------------------------------
setFlagTimer(newTime) {
lvCurrent.Modify(1, , newTime) ; Update the ListView with the provided time.
}
; ---------------------------------------------------------------------------------
; setSprinklerTimer Function
; Description: Updates the sprinkler timer displayed in the GUI.
; Operation:
; - Modifies the text of the first row in the ListView to display the provided time.
; Dependencies:
; - lvCurrent: A global variable representing the ListView control to be updated.
; Return: None; the function updates the ListView with the new time.
; ---------------------------------------------------------------------------------
setSprinklerTimer(newTime) {
lvCurrent.Modify(1, , , newTime) ; Update the ListView with the provided time.
}
; ---------------------------------------------------------------------------------
; setFruitTimer Function
; Description: Updates the fruit timer displayed in the GUI.
; Operation:
; - Modifies the text of the first row in the ListView to display the provided time.
; Dependencies:
; - lvCurrent: A global variable representing the ListView control to be updated.
; Return: None; the function updates the ListView with the new time.
; ---------------------------------------------------------------------------------
setFruitTimer(newTime) {
lvCurrent.Modify(1, , , , newTime) ; Update the ListView with the provided time.
}
; ---------------------------------------------------------------------------------
; useFlag Function
; Description: Uses a flag item if it is ready, updates the flag's usage data, and sets the next time it will be ready to use.
; Operation:
; - Checks if the current tick count is greater than or equal to the ready-to-use time for the flag.
; - Retrieves the flag item to use, the amount to use, and the boost length from settings.
; - Uses the specified flag item.
; - Updates the last used time and calculates the next ready-to-use time.
; - Stores the updated usage data in the FLAG_DATA map.
; Dependencies:
; - FLAG_DATA: Map storing data related to flag usage.
; - getSetting: Function to retrieve specific settings for the flag.
; - useItem: Function to use a specified item.
; Return: None; the function uses the flag and updates its usage data.
; ---------------------------------------------------------------------------------
useFlag() {
if (A_TickCount >= FLAG_DATA.Get("ReadyToUse")) { ; Check if the flag is ready to use.
flagToUse := getSetting("FlagToUse", "Settings") ; Retrieve the flag item to use.
amountToUse := getSetting("FlagAmountToUse", "Settings") ; Retrieve the amount to use.
boostLength := getSetting("FlagBoostLengthSeconds", "Settings") * ONE_SECOND ; Retrieve the boost length in seconds.
useItem(flagToUse, 2, amountToUse) ; Use the specified flag item.
lastUsed := A_TickCount ; Update the last used time.
readyToUse := lastUsed + (amountToUse * boostLength) ; Calculate the next ready-to-use time.
FLAG_DATA["LastUsed"] := lastUsed ; Store the last used time.
FLAG_DATA["ReadyToUse"] := readyToUse ; Store the next ready-to-use time.
}
}
; ---------------------------------------------------------------------------------
; useSprinkler Function
; Description: Uses a sprinkler item if it is ready, updates the sprinkler's usage data, and sets the next time it will be ready to use.
; Operation:
; - Checks if the current tick count is greater than or equal to the ready-to-use time for the sprinkler.
; - Retrieves the amount to use and the boost length from settings.
; - Uses the sprinkler item.
; - Updates the last used time and calculates the next ready-to-use time.
; - Stores the updated usage data in the SPRINKLER_DATA map.
; Dependencies:
; - SPRINKLER_DATA: Map storing data related to sprinkler usage.
; - getSetting: Function to retrieve specific settings for the sprinkler.
; - useItem: Function to use a specified item.
; Return: None; the function uses the sprinkler and updates its usage data.
; ---------------------------------------------------------------------------------
useSprinkler() {
if (A_TickCount >= SPRINKLER_DATA.Get("ReadyToUse")) { ; Check if the sprinkler is ready to use.
amountToUse := getSetting("SprinklerAmountToUse", "Settings") ; Retrieve the amount to use.
boostLength := getSetting("SprinklerBoostLengthSeconds", "Settings") * ONE_SECOND ; Retrieve the boost length in seconds.
useItem("Sprinkler", 2, amountToUse) ; Use the sprinkler item.
lastUsed := A_TickCount ; Update the last used time.
readyToUse := lastUsed + (amountToUse * boostLength) ; Calculate the next ready-to-use time.
SPRINKLER_DATA["LastUsed"] := lastUsed ; Store the last used time.
SPRINKLER_DATA["ReadyToUse"] := readyToUse ; Store the next ready-to-use time.
}
}
; ---------------------------------------------------------------------------------
; eatFruit Function
; Description: Checks if eating fruit is enabled, iterates through a list of fruits to use them, and updates the fruit's usage data.
; Operation:
; - Checks the setting to determine if eating fruit is enabled.
; - Checks if the current tick count is greater than or equal to the ready-to-use time for the fruit.
; - Defines an array of fruit items to be used.
; - Iterates through the fruit array and uses each fruit item.
; - Closes the inventory menu and error message window.
; - Calculates the boost length and updates the last used and ready-to-use times for the fruit.
; Dependencies:
; - getSetting: Function to retrieve specific settings.
; - useItem: Function to use a specified item.
; - closeInventoryMenu: Function to close the inventory menu.
; - closeErrorMessageWindow: Function to close the error message window.
; - FRUIT_DATA: Map storing data related to fruit usage.
; - A_TickCount: AHK built-in variable representing the number of milliseconds since the script started.
; Return: None; the function uses the specified fruit items and updates their usage data.
; ---------------------------------------------------------------------------------
eatFruit() {
if (getSetting("EatFruit", "Settings") == "true") { ; Check if eating fruit is enabled.
if (A_TickCount >= FRUIT_DATA.Get("ReadyToUse")) { ; Check if the current tick count is greater than or equal to the ready-to-use time for the fruit.
fruitArray := ["Apple", "Banana", "Orange", "Pineapple", "Rainbow Fruit", "Watermelon"] ; Define an array of fruit items.
for fruitItem in fruitArray {
useItem(fruitItem, 2, 2, true) ; Use each fruit item.
}
closeInventoryMenu() ; Close the inventory menu.
closeErrorMessageWindow() ; Close the error message window.
boostLength := getSetting("FruitTimeBetweenUseSeconds", "Settings") * 1000 ; Calculate the boost length in milliseconds.
lastUsed := A_TickCount ; Get the current tick count as the last used time.
readyToUse := lastUsed + boostLength ; Calculate the next ready-to-use time.
FRUIT_DATA["LastUsed"] := lastUsed ; Update the last used time for the fruit.
FRUIT_DATA["ReadyToUse"] := readyToUse ; Update the next ready-to-use time for the fruit.
}
}
}
; ---------------------------------------------------------------------------------
; dropItem Function
; Description: Drops an item by its name, sets the current action, and waits for a specified delay based on the item type.
; Operation:
; - Converts the item name "Pinata" to "Piñata" if necessary.
; - Sets the current action to indicate the item being used.
; - Calls the UseItem function to use the specified item.
; - Determines the delay in seconds for the specified item type using the GetSetting function.
; - Waits for the specified delay while updating the current time in the ListView.
; - Resets the current time display after the delay.
; Dependencies:
; - setCurrentAction: Function to update the current action in the GUI.
; - UseItem: Function to use the specified item.
; - GetSetting: Function to retrieve specific settings from the INI file.
; - setCurrentTime: Function to update the current time displayed in the ListView.
; - Sleep: AHK command to pause execution for a specified duration.
; - ONE_SECOND: Constant representing one second in milliseconds.
; Return: None; the function drops the specified item and waits for the corresponding delay.
; ---------------------------------------------------------------------------------
dropItem(itemToDrop) {
if (itemToDrop == "Pinata")
itemToDrop := "Piñata"
setCurrentAction("Using " itemToDrop) ; Set the current action to indicate the item being used.
UseItem(itemToDrop) ; Use the specified item.
; Determine the delay in seconds for the specified item type.
Switch itemToDrop {
Case "Party Box":
secondsToWait := GetSetting("PartyBox", "Delays")
Case "Basic Coin Jar":
secondsToWait := GetSetting("BasicCoinJar", "Delays")
Case "Comet":
secondsToWait := GetSetting("Comet", "Delays")
Case "Lucky Block":
secondsToWait := GetSetting("LuckyBlock", "Delays")
Case "Piñata":
secondsToWait := GetSetting("Pinata", "Delays")
Case "Giant Coin Jar":
secondsToWait := GetSetting("GiantCoinJar", "Delays")
Case "TNT Crate":
secondsToWait := GetSetting("TntCrate", "Delays")
Default:
secondsToWait := 10
}
; Wait for the specified delay while updating the current time in the ListView.
Loop secondsToWait {
setCurrentTime(secondsToWait - (A_Index - 1)) ; Update the current time display.
Sleep ONE_SECOND ; Wait for one second.
}
setCurrentTime("-") ; Reset the current time display after the delay.
}
; ---------------------------------------------------------------------------------
; checkForDisconnection Function
; Description: Checks for disconnection, attempts to reconnect if disconnected, and reloads the script.
; Operation:
; - Updates the current action to "Checking Connection".
; - Checks for disconnection using the checkForDisconnect function.
; - If disconnected, calls the reconnectClient function and reloads the script.
; - Resets the current action.
; Dependencies:
; - checkForDisconnect: Function to check if the client is disconnected.
; - reconnectClient: Function to attempt to reconnect the client.
; - setCurrentAction: Function to update the current action in the GUI.
; Return: None; the function handles disconnection and attempts reconnection if necessary.
; ---------------------------------------------------------------------------------
checkForDisconnection() {
setCurrentAction("Checking Connection") ; Update the current action.
isDisconnected := checkForDisconnect() ; Check for disconnection.
if (isDisconnected == true) { ; If disconnected.
reconnectClient() ; Attempt to reconnect the client.
Reload ; Reload the script.
}
setCurrentAction("-") ; Reset the current action.
}
; ---------------------------------------------------------------------------------
; closeErrorMessage Function
; Description: Attempts to close an error message by clicking a specified coordinate and waits for a specified time.
; Operation:
; - Uses a loop to click the error message close button twice.
; - Waits for a specified time after the error message is closed.
; Dependencies:
; - COORDS: Map storing coordinates for various controls and buttons.
; - leftClickMouseAndWait: Function to click a specified coordinate and wait.
; - waitTime: Function to wait for a specified time.
; Return: None; the function attempts to close the error message and waits for the specified time.
; ---------------------------------------------------------------------------------
closeErrorMessage() {
Loop 2 { ; Loop to click the error message close button twice.
leftClickMouseAndWait(COORDS["Errors"]["X"], 50) ; Click the specified coordinate and wait.
}
waitTime("ErrorAfterClosed") ; Wait for a specified time after the error message is closed.
}
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; CONNECTION FUNCTIONS
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; ---------------------------------------------------------------------------------
; checkForDisconnect Function
; Description: Checks for a disconnection message by performing OCR on a specified area and returns whether the message is found.
; Operation:
; - Activates the Roblox window.
; - Performs OCR on the specified area to detect a disconnection message.
; - Returns true if the disconnection message is found, otherwise false.
; Dependencies:
; - activateRoblox: Function to activate the Roblox window.
; - COORDS: Map storing coordinates for various controls and buttons.
; - OCR.FromRect: Function to perform OCR on a specified rectangular area.
; - RegExMatch: AHK function to match a regular expression against a string.
; Return:
; - true if the disconnection message is found.
; - false if the disconnection message is not found.
; ---------------------------------------------------------------------------------
checkForDisconnect() {
activateRoblox() ; Activate the Roblox window.
ocrStart := COORDS["OCR"]["DisconnectMessageStart"]
ocrSize := COORDS["OCR"]["DisconnectMessageSize"]
ocrObjectResult := OCR.FromRect(ocrStart[1], ocrStart[2], ocrSize[1], ocrSize[2]) ; Perform OCR on the specified area.
return (RegExMatch(ocrObjectResult.Text, "Disconnected|Reconnect|Leave")) ; Return whether the disconnection message is found.
}
; ---------------------------------------------------------------------------------
; reconnectClient Function
; Description: Attempts to reconnect the client using a private server link code if available, and updates the current action during the reconnection process.
; Operation:
; - Retrieves the reconnect time and private server link code from settings.
; - If the private server link code is not available, runs the Roblox place ID directly.
; - If the private server link code is available, runs the Roblox place ID with the link code.
; - Uses a loop to update the current action and wait for the reconnect time.
; Dependencies:
; - getSetting: Function to retrieve specific settings for the reconnect time and private server link code.
; - setCurrentAction: Function to update the current action in the GUI.
; Return: None; the function attempts to reconnect the client.
; ---------------------------------------------------------------------------------
reconnectClient(*) {
reconnectTime := getSetting("ReconnectTimeSeconds", "Settings") ; Retrieve the reconnect time.
privateServerLinkCode := getSetting("PrivateServerLinkCode", "Settings") ; Retrieve the private server link code.
if (privateServerLinkCode == "") {
try Run "roblox://placeID=8737899170" ; Run the Roblox place ID directly if no link code is available.
}
else {
try Run "roblox://placeID=8737899170&linkCode=" privateServerLinkCode ; Run the Roblox place ID with the link code if available.
}
Loop reconnectTime {
setCurrentAction("Reconnecting " A_Index "/" reconnectTime) ; Update the current action.
Sleep ONE_SECOND ; Wait for one second.
}
}
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; ULTIMATE FUNCTIONS
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; ---------------------------------------------------------------------------------
; useUltimate Function
; Description: Uses the ultimate ability and updates the current action.
; Operation:
; - Sets the current action to "Using Ultimate".
; - Sends a left-click event to use the ultimate ability at the specified coordinates.
; - Waits for a specified time after using the ultimate.
; Dependencies:
; - setCurrentAction: Function to update the current action in the GUI.
; - COORDS: Map storing coordinates for various controls and buttons.
; - leftClickMouseAndWait: Function to click a specified coordinate and wait.
; Return: None; the function uses the ultimate ability and updates the current action.
; ---------------------------------------------------------------------------------
useUltimate() {
setCurrentAction("Using Ultimate") ; Update the current action.
leftClickMouseAndWait(COORDS["Controls"]["Ultimate"], "UltimateAfterUsed") ; Click to use the ultimate ability and wait.
}
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; TIMER FUNCTIONS
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; ---------------------------------------------------------------------------------
; isSomethingReadyToUse Function
; Description: Checks if either a flag or a sprinkler is ready to use.
; Operation:
; - Calls the isFlagReadyToUse function to check if a flag is ready to use.
; - Calls the isSprinklerReadyToUse function to check if a sprinkler is ready to use.
; - Returns true if either a flag or a sprinkler is ready to use.
; Dependencies:
; - isFlagReadyToUse: Function to check if a flag is ready to use.
; - isSprinklerReadyToUse: Function to check if a sprinkler is ready to use.
; Return:
; - true if either a flag or a sprinkler is ready to use.
; - false if neither a flag nor a sprinkler is ready to use.
; ---------------------------------------------------------------------------------
isSomethingReadyToUse() {
isFlagReady := isFlagReadyToUse() ; Check if a flag is ready to use.
isSprinklerReady := isSprinklerReadyToUse() ; Check if a sprinkler is ready to use.
return (isFlagReady == true || isSprinklerReady == true) ; Return true if either is ready to use.
}
; ---------------------------------------------------------------------------------
; isFlagReadyToUse Function
; Description: Checks if flags are enabled and if a flag is ready to use.
; Operation:
; - Retrieves the flag usage setting.
; - Returns false if flag usage is disabled.
; - Checks if the current tick count is greater than or equal to the ready-to-use time for the flag.
; Dependencies:
; - getSetting: Function to retrieve specific settings for flag usage.
; - FLAG_DATA: Map storing data related to flag usage.
; Return:
; - true if flags are enabled and a flag is ready to use.
; - false if flags are disabled or not ready to use.
; ---------------------------------------------------------------------------------
isFlagReadyToUse() {
if (getSetting("useFlags", "Settings") == "false")
return false
return (A_TickCount >= FLAG_DATA.Get("ReadyToUse")) ; Check if a flag is ready to use.
}
; ---------------------------------------------------------------------------------
; isSprinklerReadyToUse Function
; Description: Checks if sprinklers are enabled and if a sprinkler is ready to use.
; Operation:
; - Retrieves the sprinkler usage setting.
; - Returns false if sprinkler usage is disabled.
; - Checks if the current tick count is greater than or equal to the ready-to-use time for the sprinkler.
; Dependencies:
; - getSetting: Function to retrieve specific settings for sprinkler usage.
; - SPRINKLER_DATA: Map storing data related to sprinkler usage.
; Return:
; - true if sprinklers are enabled and a sprinkler is ready to use.
; - false if sprinklers are disabled or not ready to use.
; ---------------------------------------------------------------------------------
isSprinklerReadyToUse() {
if (getSetting("UseSprinklers", "Settings") == "false")
return false
return (A_TickCount >= SPRINKLER_DATA.Get("ReadyToUse")) ; Check if a sprinkler is ready to use.
}
; ---------------------------------------------------------------------------------
; updateFlagTimer Function
; Description: Updates the flag timer displayed in the GUI.
; Operation:
; - Checks if the flag was used.
; - Calculates the time remaining until the flag is ready to use.
; - Converts the remaining time to minutes and seconds format.
; - Updates the flag timer in the GUI.
; Dependencies:
; - FLAG_DATA: Map storing data related to flag usage.
; - convertTimeToMinutesSeconds: Function to convert time to minutes and seconds format.
; - setFlagTimer: Function to update the flag timer in the GUI.
; Return: None; the function updates the flag timer in the GUI.
; ---------------------------------------------------------------------------------
updateFlagTimer() {
if (FLAG_DATA.Get("LastUsed") != 0) { ; Check if the flag was used.
timeRemaining := FLAG_DATA.Get("ReadyToUse") - A_TickCount ; Calculate the time remaining.
timeRemaining := timeRemaining >= 0 ? timeRemaining : 0 ; Ensure the remaining time is not negative.
timeRemainingText := convertTimeToMinutesSeconds(timeRemaining) ; Convert to minutes and seconds format.
setFlagTimer(timeRemainingText) ; Update the flag timer in the GUI.
}
}
; ---------------------------------------------------------------------------------
; updateSprinklerTimer Function
; Description: Updates the sprinkler timer displayed in the GUI.
; Operation:
; - Checks if the sprinkler was used.
; - Calculates the time remaining until the sprinkler is ready to use.
; - Converts the remaining time to minutes and seconds format.
; - Updates the sprinkler timer in the GUI.
; Dependencies:
; - SPRINKLER_DATA: Map storing data related to sprinkler usage.
; - convertTimeToMinutesSeconds: Function to convert time to minutes and seconds format.
; - setSprinklerTimer: Function to update the sprinkler timer in the GUI.
; Return: None; the function updates the sprinkler timer in the GUI.
; ---------------------------------------------------------------------------------
updateSprinklerTimer() {
if (SPRINKLER_DATA.Get("LastUsed") != 0) { ; Check if the sprinkler was used.
timeRemaining := SPRINKLER_DATA.Get("ReadyToUse") - A_TickCount ; Calculate the time remaining.
timeRemaining := timeRemaining >= 0 ? timeRemaining : 0 ; Ensure the remaining time is not negative.
timeRemainingText := convertTimeToMinutesSeconds(timeRemaining) ; Convert to minutes and seconds format.
setSprinklerTimer(timeRemainingText) ; Update the sprinkler timer in the GUI.
}
}
; ---------------------------------------------------------------------------------
; updateFruitTimer Function
; Description: Updates the fruit timer displayed in the GUI.
; Operation:
; - Checks if the fruit was used.
; - Calculates the time remaining until the fruit is ready to use.
; - Converts the remaining time to minutes and seconds format.
; - Updates the fruit timer in the GUI.
; Dependencies:
; - FRUIT_DATA: Map storing data related to fruit usage.
; - convertTimeToMinutesSeconds: Function to convert time to minutes and seconds format.
; - setFruitTimer: Function to update the fruit timer in the GUI.
; Return: None; the function updates the fruit timer in the GUI.
; ---------------------------------------------------------------------------------
updateFruitTimer() {
if (FRUIT_DATA.Get("LastUsed") != 0) { ; Check if the fruit was used.
timeRemaining := FRUIT_DATA.Get("ReadyToUse") - A_TickCount ; Calculate the time remaining.
timeRemaining := timeRemaining >= 0 ? timeRemaining : 0 ; Ensure the remaining time is not negative.
timeRemainingText := convertTimeToMinutesSeconds(timeRemaining) ; Convert to minutes and seconds format.
setFruitTimer(timeRemainingText) ; Update the fruit timer in the GUI.
}
}
; ---------------------------------------------------------------------------------
; convertTimeToMinutesSeconds Function
; Description: Converts time from milliseconds to a format of minutes and seconds.
; Operation:
; - Calculates the number of minutes by dividing the milliseconds by the number of milliseconds in a second and then by 60.
; - Calculates the remaining seconds using the modulus operator.
; - Returns the time in "Xm Ys" format.
; Dependencies:
; - ONE_SECOND: Constant representing the number of milliseconds in one second.
; Return:
; - A string representing the time in "Xm Ys" format.
; ---------------------------------------------------------------------------------
convertTimeToMinutesSeconds(milliseconds) {
minutes := Floor(milliseconds / ONE_SECOND / 60) ; Calculate the number of minutes.
seconds := Round(Mod(milliseconds / ONE_SECOND, 60)) ; Calculate the remaining seconds.
return minutes "m " seconds "s" ; Return the time in "Xm Ys" format.
}
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; TELEPORT FUNCTIONS
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; ---------------------------------------------------------------------------------
; teleportToZone Function
; Description: Teleports to a specified zone number, updating the current action, handling the teleport menu, and verifying the teleportation.
; Operation:
; - Activates the Roblox window.
; - Updates the current action to indicate the teleportation process.
; - Closes and opens the teleport menu.
; - Clicks the search box and enters the zone name.
; - Moves the mouse to the zone's coordinates and activates mouse hover.
; - Checks the pixel color to verify teleportation.
; - Closes the teleport menu and error messages if any.
; - Returns true if the zone is already selected, otherwise false.
; Dependencies:
; - activateRoblox: Function to activate the Roblox window.
; - setCurrentAction: Function to update the current action in the GUI.
; - closeTeleportMenu: Function to close the teleport menu.
; - openTeleportMenu: Function to open the teleport menu.
; - leftClickMouseAndWait: Function to click a specified coordinate and wait.
; - COORDS: Map storing coordinates for various controls and buttons.
; - ZONE: Map storing zone numbers and their corresponding names.
; - SendText: Function to send text input.
; - MouseMove: Function to move the mouse to a specified coordinate.
; - activateMouseHover: Function to activate mouse hover.
; - PixelGetColor: Function to get the color of a pixel at a specified coordinate.
; - closeErrorMessage: Function to close error messages.
; - DELAY: Map storing delay times for various actions.
; Return:
; - true if the zone is already selected.
; - false if the zone was not already selected and the function attempted to select it.
; ---------------------------------------------------------------------------------
teleportToZone(zoneNumber) {
activateRoblox() ; Activate the Roblox window.
setCurrentAction("Teleporting to Zone " zoneNumber) ; Update the current action.
closeTeleportMenu() ; Close the teleport menu.
openTeleportMenu() ; Open the teleport menu.
leftClickMouseAndWait(COORDS["Teleport"]["Search"], "TeleportAfterSearchClicked") ; Click the search box and wait.
zoneName := ZONE.Get(zoneNumber) ; Get the zone name from the zone number.
SendText zoneName ; Enter the zone name.
Sleep DELAY["TeleportAfterSearchCompleted"] ; Wait for the search to complete.
MouseMove COORDS["Teleport"]["Zone"][1], COORDS["Teleport"]["Zone"][2] ; Move the mouse to the zone's coordinates.
activateMouseHover() ; Activate mouse hover.
pixelColour := PixelGetColor(COORDS["Teleport"]["Zone"][1], COORDS["Teleport"]["Zone"][2]) ; Get the pixel color at the zone's coordinates.
if (pixelColour == 0x5edefe) { ; Check if the zone is already selected.
closeTeleportMenu() ; Close the teleport menu.
return true ; Return true if the zone is already selected.
}
leftClickMouseAndWait(COORDS["Teleport"]["Zone"], 250) ; Click to select the zone and wait.
closeTeleportMenu() ; Close the teleport menu.
closeErrorMessage() ; Close error messages if any.
Sleep DELAY["TeleportAfterZoneClicked"] ; Wait after clicking the zone.
return false ; Return false if the zone was not already selected.
}
; ---------------------------------------------------------------------------------
; openTeleportMenu Function
; Description: Opens the teleport menu by clicking the teleport control and waits for the menu to open.
; Operation:
; - Sends a left-click event to the teleport control coordinates.
; - Waits for the menu to open.
; Dependencies:
; - COORDS: Map storing coordinates for various controls and buttons.
; - leftClickMouseAndWait: Function to click a specified coordinate and wait.
; Return: None; the function opens the teleport menu.
; ---------------------------------------------------------------------------------
openTeleportMenu() {
leftClickMouseAndWait(COORDS["Controls"]["Teleport"], "TeleportAfterOpened") ; Click the teleport control and wait.
}
; ---------------------------------------------------------------------------------
; closeTeleportMenu Function
; Description: Closes the teleport menu by clicking the close button and waits for the menu to close.
; Operation:
; - Sends a left-click event to the close button coordinates of the teleport menu.
; - Waits for the menu to close.
; Dependencies:
; - COORDS: Map storing coordinates for various controls and buttons.
; - leftClickMouseAndWait: Function to click a specified coordinate and wait.
; Return: None; the function closes the teleport menu.
; ---------------------------------------------------------------------------------
closeTeleportMenu() {
leftClickMouseAndWait(COORDS["Teleport"]["X"], "TeleportAfterMenuClosed") ; Click the close button of the teleport menu and wait.
}
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; INVENTORY FUNCTIONS
; ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
; ---------------------------------------------------------------------------------
; openInventoryMenu Function
; Description: Opens the inventory menu by sending a key event and waits for a specified delay.
; Operation:
; - Sends the "f" key event to open the inventory menu.
; - Waits for the specified delay after opening the inventory menu.
; Dependencies:
; - DELAY: Map storing delay times for various actions.
; Return: None; the function opens the inventory menu and waits for the specified delay.
; ---------------------------------------------------------------------------------
openInventoryMenu() {
SendEvent "{f}" ; Send the "f" key event to open the inventory menu.
Sleep DELAY["InventoryAfterOpened"] ; Wait for the specified delay after opening the inventory menu.
}
; ---------------------------------------------------------------------------------
; closeInventoryMenu Function
; Description: Closes the inventory menu by clicking the close button and waits for the menu to close.
; Operation:
; - Sends a left-click event to the close button coordinates of the inventory menu.
; - Waits for the menu to close.
; Dependencies:
; - COORDS: Map storing coordinates for various controls and buttons.
; - leftClickMouseAndWait: Function to click a specified coordinate and wait.
; Return: None; the function closes the inventory menu.
; ---------------------------------------------------------------------------------
closeInventoryMenu() {
leftClickMouseAndWait(COORDS["Inventory"]["X"], "InventoryAfterClosed") ; Click the close button of the inventory menu and wait.
}
; ---------------------------------------------------------------------------------
; clickInventoryTab Function
; Description: Clicks the specified inventory tab and waits for the tab to be clicked.
; Operation:
; - Determines the coordinates of the specified inventory tab based on the tab index.
; - Sends a left-click event to the tab's coordinates and waits for the tab to be clicked.
; Dependencies:
; - COORDS: Map storing coordinates for various controls and buttons.
; - leftClickMouseAndWait: Function to click a specified coordinate and wait.
; Return: None; the function clicks the specified inventory tab.
; ---------------------------------------------------------------------------------
clickInventoryTab(tabToUse) {
Switch tabToUse {
Case 2: ; Tab index for the "Items" tab.
inventoryTab := COORDS["Inventory"]["Items"]
Case 3: ; Tab index for the "Potions" tab.
inventoryTab := COORDS["Inventory"]["Potions"]
Default:
}
leftClickMouseAndWait(inventoryTab, "InventoryAfterTabClicked") ; Click the tab and wait.
}
; ---------------------------------------------------------------------------------
; useItem Function
; Description: Opens the inventory menu, navigates to the specified tab, searches for a specified item, and attempts to use the item.
; Operation:
; - Opens the inventory menu.
; - Clicks the specified inventory tab.
; - Clicks the inventory search box.
; - Searches for the specified item in the inventory.
; - If the item is found, clicks to use the item with the specified amount and options.
; - Closes the inventory menu and error message window.
; - Moves the mouse to the center of the screen.
; Dependencies:
; - openInventoryMenu: Function to open the inventory menu.
; - clickInventoryTab: Function to click the specified inventory tab.
; - clickInventorySearchBox: Function to click the inventory search box.
; - searchInventoryForItem: Function to search for the specified item in the inventory.
; - clickItem: Function to click and use the specified item.
; - closeInventoryMenu: Function to close the inventory menu.
; - closeErrorMessageWindow: Function to close the error message window.
; - moveMouseToCentreOfScreen: Function to move the mouse to the center of the screen.
; Return:
; - true if the item is found and used.
; - false if the item is not found or any step fails.
; ---------------------------------------------------------------------------------
useItem(itemToUse, tabToUse := 2, amountToUse := 1, useMaxItem := false, checkForitemFound := false) {
openInventoryMenu() ; Open the inventory menu.
clickInventoryTab(tabToUse) ; Click the specified inventory tab.
clickInventorySearchBox() ; Click the inventory search box.
if (checkForitemFound == false) {
searchInventoryForItem(tabToUse, itemToUse) ; Search for the item in the inventory.
isitemFound := true ; Assume item is found.
} else {
isitemFound := searchInventoryForItem(tabToUse, itemToUse) ; Check if the item is found.
}
if (isitemFound == true) {
clickItem(tabToUse, amountToUse, useMaxItem) ; Click to use the item with the specified amount and options.
}
closeInventoryMenu() ; Close the inventory menu.
closeErrorMessageWindow() ; Close the error message window.
moveMouseToCentreOfScreen() ; Move the mouse to the center of the screen.
return isitemFound ; Return whether the item was found and used.
}
; ---------------------------------------------------------------------------------
; clickItem Function
; Description: Clicks the specified item in the inventory, handling multiple item use and specific options like using the maximum amount.
; Operation:
; - Determines the coordinates of the specified inventory tab based on the tab index.
; - If useMaxItem is true, attempts to use the maximum amount of the item.
; - Uses OCR to find and click the "Max" button or the highest available quantity.
; - If not using the maximum amount, clicks the item the specified number of times.
; Dependencies:
; - COORDS: Map storing coordinates for various controls and buttons.
; - rightClickMouseAndWait: Function to right-click a specified coordinate and wait.
; - leftClickMouseAndWait: Function to left-click a specified coordinate and wait.
; - getOcrResult: Function to obtain OCR results from a specified area.
; Return: None; the function clicks the specified item in the inventory.
; ---------------------------------------------------------------------------------
clickItem(tabToUse, amountToUse, useMaxItem) {
; Determine the coordinates of the specified inventory tab based on the tab index.
Switch tabToUse {
Case 2: ; Tab index for the "Items" tab.
inventoryTab := COORDS["Inventory"]["Item1"]
Case 3: ; Tab index for the "Potions" tab.
inventoryTab := COORDS["Inventory"]["Potion1"]
Default:
}
multipleItemUsed := false ; Initialize the flag for multiple item usage.
; If useMaxItem is true, attempt to use the maximum amount of the item.
if (useMaxItem) {
rightClickMouseAndWait(inventoryTab, 200) ; Right-click the item to open the menu.
ocrObjectResult := getOcrResult(COORDS["OCR"]["FruitMenuStart"], COORDS["OCR"]["FruitMenuSize"], 5, false) ; Obtain text from the item menu using OCR.
ocrTextResult := ocrObjectResult.Text
; Determine the search string based on the OCR result.
searchString := ""
if InStr(ocrTextResult, "Max") {
searchString := "Max"
} else if InStr(ocrTextResult, "20") {
searchString := "20"
} else if InStr(ocrTextResult, "10") {
searchString := "10"
} else if InStr(ocrTextResult, "5") {
searchString := "5"
}
Sleep 200 ; Wait for a short period.
; If a valid search string is found, click the corresponding button.
if (searchString != "") {
try {
eatMaxButtonStart := ocrObjectResult.FindString(searchString) ; Find the position of the search string in the OCR result.
Sleep 200 ; Wait for a short period.
eatMaxButton := [COORDS["OCR"]["FruitMenuStart"][1] + eatMaxButtonStart.X + (eatMaxButtonStart.W / 2), COORDS["OCR"]["FruitMenuStart"][2] + eatMaxButtonStart.Y + (eatMaxButtonStart.H / 2)]
leftClickMouseAndWait(eatMaxButton, 200) ; Click the "Max" button.
multipleItemUsed := true ; Set the flag to indicate that multiple items were used.
}
catch {
multipleItemUsed := false ; Reset the flag if an error occurs.
}
} else {
leftClickMouseAndWait(inventoryTab, "InventoryAfterItemClicked") ; Click the item if "Max" is not available.
}
}
; If not using the maximum amount or multiple item usage was not successful, click the item the specified number of times.
if (!multipleItemUsed) {
if (amountToUse == 1) {
leftClickMouseAndWait(inventoryTab, "InventoryAfterItemClicked") ; Click the item once.
} else {
Loop amountToUse {
leftClickMouseAndWait(inventoryTab, "InventoryBetweenMultipleItemsUsed") ; Click the item multiple times.
}
}
}
}
; ---------------------------------------------------------------------------------
; clickInventorySearchBox Function
; Description: Clicks the search box in the inventory and waits for the action to be completed.
; Operation:
; - Sends a left-click event to the search box coordinates in the inventory.
; - Waits for the search box to be clicked.
; Dependencies:
; - COORDS: Map storing coordinates for various controls and buttons.
; - leftClickMouseAndWait: Function to click a specified coordinate and wait.
; Return: None; the function clicks the search box in the inventory.
; ---------------------------------------------------------------------------------
clickInventorySearchBox() {
leftClickMouseAndWait(COORDS["Inventory"]["Search"], "InventoryAfterSearchClicked") ; Click the search box and wait.
}
; ---------------------------------------------------------------------------------
; closeErrorMessageWindow Function
; Description: Attempts to close an error message window by clicking a specified coordinate and waits for a specified time.
; Operation:
; - Uses a loop to click the error message close button twice.
; - Waits for a specified time after the error message is closed.
; Dependencies:
; - COORDS: Map storing coordinates for various controls and buttons.
; - leftClickMouseAndWait: Function to click a specified coordinate and wait.
; - waitTime: Function to wait for a specified time.
; Return: None; the function attempts to close the error message and waits for the specified time.
; ---------------------------------------------------------------------------------