Membercount
 

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

Membercount

Started by Yahoo, 19 July, 2010, 19:33:18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yahoo

Is it possible for someone to convert this script to latest API. It will be great

-- Member Count
-- Made by Madman
-- Requested by SwapY
-- Small bugfix, report by Markitos
-- Small changes by NL

Members = {}

function Main()
	-- Make file
	local file = io.open("Members.dat")
	if file then
		file:close()
	else
		local file = io.open("Members.dat", "w+")
		file:write("Members = {\n}")
		file:close()
	end
	-- Load file
	LoadFromFile("Members.dat")
end

function ChatArrival(curUser, data)
	local data = string.sub(data, 1, -2)
	local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%#](%S+)")
	if cmd == "membercount" then -- find cmd
	SendToAll(data)
		local RegC, OnlineC, ActiveC, vCount = 0,0,0,0
		for count,_ in pairs(frmHub:GetRegisteredUsers()) do -- Get regged users
			RegC = count -- RegC is count
		end
		for count,oUser in pairs(frmHub:GetOnlineRegUsers()) do -- Get online reg users
			OnlineC = count
			if oUser.bActive then -- If user is Active
				-- Add to table
				if Members[oUser.sName] == nil then
					Members[oUser.sName] = {Active = 1}
					SaveToFile("Members.dat", Members, "Members")
				else
					if not Members[oUser.sName].Active then
						Members[oUser.sName].Active = 1
						SaveToFile("Members.dat", Members, "Members")
					end
				end
			end
		end
		for name,_ in pairs(Members) do -- Get names from tables
			if Members[name].Active then -- Get the Active
				ActiveC = ActiveC+1 -- Count them
			end
			if Members[name].LastSeen then -- Get thoose who are offline
				if Members[name].LastSeen == os.date("%Y-%m-%d") then -- Check if they has todays date
					vCount = vCount+1 -- if they do, count
				else -- if not
					Members[name].LastSeen = nil -- Remove from table
					SaveToFile("Members.dat", Members, "Members") -- Save
				end
			end
		end
		SendToAll(frmHub:GetHubBotName(), "" ..RegC.. " registered users, " ..ActiveC.. " active, " ..vCount.. " visited the hub in last 24 hrs, " ..OnlineC.. " currently online")
		return 1
	end
end

function NewUserConnected(curUser)
	if frmHub:isNickRegged(curUser.sName) then -- Is user reg?
		if Members[curUser.sName] and  Members[curUser.sName].LastSeen then -- Is user in table with LastSeen
			Members[curUser.sName].LastSeen = nil -- Delte it
		end
		if curUser.bActive then -- Is user active?
			-- Add to table
			if Members[curUser.sName] == nil then
				Members[curUser.sName] = {Active = 1}
			else
				Members[curUser.sName].Active = 1
			end
		end
		SaveToFile("Members.dat", Members, "Members") -- Save it
	end
end

OpConnected = NewUserConnected

function UserDisconnected(curUser)
	if frmHub:isNickRegged(curUser.sName) then -- Is user reg?
		-- Add to table
		if Members[curUser.sName] == nil then
			Members[curUser.sName].LastSeen = {os.date("%Y-%m-%d")}
		else
			Members[curUser.sName].LastSeen = os.date("%Y-%m-%d")
		end
		SaveToFile("Members.dat", Members, "Members") -- Save it
	end
end

OpDisconnected = UserDisconnected

-- Serialize by nErBoS
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 pairs(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(filename)
	local f = io.open(filename)
	if f then
		local r = f:read("*a")
		f:flush()
		f:close()
		local func,err = loadstring(r)
		if func then x,err = pcall(func) end
	end
end



Thanks In Advance :D
"BoRN FIGhTEr"

TZB

-- This script is converted with PtokaX LUA API Converter v0.9b at 07/24/10 15:46:18
-- Member Count
-- Made by Madman
-- Requested by SwapY
-- Small bugfix, report by Markitos
-- Small changes by NL

Members = {}

function OnStartup()
	-- Make file
	local file = io.open("Members.dat")
	if file then
		file:close()
	else
		local file = io.open("Members.dat", "w+")
		file:write("Members = {\n}")
		file:close()
	end
	-- Load file
	LoadFromFile("Members.dat")
end

function ChatArrival(curUser,data)
	local data = string.sub(data, 1, -2)
	local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%#](%S+)")
	if cmd == "membercount" then -- find cmd
	Core.SendToAll(data)
		local RegC, OnlineC, ActiveC, vCount = 0,0,0,0
		for count,_ in pairs(RegMan.GetRegs()) do -- Get regged users
			RegC = count -- RegC is count
		end
		for count,oUser in pairs(Core.GetOnlineRegs(true)) do -- Get online reg users
			OnlineC = count
			if Core.GetUserValue(oUser,10) then -- If user is Active
				-- Add to table
				if Members[oUser.sNick] == nil then
					Members[oUser.sNick] = {Active = 1}
					SaveToFile("Members.dat", Members, "Members")
				else
					if not Members[oUser.sNick].Active then
						Members[oUser.sNick].Active = 1
						SaveToFile("Members.dat", Members, "Members")
					end
				end
			end
		end
		for name,_ in pairs(Members) do -- Get names from tables
			if Members[name].Active then -- Get the Active
				ActiveC = ActiveC+1 -- Count them
			end
			if Members[name].LastSeen then -- Get thoose who are offline
				if Members[name].LastSeen == os.date("%Y-%m-%d") then -- Check if they has todays date
					vCount = vCount+1 -- if they do, count
				else -- if not
					Members[name].LastSeen = nil -- Remove from table
					SaveToFile("Members.dat", Members, "Members") -- Save
				end
			end
		end
		Core.SendToAll("<"..SetMan.GetString(21).."> " ..RegC.. " registered users, " ..ActiveC.. " active, " ..vCount.. " visited the hub in last 24 hrs, " ..OnlineC.. " currently online")
		return true
	end
end

function UserConnected(curUser)
	if RegMan.GetReg(curUser.sNick) then -- Is user reg?
		if Members[curUser.sNick] and  Members[curUser.sNick].LastSeen then -- Is user in table with LastSeen
			Members[curUser.sNick].LastSeen = nil -- Delte it
		end
		if Core.GetUserValue(curUser,10) then -- Is user active?
			-- Add to table
			if Members[curUser.sNick] == nil then
				Members[curUser.sNick] = {Active = 1}
			else
				Members[curUser.sNick].Active = 1
			end
		end
		SaveToFile("Members.dat", Members, "Members") -- Save it
	end
end

OpConnected = UserConnected

function UserDisconnected(curUser)
	if RegMan.GetReg(curUser.sNick) then -- Is user reg?
		-- Add to table
		if Members[curUser.sNick] == nil then
			Members[curUser.sNick].LastSeen = {os.date("%Y-%m-%d")}
		else
			Members[curUser.sNick].LastSeen = os.date("%Y-%m-%d")
		end
		SaveToFile("Members.dat", Members, "Members") -- Save it
	end
end

OpDisconnected = UserDisconnected

-- Serialize by nErBoS
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 pairs(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(filename)
	local f = io.open(filename)
	if f then
		local r = f:read("*a")
		f:flush()
		f:close()
		local func,err = loadstring(r)
		if func then x,err = pcall(func) end
	end
end
RegConnected = UserConnected
RegDisconnected = UserDisconnected

Simple converter did the trick.

SMF spam blocked by CleanTalk