- Hubranks 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

- Hubranks script

Started by Optimus, 31 March, 2005, 17:11:29

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Optimus

Hi here a hubrankings script, was some crazzy idea i had togheter with timetraveller some while ago.
It's pretty basic idea maybe could add some more features or changes. Just try out and let me hear

HubRanks_v3.5

- Optimus

Requiem

#1
Just added some missing parts (imo they were missing  ;) ) and corrected some typo mistakes...

-- HubRanking Bot LUA 5.0.2
-- Made by Optimus 1-03-2005
-- Extra custom ranking members added by TiMeTrAVelleR
-- Edited by Requiem (aka GeceBekcisi)

tCommands = {}
tFunctions = {}

-- Your Bot name
sBot = "BotName"
-- Your Menu name
bMenu = "MenuName"
-- Load all rankings members into memory
dofile("ranksmembers.tbl")
-- Table used for rankings users
tRankingTable = {}
-- File where ranking users is stored
RankFile = "ranksusers.tbl"
-- Interval points between rank members + iSomeValue/number of rank
iInterval = 250
-- This value is defid by Number rank member and added to iInterval difference
iSomeValue = 5000 -- iSomeValue/number of rank
-- Total off displayed ranked members
MaxShowed = 50
-- Set ranks members of choice
tRankMembers = Standard
-- Send usercommands on connect 1=on/0=off
UserCommands = 1
-- Your command prefixes here
CmdPrefix = { ["!"] = 1, ["?"] = 1, ["+"] = 1}

-- Sets who can use Rankings script
tSetProfile = {
[0] = 1,   -- Masters
[1] = 1,   -- Operators
[2] = 1,   -- Vips
[3] = 1,   -- Regs
[4] = 1,   -- Moderator
[5] = 1,   -- NetFounder
}

Main = function()
	frmHub:RegBot(sBot)
	dofile(RankFile)
end

OnExit = function()
	saveTableToFile(RankFile, tRankingTable, "tRankingTable")
end

ChatArrival = function(user, data)
	if tSetProfile[user.iProfile] == 1 then tFunctions.UpdateRanks(user) end
	user.SendMessage = user.SendData return tFunctions.GetCommands(user, data)
end

ToArrival = function(user, data)
	local s,e,to = string.find(data, "$To: (%S+%s?%S*)%sFrom:")
	if to == sBot then
		user.SendMessage = user.SendPM return tFunctions.GetCommands(user, data)
	end
end

NewUserConnected = function(user)
	if tSetProfile[user.iProfile] == 1 then
		if tRankingTable[user.sName] then
			user:SendData(sBot, "Your ChatRank: "..tFunctions.GetRankName(tRankingTable[user.sName]).." / "..tRankingTable[user.sName].." Points")
		end tFunctions.SendCommands(user)
	end
end

OpConnected = NewUserConnected

--// Commands ----------------------------------------------------------------------------------------------------------

tCommands["ranksinfo"] = function(user, data)
	local iRankValue = 0
	local Info = " ? Current Ranking Members ?\r\n\r\n"
	Info = Info.."\t??????????????????????????????????????????\r\n"
	for i = 1,table.getn(tRankMembers) do
		local iRankDif = iSomeValue / table.getn(tRankMembers) * i
		Info = Info.."\t  "..i..". Rank: "..tRankMembers[i]..", Points: "..string.format("%0.f", iRankValue).."\r\n"
		iRankValue = iRankValue + iInterval + iRankDif
	end
	Info = Info.."\t??????????????????????????????????????????\r\n"
	user:SendMessage(sBot, Info)
	return 1
end

tCommands["getrank"] = function(user, data)
	if user.bOperator then
		local s,e,name = string.find(data, "%b<>%s+%S+%s+(%S+)")
		if name then
			if tRankingTable[name] then
				user:SendMessage(sBot, name.." ChatRank: "..tFunctions.GetRankName(tRankingTable[name]).." / "..tRankingTable[name].." Points")
			else
				user:SendMessage(sBot, "*** User not found!")
			end
		else
			user:SendMessage(sBot, "*** Usage: !getrank ")
		end
	end return 1
end

tCommands["myrank"] = function(user, data)
	if tRankingTable[user.sName] then
		user:SendMessage(sBot,"Your ChatRank: "..tFunctions.GetRankName(tRankingTable[user.sName]).." / "..tRankingTable[user.sName].." Points")
	end return 1
end

tCommands["topranks"] = function(user, data)
	user:SendMessage(sBot, tFunctions.ShowRanks())
	return 1
end

--// Functions ---------------------------------------------------------------------------------------------------------

tFunctions.GetCommands = function(user, data)
	data=string.sub(data,1,string.len(data)-1)
	local s,e,prefix,cmd = string.find(data, "%b<>%s*(%S)(%S+)")
	if prefix and CmdPrefix[prefix] and tCommands[cmd] then
		if tSetProfile[user.iProfile] == 1 then
			return tCommands[cmd](user, data)
		end
	end
