HubRanks
 

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

Started by Cêñoßy†ê, 23 March, 2006, 14:45:15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Cêñoßy†ê

-- HubRanking Bot v3.6 LUA 5.0.2
-- Made by Optimus 1-03-2005
-- Extra custom ranking members added by TiMeTrAVelleR
-- Lua 5.1 fix by C??o?y??

tCommands = {}
tFunctions = {}

-- Your Bot name
sBot = "ChatRankeR"
-- Your Menu name
bMenu = "----? ChaTRanKs"
-- 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 = iInterval + iProcent
iInterval = 500
-- Procents beeing added to iInterval
iProcent = 20 -- 20%
-- 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 Current ChatRank     "..tFunctions.GetRankName(tRankingTable[user.sName]).."    With "..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.maxn(tRankMembers) do
		Info = Info.."\t  "..i..". Rank: "..tRankMembers[i]..", Points: "..string.format("%0.f", iRankValue).."\r\n"
		iRankValue = iRankValue + iInterval + iInterval/100*iProcent
	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 <nick>")
		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

tCommands["chrank"] = function(user, data)
	if user.iProfile == 5 then
		local s,e,name,nr = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(%d+)")
		if name and nr then
			if tRankingTable[name] then
				tRankingTable[name] = tonumber(nr)
				saveTableToFile(RankFile, tRankingTable, "tRankingTable")
				user:SendMessage(sBot,"Points user "..name.." changed to: "..nr)
			end
		else
			user:SendMessage(sBot, "*** Usage: !chrank <nick> <nr>")
		end
	end 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.maxn(tRankMembers) do
		local iStart,iEnd = iRankValue, iRankValue + iInterval + iInterval/100*iProcent
		if points >= tonumber(iStart) and points <= tonumber(iEnd) then
			iRank = tRankMembers[i]
		end
		iRankValue = iEnd
	end
	return iRank
end

tFunctions.ShowRanks = function()
	local tTemp = {}
	for i,v in pairs(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.."\\Get Users Rank$<%[mynick]> !getrank %[nick] &#124;")
			user:SendData("$UserCommand 1 3 "..bMenu.."\\Ranks Info$<%[mynick]> !ranksinfo &#124;|")
			user:SendData("$UserCommand 1 3 "..bMenu.."\\Show My Rank$<%[mynick]> !myrank &#124;")
			user:SendData("$UserCommand 1 3 "..bMenu.."\\Shows Top Ranks$<%[mynick]> !topranks &#124;")
			user:SendData("$UserCommand 1 3 "..bMenu.."\\Change Users Rank (Founder Only)$<%[mynick]> !chrank %[nick] %[line:Points]&#124;")
		end
	end
end

----------------------------------------------
-- load & save Tables
----------------------------------------------
Serialize = function(tTable, sTableName, hFile)
	hFile:write(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
			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


Script needs this file allso as ranksmembers.tbl

Standard = { "Newbie", "Member", "Cool Member", "Hub-As", "Smart As", "Double-As", "Triple-As", "Conqueror", "Viking", "King", "Emperor", "Hub Legend", "Hub God","God" }
Army = { "Cadet", "Second Lieutenant", "First Lieutenant", "Army Captain", "Major", "Lieutenant Colonel", "Colonel", "Brigadier General", "Major General", "Lieutenant General", "General", "General of the Army" }
Enterprise = { "Recruit", "Crewman", "Chief Officer", "Master Chief Officer", "Ensign", "Lieutenant", "Lieutenant Commander", "Commander", "Captain", "Commodore", "Admiral", "Fleet Admiral" }
SF = { "Cadet", "Gunner", "Crew Sniper", "Maintence Officer", "Weapons Technician", "Demolitions Technician", "BioTechnician", "Ship Pilot", "Communications Officer", "Security Officer", "Squad Commander", "Commanding Officer" }


and ranksusers.tbl

tRankingTable = {
}
Powered By Leviathan™ 2nd Generation v. 1.9

TiMeTrAVelleR

when using topranks  i get this error
13:37] Syntax ...B Leviathan\scripts\HubRanks_v3.6 By Optimus_5.1.lua:155: attempt to call a table value

tryed some stuff   but stil a noob :P

greetzz TT

Markitos

Quote from: T?M??r?V?ll?R on 25 March, 2006, 13:39:33
when using topranks  i get this error
13:37] Syntax ...B Leviathan\scripts\HubRanks_v3.6 By Optimus_5.1.lua:155: attempt to call a table value

tryed some stuff   but stil a noob :P

greetzz TT
i think u should change line 156 to this
for i,v in pairs(tRankingTable) do table.insert(tTemp,{i,v}) end

TiMeTrAVelleR

#3
yup did it thanks?  stupid me  forgot that one

Cêñoßy†ê

Script updated  ;D
Powered By Leviathan™ 2nd Generation v. 1.9

balblub

Hi

It doesn?t work at me. I got an error
hubranking.lua:80: attempt to call field `maxn' (a nil value)


Can anybody help me?   ::)

Psycho_Chihuahua

well then you must have done something wrong or you are using the wrong PtokaX Version - are you sure you have a Lua 5.1 Version?
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

bastya_elvtars

Guys, please don't use table.maxn, it's rather for mixed tables. If there is an array tbl={1,2,3,4,5,6,7,8,9,10} then use print(#tbl) to get its size.
Moreover, table.getn still works. :)
Everything could have been anything else and it would have just as much meaning.

balblub


speedX

hey there are some options in ranksmembers.tbl ..........like standard, army, enterprise and SF...how do i use them???
Thanking You,

speedX

Cêñoßy†ê

Quote from: speedX on 21 August, 2006, 20:16:39
hey there are some options in ranksmembers.tbl ..........like standard, army, enterprise and SF...how do i use them???

-- Set ranks members of choice
tRankMembers = Standard
Powered By Leviathan™ 2nd Generation v. 1.9

speedX

Thanking You,

speedX

Troubadour

Added dutch member ranking value!
http://nederfun.no-ip.com/ChatRank.rar

don't forget to set
-- Set ranks members of choice
tRankMembers = Dutch
Regards,

Troubadour

** Guardian Forum **

hubaddy:   nederfun.no-ip.com

7P-Darkman

Hello friends...


In annex, HubRanking Bot v3.6 LUA 5.1, totally translated for Brazilian Portuguese, and added "Pantaneiro" members ranking value.

Respectfully,


7P-Darkman
Owner of HUB Pantanal - Brasil

SMF spam blocked by CleanTalk