-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKilltracker.lua
More file actions
166 lines (138 loc) · 4.47 KB
/
Copy pathKilltracker.lua
File metadata and controls
166 lines (138 loc) · 4.47 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
_addon.name = 'KillTracker'
_addon.author = 'Meliora'
_addon.version = '1.0.1'
_addon.commands = {'kt', 'killtracker'}
-----------------------------------------------------------
-- Description
-- Basic Kill tracker for DRK unlock quest.
-----------------------------------------------------------
-- Imports
-----------------------------------------------------------
config = require('config')
texts = require('texts')
packets = require('packets')
-----------------------------------------------------------
-- Defaults
-----------------------------------------------------------
local defaults = {
kills = 0,
pos = { x = 500, y = 200 },
bg = T {
alpha = 255, red = 0, green = 0, blue = 0,
visible = false,
},
flags = T {
bold = true
},
text = {
font = 'Consolas',
size = 12,
bold = true,
stroke = {
width = 1,
alpha = 255, red = 0, green = 0, blue = 0
},
red = 255, green = 255, blue = 255,
},
}
settings = config.load(defaults)
-----------------------------------------------------------
-- Text object
-----------------------------------------------------------
local counter = texts.new(settings)
counter:pos(settings.pos.x, settings.pos.y)
counter:font(settings.text.font)
counter:size(settings.text.size)
counter:bold(settings.text.bold)
counter:stroke_width(settings.text.stroke.width)
counter:stroke_alpha(settings.text.stroke.alpha)
counter:show()
-----------------------------------------------------------
-- Helpers
-----------------------------------------------------------
local function get_equipped_weapon()
local eq = windower.ffxi.get_items().equipment
if not eq or not eq.main_bag or not eq.main or eq.main == 0 then
return nil
end
local item = windower.ffxi.get_items(eq.main_bag, eq.main)
if not item or not item.id or item.id == 0 then
return nil
end
local res_items = require('resources').items
local entry = res_items[item.id]
if not entry or not entry.en then
return nil
end
return entry.en
end
local function is_bringer_equipped()
local name = get_equipped_weapon()
if not name then return false end
name = name:lower()
return name == 'chaosbringer' or name == 'deathbringer'
end
-----------------------------------------------------------
-- HUD update
-----------------------------------------------------------
local function update_display()
local c = settings.kills
local remaining = math.max(100 - c, 0)
local r,g,b = 255,255,255
if c >= 100 then r,g,b = 0,255,0
elseif c >= 80 then r,g,b = 255,0,0
elseif c >= 60 then r,g,b = 255,128,0
elseif c >= 40 then r,g,b = 255,255,0
elseif c >= 20 then r,g,b = 128,255,255
end
local weapon_name = get_equipped_weapon() or 'None'
local hud = string.format(
"Counter for (%s)\n\n\\cs(%d,%d,%d)Kills: %d\\cr\nRemaining: %d",
weapon_name, r,g,b, c, remaining
)
counter:text(hud)
if c >= 100 then
windower.add_to_chat(207, "[KillTracker] 100 kills reached! You're done.")
end
end
-----------------------------------------------------------
-- Events
-----------------------------------------------------------
windower.register_event('incoming chunk', function(id, data)
-- Equipment Changed (Update HUD)
if id == 0x050 then
update_display()
return
end
if id ~= 0x029 then return end
-- Kill detected, update counter
local p = packets.parse('incoming', data)
if not p or not p['Message'] then return end
local player = windower.ffxi.get_player()
if not player or not player.id then return end
if is_bringer_equipped()
and (p['Message'] == 6 or p['Message'] == 20)
and p['Actor'] == player.id then
settings.kills = settings.kills + 1
config.save(settings)
update_display()
windower.add_to_chat(207,
string.format('Kill registered (%d/100).', settings.kills))
end
end)
windower.register_event('addon command', function(cmd)
cmd = cmd and cmd:lower() or ''
if cmd == 'reset' then
settings.kills = 0
config.save(settings)
update_display()
windower.add_to_chat(207, 'Counter reset.')
elseif cmd == 'show' then
counter:show()
elseif cmd == 'hide' then
counter:hide()
else
windower.add_to_chat(207, 'Commands: //kt reset | show | hide')
end
end)
update_display()