PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: nEgativE on 09 March, 2005, 12:05:01

Title: Help converting Scripts
Post by: nEgativE on 09 March, 2005, 12:05:01
Hi there, i'm having some problems with scripts, i tried to convert them, but all of them give me errors :(
Could someone help me please ? tks in advance


-- Made by plop
-- Addys by nErBoS

Bot = "something"

sec = 1000
min = 60 * sec

LEVELSTOT = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["4"]=0, ["5"]=0}
LEVELS = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["-1"]=0, ["4"]=0, ["5"]=0}

Stattxt = "data/stat.dat"
Stat = {
logins = 0,
share = 0,
users = 0,
}

commands = {["!addreguser"]=1, ["!delreguser"]=1}
--------------------------------------------------------------------------------
function rightSize(tam)
tam = tonumber( tam )
local count = 0
local tamStr = ""
local tamTmp = tam

if  tam < 0 then
tamTmp = tamTmp * -1
end

while tamTmp > 1024 do
tamTmp = tamTmp / 1024
count = count + 1
end

tamTmp = string.format("%0.2f", tamTmp)

if count == 0 then
tamStr = "BiT" -- Bytes
elseif count == 1 then
tamStr = "KiB" -- kilobytes
elseif count == 2 then
tamStr = "MiB" -- megabytes
elseif count == 3 then
tamStr = "GiB" -- gigabytes
elseif count == 4 then
tamStr = "TiB" -- terabytes
elseif count == 5 then
tamStr = "PiB" -- petabytes
elseif count == 6 then
tamStr = "EiB" -- exabytes
elseif count == 7 then
tamStr = "ZiB" -- zettabytes
else
tamStr = "YiB" -- yottabytes
end

if tam < 0 then
tamTmp = tamTmp * -1
end

return tamTmp.." "..tamStr

end
--------------------------------------------------------------------------------
function Message(user)

local _,_,share = string.find(user.sMyInfoString, "$(%d+)%$")
if share == nil then
share = 0
end

