Please help to correct script
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Please help to correct script

Started by Oz, 18 March, 2005, 07:19:06

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Oz

i'm convert this script using LuaConverter.rar, but script have some errors, plz help to correct this errors  :))

part1

--------------------------------------------------------------------------------------
-- Top 20 ChatStats v1 - Created by Guibs Apr-15, 2003                              --
--------------------------------------------------------------------------------------
-- Modificated by Oz Sep-16, 2004
---------------------
-- Version History --
---------------------

-- v1 Added Bigstats.ini, OpStats.ini, UserStats.ini, by Guibs Apr-14, 2003

-----------------
-- Description --
-----------------

-- Show the top 5 Ops posters & the top 15 users posters
-- Stats are saved all the 10 minutes
-- Users Commands in main chat: ?stats
-- Ops Commands in pm for the stats: ?stats, ?userstats , ?mystats, !loadstats, !savestats, !clearstats, !helps

---------------
-- Greetings --
---------------

-- Helped with the retrobot? v0.99Я by tezlo
-- Thks to aMutex for his original ChatStat Script
-- Thks to A.C., [NL]Pur, Dazzler & MatrixX for their helps

------------------------------------
-- Sourcecode is below this point --
------------------------------------

Bot = "!Статистика"

TimeSpanInMinutes = 10

-------------------
-- Main function --
-------------------

function Main()

ChatOpStat={}
ChatUserStat={}

frmHub:RegBot(Bot)

tabConfig = parseINI("Stats/Bigstats.ini")
tabOpStats = parseINI("Stats/OpStats.ini")
tabUserStats = parseINI("Stats/UserStats.ini")
cfgStats = getsection(tabConfig,"stats")
InitTable ("Stats/OpStats.ini",tabOpStats,ChatOpStat)
InitTable ("Stats/UserStats.ini",tabUserStats,ChatUserStat)
smEyes = getkey(cfgStats, "eyes")
smNose = getkey(cfgStats, "nose")
smMouth = getkey(cfgStats, "mouth")
SetTimer(TimeSpanInMinutes*60000)
StartTimer()

end

