Is there a way to preserve the order of an ArrayList using Lua?
I do not want the ArrayList sorted.
I need to be able to display the ArrayList in the same order as they were added.
Here is the working script I am using:
* sample output (using FUSS SMAUG server)
* trigger and alias
I read the following in a Lua reference manual:
Is there a better way to do this?
Will the ArrayList order still be random if I use another scripting language like VBScript?
I do not want the ArrayList sorted.
I need to be able to display the ArrayList in the same order as they were added.
Here is the working script I am using:
* sample output (using FUSS SMAUG server)
Average Xp Total Xp # Death List, R.I.P.
------------------------------------------------
3 5 2 The gnoll
4 7 2 The kobold
3 5 2 The naga
3 5 2 The minotaur
------------------------------------------------
11 22 Death Count: 8* trigger and alias
<triggers>
<trigger
enabled="y"
group="death"
match="^You receive (\d*) experience points\.$"
regexp="y"
send_to="12"
sequence="100"
>
<send>local mob, cnt, tot
if not ArrayExists("arrcnt") then ArrayCreate("arrcnt") end
if not ArrayExists("arrtot") then ArrayCreate("arrtot") end
mob = string.match(GetRecentLines(2), "(.*) is DEAD!!.*")
cnt = ArrayGet("arrcnt", mob)
tot = ArrayGet("arrtot", mob)
if cnt == nil then ArraySet("arrcnt", mob, 1) else ArraySet("arrcnt", mob, cnt + 1) end
if tot == nil then ArraySet("arrtot", mob, %1) else ArraySet("arrtot", mob, tot + %1) end</send>
</trigger>
</triggers><aliases>
<alias
match="rip"
enabled="y"
group="death"
send_to="12"
sequence="100"
>
<send>local n = string.char(10)
local cnt, tot, avg
local cntsum = 0
local totsum = 0
local avgsum = 0
if ArrayExists("arrcnt") and ArrayExists("arrtot") then
AnsiNote(n .. ANSI(33) .. " Average Xp Total Xp # Death List, R.I.P. ")
AnsiNote( ANSI(37) .. "------------------------------------------------")
for k, v in pairs(ArrayList("arrcnt")) do
cnt = ArrayGet("arrcnt", k)
tot = ArrayGet("arrtot", k)
avg = tot / cnt
cntsum = cnt + cntsum
totsum = tot + totsum
avgsum = avg + avgsum
AnsiNote(string.format(ANSI(32) .. " %%10.0f %%10.0f %%3.0f %s",
avg, tot, cnt, k))
end
AnsiNote(ANSI(37) .. "----------------------")
AnsiNote(string.format(ANSI(32) .. " %%10.0f %%10.0f " .. ANSI(33) .. " Death Count: %d",
avgsum, totsum, cntsum))
else
ColourNote("tan", "", n .. "Error: death list is empty")
end</send>
</alias>
</aliases>I read the following in a Lua reference manual:
Quote:
There is no guarantee as to the order in which keys will be stored in a table when using dictionaries so the order of retrieval of keys using pairs() is not guaranteed.
There is no guarantee as to the order in which keys will be stored in a table when using dictionaries so the order of retrieval of keys using pairs() is not guaranteed.
Is there a better way to do this?
Will the ArrayList order still be random if I use another scripting language like VBScript?