PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: ConejoDelMal on 03 November, 2004, 18:16:03

Title: help needed
Post by: ConejoDelMal on 03 November, 2004, 18:16:03
I have this script for a graphic users/share, but it doesnt saves the info, so everytime i restart scripts, it all goes blank...
is it possible to put an automatic save each time you check the graph?

--#-- GraphBot by Herodes
-- Working Version (but after repeating the cmd x 5 times u don't get any refresh on the tables ...)
-- fixed correction of kb, mb, gb, tb display
-- now the user count centers on top of the column...
-- input from NotRambitWombat made it even shorter.. :)
-- Tried to get the extra tables working but I couldn't .. :(
-- Making progress on this ... Added tables tried to get them to work again ..
-- It gets the values to the tables but it has an error (indicated in script) [ 8:20 pm 30-5-2004 ]
-- After heavy tutoring session with plop, The Script is working as Intented !
--##-- thanx to All the ppl who helped ... bonus to plop  5:02 am 3-6-2004
--- Returns a graph of the present user count along with the present share and the time
--- Remembers up to three previous graphs and displays simultaneously
---** Trying the command while you are the only user turns up with error (fixed //  1:29 pm 3-6-2004 // )
---** ...  no worries wait for someone to join and then try it again ... (fixed //  1:29 pm 3-6-2004 // )

gBot = "-=RoboCop?=-" -- you may edit the bot to whatever u want
graphcmd = "!graph" -- you may edit the command to whatever u want
fullcell = "   :?:\t"
emptycell = "\t"
count = 0
tTab = { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };
tTable = { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };
tCol1= { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };
tCol2= { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };
tCol3= { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };


----------------------------------------------------------------------- the command
function DataArrival(user, data)
   if (strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data)-1)
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if cmd~=nil then
         if cmd==graphcmd then
if (frmHub:GetUsersCount() == 1) then
user:SendData(gBot, "Where did everybody go ?")
else TransferAll()
end
         end
      end
   end
end
----------------------------------------------------------------------- place the values in table and return table
function AddValues()
   tTable = {}
   GetNumbers()
   if usrC > 1 then
      local pivot = 11 - floor(usrC / maxU * 10)
      for i = 1,10 do
         if ( i < pivot ) then
            tTable[i] = emptycell
         elseif ( i == pivot ) then
            tTable[i] = userCount
         else
            tTable[i] = fullcell
         end
      end
   end
   if usrC == 1 then
      SendToAll(gBot, "Where did everybody go ?")
   end
   tTable[11] = Time
   tTable[12] = hubshrS
   return tTable
end
----------------------------------------------------------------------- push the values in a > b
function FixTable(table1, table2)
   for i, v in table1 do
      i = tonumber(i)
      if i == nil then
         i = 1
      end
      table2[i]= v
   end
end
----------------------------------------------------------------------- logical route for handling the tables ..
function TransferAll()
if count == 1 then
FixTable(tCol2, tCol3)
FixTable(tCol1, tCol2)
FixTable(tTable, tCol1)
AddValues()
GiveGraph()
else
DoTranferTab()
AddValues()
GiveGraph()
end
end
----------------------------------------------------------------------- straigth run ? pushing the tables ..
function DoTranferTab()
   if tTable[11] ~= "\t" then
      if tCol3[11] == "\t"then
         FixTable(tCol2, tCol3)
         FixTable(tCol1, tCol2)
         FixTable(tTable, tCol1)
      elseif tCol2[11] == "\t" then
         FixTable(tCol1, tCol2)
         FixTable(tTable, tCol1)
      elseif tCol1[11] == "\t" and count == 1 then
         FixTable(tTable, tCol1)
         count = 0
      end
   end
count = count +1
end
----------------------------------------------------------------------- the graph showing the values of all tables
function GiveGraph()
   tMsg = "\r\n\t\t\t- "..frmHub:GetHubName().." - Gr?fico de Users/Share -"
   tMsg = tMsg.."\r\n - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -o-0-o- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
   tMsg = tMsg.."\r\n -> Share\t:\t"..tTable[12].."\t\t"..tCol1[12].."\t\t"..tCol2[12].."\t\t"..tCol3[12]
   tMsg = tMsg.."\r\n 100% ("..maxU..")\t\t"..tTable[1].."\t"..tCol1[1].."\t"..tCol2[1].."\t"..tCol3[1]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[2].."\t"..tCol1[2].."\t"..tCol2[2].."\t"..tCol3[2]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[3].."\t"..tCol1[3].."\t"..tCol2[3].."\t"..tCol3[3]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[4].."\t"..tCol1[4].."\t"..tCol2[4].."\t"..tCol3[4]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[5].."\t"..tCol1[5].."\t"..tCol2[5].."\t"..tCol3[5]
   tMsg = tMsg.."\r\n 50% ("..midU..")\t\t"..tTable[6].."\t"..tCol1[6].."\t"..tCol2[6].."\t"..tCol3[6]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[7].."\t"..tCol1[7].."\t"..tCol2[7].."\t"..tCol3[7]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[8].."\t"..tCol1[8].."\t"..tCol2[8].."\t"..tCol3[8]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[9].."\t"..tCol1[9].."\t"..tCol2[9].."\t"..tCol3[9]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[10].."\t"..tCol1[10].."\t"..tCol2[10].."\t"..tCol3[10]
   tMsg = tMsg.."\r\n- 0% (0). . . . . . . . . . \t. .:?:. . . . . . . . . . . . .\t. .:?:. . . . . . . . . . . . .\t. .:?:. . . . . . . . . . . . .\t. .:?:. . . . . . . . . . . . ."
   tMsg = tMsg.."\r\n ->  Time\t:            "..tTable[11].."\t             "..tCol1[11].."\t             "..tCol2[11].."\t             "..tCol3[11]
   SendToAll(gBot, tMsg)
end
----------------------------------------------------------------------- get the data (numbers) needed, format and return them
function GetNumbers()
   Time, userCount, maxU, hubshare = "\t"
   Time = date("%H")..":"..date("%M")..":"..date("%S")
   usrC = frmHub:GetUsersCount()
   userCount = AddSpacesToKey(usrC)
   maxU = frmHub:GetMaxUsers()
   midU = maxU/2
   local thubshare = format("%0.1f", ( frmHub:GetCurrentShareAmount() / 1024))
   hubshrS = thubshare.." kb"
   if tonumber(thubshare) >= 1024 and tonumber(thubshare) < (1024^2) then
      hubshrS = format("%0.1f", ( frmHub:GetCurrentShareAmount() / (1024^2))).." mb"
   elseif tonumber(thubshare) >= (1024^2) and tonumber(thubshare) < (1024^3) then
      hubshrS = format("%0.1f", ( frmHub:GetCurrentShareAmount() / (1024^3))).." gb"
   elseif tonumber(thubshare) >= (1024^3) then
      hubshrS = format("%0.1f", ( frmHub:GetCurrentShareAmount() / (1024^4))).." tb"
   end
   return Time, userCount, maxU, midU, hubshare, usrC, hubshrS
end

----------------------------------------------------------------------- adding appropriate number of spaces to a string
function AddSpacesToKey(data)
   local ratio = (5 - strlen(data))
   local tcell = strrep(" ", ratio)..data.."\t"
   return tcell
end

Thx in Advance  :))
Title:
Post by: ConejoDelMal on 10 November, 2004, 04:03:15
somebody....please!!
Title:
Post by: patamon90 on 10 November, 2004, 07:38:34
I think this tread should have been started in "Finished Scripts" if you need help with it..
Title:
Post by: blackwings on 10 November, 2004, 09:07:54
I have added a save to file (Graph/graph.log), which saves when the !graph command is used

