Here is my finished script for the forum :)~
* commands
rip ~ death list in order of kill
rip m ~ death list sorted by mob
rip c ~ death list sorted by count
rip t ~ death list sorted by total
rip a ~ death list sorted by average
ripremove ~ remove the last mob in order of kill
ripremove the giant lizard ~ remove the giant lizard
ripreset ~ reset the death list
* sample input
the dwarven worker is DEAD!!
You receive 90 experience points.
* sample output
Average Xp Total Xp # Death List, R.I.P.
------------------------------------------------
89 2,307 26 the dwarven worker
407 10,588 26 the dwarven guard
344 4,127 12 the giant lizard
259 3,629 14 the barracks guard
13 188 14 the dwarven miner
416 3,331 8 the dwarven mine leader
----------------------
1,529 24,170 Death Count: 100
* script (1 trigger, 3 aliases)
note: copy to clipboard, then file > import > clipboard
<triggers>
<trigger
enabled="y"
group="death"
match="^You receive (\d+) experience points\.$"
regexp="y"
send_to="12"
sequence="100"
>
<send>if not death then death = {} end
local m = string.match(GetRecentLines(2), "(.*) is DEAD!!")
local record = death[m]
if not record then
record = {mob = m, count = 0, total = 0}
death[m] = record
table.insert(death, record)
end
record.count = record.count + 1
record.total = record.total + %1</send>
</trigger>
</triggers>
<aliases>
<alias
match="^rip(?: (.*)){0,1}$"
enabled="y"
group="death"
regexp="y"
send_to="12"
sequence="100"
>
<send>if not death then
AnsiNote("\\n" .. ANSI(33) .. "Error: death list is empty")
else
AnsiNote("\\n" .. ANSI(33) ..
" Average Xp Total Xp # Death List, R.I.P. ")
AnsiNote(ANSI(37) .. string.rep("-", 48))
local t = {}
for k, v in pairs(death) do t[k] = v end
if "%1" == "m" then
table.sort(t, function(a, b) return (a.mob < b.mob) end)
elseif "%1" == "c" then
table.sort(t, function(a, b) return (a.count < b.count) end)
elseif "%1" == "t" then
table.sort(t, function(a, b) return (a.total < b.total) end)
elseif "%1" == "a" then
table.sort(t, function(a, b)
return (a.total / a.count < b.total / b.count) end)
end
local sumcount, sumtotal, sumaverage = 0, 0, 0
local function round(n) return math.floor(n + 0.5) end
local function comma(n)
local a = n
local b
while true do
a, b = string.gsub(a, "^(%d+)(%d%d%d)", "%%1,%%2")
if b == 0 then break end
end
return a
end
for k, v in ipairs(t) do
sumcount = sumcount + v.count
sumtotal = sumtotal + v.total
sumaverage = sumaverage + v.total / v.count
AnsiNote(string.format(ANSI(32) .. " %%10s %%10s %%3d %s",
comma(round(v.total / v.count)), comma(v.total), v.count, v.mob))
end
AnsiNote(ANSI(37) .. string.rep("-", 22))
AnsiNote(string.format(ANSI(32) .. " %%10s %%10s " .. ANSI(33) ..
"Death Count: %d", comma(round(sumaverage)), comma(sumtotal), sumcount))
end</send>
</alias>
<alias
match="^ripremove(?: (.*)){0,1}$"
enabled="y"
group="death"
regexp="y"
send_to="12"
sequence="100"
>
<send>if not death then
AnsiNote("\\n" .. ANSI(33) .. "Error: death list is empty")
else
if "%1" == "" then
death[death[#death].mob] = nil
table.remove(death, #death)
else
death["%1"] = nil
for k, v in ipairs(death) do
if v.mob == "%1" then table.remove(death, k) end
end
end
if #death == 0 then death = nil end
Execute("rip")
end</send>
</alias>
<alias
match="ripreset"
enabled="y"
group="death"
send_to="12"
sequence="100"
>
<send>death = nil
AnsiNote("\\n" .. ANSI(33) .. "Death List Reset")</send>
</alias>
</aliases>
* test input
/death = {}
death["the dwarven worker"] = {mob = "the dwarven worker", count = 26, total = 2307}
death["the dwarven guard"] = {mob = "the dwarven guard", count = 26, total = 10588}
death["the giant lizard"] = {mob = "the giant lizard", count = 12, total = 4127}
death["the barracks guard"] = {mob = "the barracks guard", count = 14, total = 3629}
death["the dwarven miner"] = {mob = "the dwarven miner", count = 14, total = 188}
death["the dwarven mine leader"] = {mob = "the dwarven mine leader", count = 8, total = 3331}
table.insert(death, death["the dwarven worker"])
table.insert(death, death["the dwarven guard"])
table.insert(death, death["the giant lizard"])
table.insert(death, death["the barracks guard"])
table.insert(death, death["the dwarven miner"])
table.insert(death, death["the dwarven mine leader"])
Here is the same script in zMUD that I posted back in 2005:
http://forums.zuggsoft.com/forums/viewtopic.php?t=21358 |