This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Kill Counter.lua
86 lines (67 loc) · 1.85 KB
/
Kill Counter.lua
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
init start
-- local SCRIPT_VERSION = '1.1.1'
-- If set to true, will save kill count to $chardb so that it is persisted
-- throughout different sessions.
local saveToDB = true
-- DO NOT EDIT BELOW THIS LINE --
-- We don't want to override the object because that'd delete all data in
-- killCount.creatures
if killCount == nil then
killCount = {
creatures = {},
lastRan = $timems
}
killCount.set = function(count, ...)
local names = table.each({...}, string.lower)
for _, v in ipairs(names) do
killCount.creatures[v] = count
if killCount.saveToDB then
$chardb:setvalue('killCount', v, count)
end
end
end
killCount.add = function(addAmount, ...)
local names = table.each({...}, string.lower)
for _, v in ipairs(names) do
killCount.set(killCount.get(v) + addAmount, v)
end
end
killCount.reset = function(...)
killCount.set(0, ...)
end
killCount.get = function(...)
local names = table.each({...}, string.lower)
local count = 0
for _, v in ipairs(names) do
local cCount = killCount.creatures[v]
if cCount == nil then
cCount = 0
killCount.set(cCount, v)
end
count = count + cCount
end
return count
end
if saveToDB then
-- Thanks to @Lucas Terra for implementing database iterators for the
-- sole purpose of making this script better. Lucas, you rock!
foreach $chardb:sectionvalue v 'killCount' do
killCount.set(v.value, v.name)
end
end
end
-- We only set saveToDB now because else it would cause unnecessary updates
-- queried to the database when we first read it.
killCount.saveToDB = saveToDB
init end
auto(100)
foreach newmessage m do
if m.type == MSG_INFO then
local creature = m.content:match(REGEX_LOOT)
if creature then
killCount.add(1, creature)
end
end
end
-- You're welcome, Leonardo
killCount.lastRan = $timems