local notreg,regged,opped = 0
local _,_,hubs,slots = string.find(user.sMyInfoString, "H:(%S+),S:(%d+)")
if (hubs == nil and slots==nil) then
hubs = "SEM TAG"
slots = hubs
    elseif  (hubs ~= nil) then
    _,_,notreg,regged,opped = string.find(hubs, "(%d+)/(%d+)/(%d+)")
    if (notreg == nil) then notreg = 0; end
    if (regged == nil) then regged= 0; end
    if (opped == nil) then opped = 0; end
    hubs = notreg + regged + opped
    end
   
   if (notreg == nil) then notreg = 0; end
   if (regged == nil) then regged= 0; end
   if (opped == nil) then opped = 0; end
   
   local SC=os.clock()
   local hubshare = frmHub:GetCurrentShareAmount() + share
   local ttshare = tonumber(Stat.share)
   local tmp = LEVELSTOT["1"] + LEVELSTOT["0"]  --- total ops  (adding masters 2 ops)
   local tmp1 = (LEVELSTOT["2"] - LEVELS["2"]) if tmp1 < 0 then tmp1 = 0 end --- offline vips (total - online)
   local tmp2 = (LEVELSTOT["3"] - LEVELS["3"]) if tmp2 < 0 then tmp2 = 0 end --- offline regs (total - online)
   local tmp3 = LEVELS["0"] + LEVELS["0"] -- online ops (adding masters 2 the ops)
   local tmp4 = LEVELS["4"]
   user:SendData(":.:.:.:.:.:.:.:.: Usu?rio :.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Endere?o IP: "..user.sIP.." - Status: "..(GetProfileName(user.iProfile) or "N?o registrado").." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Conectado: "..hubs.." Hub's - Com registro: "..regged.." - Como Operador: "..opped.." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Compartilhamento: "..rightSize( share ).." - Modo: "..ModeChecker(user).." - Slot's: "..slots.." - Cliente: "..VersionChecker(user).." --- --  -")
   user:SendData(":.:.:.:.:.:.:.:.: Servidor :.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData("   -=[?]=--- --  -   -  - -- --- "..frmHub:GetHubName().." - Comunidade de Lingua Portuguesa - LUSA --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Usu?rios online: "..frmHub:GetUsersCount().." - OP's: "..tmp3.." - ViP's: "..LEVELS["2"].." - OP's de Rede: "..tmp4.." - M?x: "..frmHub:GetMaxUsers().." - Recorde: "..Stat.users.." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Usu?rios registrados: "..tmp2.." - OP's: "..tmp.." - ViP's: "..LEVELSTOT["2"].." - OP's de Rede: "..LEVELSTOT["4"].." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Compartilhamento atual: "..rightSize( hubshare ) .." - Recorde: "..rightSize( ttshare ).." - Minimo: 5 GiB --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Lista de comandos, regras, ajuda e informa??o: !ajuda - !help --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Uptime do Servidor: " ..math.floor(SC/86400).." dia's "..math.floor(math.mod(SC/3600,24)).." hora's e "..math.floor(math.mod(SC/60,60)).." minuto's - "..GetTime().." --- --  -")
   user:SendData(":.:.:.:.:.:.:.:.: Nota(s) :.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Importante - Novos comandos dispon?veis: !ajuda - !help --- --  -")
   user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData(" ")
end
--------------------------------------------------------------------------------
function GetTime()
s = os.date("%S")
h = os.date("%H")
m = os.date("%M")
d = os.date("%d")
mm = os.date("%m")
y = os.date("%y")
Date = "Hora local: "..h..":"..m..":"..s.." - "..d.."/"..mm.."/20"..y..""
return Date
end
--------------------------------------------------------------------------------
ALLUSERS={}

function NewUserConnected(user)
local s,e,usrshare = string.find(user.sMyInfoString, "%$%s*(%d+)%$")
if (readfrom(Stattxt) == nil) then
if (Stat.users < frmHub:GetUsersCount() ) then
Stat.users = frmHub:GetUsersCount()
else
end
if (Stat.share < frmHub:GetCurrentShareAmount() + usrshare) then
Stat.share = frmHub:GetCurrentShareAmount() + usrshare
end
Stat.logins = Stat.logins + 1
SaveToFile(Stattxt , Stat , "Stat")
else
LoadFromFile (Stattxt)
local logins = Stat["logins"]
local share = Stat["share"]
local users = Stat["users"]
if (users < frmHub:GetUsersCount() ) then
Stat.users = frmHub:GetUsersCount()
else
Stat.users = users
end
if (share < frmHub:GetCurrentShareAmount() + usrshare) then
Stat.share = frmHub:GetCurrentShareAmount() + usrshare
else
Stat.share = share
end
Stat.logins = logins + 1
SaveToFile(Stattxt , Stat , "Stat")
end

   if ALLUSERS[user.sName]==nil then
      ALLUSERS[user.sName]=1
      LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1
   end
   if (VersionChecker(user) == "Desconhe?ido") then
   --SendToOps(Bot, "- OP MSG - Usu?rio(a): "..user.sName..", est? com um Cliente DC sem TAG.")
   end
   Message(user)
end
--------------------------------------------------------------------------------
OpConnected = NewUserConnected
--------------------------------------------------------------------------------
function ChatArrival(user, data)
   if ALLUSERS[user.sName]==nil then
      ALLUSERS[user.sName]=1
      LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1
   end
   s,e,cmd= string.find(data, "%b<>%s+(%S+)")
   if cmd ~= nil and commands[cmd] then
      SetTimer(5 * 1000)
      StartTimer()
   end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function OnTimer()
   StopTimer()
   OpenRegisterdUsersFile()
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function UserDisconnected(user)
   if ALLUSERS[user.sName] then
      ALLUSERS[user.sName]=nil
      if LEVELS[tostring(user.iProfile)] > 0 then
         LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
      end
   end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function OpDisconnected(user)
   if ALLUSERS[user.sName] then
      ALLUSERS[user.sName]=nil
      if LEVELS[tostring(user.iProfile)] > 0 then
         LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
      end
   end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function Main()
   frmHub:RegBot(Bot)
   OpenRegisterdUsersFile()
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function OpenRegisterdUsersFile()
   readfrom("../RegisteredUsers.dat")
   for a,b in LEVELSTOT do
      LEVELSTOT[a]=0
   end
   while 1 do
      local line = read()
      local level
      if line == nil then
         readfrom()
         break
      end
      s,e,level = string.find(line,".+|.+|(.+)")
      if LEVELSTOT[level] then
         LEVELSTOT[level] = LEVELSTOT[level] +1
      end
   end  
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function Serialize(tTable, sTableName, hFile, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(hFile, "hFile equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";

write(hFile, sTab..sTableName.." = {\n" );

for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
write(hFile, sTab.."\t"..sKey.." = "..sValue);
end

write(hFile, ",\n");
end

write(hFile, sTab.."}");
end

function SaveToFile(file , table , tablename)
local hFile = openfile(file, "w");
Serialize(table, tablename, hFile);
closefile(hFile);
end

function LoadFromFile (file)
assert(readfrom(file),"Making file, not to horry")
dostring(read("*all"))
readfrom()
end

function VersionChecker(user)
local tmp = ""
if (string.find(user.sMyInfoString, " tmp = "oDC++"
elseif string.find(user.sMyInfoString,"DCDM") then
tmp = "DCDM++"
elseif string.find(user.sMyInfoString," tmp = "rmDC++"
elseif (string.find(user.sMyInfoString, "<++")) then
tmp = "DC++"
elseif (string.find(user.sMyInfoString, " tmp = "StrongDC++"
else
tmp = "unknow"
end
return tmp
end

function ModeChecker(user)
local tmp = ""
if (string.find(user.sMyInfoString, "M:P")) then
tmp = "Passive"
else
tmp = "Active"
end
return tmp
end


Syntax ..\scripts\07.onjoin.lua5.lua:210: attempt to call global `readfrom' (a nil value)
Title:
Post by: 6Marilyn6Manson6 on 09 March, 2005, 12:18:51
-- Made by plop
-- Addys by nErBoS

Bot = "something"

sec = 1000
math.min = 60 * sec

LEVELSTOT = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["4"]=0, ["5"]=0}
LEVELS = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["-1"]=0, ["4"]=0, ["5"]=0}

Stattxt = "data/stat.dat"
Stat = {
logins = 0,
share = 0,
users = 0,
}

commands = {["!addreguser"]=1, ["!delreguser"]=1}
--------------------------------------------------------------------------------
function rightSize(tam)
tam = tonumber( tam )
local count = 0
local tamStr = ""
local tamTmp = tam

if  tam < 0 then
tamTmp = tamTmp * -1
end

while tamTmp > 1024 do
tamTmp = tamTmp / 1024
count = count + 1
end

tamTmp = string.format("%0.2f", tamTmp)

if count == 0 then
tamStr = "BiT" -- Bytes
elseif count == 1 then
tamStr = "KiB" -- kilobytes
elseif count == 2 then
tamStr = "MiB" -- megabytes
elseif count == 3 then
tamStr = "GiB" -- gigabytes
elseif count == 4 then
tamStr = "TiB" -- terabytes
elseif count == 5 then
tamStr = "PiB" -- petabytes
elseif count == 6 then
tamStr = "EiB" -- exabytes
elseif count == 7 then
tamStr = "ZiB" -- zettabytes
else
tamStr = "YiB" -- yottabytes
end

if tam < 0 then
tamTmp = tamTmp * -1
end

return tamTmp.." "..tamStr

end
--------------------------------------------------------------------------------
function Message(user)

local _,_,share = string.find(user.sMyInfoString, "$(%d+)%$")
if share == nil then
share = 0
end

local notreg,regged,opped = 0
local _,_,hubs,slots = string.find(user.sMyInfoString, "H:(%S+),S:(%d+)")
if (hubs == nil and slots==nil) then
hubs = "SEM TAG"
slots = hubs
    elseif  (hubs ~= nil) then
    _,_,notreg,regged,opped = string.find(hubs, "(%d+)/(%d+)/(%d+)")
    if (notreg == nil) then notreg = 0; end
    if (regged == nil) then regged= 0; end
    if (opped == nil) then opped = 0; end
    hubs = notreg + regged + opped
    end
   
   if (notreg == nil) then notreg = 0; end
   if (regged == nil) then regged= 0; end
   if (opped == nil) then opped = 0; end
   
   local SC=os.os.clock()
   local hubshare = frmHub:GetCurrentShareAmount() + share
   local ttshare = tonumber(Stat.share)
   local tmp = LEVELSTOT["1"] + LEVELSTOT["0"]  --- total ops  (adding masters 2 ops)
   local tmp1 = (LEVELSTOT["2"] - LEVELS["2"]) if tmp1 < 0 then tmp1 = 0 end --- offline vips (total - online)
   local tmp2 = (LEVELSTOT["3"] - LEVELS["3"]) if tmp2 < 0 then tmp2 = 0 end --- offline regs (total - online)
   local tmp3 = LEVELS["0"] + LEVELS["0"] -- online ops (adding masters 2 the ops)
   local tmp4 = LEVELS["4"]
   user:SendData(":.:.:.:.:.:.:.:.: Usu?rio :.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Endere?o IP: "..user.sIP.." - Status: "..(GetProfileName(user.iProfile) or "N?o registrado").." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Conectado: "..hubs.." Hub's - Com registro: "..regged.." - Como Operador: "..opped.." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Compartilhamento: "..rightSize( share ).." - Modo: "..ModeChecker(user).." - Slot's: "..slots.." - Cliente: "..VersionChecker(user).." --- --  -")
   user:SendData(":.:.:.:.:.:.:.:.: Servidor :.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData("   -=[?]=--- --  -   -  - -- --- "..frmHub:GetHubName().." - Comunidade de Lingua Portuguesa - LUSA --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Usu?rios online: "..frmHub:GetUsersCount().." - OP's: "..tmp3.." - ViP's: "..LEVELS["2"].." - OP's de Rede: "..tmp4.." - M?x: "..frmHub:GetMaxUsers().." - Recorde: "..Stat.users.." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Usu?rios registrados: "..tmp2.." - OP's: "..tmp.." - ViP's: "..LEVELSTOT["2"].." - OP's de Rede: "..LEVELSTOT["4"].." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Compartilhamento atual: "..rightSize( hubshare ) .." - Recorde: "..rightSize( ttshare ).." - Minimo: 5 GiB --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Lista de comandos, regras, ajuda e informa??o: !ajuda - !help --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Uptime do Servidor: " ..math.math.floor(SC/86400).." dia's "..math.math.floor(math.math.mod(SC/3600,24)).." hora's e "..math.math.floor(math.math.mod(SC/60,60)).." minuto's - "..GetTime().." --- --  -")
   user:SendData(":.:.:.:.:.:.:.:.: Nota(s) :.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Importante - Novos comandos dispon?veis: !ajuda - !help --- --  -")
   user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData(" ")
end
--------------------------------------------------------------------------------
function GetTime()
s = os.os.date("%S")
h = os.os.date("%H")
m = os.os.date("%M")
d = os.os.date("%d")
mm = os.os.date("%m")
y = os.os.date("%y")
Date = "Hora local: "..h..":"..m..":"..s.." - "..d.."/"..mm.."/20"..y..""
return Date
end
--------------------------------------------------------------------------------
ALLUSERS={}

function NewUserConnected(user)
local s,e,usrshare = string.find(user.sMyInfoString, "%$%s*(%d+)%$")
if (readfrom(Stattxt) == nil) then
if (Stat.users < frmHub:GetUsersCount() ) then
Stat.users = frmHub:GetUsersCount()
else
end
if (Stat.share < frmHub:GetCurrentShareAmount() + usrshare) then
Stat.share = frmHub:GetCurrentShareAmount() + usrshare
end
Stat.logins = Stat.logins + 1
SaveToFile(Stattxt , Stat , "Stat")
else
LoadFromFile (Stattxt)
local logins = Stat["logins"]
local share = Stat["share"]
local users = Stat["users"]
if (users < frmHub:GetUsersCount() ) then
Stat.users = frmHub:GetUsersCount()
else
Stat.users = users
end
if (share < frmHub:GetCurrentShareAmount() + usrshare) then
Stat.share = frmHub:GetCurrentShareAmount() + usrshare
else
Stat.share = share
end
Stat.logins = logins + 1
SaveToFile(Stattxt , Stat , "Stat")
end

   if ALLUSERS[user.sName]==nil then
      ALLUSERS[user.sName]=1
      LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1
   end
   if (VersionChecker(user) == "Desconhe?ido") then
   --SendToOps(Bot, "- OP MSG - Usu?rio(a): "..user.sName..", est? com um Cliente DC sem TAG.")
   end
   Message(user)
end
--------------------------------------------------------------------------------
OpConnected = NewUserConnected
--------------------------------------------------------------------------------
function ChatArrival(user, data)
   if ALLUSERS[user.sName]==nil then
      ALLUSERS[user.sName]=1
      LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1
   end
   s,e,cmd= string.find(data, "%b<>%s+(%S+)")
   if cmd ~= nil and commands[cmd] then
      SetTimer(5 * 1000)
      StartTimer()
   end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function OnTimer()
   StopTimer()
   OpenRegisterdUsersFile()
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function UserDisconnected(user)
   if ALLUSERS[user.sName] then
      ALLUSERS[user.sName]=nil
      if LEVELS[tostring(user.iProfile)] > 0 then
         LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
      end
   end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function OpDisconnected(user)
   if ALLUSERS[user.sName] then
      ALLUSERS[user.sName]=nil
      if LEVELS[tostring(user.iProfile)] > 0 then
         LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
      end
   end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function Main()
   frmHub:RegBot(Bot)
   OpenRegisterdUsersFile()
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function OpenRegisterdUsersFile()
   readfrom("../RegisteredUsers.dat")
   for a,b in LEVELSTOT do
      LEVELSTOT[a]=0
   end
   while 1 do

      local level
      if line == nil then
         readfrom()
         break
      end
      s,e,level = string.find(line,".+|.+|(.+)")
      if LEVELSTOT[level] then
         LEVELSTOT[level] = LEVELSTOT[level] +1
      end
   end  
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function Serialize(tTable, sTableName, hFile, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(hFile, "hFile equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";

write(hFile, sTab..sTableName.." = {\n" );

for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
write(hFile, sTab.."\t"..sKey.." = "..sValue);
end

write(hFile, ",\n");
end

write(hFile, sTab.."}");
end

function SaveToFile(file , table , tablename)
local hFile = io.open(file, "w");
Serialize(table, tablename, hFile);
io.close(hFile);
end

function LoadFromFile (file)
assert(readfrom(file),"Making file, not to horry")

readfrom()
end

function VersionChecker(user)
local tmp = ""
if (string.find(user.sMyInfoString, " tmp = "oDC++"
elseif string.find(user.sMyInfoString,"DCDM") then
tmp = "DCDM++"
elseif string.find(user.sMyInfoString," tmp = "rmDC++"
elseif (string.find(user.sMyInfoString, "<++")) then
tmp = "DC++"
elseif (string.find(user.sMyInfoString, " tmp = "StrongDC++"
else
tmp = "unknow"
end
return tmp
end

function ModeChecker(user)
local tmp = ""
if (string.find(user.sMyInfoString, "M:P")) then
tmp = "Passive"
else
tmp = "Active"
end
return tmp
end

test it ;)
Title:
Post by: nEgativE on 09 March, 2005, 12:23:00
6Marilyn6Manson6, it gives the same syntax error :((
Title:
Post by: Jelf on 09 March, 2005, 21:43:50
Here ya go...
-- Made by plop
-- Addys by nErBoS
-- Converted to Lua5 By Jelf 09/03/05

Bot = "something"

sec = 1000
min = 60 * sec

LEVELSTOT = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["4"]=0, ["5"]=0}
LEVELS = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["-1"]=0, ["4"]=0, ["5"]=0}
Path = "data"
Stattxt = "data/stat.dat"
Stat = {
logins = 0,
share = 0,
users = 0,
}
os.execute("mkdir ".."\""..string.gsub(Path, "/", "\\").."\"")
commands = {["!addreguser"]=1, ["!delreguser"]=1}
--------------------------------------------------------------------------------
function rightSize(tam)
tam = tonumber( tam )
local count = 0
local tamStr = ""
local tamTmp = tam

if  tam < 0 then
tamTmp = tamTmp * -1
end

while tamTmp > 1024 do
tamTmp = tamTmp / 1024
count = count + 1
end

tamTmp = string.format("%0.2f", tamTmp)

if count == 0 then
tamStr = "BiT" -- Bytes
elseif count == 1 then
tamStr = "KiB" -- kilobytes
elseif count == 2 then
tamStr = "MiB" -- megabytes
elseif count == 3 then
tamStr = "GiB" -- gigabytes
elseif count == 4 then
tamStr = "TiB" -- terabytes
elseif count == 5 then
tamStr = "PiB" -- petabytes
elseif count == 6 then
tamStr = "EiB" -- exabytes
elseif count == 7 then
tamStr = "ZiB" -- zettabytes
else
tamStr = "YiB" -- yottabytes
end

if tam < 0 then
tamTmp = tamTmp * -1
end

return tamTmp.." "..tamStr

end
--------------------------------------------------------------------------------
function Message(user)

local _,_,share = string.find(user.sMyInfoString, "$(%d+)%$")
if share == nil then
share = 0
end

local notreg,regged,opped = 0
local _,_,hubs,slots = string.find(user.sMyInfoString, "H:(%S+),S:(%d+)")
if (hubs == nil and slots==nil) then
hubs = "SEM TAG"
slots = hubs
    elseif  (hubs ~= nil) then
    _,_,notreg,regged,opped = string.find(hubs, "(%d+)/(%d+)/(%d+)")
    if (notreg == nil) then notreg = 0; end
    if (regged == nil) then regged= 0; end
    if (opped == nil) then opped = 0; end
    hubs = notreg + regged + opped
    end
   
   if (notreg == nil) then notreg = 0; end
   if (regged == nil) then regged= 0; end
   if (opped == nil) then opped = 0; end
   
   local SC=os.clock()
   local hubshare = frmHub:GetCurrentShareAmount() + share
   local ttshare = tonumber(Stat.share)
   local tmp = LEVELSTOT["1"] + LEVELSTOT["0"]  --- total ops  (adding masters 2 ops)
   local tmp1 = (LEVELSTOT["2"] - LEVELS["2"]) if tmp1 < 0 then tmp1 = 0 end --- offline vips (total - online)
   local tmp2 = (LEVELSTOT["3"] - LEVELS["3"]) if tmp2 < 0 then tmp2 = 0 end --- offline regs (total - online)
   local tmp3 = LEVELS["0"] + LEVELS["0"] -- online ops (adding masters 2 the ops)
   local tmp4 = LEVELS["4"]
   user:SendData(":.:.:.:.:.:.:.:.: Usu?rio :.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Endere?o IP: "..user.sIP.." - Status: "..(GetProfileName(user.iProfile) or "N?o registrado").." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Conectado: "..hubs.." Hub's - Com registro: "..regged.." - Como Operador: "..opped.." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Compartilhamento: "..rightSize( share ).." - Modo: "..ModeChecker(user).." - Slot's: "..slots.." - Cliente: "..VersionChecker(user).." --- --  -")
   user:SendData(":.:.:.:.:.:.:.:.: Servidor :.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData("   -=[?]=--- --  -   -  - -- --- "..frmHub:GetHubName().." - Comunidade de Lingua Portuguesa - LUSA --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Usu?rios online: "..frmHub:GetUsersCount().." - OP's: "..tmp3.." - ViP's: "..LEVELS["2"].." - OP's de Rede: "..tmp4.." - M?x: "..frmHub:GetMaxUsers().." - Recorde: "..Stat.users.." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Usu?rios registrados: "..tmp2.." - OP's: "..tmp.." - ViP's: "..LEVELSTOT["2"].." - OP's de Rede: "..LEVELSTOT["4"].." --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Compartilhamento atual: "..rightSize( hubshare ) .." - Recorde: "..rightSize( ttshare ).." - Minimo: 5 GiB --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Lista de comandos, regras, ajuda e informa??o: !ajuda - !help --- --  -")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Uptime do Servidor: " ..math.floor(SC/86400).." dia's "..math.floor(math.mod(SC/3600,24)).." hora's e "..math.floor(math.mod(SC/60,60)).." minuto's - "..GetTime().." --- --  -")
   user:SendData(":.:.:.:.:.:.:.:.: Nota(s) :.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData("   -=[?]=--- --  -   -  - -- --- Importante - Novos comandos dispon?veis: !ajuda - !help --- --  -")
   user:SendData(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
   user:SendData(" ")
end
--------------------------------------------------------------------------------
function GetTime()
s = os.date("%S")
h = os.date("%H")
m = os.date("%M")
d = os.date("%d")
mm = os.date("%m")
y = os.date("%y")
Date = "Hora local: "..h..":"..m..":"..s.." - "..d.."/"..mm.."/20"..y..""
return Date
end
--------------------------------------------------------------------------------
ALLUSERS={}

function NewUserConnected(user)
local s,e,usrshare = string.find(user.sMyInfoString, "%$%s*(%d+)%$")
if (io.open(Stattxt) == nil) then
if (Stat.users < frmHub:GetUsersCount() ) then
Stat.users = frmHub:GetUsersCount()
else
end
if (Stat.share < frmHub:GetCurrentShareAmount() + usrshare) then
Stat.share = frmHub:GetCurrentShareAmount() + usrshare
end
Stat.logins = Stat.logins + 1
SaveToFile(Stattxt , Stat , "Stat")
else
LoadFromFile (Stattxt)
local logins = Stat["logins"]
local share = Stat["share"]
local users = Stat["users"]
if (users < frmHub:GetUsersCount() ) then
Stat.users = frmHub:GetUsersCount()
else
Stat.users = users
end
if (share < frmHub:GetCurrentShareAmount() + usrshare) then
Stat.share = frmHub:GetCurrentShareAmount() + usrshare
else
Stat.share = share
end
Stat.logins = logins + 1
SaveToFile(Stattxt , Stat , "Stat")
end

   if ALLUSERS[user.sName]==nil then
      ALLUSERS[user.sName]=1
      LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1
   end
   if (VersionChecker(user) == "Desconhe?ido") then
   --SendToOps(Bot, "- OP MSG - Usu?rio(a): "..user.sName..", est? com um Cliente DC sem TAG.")
   end
   Message(user)
end
--------------------------------------------------------------------------------
OpConnected = NewUserConnected
--------------------------------------------------------------------------------
function ChatArrival(user, data)
   if ALLUSERS[user.sName]==nil then
      ALLUSERS[user.sName]=1
      LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]+1
   end
   s,e,cmd= string.find(data, "%b<>%s+(%S+)")
   if cmd ~= nil and commands[cmd] then
      SetTimer(5 * 1000)
      StartTimer()
   end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function OnTimer()
   StopTimer()
   OpenRegisterdUsersFile()
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function UserDisconnected(user)
   if ALLUSERS[user.sName] then
      ALLUSERS[user.sName]=nil
      if LEVELS[tostring(user.iProfile)] > 0 then
         LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
      end
   end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function OpDisconnected(user)
   if ALLUSERS[user.sName] then
      ALLUSERS[user.sName]=nil
      if LEVELS[tostring(user.iProfile)] > 0 then
         LEVELS[tostring(user.iProfile)]=LEVELS[tostring(user.iProfile)]-1
      end
   end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function Main()
   frmHub:RegBot(Bot)
   OpenRegisterdUsersFile()
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function OpenRegisterdUsersFile()
local handle = io.open("../RegisteredUsers.dat","r")
for a,b in LEVELSTOT do
LEVELSTOT[a]=0
end
while 1 do
local line = handle:read()
local level
if line == nil then
handle:flush()
handle:close()
break
end
s,e,level = string.find(line,".+|.+|(.+)")
if LEVELSTOT[level] then
LEVELSTOT[level] = LEVELSTOT[level] +1
end
end  
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function Serialize(tTable, sTableName, sTab)
        assert(tTable, "tTable equals nil");
        assert(sTableName, "sTableName equals nil");

        assert(type(tTable) == "table", "tTable must be a table!");
        assert(type(sTableName) == "string", "sTableName must be a string!");

        sTab = sTab or "";
        sTmp = ""

        sTmp = sTmp..sTab..sTableName.." = {\n"

        for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);

                if(type(value) == "table") then
                        sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
                        local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
                        sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
                end

                sTmp = sTmp..",\n"
        end

        sTmp = sTmp..sTab.."}"
        return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end

function LoadFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
loadstring(handle:read("*all"))
handle:flush()
handle:close()
end
end

function VersionChecker(user)
local tmp = ""
if (string.find(user.sMyInfoString, " tmp = "oDC++"
elseif string.find(user.sMyInfoString,"DCDM") then
tmp = "DCDM++"
elseif string.find(user.sMyInfoString," tmp = "rmDC++"
elseif (string.find(user.sMyInfoString, "<++")) then
tmp = "DC++"
elseif (string.find(user.sMyInfoString, " tmp = "StrongDC++"
else
tmp = "unknow"
end
return tmp
end

function ModeChecker(user)
local tmp = ""
if (string.find(user.sMyInfoString, "M:P")) then
tmp = "Passive"
else
tmp = "Active"
end
return tmp
end
Title:
Post by: nEgativE on 10 March, 2005, 11:54:05
Jelf.. tks :) i think is working good,
can u help me on more scripts ? i think all errors r related to file handler :\ tks in advance



-- Definir limites de tempo
-- Tempo minimo entre mensagens (em minutos)
time1 = 10
-- Tempo maximo entre mensagens (em minutos)
time2 = 120
-- Just some variables
textArray = {}
QWarray = {}
antall = 0

-- Main function
function Main()
-- Enable next line to use norwegian letters
--     setlocale("no")
     loadText()
   TimeSpanInMinutes = random (time1, time2)
     SetTimer(TimeSpanInMinutes*60000)
     getLine()
     StartTimer()
end

-- Just another function
function GetArgs(data)
   s,e,whoTo,from,cmd,arg,arg2 = string.find(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
   return arg,arg2
end

-- funcao que permite ir buscar as mensagens ao ficheiro .txt
function getLine()
lngWord = math.random(1, antall)
QWarray = tokenize(textArray[lngWord], "*")
txt1 = QWarray[1]
txt2 = QWarray[2]
end

-- Timer function
function OnTimer()
   SendToAll (txt1, txt2)
      TimeSpanInMinutes = random (time1, time2)
     SetTimer(TimeSpanInMinutes*60000)
     getLine()
     StartTimer()
end

-- funcao que define onde esta a pasta txt
function loadText()
handle = openfile("Data/CLP.Frases.dat", "r")
if (handle) then
local line = read(handle)
   while line do
      if ((line ~= "") and (string.find(line, "*", 1, plain))) then
      table.insert(textArray, line)
      antall = antall + 1
   end
   line = read(handle)
   end
closefile(handle)
end
end

-- Function to split the textline i bot and message
function tokenize (inString,token)
   _WORDS = {}
   local matcher = "([^"..token.."]+)"
   string.gsub(inString, matcher, function (w) table.insert(_WORDS,w) end)
   return _WORDS
end


Syntax ..\scripts\02.CLP.Frases.lua5.lua:48: attempt to call global `openfile' (a nil value)
Title:
Post by: Jelf on 10 March, 2005, 22:10:24
Use this..
-- funcao que define onde esta a pasta txt
function loadText()
local handle = io.open("Data/CLP.Frases.dat", "r")
if (handle) then
local line = handle:read()
    while line do
      if ((line ~= "") and (string.find(line, "*", 1, plain))) then
      table.insert(textArray, line)
      antall = antall + 1
    end
    line = handle:read()
    end
handle:flush()
handle:close()
end
end
Hope it works :)
Title:
Post by: nEgativE on 11 March, 2005, 11:35:55
It's working.. tks again :)

Another help, it's writing well, but not reading well.. i think


function WriteRelease(user, data, cmd)

arg = GetArgs(data)
if arg == nil then
arg = "Sem coment?rios no Hub."
user:SendData(sBot, arg)
return 1
end

local handle = io.open("Data/CLP.GuestBook.dat","a")
timedate = os.date()
handle.write(handle,timedate.." - "..user.sName..": "..arg.."?")
SendToOps(sBot,"OP MSG - Novo coment?rio no GuestBook do Hub por: "..user.sName.."")
SendToAll(sBot,"DC:CLP - Novo coment?rio no GuestBook do Hub, digite: !livro para ler o(s) coment?rio(s).")
handle:close()
end

function ReadRelease(user, data, cmd)

user:SendPM(sBot, ":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
handle = io.open("Data/CLP.GuestBook.dat","r")
if (handle) then
line = handle:read(handle,"*a")
line=string.sub(line,1,string.len(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(sBot,linearray[i])
end
handle:close()
user:SendPM(sBot, ":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
end
end