-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScripsFarming.lua
More file actions
1255 lines (1168 loc) · 44.8 KB
/
ScripsFarming.lua
File metadata and controls
1255 lines (1168 loc) · 44.8 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
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
import("System.Numerics")
--[=====[
[[SND Metadata]]
author: 'pot0to (https://ko-fi.com/pot0to) || Updated by: loonsies'
version: 0.5.9
description: Crafter Scrips - Script for Crafting & Turning In
plugin_dependencies:
- Artisan
- vnavmesh
configs:
CrafterClass:
description: Select the crafting class to use for turn-ins and crafting tasks.
is_choice: true
choices: ["Carpenter", "Blacksmith", "Armorer", "Goldsmith", "Leatherworker", "Weaver", "Alchemist", "Culinarian"]
ScripColor:
default: "Orange"
description: Type of scrip to use for crafting / purchases (Orange, Purple).
is_choice: true
choices: ["Orange", "Purple"]
ArtisanListId:
default: ""
description: Id of Artisan list for crafting all the intermediate materials (eg black star, claro walnut lumber, etc.).
ItemToBuy:
default: "Crafter's Command Materia XII"
description: Name of the item to purchase using scrips.
HomeCommand:
default: "/li auto"
description: Command to hide somewhere (e.g., /li auto for inn). Leave blank to stay in Solution Nine.
HubCity:
default: "Gridania"
description: Main city to use as a hub for turn-ins and purchases.
is_choice: true
choices: ["Ul'dah", "Limsa", "Gridania", "Solution Nine"]
Potion:
default: ""
description: Potion to use. Leave blank to disable.
Food:
default: ""
description: Food to use. Leave blank to disable.
Retainers:
default: true
description: Automatically interact with retainers for ventures.
Retainers_Amount:
default: 4
description: Amount of retainers - potential slots to keep free in inventory.
GrandCompanyTurnIn:
default: true
description: Do Grand Company TurnIns.
Do_Repair:
default: false
description: Enable repairs. Options - false, "npc", "self"
Repair_Npc_Name:
default: "Loporrit Mender"
description: Name of the NPC to repair with if using NPC repairs.
Repair_Threshold:
default: 33
description: Durability threshold percentage for repairs.
[[End Metadata]]
--]=====]
--[[
********************************************************************************
* Crafter Scrips (7.4 Patch) *
* Version 0.5.9 *
********************************************************************************
Created by: pot0to (https://ko-fi.com/pot0to)
Updated by: loonsies (personal script, mostly used https://github.com/MinnuVerse/SnD/blob/d579d3061348fe338a8af6268f0bcc842412e01f/Crafters/CraftersScrips.lua as a reference for updating, but that script wasn't working for me)
Crafts orange scrip item matching whatever class you're on, turns it in, buys
stuff, repeat.
********************************************************************************
* Required Plugins *
********************************************************************************
1. SND
2. Artisan
3. Vnavmesh
4. Optional: Lifestream (for hiding in inn)
--------------------------------------------------------------------------------------------------------------------------------------------------------------
]]
--#region Settings (Configured via SND Metadata)
-- Configuration variables - loaded at runtime in init()
local CrafterClass, ScripColor, ArtisanListId, ItemToBuy, HomeCommand, HubCity
local Potion, Food, Retainers, Retainers_Amount, GrandCompanyTurnIn
local Do_Repair, Repair_Npc_Name, Repair_Threshold
local MinInventoryFreeSlots
--#endregion Settings
--[[
********************************************************************************
* Code: Don't touch this unless you know what you're doing *
********************************************************************************
]]
local ScripsFarming = {
State = nil,
AtInn = false,
SelectedHubCity = nil,
CrafterScripId = nil,
RecipeId = nil,
ItemId = nil,
SelectedItemToBuy = nil,
ArtisanTimeoutStartTime = 0,
SelectTurnInPage = false,
StopFlag = false
}
-- State ID constants
local StateId = {
ready = 1,
crafting = 2,
goToHubCity = 3,
turnIn = 4,
scripExchange = 5,
processRetainers = 6,
gcTurnIn = 7
}
function HasPlugin(name)
for plugin in luanet.each(Svc.PluginInterface.InstalledPlugins) do
if plugin.InternalName == name and plugin.IsLoaded then
Dalamud.Log(string.format("[CraftersScrips] Plugin '%s' found in InstalledPlugins.", name))
return true
end
end
Dalamud.Log(string.format("[CraftersScrips] Plugin '%s' not found in InstalledPlugins list.", name))
return false
end
function IsPlayerCasting()
return Svc.Condition[CharacterCondition.casting]
end
function GetCharacterCondition(condition)
return Svc.Condition[condition]
end
function HasStatusId(targetId)
local statusList = Player.Status
if not statusList then
return false
end
for i = 0, statusList.Count - 1 do
local status = statusList:get_Item(i)
if status and status.StatusId == targetId then
return true
end
end
return false
end
function IsInZone(zoneId)
return Svc.ClientState.TerritoryType == zoneId
end
function IsAddonReady(addonName)
return Addons.GetAddon(addonName).Ready
end
function GetDistanceToPoint(dX, dY, dZ)
local player = Svc.ClientState.LocalPlayer
if not player or not player.Position then
return math.huge
end
local px = player.Position.X
local py = player.Position.Y
local pz = player.Position.Z
local dx = dX - px
local dy = dY - py
local dz = dZ - pz
local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
return distance
end
function GetDistanceToTarget()
if not Entity or not Entity.Player then
return nil
end
if not Entity.Target then
return nil
end
-- Retrieve positions
local playerPos = Entity.Player.Position
local targetPos = Entity.Target.Position
-- Calculate the distance manually using Euclidean formula
local dx = playerPos.X - targetPos.X
local dy = playerPos.Y - targetPos.Y
local dz = playerPos.Z - targetPos.Z
local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
return distance
end
function DistanceBetween(px1, py1, pz1, px2, py2, pz2)
local dx = px2 - px1
local dy = py2 - py1
local dz = pz2 - pz1
return math.sqrt(dx * dx + dy * dy + dz * dz)
end
-- Inlined data tables (no external dependencies)
ScripExchangeItems = {
{
itemName = "Condensed Solution",
categoryMenu = 1,
subcategoryMenu = 10,
listIndex = 0,
price = 125
},
{
itemName = "Crafter's Competence Materia XII",
categoryMenu = 2,
subcategoryMenu = 2,
listIndex = 0,
price = 500
},
{
itemName = "Crafter's Cunning Materia XII",
categoryMenu = 2,
subcategoryMenu = 2,
listIndex = 1,
price = 500
},
{
itemName = "Crafter's Command Materia XII",
categoryMenu = 2,
subcategoryMenu = 2,
listIndex = 2,
price = 500
},
{
itemName = "Crafter's Competence Materia XI",
categoryMenu = 2,
subcategoryMenu = 1,
listIndex = 0,
price = 250
},
{
itemName = "Crafter's Cunning Materia XI",
categoryMenu = 2,
subcategoryMenu = 1,
listIndex = 1,
price = 250
},
{
itemName = "Crafter's Command Materia XI",
categoryMenu = 2,
subcategoryMenu = 1,
listIndex = 2,
price = 250
},
{
itemName = "Artful Afflatus Ring",
categoryMenu = 0,
subcategoryMenu = 10,
listIndex = 24,
price = 75,
oneAtATime = true
}
}
local OrangeCrafterScripId = 41784
OrangeScripRecipes = {
{
className = "Carpenter",
classId = 8,
itemName = "Rarefied Claro Walnut Fishing Rod",
itemId = 44190,
recipeId = 35787
},
{
className = "Blacksmith",
classId = 9,
itemName = "Rarefied Ra'Kaznar Round Knife",
itemId = 44196,
recipeId = 35793
},
{
className = "Armorer",
classId = 10,
itemName = "Rarefied Ra'Kaznar Ring",
itemId = 44202,
recipeId = 35799
},
{
className = "Goldsmith",
classId = 11,
itemName = "Rarefied Black Star Earrings",
itemId = 44208,
recipeId = 35805
},
{
className = "Leatherworker",
classId = 12,
itemName = "Rarefied Gargantuaskin Hat",
itemId = 44214,
recipeId = 35817
},
{
className = "Weaver",
classId = 13,
itemName = "Rarefied Thunderyard Silk Culottes",
itemId = 44220,
recipeId = 35817
},
{
className = "Alchemist",
classId = 14,
itemName = "Rarefied Claro Walnut Flat Brush",
itemId = 44226,
recipeId = 35823
},
{
className = "Culinarian",
classId = 15,
itemName = "Rarefied Tacos de Carne Asada",
itemId = 44232,
recipeId = 35829
}
}
local PurpleCrafterScripId = 33913
PurpleScripRecipes = {
{
className = "Carpenter",
classId = 8,
itemName = "Rarefied Claro Walnut Grinding Wheel",
itemId = 44189,
recipeId = 35786
},
{
className = "Blacksmith",
classId = 9,
itemName = "Rarefied Ra'Kaznar War Scythe",
itemId = 44195,
recipeId = 35792
},
{
className = "Armorer",
classId = 10,
itemName = "Rarefied Ra'Kaznar Greaves",
itemId = 44201,
recipeId = 35798
},
{
className = "Goldsmith",
classId = 11,
itemName = "Rarefied Ra'Kaznar Orrery",
itemId = 44207,
recipeId = 35804
},
{
className = "Leatherworker",
classId = 12,
itemName = "Rarefied Gargantuaskin Trouser",
itemId = 44213,
recipeId = 35816
},
{
className = "Weaver",
classId = 13,
itemName = "Rarefied Thunderyards Silk Gloves",
itemId = 44219,
recipeId = 35816
},
{
className = "Alchemist",
classId = 14,
itemName = "Rarefied Gemdraught of Vitality",
itemId = 44225,
recipeId = 35822
},
{
className = "Culinarian",
classId = 15,
itemName = "Rarefied Stuffed Peppers",
itemId = 44231,
recipeId = 35828
}
}
local HubCities = {
{
zoneName = "Limsa",
zoneId = 129,
aethernet = {
aethernetZoneId = 129,
aethernetName = "Hawkers' Alley",
x = -213.61108,
y = 16.739136,
z = 51.80432
},
retainerBell = { x = -123.88806, y = 17.990356, z = 21.469421, requiresAethernet = false },
scripExchange = { x = -258.52585, y = 16.2, z = 40.65883, requiresAethernet = true }
},
{
zoneName = "Gridania",
zoneId = 132,
aethernet = {
aethernetZoneId = 133,
aethernetName = "Leatherworkers' Guild & Shaded Bower",
x = 131.9447,
y = 4.714966,
z = -29.800903
},
retainerBell = { x = 168.72, y = 15.5, z = -100.06, requiresAethernet = true },
scripExchange = { x = 142.15, y = 13.74, z = -105.39, requiresAethernet = true }
},
{
zoneName = "Ul'dah",
zoneId = 130,
aethernet = {
aethernetZoneId = 131,
aethernetName = "Sapphire Avenue Exchange",
x = 101,
y = 9,
z = -112
},
retainerBell = { x = 171, y = 15, z = -102, requiresAethernet = true },
scripExchange = { x = 142.68, y = 13.75, z = -104.59, requiresAethernet = true }
},
{
zoneName = "Solution Nine",
zoneId = 1186,
aethernet = {
aethernetZoneId = 1186,
aethernetName = "Nexus Arcade",
x = -161,
y = -1,
z = 21
},
retainerBell = { x = -152.465, y = 0.660, z = -13.557, requiresAethernet = true },
scripExchange = { x = -158.019, y = 0.922, z = -37.884, requiresAethernet = true }
}
}
local ClassList = {
crp = { classId = 8, className = "Carpenter" },
bsm = { classId = 9, className = "Blacksmith" },
arm = { classId = 10, className = "Armorer" },
gsm = { classId = 11, className = "Goldsmith" },
ltw = { classId = 12, className = "Leatherworker" },
wvr = { classId = 13, className = "Weaver" },
alc = { classId = 14, className = "Alchemist" },
cul = { classId = 15, className = "Culinarian" }
}
CharacterCondition = {
craftingMode = 5,
casting = 27,
occupiedInQuestEvent = 32,
occupiedMateriaExtractionAndRepair = 39,
executingCraftingSkill = 40,
craftingModeIdle = 41,
betweenAreas = 45,
occupiedSummoningBell = 50,
beingMoved = 70
}
local function init()
-- Load configuration from SND metadata at runtime
CrafterClass = Config.Get("CrafterClass")
ScripColor = Config.Get("ScripColor")
ArtisanListId = Config.Get("ArtisanListId")
ItemToBuy = Config.Get("ItemToBuy")
HomeCommand = Config.Get("HomeCommand")
HubCity = Config.Get("HubCity")
Potion = Config.Get("Potion")
Food = Config.Get("Food")
Retainers = Config.Get("Retainers")
Retainers_Amount = Config.Get("Retainers_Amount")
GrandCompanyTurnIn = Config.Get("GrandCompanyTurnIn")
Do_Repair = Config.Get("Do_Repair")
Repair_Npc_Name = Config.Get("Repair_Npc_Name")
Repair_Threshold = Config.Get("Repair_Threshold")
-- Calculate MinInventoryFreeSlots based on Retainers_Amount
MinInventoryFreeSlots = Retainers and (Retainers_Amount * 2) or 5
ScripsFarming.State = StateId.ready
ScripsFarming.AtInn = false
ScripsFarming.SelectedHubCity = nil
ScripsFarming.CrafterScripId = nil
ScripsFarming.RecipeId = nil
ScripsFarming.ItemId = nil
ScripsFarming.SelectedItemToBuy = nil
ScripsFarming.ArtisanTimeoutStartTime = 0
ScripsFarming.SelectTurnInPage = false
ScripsFarming.StopFlag = false
RequiredPlugins = {
"Artisan",
"vnavmesh"
}
-- add optional plugins
if HomeCommand ~= "" then
table.insert(RequiredPlugins, "Lifestream")
end
if Retainers then
table.insert(RequiredPlugins, "AutoRetainer")
end
if GrandCompanyTurnIn then
table.insert(RequiredPlugins, "Deliveroo")
end
for _, plugin in ipairs(RequiredPlugins) do
if not HasPlugin(plugin) then
yield(
"/e Missing required plugin: " ..
plugin .. ", stopping script. Please install the required plugin and try again."
)
ScripsFarming.StopFlag = true
end
end
yield("/at y")
local classId = 0
for _, class in pairs(ClassList) do
if CrafterClass == class.className then
classId = class.classId
end
end
if classId == 0 then
Dalamud.Log("Could not find crafter class: " .. CrafterClass)
yield("/snd stop")
end
if ScripColor == "Orange" then
ScripsFarming.CrafterScripId = OrangeCrafterScripId
ScripRecipes = OrangeScripRecipes
elseif ScripColor == "Purple" then
ScripsFarming.CrafterScripId = PurpleCrafterScripId
ScripRecipes = PurpleScripRecipes
else
Dalamud.Log("Cannot recognize crafter scrip color: " .. ScripColor)
yield("/snd stop")
end
ScripsFarming.ItemId = 0
ScripsFarming.RecipeId = 0
for _, data in ipairs(ScripRecipes) do
if data.classId == classId then
ScripsFarming.ItemId = data.itemId
ScripsFarming.RecipeId = data.recipeId
end
end
Dalamud.Log("[ScripsFarming] Using Crafter Scrip ID: " .. tostring(ScripsFarming.ItemId))
for _, item in ipairs(ScripExchangeItems) do
if item.itemName == ItemToBuy then
ScripsFarming.SelectedItemToBuy = item
end
end
if ScripsFarming.SelectedItemToBuy == nil then
Dalamud.Log("Could not find " .. ItemToBuy .. " on the list of scrip exchange items.")
ScripsFarming.StopFlag = true
end
for _, city in ipairs(HubCities) do
if city.zoneName == HubCity then
ScripsFarming.SelectedHubCity = city
ScripsFarming.SelectedHubCity.aetheryte = Excel.GetRow("TerritoryType", city.zoneId).Aetheryte.PlaceName
.Name
end
end
if ScripsFarming.SelectedHubCity == nil then
Dalamud.Log("Could not find hub city: " .. HubCity)
yield("/vnav stop")
end
Dalamud.Log("[ScripsFarming] Starting script")
end
local function waitForArtisan()
while IPC.Artisan.GetEnduranceStatus() and not Player.Available do
Dalamud.Log("[ScripsFarming] Waiting for Artisan to finish crafting...")
yield("/wait 1")
end
end
local function checkAlreadyInHouse()
if (GetCharacterCondition(CharacterCondition.occupiedSummoningBell)) then
return true
end
yield("/target Summoning Bell")
yield("/wait 1")
target1 = Entity.Target and Entity.Target.Name
yield("/target " .. Repair_Npc_Name)
yield("/wait 1")
target2 = Entity.Target and Entity.Target.Name
if target1 == "Summoning Bell" and target2 == Repair_Npc_Name then
Dalamud.Log("[ScripsFarming] Already in house")
return true
else
Dalamud.Log("[ScripsFarming] not Already in house")
return false
end
end
local function IsNeedRepair()
if type(Do_Repair) ~= "string" then
return false
else
Repair_Threshold = tonumber(Repair_Threshold) or 99
if NeedsRepair(tonumber(Repair_Threshold)) then
if string.find(string.lower(Do_Repair), "self") then
return "self"
elseif string.find(string.lower(Do_Repair), "npc") then
return "npc"
end
else
return false
end
end
end
local function RepairExtractReduceCheck()
local repair_token = IsNeedRepair()
Dalamud.Log("[ScripsFarming] Repair token: " .. tostring(repair_token))
if repair_token then
if repair_token == "self" then
while not Player.Available do
yield("/wait 0.2")
end
Dalamud.Log("[ScripsFarming] Attempting to self repair...")
while CanCharacterDoActions() and not IsAddonReady("Repair") and not IsAddonReady("Repair") do
yield('/gaction "Repair"')
repeat
if not CanCharacterDoActions() then
return
end
yield("/wait 0.2")
until Player.Available
end
yield("/wait 0.1")
yield("/pcall Repair true 0")
repeat
yield("/wait 0.2")
until IsAddonReady("SelectYesno") and IsAddonReady("SelectYesno")
yield("/pcall SelectYesno true 0")
repeat
yield("/wait 0.2")
until not IsAddonReady("SelectYesno")
while GetCharacterCondition(39) do
yield("/wait 0.2")
end
while IsAddonReady("Repair") do
yield('/gaction "Repair"')
repeat
yield("/wait 0.2")
until Player.Available
end
if NeedsRepair() then
Dalamud.Log("[ScripsFarming] Self Repair failed!")
Dalamud.Log("[ScripsFarming] Please place the appropriate Dark Matter in your inventory,")
Dalamud.Log("[ScripsFarming] Or find a NPC mender.")
return false
else
Dalamud.Log("[ScripsFarming] Repairs complete!")
end
elseif repair_token == "npc" then
while not IsAddonReady("Repair") do
yield("/target " .. Repair_Npc_Name)
yield("/wait 0.2")
yield("/interact")
end
repeat
yield("/pcall Repair true 0")
yield("/wait 0.2")
until IsAddonReady("SelectYesno") and IsAddonReady("SelectYesno")
yield("/pcall SelectYesno true 0")
repeat
yield("/wait 0.2")
until not IsAddonReady("SelectYesno")
while GetCharacterCondition(39) do
yield("/wait 0.2")
end
while IsAddonReady("Repair") do
yield('/gaction "Repair"')
repeat
yield("/wait 0.2")
until Player.Available
end
if NeedsRepair() then
Dalamud.Log("[ScripsFarming] Self Repair failed!")
return false
end
return true
end
end
return true
end
local function TeleportTo(aetheryteName)
yield("/tp " .. aetheryteName)
yield("/wait 1") -- wait for casting to begin
while GetCharacterCondition(CharacterCondition.casting) do
Dalamud.Log("[ScripsFarming] Casting teleport...")
yield("/wait 1")
end
yield("/wait 1") -- wait for that microsecond in between the cast finishing and the transition beginning
while GetCharacterCondition(CharacterCondition.betweenAreas) do
Dalamud.Log("[ScripsFarming] Teleporting...")
yield("/wait 1")
end
yield("/wait 1")
end
function OutOfCrystals()
local crystalsRequired1 = tonumber(Addons.GetAddon("RecipeNote"):GetNode(1, 57, 83, 2).Text)
local crystalsInInventory1 = tonumber(Addons.GetAddon("RecipeNote"):GetNode(1, 57, 83, 3).Text)
if crystalsRequired1 ~= nil and crystalsInInventory1 ~= nil and crystalsRequired1 > crystalsInInventory1 then
return true
end
local crystalsRequired2 = tonumber(Addons.GetAddon("RecipeNote"):GetNode(1, 57, 82, 2).Text)
local crystalsInInventory2 = tonumber(Addons.GetAddon("RecipeNote"):GetNode(1, 57, 82, 3).Text)
if crystalsRequired2 ~= nil and crystalsInInventory2 ~= nil and crystalsRequired2 > crystalsInInventory2 then
return true
end
return false
end
local function OutOfMaterials()
while not IsAddonReady("RecipeNote") do
if not IsAddonReady("RecipeNote") then
Dalamud.Log("[ScripsFarming] RecipeNote no longer visible")
return false
end
yield("/wait 0.1")
end
for i = 0, 5 do
local materialCountNQ = Addons.GetAddon("RecipeNote"):GetNode(1, 57, 88, 89 + i, 10, 12).Text
local materialCountHQ = Addons.GetAddon("RecipeNote"):GetNode(1, 57, 88, 89 + i, 13, 15).Text
local materialRequirement = Addons.GetAddon("RecipeNote"):GetNode(1, 57, 88, 89 + i, 4).Text
if materialCountNQ ~= "" and materialCountHQ ~= "" and materialRequirement ~= "" then
if tonumber(materialCountNQ) + tonumber(materialCountHQ) < tonumber(materialRequirement) then
return true
end
end
end
if OutOfCrystals() then
Dalamud.Log("Out of crystals. Stopping script.")
ScripsFarming.StopFlag = true
return true
end
return false
end
local function Crafting()
if
(IPC.Lifestream.IsBusy()) or GetCharacterCondition(CharacterCondition.occupiedInQuestEvent)
then
yield("/wait 1")
return
elseif not ScripsFarming.AtInn and checkAlreadyInHouse() and HomeCommand ~= "" then
ScripsFarming.AtInn = true
return
elseif not ScripsFarming.AtInn and HomeCommand ~= "" then
yield(HomeCommand)
while IPC.Lifestream.IsBusy() do
yield("/wait 1")
end
ScripsFarming.AtInn = true
return
end
local slots = Inventory.GetFreeInventorySlots()
if IPC.Artisan.GetEnduranceStatus() then
if IsNeedRepair() then
Dalamud.Log("[ScripsFarming] Setting Artisan endurance status to false")
ArtisanSetEnduranceStatus(false)
waitForArtisan()
RepairExtractReduceCheck()
yield("/wait 1")
ScripsFarming.State = StateId.ready
Dalamud.Log("[ScripsFarming] State Change: Ready")
end
return
elseif slots == nil then
Dalamud.Log("Inventory.GetFreeInventorySlots() is nil. WHYYY???")
elseif (IPC.Artisan.IsListRunning() and not IPC.Artisan.IsListPaused()) or IsAddonReady("Synthesis") then
yield("/wait 1")
elseif slots <= MinInventoryFreeSlots then
Dalamud.Log("[ScripsFarming] Out of inventory space")
if Inventory.GetCollectableItemCount(ScripsFarming.ItemId, 1) > 0 then
if IsAddonReady("RecipeNote") then
Dalamud.Log("[ScripsFarming] Closing RecipeNote to transition to TurnIn")
yield("/pcall RecipeNote true -1")
yield("/wait 1")
elseif not GetCharacterCondition(CharacterCondition.craftingMode) then
ScripsFarming.State = StateId.turnIn
Dalamud.Log("[ScripsFarming] State Change: TurnIn")
end
else
-- Wait for inventory to free up or for craft to finish
yield("/wait 1")
return
end
elseif IsAddonReady("RecipeNote") and OutOfMaterials() then
Dalamud.Log("[ScripsFarming] Out of materials")
if not ScripsFarming.StopFlag then
if slots > MinInventoryFreeSlots and (ScripsFarming.ArtisanTimeoutStartTime == 0) then
Dalamud.Log("[ScripsFarming] Attempting to craft intermediate materials")
yield("/artisan lists " .. ArtisanListId .. " start")
ScripsFarming.ArtisanTimeoutStartTime = os.clock()
elseif os.clock() - ScripsFarming.ArtisanTimeoutStartTime > 5 then
Dalamud.Log("[ScripsFarming] Artisan not starting, StopFlag = true")
-- if artisan has not entered crafting mode within 15s of being called,
-- then you're probably out of mats so just stop the script
Dalamud.Log("Artisan took too long to start. Are you out of intermediate mat materials?")
ScripsFarming.StopFlag = true
end
end
elseif Retainers and IPC.AutoRetainer.AreAnyRetainersAvailableForCurrentChara() and Inventory.GetFreeInventorySlots() > MinInventoryFreeSlots then
ScripsFarming.State = StateId.processRetainers
Dalamud.Log("[ScripsFarming] State Change: ProcessingRetainers")
return
elseif not IsAddonReady("Synthesis") then -- GetCharacterCondition(CharacterCondition.craftingMode) then
RepairExtractReduceCheck()
Dalamud.Log(
"[ScripsFarming] Attempting to craft " ..
(slots - MinInventoryFreeSlots) .. " of recipe #" .. ScripsFarming.RecipeId
)
ScripsFarming.ArtisanTimeoutStartTime = 0
IPC.Artisan.CraftItem(ScripsFarming.RecipeId, slots - MinInventoryFreeSlots)
yield("/wait 5")
if IPC.Artisan.GetEnduranceStatus() and GetCharacterCondition(5) then
ScripsFarming.ArtisanTimeoutStartTime = 0
end
else
Dalamud.Log("[ScripsFarming] Else condition hit")
end
end
local function GoToHubCity()
if not Player.Available then
yield("/wait 1")
elseif not IsInZone(ScripsFarming.SelectedHubCity.zoneId) then
TeleportTo(ScripsFarming.SelectedHubCity.aetheryte)
else
ScripsFarming.State = StateId.ready
Dalamud.Log("[ScripsFarming] State Change: Ready")
end
end
local function TurnIn()
ScripsFarming.AtInn = false
if Inventory.GetCollectableItemCount(ScripsFarming.ItemId, 1) == 0 or Inventory.GetItemCount(ScripsFarming.CrafterScripId) >= 3800 then
if IsAddonReady("CollectablesShop") then
yield("/callback CollectablesShop true -1")
else
ScripsFarming.State = StateId.ready
Dalamud.Log("[ScripsFarming] State Change: Ready")
end
elseif
not IsInZone(ScripsFarming.SelectedHubCity.zoneId) and
(not ScripsFarming.SelectedHubCity.scripExchange.requiresAethernet or
(ScripsFarming.SelectedHubCity.scripExchange.requiresAethernet and
not IsInZone(ScripsFarming.SelectedHubCity.aethernet.aethernetZoneId)))
then
ScripsFarming.State = StateId.goToHubCity
Dalamud.Log("[ScripsFarming] State Change: GoToHubCity")
elseif
ScripsFarming.SelectedHubCity.scripExchange.requiresAethernet and
(not IsInZone(ScripsFarming.SelectedHubCity.aethernet.aethernetZoneId) or
GetDistanceToPoint(
ScripsFarming.SelectedHubCity.scripExchange.x,
ScripsFarming.SelectedHubCity.scripExchange.y,
ScripsFarming.SelectedHubCity.scripExchange.z
) >
DistanceBetween(
ScripsFarming.SelectedHubCity.aethernet.x,
ScripsFarming.SelectedHubCity.aethernet.y,
ScripsFarming.SelectedHubCity.aethernet.z,
ScripsFarming.SelectedHubCity.scripExchange.x,
ScripsFarming.SelectedHubCity.scripExchange.y,
ScripsFarming.SelectedHubCity.scripExchange.z
) +
10)
then
if not IPC.Lifestream.IsBusy() then
Dalamud.Log("[ScripsFarming] TurnIn /li " .. ScripsFarming.SelectedHubCity.aethernet.aethernetName)
yield("/li " .. ScripsFarming.SelectedHubCity.aethernet.aethernetName)
yield("/wait 4")
end
elseif IsAddonReady("TelepotTown") then
Dalamud.Log("[ScripsFarming] TelepotTown open")
yield("/callback TelepotTown false -1")
elseif
GetDistanceToPoint(
ScripsFarming.SelectedHubCity.scripExchange.x,
ScripsFarming.SelectedHubCity.scripExchange.y,
ScripsFarming.SelectedHubCity.scripExchange.z
) > 1
then
if not (IPC.vnavmesh.PathfindInProgress() or IPC.vnavmesh.IsRunning()) then
Dalamud.Log("[ScripsFarming] Path not running")
IPC.vnavmesh.PathfindAndMoveTo(Vector3(
ScripsFarming.SelectedHubCity.scripExchange.x,
ScripsFarming.SelectedHubCity.scripExchange.y,
ScripsFarming.SelectedHubCity.scripExchange.z
),
false
)
end
else
if IPC.vnavmesh.PathfindInProgress() or IPC.vnavmesh.IsRunning() then
yield("/vnav stop")
end
if not IsAddonReady("CollectablesShop") then
local appraiser = Entity.GetEntityByName("Collectable Appraiser")
if appraiser then
appraiser:SetAsTarget()
appraiser:Interact()
end
else
if ScripColor == "Purple" then
Dalamud.Log("[ScripsFarming] Selecting purple scrip item")
yield("/callback CollectablesShop true 12 1")
yield("/wait 0.5")
else
Dalamud.Log("[CraftersScrips] Selecting orange scrip item")
end
yield("/callback CollectablesShop true 15 0") -- submit
yield("/wait 1")
end
end
end
local function ScripExchange()
if Inventory.GetItemCount(ScripsFarming.CrafterScripId) < ScripsFarming.SelectedItemToBuy.price or Inventory.GetFreeInventorySlots() <= MinInventoryFreeSlots then
if IsAddonReady("InclusionShop") then
yield("/callback InclusionShop true -1")
elseif Inventory.GetCollectableItemCount(ScripsFarming.ItemId, 1) > 0 and Inventory.GetItemCount(ScripsFarming.CrafterScripId) < 3800 then
ScripsFarming.SelectTurnInPage = false
ScripsFarming.State = StateId.turnIn
Dalamud.Log("[ScripsFarming] State Change: TurnIn")
elseif Inventory.GetFreeInventorySlots() <= MinInventoryFreeSlots then
ScripsFarming.SelectTurnInPage = false
ScripsFarming.State = StateId.gcTurnIn
Dalamud.Log("[ScripsFarming] State Change: GCTurnIn")
else
ScripsFarming.SelectTurnInPage = false
ScripsFarming.State = StateId.ready
Dalamud.Log("[ScripsFarming] State Change: Ready")
end
elseif
not IsInZone(ScripsFarming.SelectedHubCity.zoneId) and
(not ScripsFarming.SelectedHubCity.scripExchange.requiresAethernet or
(ScripsFarming.SelectedHubCity.scripExchange.requiresAethernet and
not IsInZone(ScripsFarming.SelectedHubCity.aethernet.aethernetZoneId)))
then
ScripsFarming.SelectTurnInPage = false
ScripsFarming.State = StateId.goToHubCity
Dalamud.Log("[ScripsFarming] State Change: GoToHubCity")
elseif
ScripsFarming.SelectedHubCity.scripExchange.requiresAethernet and
(not IsInZone(ScripsFarming.SelectedHubCity.aethernet.aethernetZoneId) or
GetDistanceToPoint(
ScripsFarming.SelectedHubCity.scripExchange.x,
ScripsFarming.SelectedHubCity.scripExchange.y,
ScripsFarming.SelectedHubCity.scripExchange.z
) >
DistanceBetween(
ScripsFarming.SelectedHubCity.aethernet.x,
ScripsFarming.SelectedHubCity.aethernet.y,
ScripsFarming.SelectedHubCity.aethernet.z,
ScripsFarming.SelectedHubCity.scripExchange.x,
ScripsFarming.SelectedHubCity.scripExchange.y,
ScripsFarming.SelectedHubCity.scripExchange.z
) +
10)
then