Author Topic: - Hubranks script  (Read 5409 times)

0 Members and 1 Guest are viewing this topic.

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
- Hubranks script
« on: 31 March, 2005, 17:11:29 »
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

PtokaX forum

- Hubranks script
« on: 31 March, 2005, 17:11:29 »

Offline Requiem

  • Forum Ace
  • *****
  • Posts: 95
  • Karma: +0/-0
(No subject)
« Reply #1 on: 01 April, 2005, 12:39:09 »
Just added some missing parts (imo they were missing  ;) ) and corrected some typo mistakes...

Code: [Select]
-- 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
« Last Edit: 01 April, 2005, 12:42:50 by Requiem »

Offline kash?

  • Double Ace
  • *
  • Posts: 101
  • Karma: +0/-1
(No subject)
« Reply #2 on: 24 May, 2005, 20:10:03 »
Is it possible to display those
chat stats after MOTD...
because of MOTD, that message can
not be seen as it goes upwards

Offline TRANCEMASTER

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
(No subject)
« Reply #3 on: 08 July, 2005, 06:05:49 »
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

Offline Sarpanch

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #4 on: 08 July, 2005, 16:20:17 »
Any way i can get it into pm instead of main??

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #5 on: 08 July, 2005, 16:57:04 »
use this ;)

Code: [Select]
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

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #6 on: 08 July, 2005, 16:58:55 »
Quote
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
Sorry i have no LUA4 version for hands at the moment. I'm sure some 1 will convert this for you

- Optimus

Offline Sarpanch

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #7 on: 08 July, 2005, 21:16:21 »
;) thanks alot!!

Offline Jacko

  • Member
  • ***
  • Posts: 32
  • Karma: +0/-0
  • STARE and you will see
(No subject)
« Reply #8 on: 08 July, 2005, 22:43:57 »
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

Offline Sarpanch

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #9 on: 09 July, 2005, 23:22:49 »
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 :]

Offline Jacko

  • Member
  • ***
  • Posts: 32
  • Karma: +0/-0
  • STARE and you will see
(No subject)
« Reply #10 on: 10 July, 2005, 21:04:48 »
BIG thanks Sarpanch....working fine now :))
if I read this for long enough maybe one day i will understand

Offline Sarpanch

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #11 on: 05 September, 2005, 01:41:30 »
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  :]

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #12 on: 23 October, 2005, 22:09:22 »
Updated version to more logical algorithm, download HubRanks_v3.6.rar   here

- Enjoy Optimus

PtokaX forum

(No subject)
« Reply #12 on: 23 October, 2005, 22:09:22 »