-- 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] |")
user:SendData("$UserCommand 1 3 "..bMenu.."\\Ranks Info$<%[mynick]> !ranksinfo ||")
user:SendData("$UserCommand 1 3 "..bMenu.."\\Show My Rank$<%[mynick]> !myrank |")
user:SendData("$UserCommand 1 3 "..bMenu.."\\Shows Top Ranks$<%[mynick]> !topranks |")
user:SendData("$UserCommand 1 3 "..bMenu.."\\Change Users Rank (Founder Only)$<%[mynick]> !chrank %[nick] %[line:Points]|")
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 = {
}
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
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
yup did it thanks? stupid me forgot that one
Script updated ;D
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? ::)
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?
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. :)
thx work fine ;)
hey there are some options in ranksmembers.tbl ..........like standard, army, enterprise and SF...how do i use them???
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
oh thx dude....
Added dutch member ranking value!
http://nederfun.no-ip.com/ChatRank.rar (http://nederfun.no-ip.com/ChatRank.rar)
don't forget to set
-- Set ranks members of choice
tRankMembers = Dutch
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