end

tFunctions.GetRankName = function(points)
	local iRank,iRankValue = tRankMembers[table.getn(tRankMembers)],0
	for i = 1,table.getn(tRankMembers) do
		local iRankDif = iSomeValue / table.getn(tRankMembers) * i
		local iStart,iEnd = string.format("%0.f", iRankValue), string.format("%0.f", iRankValue + iInterval + iRankDif)
		if points >= tonumber(iStart) and points <= tonumber(iEnd) then
			iRank = tRankMembers[i]
		end
		iRankValue = iRankValue + iInterval + iRankDif
	end
	return iRank
end

tFunctions.ShowRanks = function()
	local tTemp = {}
	for i,v in tRankingTable do table.insert(tTemp,{i,v}) end
	table.sort(tTemp,function(a,b) return (a[2] > b[2]) end)
	local disp = " ? Current Top ChatRankings ?\r\n\r\n"
	disp = disp.."\tNr:\tPoints:\tRank:\t\tNick:\r\n"
	disp = disp.."\t??????????????????????????????????????????????????\r\n"
	for i = 1,MaxShowed do
		if tTemp[i] then
			disp = disp.."\t"..i..".\t"..tTemp[i][2].."\t"..tFunctions.GetRankName(tTemp[i][2]).."\t\t"..tTemp[i][1].."\r\n"
		end
	end 
	disp = disp.."\t??????????????????????????????????????????????????\r\n"
	return disp
end

tFunctions.UpdateRanks = function(user)
	local iUpdate = tRankingTable[user.sName] or 0
	iUpdate = iUpdate + 1 tRankingTable[user.sName] = iUpdate
end

----------------------------------------------
-- Modify [ "..bMenu.."\\Ranks\\ ] part of script as [ "..bMenu.."\\ ] if you dont want items to be displayed under a " Ranks " menu
----------------------------------------------
tFunctions.SendCommands = function(user)
	if UserCommands == 1 then
		if user.bUserCommand then
			user:SendData("$UserCommand 0 3")
			user:SendData("$UserCommand 1 3 "..bMenu.."\\Ranks\\Get Users Rank$<%[mynick]> !getrank %[nick] ||")
			user:SendData("$UserCommand 1 3 "..bMenu.."\\Ranks\\Ranks Info$<%[mynick]> !ranksinfo ||")
			user:SendData("$UserCommand 1 3 "..bMenu.."\\Ranks\\Show My Rank$<%[mynick]> !myrank ||")
			user:SendData("$UserCommand 1 3 "..bMenu.."\\Ranks\\Shows Top Ranks$<%[mynick]> !topranks ||")
		end
	end
end

----------------------------------------------
-- load & save Tables
----------------------------------------------
Serialize = function(tTable, sTableName, hFile)
	hFile:write(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)
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value)
			hFile:write(sKey.." = "..sValue)
		end hFile:write(",\n")
	end hFile:write("}")
end
-----------------------------------------------------------
saveTableToFile = function(file, table, tablename)
	local handle = io.open(file,"w")
	Serialize(table,tablename,handle)
   	handle:close()
end

kash?

Is it possible to display those
chat stats after MOTD...
because of MOTD, that message can
not be seen as it goes upwards

TRANCEMASTER

Hi friends

i need the HubRank script in Lua4

This is a greatfull script.

can anyone change it in Lua4 ?.....

......Big THX to the scripters

Sarpanch

Any way i can get it into pm instead of main??

Optimus

use this ;)

NewUserConnected = function(user)
	if tSetProfile[user.iProfile] == 1 then
		if tRankingTable[user.sName] then
			user:SendPM(sBot, "Your ChatRank: "..tFunctions.GetRankName(tRankingTable[user.sName]).." / "..tRankingTable[user.sName].." Points")
		end tFunctions.SendCommands(user)
	end
end

Optimus

QuoteHi friends

i need the HubRank script in Lua4

This is a greatfull script.

can anyone change it in Lua4 ?.....

......Big THX to the scripters
Sorry i have no LUA4 version for hands at the moment. I'm sure some 1 will convert this for you

- Optimus

Sarpanch


Jacko

Hiya
can i pick the brains of you wise ones please...Do i need to make a file or folder for this script or should it make its own....the reason i ask is i get this error

Syntax cannot read ranksmembers.tbl: No such file or directory
if I read this for long enough maybe one day i will understand

Sarpanch

Hey yea it wont work without the two other files needed go here Hub Ranks
but delte the actual lua file as there are some missing parts n shud work :]

Jacko

BIG thanks Sarpanch....working fine now :))
if I read this for long enough maybe one day i will understand

Sarpanch

Hi again just need abit of help is it possible to get "Current Top ChatRankings" so that evreyone else can see it not only the one user? Thanks in advanced  :]

Optimus

Updated version to more logical algorithm, download HubRanks_v3.6.rar   here

- Enjoy Optimus

SMF spam blocked by CleanTalk