PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Mikey on 15 March, 2005, 05:54:00

Title: Share Growth Checker Mod Please !
Post by: Mikey on 15 March, 2005, 05:54:00
Hello. I have tried to modify this script so I can set it up to add certain names I want this to pm to...Not seeming to have to much luck with it...Could someone do it for me please.  Thanks, Mikey

P.S. I would also like the script to have a on/off feature to where that op can turn the message on and off if they don't want to see it. Example !share on/off


Bot = "?ShareCheck?"

sharertxt = "shares.txt" --Will be created in the script folder
sh = {}

function Main()
   frmHub:RegBot(Bot)
end

function NewUserConnected(user, data)
   local s,e,share = strfind(user.sMyInfoString, "%$%s*(%d+)%$")
   share = format("%0.2f", tonumber(share)/(1024*1024*1024))
   CheckShare(user, share)
end

OpConnected = NewUserConnected

function DataArrival(user, data)
   if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
   data=strsub(data,1,strlen(data)-1)
   s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if (cmd=="!sgrw") then
         if (user.bOperator) then
            local s,e,who = strfind(data,"%b<>%s+%S+%s+(%S+)")
            if (who == nil or who == "") then
               user:SendPM(Bot, "Syntax Error, !sgrw , you must write a name.")
            else
               user:SendPM(Bot, CheckUser(who))
            end
         else
            user:SendPM(Bot, "You don?t have permission to use this command.")
         end
         return 1
      end
   end
end

function CheckUser(user)
local tmp = ""
   if (readfrom(sharertxt) == nil) then
      tmp = tmp.."the file hasn't been created yet."
   else
      readfrom(sharertxt)
      while 1 do
      local line = read()
         if (line == nil) then
            tmp = tmp.."The user "..user.." wasn't found in the list, have you write the right name ?"
            break
         else
            local s,e,who,lshare, fshare = strfind(line, "(%S+)%s+%&%s+(%S+)%s+&%s+(%S+)")
            if (who ~= nil and strlower(who) == strlower(user) ) then
               if (GetItemByName(user) ~= nil) then
                  tmp = tmp.."The user "..user.." is sharing "..lshare.." GB there last share was "..fshare.." GB."
               else
                  tmp = tmp.."The user "..user.." has shared "..lshare.." GB."
               end
               break
            end
         end
      end
      readfrom()
   end
return tmp
end
      

function CheckShare(user, share)
local tmp = ""
local time = 0
   if (readfrom(sharertxt) == nil) then
      writeto(sharertxt)
      write(user.sName.." & "..share.." & 0\r\n")
      writeto()
   else
      readfrom(sharertxt)
      while 1 do
      local line = read()
         if (line == nil) then
            if (time == 0) then
               tmp = tmp..user.sName.." & "..share.." & 0\r\n"
            end
            break
         else
            local s,e,who,nshare = strfind(line, "(%S+)%s+%&%s+(%S+)%s+&%s+%S+")
            if (who ~= nil and strlower(who) == strlower(user.sName)) then
               if (tonumber(nshare) > tonumber(share)) then
                  SendPmToOps(Bot, "The user "..user.sName.." has a smaller share then there last loggin.")
                  SendPmToOps(Bot, "They had "..nshare.." GB and now they have "..share.." GB.")
                  tmp = tmp..user.sName.." & "..share.." & "..nshare.."\r\n"
                  sh[user.sName] = share
                  time = 1
               elseif (tonumber(nshare) < tonumber(share)) then
                  SendPmToOps(Bot, "The user "..user.sName.." has more shared then there last loggin.")
                  SendPmToOps(Bot, "They had "..nshare.." GB and now they have "..share.." GB.")
                  tmp = tmp..user.sName.." & "..share.." & "..nshare.."\r\n"
                  sh[user.sName] = share
                  time = 1
               elseif (tonumber(nshare) == tonumber(share)) then
                  tmp = tmp..user.sName.." & "..share.." & "..nshare.."\r\n"
                  sh[user.sName] = share
                  time = 1
               end
            else
               tmp = tmp..line.."\r\n"
            end
         end
      end
      readfrom()
      writeto(sharertxt)
      write(tmp)
      writeto()
   end
end
Title: Please Help
Post by: Mikey on 22 March, 2005, 18:02:32
Could someone please give me a hand and make the mod for this script. I really need it. Thanks !