-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_samurai_ws.lua
More file actions
202 lines (170 loc) · 5.62 KB
/
Copy pathauto_samurai_ws.lua
File metadata and controls
202 lines (170 loc) · 5.62 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
_addon.name = 'auto_samurai_ws'
_addon.author = 'TheGwardian'
_addon.version = '1.9'
_addon.commands = {'samws','asw','asws'}
-- Localize frequently-used functions for faster access
local ffxi_get_player = windower.ffxi.get_player
local send_command = windower.send_command
local register_event = windower.register_event
local os_clock = os.clock
local string_format = string.format
-- Load texts library for status display
local texts = require('texts')
-- Player reference will be fetched fresh each time
local player = nil
-- ###################### USER CONFIGURATION SECTION ######################
-- ***** Change ONLY the variable below to set your default Weaponskill *****
local ws_name = "Tachi: Fudo" -- <<<<< Change this to any weaponskill name
-- Optionally change these to equipset numbers (Gearswap)
local equip_pre = 11 -- Gearset before WS
local equip_post = 12 -- Gearset after WS
local tp_threshold = 2500 -- Minimum TP required to WS (default: 2500)
local wait_pre = 1 -- Wait before using WS (seconds)
local wait_post = 2 -- Wait after using WS (seconds)
local ws_cooldown = 1.0 -- Cooldown between WS attempts (seconds)
-- ###################### END USER CONFIGURATION ###########################
local ws_command = nil
local last_ws_time = 0
-- Create status display window
local status_display = texts.new('${current_content}', {
pos = {
x = 0,
y = 200
},
bg = {
alpha = 200,
red = 0,
green = 0,
blue = 0,
visible = true
},
flags = {
bold = true,
draggable = true
},
text = {
size = 10,
font = 'Consolas',
alpha = 255,
red = 255,
green = 255,
blue = 255
},
padding = 8
})
-- Update display text
local function update_display()
local current_tp = 0
if player and player.vitals then
current_tp = player.vitals.tp or 0
end
local display_text = string_format(
'Auto Samurai WS\n' ..
'─────────────────────\n' ..
'WS: %s\n' ..
'TP Threshold: %d\n' ..
'Current TP: %d\n' ..
'─────────────────────',
ws_name,
tp_threshold,
current_tp
)
status_display.current_content = display_text
end
-- Build the Windower command string for the weaponskill macro
local function rebuild_ws_command()
if not ws_name or ws_name == "" then
return
end
-- Pre-build command once at initialization
ws_command = string_format('input /equipset %d; wait %d; input /ws "%s" <t>; wait %d; input /equipset %d',
equip_pre, wait_pre, ws_name, wait_post, equip_post)
end
-- Executes the weaponskill macro if ready
local function execute_ws()
send_command(ws_command)
last_ws_time = os_clock()
end
-- Main logic: Checks player status and TP, triggers WS when conditions are met
-- Using prerender for fastest response time
register_event('prerender', function()
-- Fetch player fresh each frame to ensure we get updated data
player = ffxi_get_player()
if not player then
return
end
-- Update display every frame
update_display()
-- Early exit: Only WS if engaged with an enemy (status == 1)
if player.status ~= 1 then
return
end
-- Check cooldown first (cheaper check)
if (os_clock() - last_ws_time) < ws_cooldown then
return
end
-- Check TP threshold
local vitals = player.vitals
if not vitals then
return
end
local tp = vitals.tp
if tp and tp >= tp_threshold then
execute_ws()
end
end)
-- Weaponskill name mapping (short name -> full name)
local ws_map = {
fudo = "Tachi: Fudo",
shoha = "Tachi: Shoha",
kasha = "Tachi: Kasha",
gekko = "Tachi: Gekko",
yukikaze = "Tachi: Yukikaze",
jinpu = "Tachi: Jinpu",
kagero = "Tachi: Kagero",
rana = "Tachi: Rana",
kaiten = "Tachi: Kaiten",
enpi = "Tachi: Enpi",
hobaku = "Tachi: Hobaku",
goten = "Tachi: Goten",
ageha = "Tachi: Ageha",
koki = "Tachi: Koki",
}
-- Command handler for weaponskill switching
register_event('addon command', function(cmd, ...)
if not cmd then
windower.add_to_chat(207, '[auto_samurai_ws] Current WS: ' .. ws_name)
windower.add_to_chat(207, '[auto_samurai_ws] Usage: //asws <ws_name> or //asws status')
return
end
cmd = cmd:lower()
if cmd == 'status' then
windower.add_to_chat(207, '[auto_samurai_ws] Current WS: ' .. ws_name)
windower.add_to_chat(207, '[auto_samurai_ws] TP Threshold: ' .. tp_threshold)
windower.add_to_chat(207, '[auto_samurai_ws] Cooldown: ' .. ws_cooldown .. 's')
return
end
-- Check if it's a short name in the map
local new_ws = ws_map[cmd]
-- If not in map, treat as full weaponskill name
if not new_ws then
new_ws = table.concat({cmd, ...}, ' ')
-- Capitalize first letter of each word
new_ws = new_ws:gsub("(%a)([%w_']*)", function(first, rest)
return first:upper() .. rest:lower()
end)
end
ws_name = new_ws
rebuild_ws_command()
update_display()
windower.add_to_chat(158, '[auto_samurai_ws] Weaponskill changed to: ' .. ws_name)
end)
-- Build initial WS macro once at load time
rebuild_ws_command()
-- Show display on load
status_display:show()
update_display()
-- Reset cooldown on zone change
register_event('zone change', function()
last_ws_time = 0
end)