-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFocusTarget.lua
More file actions
367 lines (320 loc) · 10.4 KB
/
FocusTarget.lua
File metadata and controls
367 lines (320 loc) · 10.4 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
_addon.name = 'FocusTarget'
_addon.author = 'Dean James (Xurion of Bismarck)'
_addon.command = 'ft'
_addon.version = '2.0.0'
config = require('config')
texts = require('texts')
images = require('images')
res = require('resources')
local defaults = {}
defaults.pos = {}
defaults.pos.x = 0
defaults.pos.y = 0
defaults.title = true
defaults.abilities = true
defaults.autofocus = false
settings = config.load(defaults)
tracking = nil
setup = {}
setup.flags = {}
setup.flags.draggable = false
title = texts.new(setup)
title:bg_visible(false)
title:size(20)
title:stroke_transparency(100)
title:stroke_width(1)
title:color(252, 245, 173)
title:bold(true)
title:text('FOCUS TARGET')
title_offset_x = -2
title_offset_y = -6
hp_text = texts.new(setup)
hp_text:bg_visible(false)
hp_text:size(16)
hp_text:stroke_width(1)
hp_text:bold(false)
hp_text_offset_x = 0
hp_text_offset_y = 25
hp_bg = images.new(setup)
hp_bg:repeat_xy(1, 1)
hp_bg:draggable(false)
hp_bg:fit(true)
hp_bg_offset_x = 0
hp_bg_offset_y = 56
hp_percentage = images.new(setup)
hp_percentage:path('')
hp_percentage_offset_x = 1
hp_percentage_offset_y = 57
hp_percentage_max_width = 376
ability_icon = images.new(setup)
ability_icon:repeat_xy(1, 1)
ability_icon:draggable(false)
ability_icon:fit(true)
ability_icon_offset_x = 0
ability_icon_offset_y = 70
ability_text = texts.new(setup)
ability_text:bg_visible(false)
ability_text:size(14)
ability_text:stroke_transparency(100)
ability_text:stroke_width(1)
ability_text_offset_x = 30
ability_text_offset_y = 75
hp_colors = {
player = { 233, 255, 253 },
npc = { 185, 255, 163 },
unclaimed = { 252, 245, 173 },
claimed = { 255, 189, 193 },
outclaimed = { 252, 173, 252 },
cfh = { 255, 208, 106 },
defeated = { 152, 152, 152 }
}
hp_stroke_colors = {
player = { 30, 107, 76 },
npc = { 50, 87, 38 },
unclaimed = { 173, 150, 54 },
claimed = { 190, 84, 84 },
outclaimed = { 156, 44, 156 },
cfh = { 166, 115, 0 },
defeated = { 72, 72, 72 }
}
element_colors = {
[0] = { 240, 110, 110 }, --fire
[1] = { 77, 212, 219 }, --ice
[2] = { 126, 211, 33 }, --wind
[3] = { 237, 161, 34 }, --earth
[4] = { 212, 57, 198 }, --lightning
[5] = { 69, 134, 210 }, --water
[6] = { 255, 255, 255 }, --light
[7] = { 0, 0, 0 }, --dark
[15] = { 255, 255, 255 }, --none
tp = { 181, 47, 22 },
item = { 133, 79, 24 }
}
function with_element_color(element, text)
if not element then return text end
return ' \\cs(' .. table.concat(element_colors[element], ",") .. ')' .. text .. '\\cr'
end
function set_ability(ability, element, target)
local text = with_element_color(element, ability)
if target then
text = text .. ' → ' .. target
end
local img = element or 'none' -- Have to use transparent image due to bug in images lib
ability_icon:path(windower.addon_path .. 'img/elements/' .. img .. '.png')
ability_text:text(text)
end
function is_player(target)
return target.spawn_type == 1 or target.spawn_type == 13
end
function set_hp_colors_for_target(target)
local color = 'unclaimed'
if is_player(target) then
color = 'player'
elseif target.spawn_type == 2 or target.spawn_type == 14 then
color = 'npc'
elseif target.spawn_type == 16 then
if target.status == 1 then
local party = windower.ffxi.get_party()
local party_claimed = false
for i = 0, 5 do
if not party['p' .. i] then
break
end
if party['p' .. i].mob.id == target.claim_id then
party_claimed = true
break
end
end
if party_claimed then
color = 'claimed'
else
color = 'outclaimed'
end
elseif target.status == 2 or target.status == 3 then
color = 'defeated'
end
end
hp_bg:path(windower.addon_path .. 'img/' .. color .. '-hp.png')
hp_percentage:color(hp_colors[color][1], hp_colors[color][2], hp_colors[color][3])
hp_text:color(hp_colors[color][1], hp_colors[color][2], hp_colors[color][3])
hp_text:stroke_color(hp_stroke_colors[color][1], hp_stroke_colors[color][2], hp_stroke_colors[color][3])
end
function set_hp_percentage(percent)
hp_percentage:size(hp_percentage_max_width * (percent / 100), 10)
end
function show()
if settings.title then
title:show()
end
hp_text:show()
hp_bg:show()
hp_percentage:show()
if settings.abilities then
ability_text:show()
ability_icon:show()
end
end
function hide()
title:hide()
hp_text:hide()
hp_bg:hide()
hp_percentage:hide()
ability_text:hide()
ability_icon:hide()
end
function update_position()
title:pos(settings.pos.x + title_offset_x, settings.pos.y + title_offset_y)
hp_text:pos(settings.pos.x + hp_text_offset_x, settings.pos.y + hp_text_offset_y)
hp_bg:pos(settings.pos.x + hp_bg_offset_x, settings.pos.y + hp_bg_offset_y)
hp_percentage:pos(settings.pos.x + hp_percentage_offset_x, settings.pos.y + hp_percentage_offset_y)
ability_text:pos(settings.pos.x + ability_text_offset_x, settings.pos.y + ability_text_offset_y)
ability_icon:pos(settings.pos.x + ability_icon_offset_x, settings.pos.y + ability_icon_offset_y)
end
commands = {}
commands.focus = function()
local target = windower.ffxi.get_mob_by_target('t')
if not target or target.id == tracking then
tracking = nil
hide()
return
end
set_ability('')
tracking = target.id
end
commands.pos = function(x, y)
if not x or not y then
windower.add_to_chat(8, 'Current x and y position: ' .. settings.pos.x .. ', ' .. settings.pos.y)
windower.add_to_chat(8, 'To set the position: //ft pos 100 200')
return
end
settings.pos.x = tonumber(x)
settings.pos.y = tonumber(y)
settings:save()
update_position()
end
commands.title = function()
settings.title = not settings.title
settings:save()
end
commands.abilities = function()
settings.abilities = not settings.abilities
settings:save()
windower.add_to_chat(8, 'Ability and spell display: ' .. tostring(settings.abilities))
end
commands.spells = commands.abilities
commands.autofocus = function()
settings.autofocus = not settings.autofocus
settings:save()
windower.add_to_chat(8, 'Auto focus: ' .. tostring(settings.autofocus))
end
commands.help = function()
windower.add_to_chat(8, 'FocusTarget:')
windower.add_to_chat(8, ' //ft - toggle focus on current target')
windower.add_to_chat(8, ' //ft pos - show the current x and y position')
windower.add_to_chat(8, ' //ft pos <x> <y> - set the x and y position')
windower.add_to_chat(8, ' //ft title - toggle the display of the FOCUS TARGET title')
windower.add_to_chat(8, ' //ft abilities - toggle the display of spells and abilities')
windower.add_to_chat(8, ' //ft spells - alias command for //ft abilities')
windower.add_to_chat(8, ' //ft autofocus - automatically focus your current target')
windower.add_to_chat(8, ' //ft help - display this help')
end
windower.register_event('addon command', function(command, ...)
command = command and command:lower() or 'focus'
if commands[command] then
commands[command](...)
else
commands.help()
end
end)
windower.register_event("target change", function(index)
if settings.autofocus then
if index == 0 then
tracking = nil
hide()
else
commands.focus()
end
end
end)
windower.register_event("prerender", function()
if not tracking then return end
local focused_target = windower.ffxi.get_mob_by_id(tracking)
if not focused_target then
tracking = nil
return
end
-- target is not in range, or dead and depopped
if not focused_target.valid_target then
tracking = nil
hide()
return
end
set_hp_colors_for_target(focused_target)
set_hp_percentage(focused_target.hpp)
hp_text:text(focused_target.hpp .. '% ' .. focused_target.name)
show()
end)
windower.register_event('zone change', function ()
hide()
end)
windower.register_event('action', function (action)
if not tracking or action.actor_id ~= tracking then return end
--[[
Categories:
3: Finish weapon skill
4: Finish casting spell
5: Finish item use
7: Begin weapon skill or TP move
8: Begin spell casting or interrupt casting, param 24931 = start, param 28787 = interupt
9: Begin item use or interrupt usage
11: Finish TP move
]]
if action.category == 7 or action.category == 8 then
-- Interupted
if action.param == 28787 then
set_ability('')
return
end
-- Casting new spell or TP move
local ability_id = action.targets[1].actions[1].param
local ability_name
local ability_element
if action.category == 7 then
ability_element = 'tp'
local actor = windower.ffxi.get_mob_by_id(action.actor_id)
-- Detect if the actor is a player or mob
if is_player(actor) then
ability_name = res.weapon_skills[ability_id].name
else
ability_name = res.monster_abilities[ability_id].name
end
else
ability_name = res.spells[ability_id].name
ability_element = res.spells[ability_id].element
end
local target_id = action.targets[1].id
local target_name
if target_id ~= tracking then
target_name = windower.ffxi.get_mob_by_id(target_id).name
end
set_ability(ability_name, ability_element, target_name)
elseif action.category == 9 then
-- Interupted
if action.param == 28787 then
set_ability('')
return
end
-- Using item
local item_id = action.targets[1].actions[1].param
local item_name = res.items[item_id].name
local target_id = action.targets[1].id
local target_name
if target_id ~= tracking then
target_name = windower.ffxi.get_mob_by_id(target_id).name
end
set_ability(item_name, 'item', target_name)
elseif action.category == 3 or action.category == 4 or action.category == 5 or action.category == 11 then
set_ability('')
end
end)
update_position()