function DataArrival(user,data)
local tmp = string.sub(data,1,1)
   if tmp == "<" then
      local s, e, str = string.find(data,"%b<> (.*)|")
      if not iscommand(str) then
         if (user.bOperator) then
            DoUpdOpStats(user,str)
         else
            DoUpdUserStats(user,str)
         end
      end
   end

   if (string.sub(data,1,1) == "<" ) then
      data=string.sub(data,1,string.len(data)-1)
      s,e,cmd = string.find( data,"%b<>%s+(%S+)" )
         if (cmd=="?stats")then
            pm = 0
            ShowTop20(user)

         elseif (cmd=="!helps")then
            if user.bOperator then
               ShowHelpStats(user)
               returndata = 1
            end
         end
   end

   if(string.sub(data,1,4) == "$To:") then
      data=string.sub(data,1,string.len(data)-1)
      s,e,whoTo = string.find(data,"$To:%s+(%S+)")
      if (whoTo == Bot) then
         s,e,whoTo,from,cmd = string.find(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
         if (user.bOperator) then
            if (cmd=="!helps")then
               ShowHelpStats(user)

            elseif (cmd=="!savestats") then
               SaveStats(user)

            elseif (cmd=="!loadstats") then
               LoadStats(user)

            elseif (cmd=="!clearstats") then
               Reset(user)

            elseif (cmd=="?mystats") then
               ShowYourStats(user,cmd,args)

            elseif (cmd=="?stats")then
               pm = 1
               ShowTop20(user)

            elseif (cmd=="?userstats") then
               s,e,cmd,userName= string.find(data,"%b<>%s+(%S+)%s+(.+)")
               if not userName then
                  user:SendPM(Bot,"***Wrong synthax: ?userstats ")
               else
                  ShowUserStats(user,cmd,userName)
               end
            end
         end
      end
   end
end

--------- Upos.date Chat Stats ---------

function DoUpdUserStats(user, str)
   local table = getitem(tabUserStats, user.sName)
   if not table then table = mkUserStats(user) end
   local stats = getvalue(table.tItems, "stats")
   local s, e, chars, words, smilies = string.find(stats, "(%d+)|(%d+)|(%d+)")

   chars = tonumber(chars)+string.len(str)
   words = tonumber(words)+cntargs(str, "(%a+)", 2)
   smilies = tonumber(smilies)+cntsmilies(str)

   ChatUserStat[user.sName]=chars

   putvalue(table.tItems, "stats", chars.."|"..words.."|"..smilies)
end

function DoUpdOpStats(user, str)
   local table = getitem(tabOpStats, user.sName)
   if not table then table = mkOpStats(user) end
   local stats = getvalue(table.tItems, "stats")
   local s, e, chars, words, smilies = string.find(stats, "(%d+)|(%d+)|(%d+)")

   chars = tonumber(chars)+string.len(str)
   words = tonumber(words)+cntargs(str, "(%a+)", 2)
   smilies = tonumber(smilies)+cntsmilies(str)

   ChatOpStat[user.sName]=chars

   putvalue(table.tItems, "stats", chars.."|"..words.."|"..smilies)
end

--------- Show Chat Stats Commands ---------

function ShowHelpStats(user)
   user:SendPM(Bot,"\r\n\===============================================\r\nUsers Commands in main chat:\r\nЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇ\r\n?stats\t\t- Show the Top 20 Chaters, and the stats user's\r\n\r\nOps Commands in pm for the stats:\r\nЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇЇ\r\n?stats\t\t- Show the Top 20 Chaters and the stats user's\r\n?userstats \t- Show stats user's\r\n?mystats\t\t- Show ur current stats\r\n!loadstats\t- Load stats\r\n!savestats\t- Saves stats\r\n!clearstats\t- All stats initialized\r\n!helps\t\t- This help again\r\n===============================================")
end

--------- Load Chat Stats ---------

function LoadStats(user)
   tabConfig = parseINI("Stats/Bigstats.ini")
   tabOpStats = parseINI("Stats/OpStats.ini")
   tabUserStats = parseINI("Stats/UserStats.ini")
   cfgStats = getsection(tabConfig,"stats")
   InitTable ("Stats/OpStats.ini",tabOpStats,ChatOpStat)
   InitTable ("Stats/UserStats.ini",tabUserStats,ChatUserStat)
   smEyes = getkey(cfgStats, "eyes")
   smNose = getkey(cfgStats, "nose")
   smMouth = getkey(cfgStats, "mouth")
   user:SendPM(Bot,"Chatstat has been successfully loaded ...")
end

--------- Reset Chat Stats ---------

function Reset(user)
   ChatOpStat={}
   ChatUserStat={}
   os.remove("Stats/OpStats.ini")
   local handle=io.open("Stats/OpStats.ini","a")
   write(handle,"\n")
   io.close(handle)
   os.remove("Stats/UserStats.ini")
   local handle=io.open("Stats/UserStats.ini","a")
   write(handle,"\n")
   io.close(handle)
   tabConfig = parseINI("Stats/Bigstats.ini")
   tabOpStats = parseINI("Stats/OpStats.ini")
   tabUserStats = parseINI("Stats/UserStats.ini")
   user:SendPM(Bot,"Chat-Stats initialized!")
end

--------- Save Chat Stats ---------

function SaveStats(user)
   writeINI("Stats/OpStats.ini",tabOpStats)
   writeINI("Stats/UserStats.ini",tabUserStats)
   user:SendPM(Bot,"Chatstat has been successfully saved ...")
end

--------- Your Chat Stats ---------

function ShowYourStats(user, cmd, args)
   local table = getitem(tabOpStats, user.sName)
   if not table then table = mkOpStats(user, "") end
   local stats = getkey(table, "stats")
   local s, e, chars, words, smilies = string.find(stats, "(%d+)|(%d+)|(%d+)", 1)
   user:SendPM(Bot,user.sName.." "..chars.." characters "..words.." words ".. smilies.." smilies")
end

--------- User Chat Stats ---------

function ShowUserStats(user, cmd, userName)
   local table = getitem(tabUserStats, userName)
   UserError=0
   OpError=0
   if not table then
      UserError=1
   else
      local stats = getkey(table, "stats")
      local s, e, chars, words, smilies = string.find(stats, "(%d+)|(%d+)|(%d+)", 1)
      user:SendPM(Bot,userName.." "..chars.." characters "..words.." words ".. smilies.." smilies")
   end
   local table = getitem(tabOpStats, userName)
   if not table then
      OpError=1
   else
      local stats = getkey(table, "stats")
      local s, e, chars, words, smilies = string.find(stats, "(%d+)|(%d+)|(%d+)", 1)
      user:SendPM(Bot,userName.." "..chars.." characters "..words.." words ".. smilies.." smilies")
   end
   if UserError==1 and OpError==1 then
      user:SendPM(Bot,userName.." is not in my stats file...")
   end
end

--------- Show Top 20 Chatters ---------

function ShowTop20(user)

   local user1, userkey1
   local user2, userkey2
   local user3, userkey3
   local user4, userkey4
   local user5, userkey5
   local user6, userkey6
   local user7, userkey7
   local user8, userkey8
   local user9, userkey9
   local user10, userkey10
        local user11, userkey11
        local user12, userkey12
        local user13, userkey13
        local user14, userkey14
        local user15, userkey15

   local op1, opkey1
   local op2, opkey2
   local op3, opkey3
   local op4, opkey4
   local op5, opkey5

   userkey1=0
   userkey2=0
   userkey3=0
   userkey4=0
   userkey5=0
   userkey6=0
   userkey7=0
   userkey8=0
   userkey9=0
   userkey10=0
   userkey11=0
   userkey12=0
   userkey13=0
   userkey14=0
   userkey15=0

   opkey1=0
   opkey2=0
   opkey3=0
   opkey4=0
   opkey5=0

   for a,b in ChatOpStat do
      if (ChatOpStat[a]>opkey1) then
         op5=op4
         opkey5=opkey4
         op4=op3
         opkey4=opkey3
         op3=op2
         opkey3=opkey2
         op2=op1
         opkey2=opkey1
         op1=a
         opkey1=ChatOpStat[a]
      else
         if (ChatOpStat[a]>opkey2) then
            op5=op4
            opkey5=opkey4
            op4=op3
            opkey4=opkey3
            op3=op2
            opkey3=opkey2
            op2=a
            opkey2=ChatOpStat[a]
         else
            if (ChatOpStat[a]>opkey3) then
               op5=op4
               opkey5=opkey4
               op4=op3
               opkey4=opkey3
               op3=a
               opkey3=ChatOpStat[a]
            else
               if (ChatOpStat[a]>opkey4) then
                  op5=op4
                  opkey5=opkey4
                  op4=a
                  opkey4=ChatOpStat[a]
               else
                  if (ChatOpStat[a]>opkey5) then
                     op5=a
                     opkey5=ChatOpStat[a]
                  end
               end
            end
         end
      end
   end

   opstats1 = ""
   opstats2 = ""
   opstats3 = ""
   opstats4 = ""
   opstats5 = ""

   if (op1~=nil) then
      opstats1 = ("* 1.\t"..ChatOpStat[op1]..":\t"..op1)
   end

   if (op2~=nil) then
      opstats2 = ("\r\n* 2.\t"..ChatOpStat[op2]..":\t"..op2)
   end

   if (op3~=nil) then
      opstats3 = ("\r\n* 3.\t"..ChatOpStat[op3]..":\t"..op3)
   end

   if (op4~=nil) then
      opstats4 = ("\r\n* 4.\t"..ChatOpStat[op4]..":\t"..op4)
   end

   if (op5~=nil) then
      opstats5 = ("\r\n* 5.\t"..ChatOpStat[op5]..":\t"..op5)
   end

   opstats = opstats1..opstats2..opstats3..opstats4..opstats5

   for a,b in ChatUserStat do
      if (ChatUserStat[a]>userkey1) then
         user15=user14
         userkey15=userkey14
         user14=user13
         userkey14=userkey13
         user13=user12
         userkey13=userkey12
         user12=user11
         userkey12=userkey11
         user11=user10
         userkey11=userkey10
         user10=user9
         userkey10=userkey9
         user9=user8
         userkey9=userkey8
         user8=user7
         userkey8=userkey7
         user7=user6
         userkey7=userkey6
         user6=user5
         userkey6=userkey5
         user5=user4
         userkey5=userkey4
         user4=user3
         userkey4=userkey3
         user3=user2
         userkey3=userkey2
         user2=user1
         userkey2=userkey1
         user1=a
         userkey1=ChatUserStat[a]
      else
         if (ChatUserStat[a]>userkey2) then
            user15=user14
            userkey15=userkey14
            user14=user13
            userkey14=userkey13
            user13=user12
            userkey13=userkey12
            user12=user11
            userkey12=userkey11
            user11=user10
            userkey11=userkey10
            user10=user9
            userkey10=userkey9
            user9=user8
            userkey9=userkey8
            user8=user7
            userkey8=userkey7
            user7=user6
            userkey7=userkey6
            user6=user5
            userkey6=userkey5
            user5=user4
            userkey5=userkey4
            user4=user3
            userkey4=userkey3
            user3=user2
            userkey3=userkey2
            user2=a
            userkey2=ChatUserStat[a]
         else
            if (ChatUserStat[a]>userkey3) then
               user15=user14
               userkey15=userkey14
               user14=user13
               userkey14=userkey13
               user13=user12
               userkey13=userkey12
               user12=user11
               userkey12=userkey11
               user11=user10
               userkey11=userkey10
               user10=user9
               userkey10=userkey9
               user9=user8
               userkey9=userkey8
               user8=user7
               userkey8=userkey7
               user7=user6
               userkey7=userkey6
               user6=user5
               userkey6=userkey5
               user5=user4
               userkey5=userkey4
               user4=user3
               userkey4=userkey3
               user3=a
               userkey3=ChatUserStat[a]
            else

Oz

part 2

      if (ChatUserStat[a]>userkey4) then
                  user15=user14
                  userkey15=userkey14
                  user14=user13
                  userkey14=userkey13
                  user13=user12
                  userkey13=userkey12
                  user12=user11
                  userkey12=userkey11
                  user11=user10
                  userkey11=userkey10
                  user10=user9
                  userkey10=userkey9
                  user9=user8
                  userkey9=userkey8
                  user8=user7
                  userkey8=userkey7
                  user7=user6
                  userkey7=userkey6
                  user6=user5
                  userkey6=userkey5
                  user5=user4
                  userkey5=userkey4
                  user4=a
                  userkey4=ChatUserStat[a]
               else
                  if (ChatUserStat[a]>userkey5) then
                     user15=user14
                     userkey15=userkey14
                     user14=user13
                     userkey14=userkey13
                     user13=user12
                     userkey13=userkey12
                     user12=user11
                     userkey12=userkey11
                     user11=user10
                     userkey11=userkey10
                     user10=user9
                     userkey10=userkey9
                     user9=user8
                     userkey9=userkey8
                     user8=user7
                     userkey8=userkey7
                     user7=user6
                     userkey7=userkey6
                     user6=user5
                     userkey6=userkey5
                     user5=a
                     userkey5=ChatUserStat[a]
                  else
                     if (ChatUserStat[a]>userkey6) then
                        user15=user14
                        userkey15=userkey14
                        user14=user13
                        userkey14=userkey13
                        user13=user12
                        userkey13=userkey12
                        user12=user11
                        userkey12=userkey11
                        user11=user10
                        userkey11=userkey10
                        user10=user9
                        userkey10=userkey9
                        user9=user8
                        userkey9=userkey8
                        user8=user7
                        userkey8=userkey7
                        user7=user6
                        userkey7=userkey6
                        user6=a
                        userkey6=ChatUserStat[a]
                     else
                        if (ChatUserStat[a]>userkey7) then
                           user15=user14
                           userkey15=userkey14
                           user14=user13
                           userkey14=userkey13
                           user13=user12
                           userkey13=userkey12
                           user12=user11
                           userkey12=userkey11
                           user11=user10
                           userkey11=userkey10
                           user10=user9
                           userkey10=userkey9
                           user9=user8
                           userkey9=userkey8
                           user8=user7
                           userkey8=userkey7
                           user7=a
                           userkey7=ChatUserStat[a]
                        else
                           if (ChatUserStat[a]>userkey8) then
                              user15=user14
                              userkey15=userkey14
                              user14=user13
                              userkey14=userkey13
                              user13=user12
                              userkey13=userkey12
                              user12=user11
                              userkey12=userkey11
                              user11=user10
                              userkey11=userkey10
                              user10=user9
                              userkey10=userkey9
                              user9=user8
                              userkey9=userkey8
                              user8=a
                              userkey8=ChatUserStat[a]
                           else
                              if (ChatUserStat[a]>userkey9) then
                                 user15=user14
                                 userkey15=userkey14
                                 user14=user13
                                 userkey14=userkey13
                                 user13=user12
                                 userkey13=userkey12
                                 user12=user11
                                 userkey12=userkey11
                                 user11=user10
                                 userkey11=userkey10
                                 user10=user9
                                 userkey10=userkey9
                                 user9=a
                                 userkey9=ChatUserStat[a]
                              else
                                 if (ChatUserStat[a]>userkey10) then
                                    user15=user14
                                    userkey15=userkey14
                                    user14=user13
                                    userkey14=userkey13
                                    user13=user12
                                    userkey13=userkey12
                                    user12=user11
                                    userkey12=userkey11
                                    user11=user10
                                    userkey11=userkey10
                                    user10=a
                                    userkey10=ChatUserStat[a]
                                 else
                                    if (ChatUserStat[a]>userkey11) then
                                       user15=user14
                                       userkey15=userkey14
                                       user14=user13
                                       userkey14=userkey13
                                       user13=user12
                                       userkey13=userkey12
                                       user12=user11
                                       userkey12=userkey11
                                       user11=user10
                                       user11=a
                                       userkey11=ChatUserStat[a]
                                    else
                                       if (ChatUserStat[a]>userkey12) then
                                          user15=user14
                                          userkey15=userkey14
                                          user14=user13
                                          userkey14=userkey13
                                          user13=user12
                                          userkey13=userkey12
                                          user12=user11
                                          user12=a
                                          userkey12=ChatUserStat[a]
                                       else
                                          if (ChatUserStat[a]>userkey13) then
                                             user15=user14
                                             userkey15=userkey14
                                             user14=user13
                                             userkey14=userkey13
                                             user13=user12
                                             user13=a
                                             userkey13=ChatUserStat[a]
                                          else
                                             if (ChatUserStat[a]>userkey14) then
                                                user15=user14
                                                userkey15=userkey14
                                                user14=user13
                                                user14=a
                                                userkey14=ChatUserStat[a]
                                             else
                                                if (ChatUserStat[a]>userkey15) then
                                                   user15=user14
                                                   user15=a
                                                   userkey15=ChatUserStat[a]
                                                end
                                             end
                                          end
                                       end
                                    end
                                 end
                              end
                           end
                        end
                     end
                  end
               end
            end
         end
      end
   end

   userstats1 = ""
   userstats2 = ""
   userstats3 = ""
   userstats4 = ""
   userstats5 = ""
   userstats6 = ""
   userstats7 = ""
   userstats8 = ""
   userstats9 = ""
   userstats10 = ""
   userstats11 = ""
   userstats12 = ""
   userstats13 = ""
   userstats14 = ""
   userstats15 = ""

   if (user1~=nil) then
      userstats1 = ("* 1.\t"..ChatUserStat[user1]..":\t"..user1)
   end

   if (user2~=nil) then
      userstats2 = ("\r\n* 2.\t"..ChatUserStat[user2]..":\t"..user2)
   end

   if (user3~=nil) then
      userstats3 = ("\r\n* 3.\t"..ChatUserStat[user3]..":\t"..user3)
   end

   if (user4~=nil) then
      userstats4 = ("\r\n* 4.\t"..ChatUserStat[user4]..":\t"..user4)
   end

   if (user5~=nil) then
      userstats5 = ("\r\n* 5.\t"..ChatUserStat[user5]..":\t"..user5)
   end

   if (user6~=nil) then
      userstats6 = ("\r\n* 6.\t"..ChatUserStat[user6]..":\t"..user6)
   end

   if (user7~=nil) then
      userstats7 = ("\r\n* 7.\t"..ChatUserStat[user7]..":\t"..user7)
   end

   if (user8~=nil) then
      userstats8 = ("\r\n* 8.\t"..ChatUserStat[user8]..":\t"..user8)
   end

   if (user9~=nil) then
      userstats9 = ("\r\n* 9.\t"..ChatUserStat[user9]..":\t"..user9)
   end

   if (user10~=nil) then
      userstats10 = ("\r\n*10.\t"..ChatUserStat[user10]..":\t"..user10)
   end

   if (user11~=nil) then
      userstats11 = ("\r\n*11.\t"..ChatUserStat[user11]..":\t"..user11)
   end

   if (user12~=nil) then
      userstats12 = ("\r\n*12.\t"..ChatUserStat[user12]..":\t"..user12)
   end

   if (user13~=nil) then
      userstats13 = ("\r\n*13.\t"..ChatUserStat[user13]..":\t"..user13)
   end

   if (user14~=nil) then
      userstats14 = ("\r\n*14.\t"..ChatUserStat[user14]..":\t"..user14)
   end

   if (user15~=nil) then
      userstats15 = ("\r\n*15.\t"..ChatUserStat[user15]..":\t"..user15)
   end

   userstats = userstats1..userstats2..userstats3..userstats4..userstats5..userstats6..userstats7..userstats8..userstats9..userstats10..userstats11..userstats12..userstats13..userstats14..userstats15

   chars,words,smilies=nil,nil,nil

   if user.bOperator then
      local table = getitem(tabOpStats, user.sName)
      if not table then table = mkOpStats(user) end
      local stat = getkey(table, "stats")
      s, e, chars, words, smilies = string.find(stat, "(%d+)|(%d+)|(%d+)", 1)
   else
      local table = getitem(tabUserStats, user.sName)
      if not table then table = mkUserStats(user) end
      local stat = getkey(table, "stats")
      s, e, chars, words, smilies = string.find(stat, "(%d+)|(%d+)|(%d+)", 1)
   end

   if pm == 0 then
      if user.bOperator then
         SendToAll( "Stats","\r\nTop 5 ops posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..opstats.."\r\nTop 15 users posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..userstats.."\r\n\r\nUr current Stats:\r\n"..user.sName.." "..chars.." characters "..words.." words "..smilies.." smilies")
      else
         user:SendPM(Bot,"\r\nTop 5 ops posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..opstats.."\r\nTop 15 users posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..userstats.."\r\n\r\nUr current Stats:\r\n"..user.sName.." "..chars.." characters "..words.." words "..smilies.." smilies")
         SendToAll(Bot,"Ur current Stats:\r\n"..user.sName.." "..chars.." characters "..words.." words "..smilies.." smilies")
      end
   elseif pm == 1 then
      user:SendPM(Bot,"\r\nTop 5 ops posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..opstats.."\r\nTop 15 users posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..userstats.."\r\n\r\nUr current Stats:\r\n"..user.sName.." "..chars.." characters "..words.." words "..smilies.." smilies")
   end
end
function iscommand(str)
   return string.sub(str, 1, 1) == "!" or string.sub(str, 1, 1) == "?" or string.sub(str, 1, 1) == "+" or string.sub(str, 1, 1) == "#"
end

function OnTimer()
   writeINI("Stats/OpStats.ini", tabOpStats)
   writeINI("Stats/UserStats.ini", tabUserStats)
end

Oz

part 3


--------- Tables Functions ---------

function mkOpStats(user)
   local stats = { sName = user.sName, tItems = {n=0} }
   putvalue(stats.tItems, "stats", "0|0|0" )
   putitem(tabOpStats, stats) return stats
end

function mkUserStats(user)
   local stats = { sName = user.sName, tItems = {n=0} }
   putvalue(stats.tItems, "stats", "0|0|0" )
   putitem(tabUserStats, stats) return stats
end

function getvalue(table, name)
   local id = getid(table, name)
   if id then
      return table[id].sValue
   end
end

function getid(table, name)
   return table.foreachi(table, function(id, item) if item.sName == %name then return id end end)
end

function cntargs(str, rule, len)
   local tmp = getargs(str, rule, len) return tmp.n
end

function getargs(str, rule, len)
   local tmp = {n=0}
   string.gsub(str, rule, function(s) if string.len(s) >= %len then table.insert(%tmp, s) end end)
   return tmp
end

function getkey(table,  key)
   local id = getid(table.tItems, key)
   assert(id, "getkey() ["..table.sName.."] "..key)
   return table.tItems[id].sValue
end

function getsection(table, section)
   local id = getid(table, section)
   assert(id, "getkey() ["..section.."]")
   return table[id]
end

function getitem(table, name)
   local id = getid(table, name)
   if id then return table[id] end
end

function parsekeys(keys)
   local table = {n=0}
   string.gsub(keys, "%s*(%C-)=(%C*)%c*", function(key, value) putvalue(%table, key, value) end)
   return table
end

function putitem(table, item)
   if not item then return end
   local id = getid(table, item.sName)
   if id then
      table[id] = item
   else
      table.insert(table, item)
      id = table.n
   end return id
end

function putvalue(table, name, value)
   if not value then return end
   local id = getid(table, name)
   if id then
      table[id].sValue = value
   else
      table.insert(table, { sName = name, sValue = value })
      id = table.n
   end return id
end

function writeINI(fName, struc)
   if not struc then return end
   local fHandle = io.open(fName, "w")
   if fHandle then for i = 1, struc.n do
      local section = struc write(fHandle, "\n["..section.sName.."]\n")
      for j = 1, section.tItems.n do write(fHandle, section.tItems[j].sName.."="..section.tItems[j].sValue.."\n") end
      write(fHandle, "\n")
   end io.close(fHandle) end
end

function parseINI(fName)
   local table = {n=0}
   local config = readfile(fName)
   assert(config, "parseINI() "..fName)
   local s, e, sec = string.find(config, "%[(%S+)%]%c", 1)
   while sec do local section = { sName = sec, tItems = {n=0} }
      s, ke, keys, sec = string.find(config, "(.-)%c%[(%S+)%]%c", e+1)
      if not s then s, ke, keys = string.find(config, "(.*)", e+1) else e = ke end
      section.tItems = parsekeys(keys) putitem(table, section)
   end return table
end

function InitTable(fName,ctable,tname)
   local config = readfile(fName)
   local s, e, sec = string.find(config, "%[(%S+)%]%c", 1)
      if sec then
         local table = getitem(ctable, sec)
         local stats = getvalue(table.tItems, "stats")
         local s, e, chars = string.find(stats, "(%d+)")
         tname[sec]=tonumber(chars)
      end
   while sec do local section = { sName = sec, tItems = {n=0} }
      s, ke, keys, sec = string.find(config, "(.-)%c%[(%S+)%]%c", e+1)
      if sec then
         local table = getitem(ctable, sec)
         local stats = getvalue(table.tItems, "stats")
         local s, e, chars = string.find(stats, "(%d+)")
         tname[sec]=tonumber(chars)
      end
      if not s then
         s, ke, keys = string.find(config, "(.*)", e+1)
      else
         e = ke
      end
   end
end

function cntsmilies(str)
   local tmp = {n=0}
      string.gsub(str, "(["..smEyes.."])(["..smNose.."]?)(["..smMouth.."])", function(e, n, m) table.insert(%tmp, e..n..m) end)
   string.gsub(str, "(["..smMouth.."])(["..smNose.."]?)(["..smEyes.."])", function(m, n, e) table.insert(%tmp, m..n..e) end)
   return tmp.n
end

function readfile(fName)
   local fHandle = io.open(fName, "r")

end

function iscommand(str)
   return string.sub(str, 1, 1) == "!" or string.sub(str, 1, 1) == "?" or string.sub(str, 1, 1) == "+" or string.sub(str, 1, 1) == "#"
end

function OnTimer()
   writeINI("Stats/OpStats.ini", tabOpStats)
   writeINI("Stats/UserStats.ini", tabUserStats)
end

bastya_elvtars

Hey Oz,

You might want not put here this big script directly. Pleae upload to a free server and paste the link. And, please state what error messages you get.
Everything could have been anything else and it would have just as much meaning.

Pothead

From --------- Show Top 20 Chatters ---------  down in part one and most of part 2 , you can do in a few FOR loops, which should make you code a lot smaller. :)

Oz


SMF spam blocked by CleanTalk