[Help]
 

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

[Help]

Started by nEgativE, 16 May, 2004, 17:23:39

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nEgativE

Hi there, could someone give a help on this script..
The problem is when i add a new profile i get this syntax erros, when that user with new profile get in and out :(
Thank U.

maybe i need to include some more levels on those tables ? like profile 4 and 5 .. or may be not, guessing here =)

Syntax error: attempt to perform arithmetic on a nil value
stack traceback:
   1:  function `DataArrival' at line 158 [file `...\ptokax\scripts\onjoin.lua']

Syntax error: attempt to compare nil with number
stack traceback:
   1:  function `UserDisconnected' at line 175 [file `...\ptokax\scripts\onjoin.lua']

Script

Bot = "[operserv]"

-- couter tables, if you have more levels add there numbers in BOTH tables,
-- except unreg users, those only work in the lower table
LEVELSTOT = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0}
LEVELS = {["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["-1"]=0}

Stattxt = "txt/lusobrasil.stat.txt" --Will be created in the script folder

Stat = {
	logins = 0,
	share = 0,
	users = 0,
}

-- table holding the commands ptokax uses 2 add/delete users
-- add your bot's commands 2 this table if you use a bot 2 add/delete ppl
commands = {["!addreguser"]=1, ["!delreguser"]=1}
-------------------------------------------------------------------------------------------------------------------------------------------------
function Message(user)
   local s,e,share = strfind(user.sMyInfoString, "$(%d+)%$")
   local s,e,hubs,slots = strfind(user.sMyInfoString, "H:(%S+),S:(%d+)")
   if share ~= nil then
   share = format("%0.2f", ( share / (1024*1024*1024)))
   else
   share = 0
   end
   if (hubs == nil and slots == nil) then
	hubs = "SEM TAG"
	slots = hubs
   elseif (strfind(hubs, "%d+/") ~= nil) then
   local s,e,notreg,reg,opped = strfind(hubs, "(%d+)/(%d+)/(%d+)")
   hubs = notreg + reg + opped
   end
   local hubshare = format("%0.2f",  ( frmHub:GetCurrentShareAmount() / (1024*1024*1024)))
   local ttshare = format("%0.2f", tonumber(Stat.share)/(1024*1024*1024))
   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["1"] + LEVELS["0"] -- online ops (adding masters 2 the ops)
   user:SendData(Bot, "-=[?]=-----------------------------------------------------------------------------------------------------------------=[?]=-") 
   user:SendData(Bot, "		<-----=[- "..frmHub:GetHubName().." ? v2004 ? Multi-Hub -]=----->") 
   user:SendData(Bot, "-=[?]=-----------------------------------------------------------------------------------------------------------------=[?]=-") 
   user:SendData(Bot, "    	  ? Comunidade Lusobrasileira de ?irect C?nnect - Generalista.") 
   user:SendData(Bot, "    	  ? "..user.sName..", bem vindo ao Servidor [nacional.no-ip.com]") 
   user:SendData(Bot, "    	  ? Seu endere?o IP: "..user.sIP.." - StatuS: "..(GetProfileName(user.iProfile) or "N?o registrado")..".") 
   user:SendData(Bot, "    	  ? Voc? est? compartilhando: "..share.." GB. Limite minimo: "..frmHub:GetMinShare()/(1024).." GB.") 
   user:SendData(Bot, "    	  ? Voc? est? conectado em: "..hubs.." Hub(s) e tem: "..slots.." Slot(s) liberado(s).")
   user:SendData(Bot, "    	  ? Voc? est? usando o Cliente: "..VersionChecker(user)..", em Modo: "..ModeChecker(user)..".")
   user:SendData(Bot, "    	  ? Usu?rios Online no Hub: "..frmHub:GetUsersCount()..". Recorde: "..Stat.users..". M?x: "..frmHub:GetMaxUsers()..".") 
   user:SendData(Bot, "    	  ? Operadores Online no Hub: "..tmp3..". ViPs: "..LEVELS["2"]..".")
   user:SendData(Bot, "    	  ? Operadores registrados no Hub: "..tmp..". ViPs: "..LEVELSTOT["2"]..".")
   user:SendData(Bot, "    	  ? Registros no Hub [n?o conectados]: "..tmp2..".")
   user:SendData(Bot, "    	  ? Compartilhamento atual no Hub: "..hubshare.." GB. Recorde: "..ttshare.." GB.") 
   user:SendData(Bot, "    	  ? Logins no Hub: "..Stat.logins.." - Resetado: 21/03/04.")
   user:SendData(Bot, "    	  ? Lista de comandos, regras, ajuda e informa??o: !ajuda") 
   user:SendData(Bot, "    	  ? "..GetTime().."") 
   user:SendData(Bot, "    	  ? Website - F?rum: [URL]www.lusobrasil.site.vu[/URL]") 
   user:SendData(Bot, "-=[?]=-----------------------------------------------------------------------------------------------------------------=[?]=-") 
   user:SendData(Bot, "		<-----=[- "..frmHub:GetHubName().." ? v2004 ? Multi-Hub -]=----->") 
   user:SendData(Bot, "-=[?]=-----------------------------------------------------------------------------------------------------------------=[?]=-") 
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function GetTime()
	s = date("%S")
	h = date("%H")
	m = date("%M")
	d = date("%d")
	mm = date("%m")
	y = date("%y")
	Date = "Hora local: "..h..":"..m..":"..s.." - "..d.."/"..mm.."/20"..y.."."
	return Date
end
-------------------------------------------------------------------------------------------------------------------------------------------------
ALLUSERS={}

function NewUserConnected(user)
	local s,e,usrshare = strfind(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) == "Cliente sem TAG ou Cliente desconhecido.") then
	SendToOps(Bot, "Usu?rio: "..user.sName..", est? com um Cliente sem TAG ou Cliente desconhecido.")
   end
   Message(user)
end
-------------------------------------------------------------------------------------------------------------------------------------------------
OpConnected = NewUserConnected
-------------------------------------------------------------------------------------------------------------------------------------------------
function DataArrival(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= strfind(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 = strfind(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 format("[%q]",key) or format("[%d]",key);

		if(type(value) == "table") then
			Serialize(value, sKey, hFile, sTab.."\t");
		else
			local sValue = (type(value) == "string") and 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 (strfind(user.sMyInfoString, "

SMF spam blocked by CleanTalk