Hi guy's i'm trying to sort this Table, but without any succes.
if (cmd == "!show") then
n=1
local disp = ""
disp = disp.."\t\tNr:\tTime:\tNick:\r\n"
for i,v in UserHubTime do
local T = UserHubTime["Total"]
disp = disp.."\t\t"..n..".\t"..T.." min\t"..i.."\r\n"
n = n + 1
end
user:SendData(sBot, disp)
end
end
Thx allready L8trs
Buy, entering all your table entries in a non assocciative table, like this
test = {}
for i, v un UserHUbTime do
tinsert(test,{ i,v["Total"] }
end
sort(test, function(a,b) return (a[2] > b[2]) end)
or something like that... in one of my elder scripts i also found this... but not usefull actually.. but it works
--max is the maximum number of shown entries
function GetUserMaxTime()
TCopy={}
for i,v in UserHubTime do
TCopy[i]=v
end
local msgfromtxt ="\r\n"
for i = 1,Max do
var1 = 0
for index, value in TCopy do
value = tonumber (value)
if value > var1 then
var1 = value
userm = index
end
end
local tmp = TCopy[userm]
local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
TCopy[userm]=0
msgfromtxt = msgfromtxt.." "..i.." - "..userm.." :: "..months.." Months, "..days.." Days, "..hours.." Hours, "..minutes.." Min ( "..tmp.." min ).\r\n"
end
return msgfromtxt
end
there seems to be something wrong with this Line:
tinsert(test,{i,v["Total"]}
try
tinsert(test,{i,UserHubTime.Total})
or tinsert(test,{i,UserHubTime["Total"]})
else just try around.. or just
send me a copy of the table of how it looks like
Hi there,,
Optimus,.. i'm not sure to get what you wish,.... but,
maybe try:
---
for i,v in UserHubTime do
local T = UserHubTime
disp = disp.."\t\t"..n..".\t"..T.." Total min\t"..i.."\r\n"
n = n + 1
end
---
If i get your idea,,,... :)
l8tr,, ;)
kk Chilla i will send you a copy in PM.
And thx Guibs for having a look also... Structure is just abit more complex :D
lol,,
ok,... :o)
Ok solved now by Chilla... Big Thanks
Code:
function GetUserMaxTime()
TCopy={}
for i,v in UserHubTime do
tinsert(TCopy,{i,v.Total})
end
sort(TCopy,function(a,b) return (a[2] > b[2]) end)
local msgfromtxt ="\r\n"
for i = 1,Max do
if TCopy then
msgfromtxt = msgfromtxt..""..i.." - "..TCopy[1].." :: "..TCopy[2].."\r\n"
end
end
return msgfromtxt
end
looks very nice, yep,...
Thks to both of you to have post this syntax,... :)
l8tr,, ;)
Hihi, no prob Guibs m8
Btw, this was the reason for the Sorting Structure...
Having a abnormal Table *lol*
{{
["[SU]Guibs"]={2},
["[SU]Me"]={3},
},
{
["Session"]=56,
["Total"]=101,
},
{
["Session"]=34,
["Total"]=86,
},
}
h? h? h?
yup, i get your '["Total"]' problem,, now,.. ;)