I haven't tested it, but I think it should work =--#-- GraphBot by Herodes
-- Working Version (but after repeating the cmd x 5 times u don't get any refresh on the tables ...)
-- fixed correction of kb, mb, gb, tb display
-- now the user count centers on top of the column...
-- input from NotRambitWombat made it even shorter.. :)
-- Tried to get the extra tables working but I couldn't .. :(
-- Making progress on this ... Added tables tried to get them to work again ..
-- It gets the values to the tables but it has an error (indicated in script) [ 8:20 pm 30-5-2004 ]
-- After heavy tutoring session with plop, The Script is working as Intented !
--##-- thanx to All the ppl who helped ... bonus to plop  5:02 am 3-6-2004
--- Returns a graph of the present user count along with the present share and the time
--- Remembers up to three previous graphs and displays simultaneously
---** Trying the command while you are the only user turns up with error (fixed //  1:29 pm 3-6-2004 // )
---** ...  no worries wait for someone to join and then try it again ... (fixed //  1:29 pm 3-6-2004 // )
--- added a save to file by blackwings

gBot = "-=RoboCop?=-" -- you may edit the bot to whatever u want
graphcmd = "!graph" -- you may edit the command to whatever u want
fullcell = "   :?:\t"
emptycell = "\t"
fFile = "graph.log"
fFolder = "Graph"
count = 0
tTab = { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };
tTable = { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };
tCol1= { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };
tCol2= { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };
tCol3= { [1] = "\t", [2] = "\t", [3] = "\t", [4] = "\t", [5] = "\t", [6] = "\t", [7] = "\t", [8] = "\t", [9] = "\t", [10] = "\t", [11] = "\t", [12] = "\t", };


----------------------------------------------------------------------- the command
function DataArrival(user, data)
   if (strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data)-1)
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if cmd~=nil then
         if cmd==graphcmd then
if (frmHub:GetUsersCount() == 1) then
user:SendData(gBot, "Where did everybody go ?")
else TransferAll()
end
         end
      end
   end
end
----------------------------------------------------------------------- place the values in table and return table
function AddValues()
   tTable = {}
   GetNumbers()
   if usrC > 1 then
      local pivot = 11 - floor(usrC / maxU * 10)
      for i = 1,10 do
         if ( i < pivot ) then
            tTable[i] = emptycell
         elseif ( i == pivot ) then
            tTable[i] = userCount
         else
            tTable[i] = fullcell
         end
      end
   end
   if usrC == 1 then
      SendToAll(gBot, "Where did everybody go ?")
   end
   tTable[11] = Time
   tTable[12] = hubshrS
   return tTable
end
----------------------------------------------------------------------- push the values in a > b
function FixTable(table1, table2)
   for i, v in table1 do
      i = tonumber(i)
      if i == nil then
         i = 1
      end
      table2[i]= v
   end
end
----------------------------------------------------------------------- logical route for handling the tables ..
function TransferAll()
if count == 1 then
FixTable(tCol2, tCol3)
FixTable(tCol1, tCol2)
FixTable(tTable, tCol1)
AddValues()
GiveGraph()
else
DoTranferTab()
AddValues()
GiveGraph()
end
end
----------------------------------------------------------------------- straigth run ? pushing the tables ..
function DoTranferTab()
   if tTable[11] ~= "\t" then
      if tCol3[11] == "\t"then
         FixTable(tCol2, tCol3)
         FixTable(tCol1, tCol2)
         FixTable(tTable, tCol1)
      elseif tCol2[11] == "\t" then
         FixTable(tCol1, tCol2)
         FixTable(tTable, tCol1)
      elseif tCol1[11] == "\t" and count == 1 then
         FixTable(tTable, tCol1)
         count = 0
      end
   end
count = count +1
end
----------------------------------------------------------------------- the graph showing the values of all tables
function GiveGraph()
   tMsg = "\r\n\t\t\t- "..frmHub:GetHubName().." - Gr?fico de Users/Share -"
   tMsg = tMsg.."\r\n - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -o-0-o- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
   tMsg = tMsg.."\r\n -> Share\t:\t"..tTable[12].."\t\t"..tCol1[12].."\t\t"..tCol2[12].."\t\t"..tCol3[12]
   tMsg = tMsg.."\r\n 100% ("..maxU..")\t\t"..tTable[1].."\t"..tCol1[1].."\t"..tCol2[1].."\t"..tCol3[1]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[2].."\t"..tCol1[2].."\t"..tCol2[2].."\t"..tCol3[2]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[3].."\t"..tCol1[3].."\t"..tCol2[3].."\t"..tCol3[3]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[4].."\t"..tCol1[4].."\t"..tCol2[4].."\t"..tCol3[4]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[5].."\t"..tCol1[5].."\t"..tCol2[5].."\t"..tCol3[5]
   tMsg = tMsg.."\r\n 50% ("..midU..")\t\t"..tTable[6].."\t"..tCol1[6].."\t"..tCol2[6].."\t"..tCol3[6]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[7].."\t"..tCol1[7].."\t"..tCol2[7].."\t"..tCol3[7]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[8].."\t"..tCol1[8].."\t"..tCol2[8].."\t"..tCol3[8]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[9].."\t"..tCol1[9].."\t"..tCol2[9].."\t"..tCol3[9]
   tMsg = tMsg.."\r\n --- - -  -   -\t\t"..tTable[10].."\t"..tCol1[10].."\t"..tCol2[10].."\t"..tCol3[10]
   tMsg = tMsg.."\r\n- 0% (0). . . . . . . . . . \t. .:?:. . . . . . . . . . . . .\t. .:?:. . . . . . . . . . . . .\t. .:?:. . . . . . . . . . . . .\t. .:?:. . . . . . . . . . . . ."
   tMsg = tMsg.."\r\n ->  Time\t:            "..tTable[11].."\t             "..tCol1[11].."\t             "..tCol2[11].."\t             "..tCol3[11]
   tMsg = tMsg.."\r\n -----------------------------------------------------------\t\t"
   tMsg = tMsg.."\r\n -----------------------------------------------------------\t\t"
   SendToAll(gBot, tMsg)
   StoreGraph(user.sName, tMsg)
end
----------------------------------------------------------------------- get the data (numbers) needed, format and return them
function GetNumbers()
   Time, userCount, maxU, hubshare = "\t"
   Time = date("%H")..":"..date("%M")..":"..date("%S")
   usrC = frmHub:GetUsersCount()
   userCount = AddSpacesToKey(usrC)
   maxU = frmHub:GetMaxUsers()
   midU = maxU/2
   local thubshare = format("%0.1f", ( frmHub:GetCurrentShareAmount() / 1024))
   hubshrS = thubshare.." kb"
   if tonumber(thubshare) >= 1024 and tonumber(thubshare) < (1024^2) then
      hubshrS = format("%0.1f", ( frmHub:GetCurrentShareAmount() / (1024^2))).." mb"
   elseif tonumber(thubshare) >= (1024^2) and tonumber(thubshare) < (1024^3) then
      hubshrS = format("%0.1f", ( frmHub:GetCurrentShareAmount() / (1024^3))).." gb"
   elseif tonumber(thubshare) >= (1024^3) then
      hubshrS = format("%0.1f", ( frmHub:GetCurrentShareAmount() / (1024^4))).." tb"
   end
   return Time, userCount, maxU, midU, hubshare, usrC, hubshrS
end

----------------------------------------------------------------------- adding appropriate number of spaces to a string
function AddSpacesToKey(data)
   local ratio = (5 - strlen(data))
   local tcell = strrep(" ", ratio)..data.."\t"
   return tcell
end

----------------------------------------------------------------------- write the log file.
function StoreGraph(nick, tMsg)
   local sDate = gsub(date("%x"), "%D", "-")
   appendto(fFolder.."/"..sDate.."-"..fFile)
   write(tMsg.."\n")
   writeto()
   tMsg = nil
end
Title:
Post by: ConejoDelMal on 18 November, 2004, 03:45:40
Sorry about that Patamon, i was a bit confused....

thx a lot blackwings, i will try it  :D

I love this board.....
Title:
Post by: ConejoDelMal on 18 November, 2004, 03:52:25
humm.....not saving:

Syntax error: attempt to index global `user' (a nil value)
stack traceback:
   1:  function `GiveGraph' at line 130 [file `...oLeader Stuff\LusoLeader Hub\scripts\graph2.lua']
   2:  function `TransferAll' at line 90 [file `...oLeader Stuff\LusoLeader Hub\scripts\graph2.lua']
   3:  function `DataArrival' at line 40 [file `...oLeader Stuff\LusoLeader Hub\scripts\graph2.lua']

....somebody?  :(