this is what i asked in the ptokax admin hub:
[11:14:29] <vin-diesel> Is there a possibility that you can make a script like Topchatters but then rank with profiles. So if you chat and you got enough points that you change youre profile from reg to vip and then from vip to op??
[11:15:11] <blastbeat> yes
[11:15:54] <vin-diesel> can you make that for me then?
[11:16:02] <vin-diesel> I want it
[11:16:10] <vin-diesel> I want to make a mafia hub
[11:16:20] <vin-diesel> make about 13 profiles in ptokax
[11:16:42] <blastbeat> I think it makes no sense because everyone can spam and then get op
[11:17:07] <vin-diesel> it makes sense
[11:17:12] <vin-diesel> but they dont get a key
[11:17:25] <vin-diesel> I want to make 13 user profiles with no key
[11:17:38] <vin-diesel> and that they can rank in those profiles
[11:17:46] <vin-diesel> Scum
[11:17:48] <vin-diesel> Thug
[11:17:49] <vin-diesel> Gangster
[11:17:53] <vin-diesel> Hitman
[11:17:54] <vin-diesel> Boss
[11:17:59] <blastbeat> LooL
[11:19:34] <blastbeat> I am busy at the moment, write a script request at ptokax board maybe someone will help you
So what i want --> Is there a possibility that you can make a script like Topchatters but then rank with profiles. So if you chat and you got enough points that you change youre profile from reg to vip and then from vip to op??
Thx in advanced who makes it.
Greats
Syphrone-NL
Quote from: Mutor on 15 July, 2007, 12:50:21
Are you for real? What does how much one chats
have to do with being an operator?
They won't become operators, he did write it down. He creates funny mafia profiles.
Isn't there a Topchatter script allready that gives Rank?
Wouldn't that be enough, No need to change profiles, they just get a rank...
Quote from: Mutor on 15 July, 2007, 13:21:11
I think it a bad idea to upgrade to key holder profiles and beyond.
Agreed. Operators should be elected on a slightly different basis.
I dont want to give them a key.
but i give each profile 1 permission more. I know topchatters and that you can rank there. But i want to change profile not change a rank. So maybe then people go chat more. Just want to create a fun mafia hub. So is it possible or not? And if its possible who wants to make it for me? Or is it not allowed?
-- ChatStats v3 Made By Optimus
-- Based on Tezlo chats
-- Added Send Commands By TiMeTrAVelleR
-- Madman fixed some in commands
-- Converted to lua5 by Madman with very little help by Jelf
-- with some help by ?
-- fixed stats saving on exit by jiten
---- Modded by Madman
-- Added so it's creates ChatStatsFile, if it's missing
-- Fixed so it dont counts commands
-- Added a IgnoreTable, users in that wont be counted
---- Madman Return's
-- Changed: New ChatArrival
-- Changed: Some Commands
-- Changed: Some small code...
-- Changed: Modded 4 my hub
---- Madman strikes again
-- Added: a lowerchatter cmd, use it to lower someones chatstats post
-- Changed to lua 5.1 by TT
-- Added: chatter of Month, Madman, requested by BrotherBear
-- Added: not case senastive, all nicks will be loged in lower case, Madman, requested by Yahoo
-- Madman does it again
-- Added: Total (char+words+post), request by -SkA-
-- Adedd: Option for Total
-- Changed: Cleaned up code, chatstats,chatmonth and topchat now use same function
-- Added: Sorting by Total, request by -SkA-
-- Changed: Shortstats Option
---- Updated again, by Madman
-- Added: UseMonthStats, so you don't have to use the month stats
-- Added: Profile ranking code..., request by Syphrone-NL
-- Changed: New ranking code
-- Added: Kill command, request by Syphrone-NL
-- Fixed: bugs in kill command
sBot = frmHub:GetHubBotName() -- Name of Bot
SendComm = 1 -- Send UserCommands, 1 = On 0 = Off
pMenu = "-=( ChatStats )=-" -- Name of Menu
UseMonthStats = 1 -- 1 = On / 0 = Off
UseTotal = 1 -- Add Total (char+words+post) in the chatstats, 1 = On 0 = Off
Sortstats = 5 -- 2=posts / 3 = chars / 4 = words / 5 = Total
Chatstats = {}
ChatstatsMonth = {}
ChatStatsFile = "chatstats.tbl"
IgnoreTable = {
-- 0=dont ignore/1=ignore
["-=FakeKiller=-"] = 1,
}
EnableChatStats = {
[0] = 1, -- Master
[1] = 1, -- Operators
[2] = 1, -- Vips
[3] = 1, -- Regs
[-1] = 1, -- Users (UnRegged)
}
AllowedProfiles = {
[0] = 1, -- Masters
[1] = 0, -- Operators
}
rankProfiles = {
-- Posts = Rank to get
["1000"] = "1",
["2000"] = "2",
}
---------- Warning! Do Not Edit! -----------
ChatStatsFileMonth = "chatstats - " ..os.date("%y-%m").. ".tbl"
---------- Warning! Do Not Edit! -----------
function Main()
frmHub:RegBot(sBot)
CheckFile(ChatStatsFile)
dofile(ChatStatsFile)
if UseMonthStats == 1 then
CheckFile(ChatStatsFileMonth)
dofile(ChatStatsFileMonth)
end
end
function CheckFile(File)
local file = io.open(File, "r")
if file then
file:close()
else
local file = io.open(File, "w+")
file:write()
file:close()
end
end
function NewUserConnected(user)
if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
if Chatstats[string.lower(user.sName)] then
user:SendData(sBot, "---===[ Your Chat Stats: You Made "..Chatstats[string.lower(user.sName)]["post"].." Posts In Main Used "..Chatstats[string.lower(user.sName)]["chars"].." Characters, And "..Chatstats[string.lower(user.sName)]["words"].." Words ]===---")
end
user:SendData("$UserCommand 1 3 "..pMenu.."\\Chat stats$<%[mynick]> !chatstats|")
if UseMonthStats == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Chat stats Year-Month$<%[mynick]> !chatmonth %[line:YY-MM]|")
end
user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mystats|")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Op menu\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]|")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Op Menu\\Lower Chatter$<%[mynick]> !lowerchatter %[line:Nick] %[line:New posts]|")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Op Menu\\Clear Chat Stats$<%[mynick]> !clearstats|")
end
if user.bOperator then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Op Menu\\TopChatters in Main$<%[mynick]> !topchat|")
end
end
end
OpConnected = NewUserConnected
function OnExit()
if isEmpty(Chatstats) then
else
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
if UseMonthStats == 1 then
saveTableToFile(ChatStatsFileMonth, ChatstatsMonth, "ChatstatsMonth")
end
end
end
function IsCmd(str)
return string.sub(str, 1, 1) == "!" or string.sub(str, 1, 1) == "?" or string.sub(str, 1, 1) == "+" or string.sub(str, 1, 1) == "$"
end
function ChatArrival(user, data)
if EnableChatStats[user.iProfile] == 1 then
local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if IsCmd(cmd) then
elseif IgnoreTable[string.lower(user.sName)] == 1 then
else
local s,e,str = string.find(data, "%b<>%s+(.*)%|")
updStats(string.lower(user.sName), str)
end
end
local data = string.sub(data,1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?](%S+)")
if cmd then
cmd = string.lower(cmd)
local tCmds = {
["kill"] = function(user,data)
local s,e,nick = string.find(data,"%b<>%s+%S+%s+(%S+)")
Z,u,Hit = nil,nil,0
if nick then
Zombie = GetItemByName(nick)
if Zombie then
if user.iProfile >= Zombie.iProfile then
for posts,prof in pairs(rankProfiles) do
prof = tonumber(prof)
if prof == Zombie.iProfile then
Z = 1
end
if prof == user.iProfile then
u = 1
end
end
if Z and u then
math.randomseed(os.clock())
Hit = math.random(0,10)
SendToAll(Hit)
if Hit >= 5 then
Posts = math.random(1,20)
local tmp = Chatstats[string.lower(Zombie.sName)]
tmp["post"] = tmp["post"] - Posts
for posts,prof in pairs(rankProfiles) do
prof = tonumber(prof)
if Zombie.iProfile == prof then
-- Do Nothing atm
else
ChangeRegUser(Zombie.sName,frmHub:GetUserPassword(Zombie.sName),prof)
Zombie:SendPM(sBot,"You have be downgraded to " ..GetProfileName(prof).. ". Please reconnect")
end
break
end
Chatstats[string.lower(Zombie.sName)] = tmp
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
SendToAll(sBot,Zombie.sName.. " got shot " ..user.sName.. ", and lost " ..Posts)
else
SendToAll(sBot,user.sName.. " tried to killed " .. Zombie.sName.. " but failed")
end
else
user:SendData(sBot,"Sorry, you can't play")
end
else
user:SendData(sBot, nick.. " has a higher rank you cant kill him")
end
else
user:SendData(sBot,nick.. " is not online")
end
else
user:SendData(sBot,"Syntax: !" ..cmd.." <nick>")
end
return 1
end,
["mystats"] = function(user, data)
if Chatstats[string.lower(user.sName)] then
user:SendData(sBot, "---===[ Your Chat Stats: You Made "..Chatstats[string.lower(user.sName)]["post"].." Posts In Main Used "..Chatstats[string.lower(user.sName)]["chars"].." Characters, And "..Chatstats[string.lower(user.sName)]["words"].." Words ]===---")
else
user:SendData(sBot, "*** No chat statics found!")
end
return 1
end,
["chatstats"] = function(user, data)
Topic = "Current Top Chatters"
Msg = Stats(Topic)
user:SendPM(sBot,Msg)
return 1
end,
["chatmonth"] = function(user,data)
if UseMonthStats == 1 then
local _,_,Y,M = string.find(data,"%b<>%s+%S+%s+(%d%d)%-(%d%d)")
if Y and M then
Topic = "Current Top Chatters of Month"
Msg = Stats(Topic,Y,M)
user:SendPM(sBot,Msg)
else
user:SendData(sBot, "Syntax: !chatmonth YY-MM i.e 07-02 for feb, 07")
end
else
user:SendData(sBot,"This function is disabled")
end
return 1
end,
["topchat"] = function(user, data)
if user.bOperator then
Topic = "Current Top Chatters"
Msg = Stats(Topic)
SendToAll(sBot,Msg)
return 1
end
end,
["lowerchatter"] = function(user, data)
if AllowedProfiles[user.iProfile] == 1 then
local s,e,name,chat = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(%d+)")
if name and chat then
if Chatstats[name] then
chat = tonumber(chat)
if Chatstats[name]["post"] <= chat then
user:SendData(sBot, "*** You can not raise the stats!")
else
local OldChat = Chatstats[name]["post"]
Chatstats[name]["post"] = chat
SendToOps(sBot, "*** Chatstats posts for " ..name.. " has been lowered to " ..chat.. " from " ..OldChat.. " by " ..string.lower(user.sName))
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end
else
user:SendData(sBot, "*** " ..name.. " is not in chatstats")
end
else
user:SendData(sBot, "*** Usage: !lowerchatter <name> <new posts>")
end
return 1
end
end,
["delchatter"] = function(user, data)
if AllowedProfiles[user.iProfile] == 1 then
local s,e,name = string.find(data, "%b<>%s+%S+%s+(%S+)" )
if name then
if Chatstats[name] then
Chatstats[name] = nil
SendToOps(sBot, "Chatstats from user "..name.." are now removed!")
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
else
user:SendData(sBot, "*** Chatstats from user "..name.." not found!")
end
else
user:SendData(sBot, "*** Usage: !delchatter <name>")
end
return 1
end
end,
["clearstats"] = function(user, data)
if AllowedProfiles[user.iProfile] == 1 then
Chatstats = {}
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
SendToAll(sBot, "Chatstats are cleared by "..user.sName)
return 1
end
end,
}
if tCmds[cmd] then
return tCmds[cmd](user, data)
end
end
end
function Stats(Topic,Y,M)
if Chatstats then
if Y and M then
if loadfile("chatstats - " ..Y.. "-" ..M.. ".tbl") then
loadTableFromFile("chatstats - " ..Y.. "-" ..M.. ".tbl")
Table = ChatstatsMonth
else
return "That month has not been loged"
end
else
Table = Chatstats
end
TCopy={}
for i,v in pairs(Table) do
table.insert(TCopy,{i,v.post,v.chars,v.words,v.tot})
end
table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
local chat = Topic..":\r\n\r\n"
chat = chat.."\t ------------------------------------------------------------------------\r\n"
if UseTotal == 1 then
chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tTotal:\tName:\r\n"
else
chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
end
chat = chat.."\t ------------------------------------------------------------------------\r\n"
for i = 1,25 do
if TCopy[i] then
if UseTotal == 1 then
chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t "..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][5].."\t"..TCopy[i][1].."\r\n"
else
chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t "..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][1].."\r\n"
end
end
end
return chat
end
TCopy={}
end
function updStats(nick, str)
local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x"),["tot"]=0,}
tmp["post"], tmp["chars"], tmp["words"], tmp["time"], tmp["tot"] = tmp["post"]+1, tmp["chars"]+string.len(str), tmp["words"]+cntargs(str,"(%a+)"), os.date("%x"), tmp["tot"]+string.len(str)+cntargs(str,"(%a+)")+1
-- Ranking code
for posts,prof in pairs(rankProfiles) do
if tmp["post"] == tonumber(posts) then
user = GetItemByName(nick)
prof = tonumber(prof)
if user.iProfile == prof then
-- Do Nothing atm
else
if user.iProfile == -1 then
AddRegUser(user.sName,"temp",prof)
user:SendPM(sBot,"You have be regged as " ..GetProfileName(prof).. " with the pass temp, reconnect and then user !passwd <new password> to change it, then reconnect again, and login with the pass of you choise")
else
ChangeRegUser(user.sName,frmHub:GetUserPassword(user.sName),prof)
user:SendPM(sBot,"You have be upgraded to " ..GetProfileName(prof).. ". Please reconnect")
end
end
break
end
end
-- Ranking code
Chatstats[nick] = tmp
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
-- Update Monthfile
if UseMonthStats == 1 then
local tmpM = ChatstatsMonth[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x"),["tot"]=0}
tmpM["post"], tmpM["chars"], tmpM["words"], tmpM["time"], tmpM["tot"] = tmpM["post"]+1, tmpM["chars"]+string.len(str), tmpM["words"]+cntargs(str,"(%a+)"), os.date("%x"), tmpM["tot"]+string.len(str)+cntargs(str,"(%a+)")+1
ChatstatsMonth[nick] = tmpM
saveTableToFile(ChatStatsFileMonth,ChatstatsMonth,"ChatstatsMonth")
end
end
function cntargs(str, rule)
local s,n = string.gsub(str, rule, "")
return n
end
----------------------------------------------
-- load & save Tables
----------------------------------------------
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 saveTableToFile(file, table, tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
-----------------------------------------------------------
function loadTableFromFile(file)
local f = io.open(file)
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
-------------table checker by herodes
--- for an associative table, like ["smth"] = "smth else",
function isEmpty(t)
for i,v in pairs(t) do
return false;
end
return true;
end;
This should do the trick, not really tested, and probarly not the best way to do it.
Anyway, when a user reaches X thousand post, they will be upgraded to next profile (if there is any).
However, standard Px profiles, will not be affected, and unregged users will be regged with the first profile that is not an standatd Px profile
Chatstats for the month do not support the profile upgrading
Halo :-)
Smal probem: \scripts\Ranking.lua:274: 'then' expected near '='
This place is there:
function updStats(nick, str)
--local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x"),["tot"]=0,}
local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x"),["tot"]=0,["countrank"]=0}
tmp["post"], tmp["chars"], tmp["words"], tmp["time"], tmp["tot"] = tmp["post"]+1, tmp["chars"]+string.len(str), tmp["words"]+cntargs(str,"(%a+)"), os.date("%x"), tmp["tot"]+string.len(str)+cntargs(str,"(%a+)")+1
[b][font=Verdana][size=12pt]if tmp["post"] - tonumber(tmp["countrank"]) =1000 then[/size][/font][/b]
user = GetItemByName(nick)
if user.iProfile >= 4 or user.iProfile == -1 then -- Protect Px Standard profiles
if user.iProfile == -1 then
Profile = 4
Edit by Psycho_Chihuahua: please use code tags when posting codes
fixed, post updated.
It was suppose to be == 1000 not = 1000 on line 274...
THX it works :D
Quote from: Madman on 15 July, 2007, 16:21:49
chatstats v3 [removed in this quote the rest]
This should do the trick, not really tested, and probarly not the best way to do it.
Anyway, when a user reaches X thousand post, they will be upgraded to next profile (if there is any).
However, standard Px profiles, will not be affected, and unregged users will be regged with the first profile that is not an standatd Px profile
Chatstats for the month do not support the profile upgrading
Where can i edit the total points needed for going a profile up?? And where can i edit which profile it gets when it reaches the max point for the profile when you need to go a profile up.
Quote from: Syphrone-NL on 16 July, 2007, 19:34:25
Where can i edit the total points needed for going a profile up?? And where can i edit which profile it gets when it reaches the max point for the profile when you need to go a profile up.
In the updStats function where it says
if tmp["post"] - tonumber(tmp["countrank"]) == 1000 then
Change 1000.
As for the profiles, Just add and sort them in PtokaX profile manager.
The script will ignore PtokaX standard profiles.
At X thousand point it will change the user to the profile that is under his current one.
I.e
Profile # 3 Name: Reg <-- Ignored by script
Profile # 4 Name: Thug <-- users profile when haveing 1000 - 1999 posts
Profile # 5 Name: Wiseguy <-- user profile 2000 - 2999 posts
This is my profile list:
- = 1, --Operator <--- Ptokax profile
[1] = 1, --Game-Owner <--- Dont want to have this profile in the ranking
[2] = 1, --Game Admin <--- Dont want to have this profile in the ranking
[3] = 1, --Scum
[4] = 1, --Game Mod <--- Dont want to have this profile in the ranking
[5] = 1, --Pee Wee
[6] = 1, --Thug
[7] = 1, --Gangster
[8] = 1, --Hitman
[9] = 1, --Assassin
[10] = 1, --Boss
[11] = 1, --Godfather
[12] = 1, --Legendary Godfather
[13] = 1, --Don
[14] = 1, --Respectable Don
[15] = 1, --Legendary Don
[-1] = 1, -- Users (UnRegged)
If they reg there Scum.
Is it possible to do it without the profiles i checked above?
So it goes from 3 to 5 and then to 6, 7 ,8, 9 etc.
I get this error --> [14:32] Syntax ...documenten\Downloads\ptokax 0.3.6.0\scripts\rank.lua:288: attempt to perform arithmetic on a nil value
I think i know why because he begins at profile 1 and wants to profile 2 but hes already profile 3
So if sort it out like this:
- = 1, --Operator
[1] = 1, --Scum
[2] = 1, --Pee Wee
[3] = 1, --Thug
[4] = 1, --Gangster
[5] = 1, --Hitman
[6] = 1, --Assassin
[7] = 1, --Boss
[8] = 1, --Godfather
[9] = 1, --Legendary Godfather
[10] = 1, --Don
[11] = 1, --Respectable Don
[12] = 1, --Legendary Don
[13] = 1, --Game Mod
[14] = 1, --Game Admin
[15] = 1, --Game-Owner
[-1] = 1, -- Users (UnRegged)
Is it then possible to disable in the script 13, 14 and 15? so the script goes to profile 13
Script updated
added a table called rankProfiles
Pretty simple ["1000"] = "1" means when user reach 1000 post they will be upgrade to profile 1 unless they allready are at that profile.
Pretty cool i like it. Gonna try it today.
I tested it and it works good thx thx thx thx thx madman
This is my version of the script i changed some things to mafia style:
-- ChatStats v3 Made By Optimus
-- Based on Tezlo chats
-- Added Send Commands By TiMeTrAVelleR
-- Madman fixed some in commands
-- Converted to lua5 by Madman with very little help by Jelf
-- with some help by ?
-- fixed stats saving on exit by jiten
---- Modded by Madman
-- Added so it's creates ChatStatsFile, if it's missing
-- Fixed so it dont counts commands
-- Added a IgnoreTable, users in that wont be counted
---- Madman Return's
-- Changed: New ChatArrival
-- Changed: Some Commands
-- Changed: Some small code...
-- Changed: Modded 4 my hub
---- Madman strikes again
-- Added: a lowerchatter cmd, use it to lower someones chatstats post
-- Changed to lua 5.1 by TT
-- Added: chatter of Month, Madman, requested by BrotherBear
-- Added: not case senastive, all nicks will be loged in lower case, Madman, requested by Yahoo
-- Madman does it again
-- Added: Total (char+words+post), request by -SkA-
-- Adedd: Option for Total
-- Changed: Cleaned up code, chatstats,chatmonth and topchat now use same function
-- Added: Sorting by Total, request by -SkA-
-- Changed: Shortstats Option
---- Updated again, by Madman
-- Added: UseMonthStats, so you don't have to use the month stats
-- Added: Profile ranking code..., request by Syphrone-NL
-- Changed: New ranking code
sBot = frmHub:GetHubBotName() -- Name of Bot
SendComm = 1 -- Send UserCommands, 1 = On 0 = Off
pMenu = "? CrimeLife Stats ?" -- Name of Menu
xMenu = "CrimeLife Game Menu" -- Name of the OP Menu
UseMonthStats = 0 -- 1 = On / 0 = Off
UseTotal = 1 -- Add Total (char+words+post) in the chatstats, 1 = On 0 = Off
Sortstats = 2 -- 2=posts / 3 = chars / 4 = words / 5 = Total
Chatstats = {}
ChatstatsMonth = {}
ChatStatsFile = "chatstats.tbl"
IgnoreTable = {
-- 0=dont ignore/1=ignore
["-=FakeKiller=-"] = 1,
}
EnableChatStats = {
[0] = 1, --Operator
[1] = 1, --Game-Owner
[2] = 1, --Game Admin
[3] = 1, --Scum
[4] = 1, --Game Mod
[5] = 1, --Pee Wee
[6] = 1, --Thug
[7] = 1, --Gangster
[8] = 1, --Hitman
[9] = 1, --Assassin
[10] = 1, --Boss
[11] = 1, --Godfather
[12] = 1, --Legendary Godfather
[13] = 1, --Don
[14] = 1, --Respectable Don
[15] = 1, --Legendary Don
[-1] = 1, -- Users (UnRegged)
}
AllowedProfiles = {
[0] = 0, --Operator
[1] = 1, --Game-Owner
[2] = 1, --Game Admin
[3] = 0, --Scum
[4] = 1, --Game Mod
}
rankProfiles = {
-- Posts = Rank to get
["10"] = "5",
["25"] = "6",
["50"] = "7",
["100"] = "8",
["200"] = "9",
["350"] = "10",
["500"] = "11",
["750"] = "12",
["1000"] = "13",
["1500"] = "14",
["2500"] = "15",
}
---------- Warning! Do Not Edit! -----------
ChatStatsFileMonth = "chatstats - " ..os.date("%y-%m").. ".tbl"
---------- Warning! Do Not Edit! -----------
function Main()
frmHub:RegBot(sBot)
CheckFile(ChatStatsFile)
dofile(ChatStatsFile)
if UseMonthStats == 1 then
CheckFile(ChatStatsFileMonth)
dofile(ChatStatsFileMonth)
end
end
function CheckFile(File)
local file = io.open(File, "r")
if file then
file:close()
else
local file = io.open(File, "w+")
file:write()
file:close()
end
end
function NewUserConnected(user)
if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
if Chatstats[string.lower(user.sName)] then
user:SendData(sBot, "---===[ Your CrimeLife Stats: You Made "..Chatstats[string.lower(user.sName)]["post"].." Crimes, You Made ?"..Chatstats[string.lower(user.sName)]["chars"].." Money On The Crimes, And You Stole "..Chatstats[string.lower(user.sName)]["words"].." Vehicles ]===---")
end
user:SendData("$UserCommand 1 3 "..pMenu.."\\All CrimeLife Stats$<%[mynick]> !chatstats|")
if UseMonthStats == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Chat stats Year-Month$<%[mynick]> !chatmonth %[line:YY-MM]|")
end
user:SendData("$UserCommand 1 3 "..pMenu.."\\My CrimeLife Stat$<%[mynick]> !mystats|")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\"..xMenu.."\\Del CrimeLife User$<%[mynick]> !delchatter %[line:Nick]|")
user:SendData("$UserCommand 1 3 "..pMenu.."\\"..xMenu.."\\Lower CrimeLife User$<%[mynick]> !lowerchatter %[line:Nick] %[line:New Crimes]|")
user:SendData("$UserCommand 1 3 "..pMenu.."\\"..xMenu.."\\Clear CrimeLife Stats$<%[mynick]> !clearstats|")
end
if user.bOperator then
user:SendData("$UserCommand 1 3 "..pMenu.."\\"..xMenu.."\\Top CrimeLife Users in Main$<%[mynick]> !topchat|")
end
end
end
OpConnected = NewUserConnected
function OnExit()
if isEmpty(Chatstats) then
else
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
if UseMonthStats == 1 then
saveTableToFile(ChatStatsFileMonth, ChatstatsMonth, "ChatstatsMonth")
end
end
end
function IsCmd(str)
return string.sub(str, 1, 1) == "!" or string.sub(str, 1, 1) == "?" or string.sub(str, 1, 1) == "+" or string.sub(str, 1, 1) == "$"
end
function ChatArrival(user, data)
if EnableChatStats[user.iProfile] == 1 then
local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if IsCmd(cmd) then
elseif IgnoreTable[string.lower(user.sName)] == 1 then
else
local s,e,str = string.find(data, "%b<>%s+(.*)%|")
updStats(string.lower(user.sName), str)
end
end
local data = string.sub(data,1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?](%S+)")
if cmd then
cmd = string.lower(cmd)
local tCmds = {
["mystats"] = function(user, data)
if Chatstats[string.lower(user.sName)] then
user:SendData(sBot, "---===[ Your CrimeLife Stats: You Made "..Chatstats[string.lower(user.sName)]["post"].." Crimes, You Made ?"..Chatstats[string.lower(user.sName)]["chars"].." Money On The Crimes, And You Stole "..Chatstats[string.lower(user.sName)]["words"].." Vehicles ]===---")
else
user:SendData(sBot, "*** No CrimeLife Statics Found!")
end
return 1
end,
["chatstats"] = function(user, data)
Topic = "Current Top CrimeLife Users"
Msg = Stats(Topic)
user:SendPM(sBot,Msg)
return 1
end,
["chatmonth"] = function(user,data)
if UseMonthStats == 1 then
local _,_,Y,M = string.find(data,"%b<>%s+%S+%s+(%d%d)%-(%d%d)")
if Y and M then
Topic = "Current Top Chatters of Month"
Msg = Stats(Topic,Y,M)
user:SendPM(sBot,Msg)
else
user:SendData(sBot, "Syntax: !chatmonth YY-MM i.e 07-02 for feb, 07")
end
else
user:SendData(sBot,"This function is disabled")
end
return 1
end,
["topchat"] = function(user, data)
if user.bOperator then
Topic = "Current Top CrimeLife Users"
Msg = Stats(Topic)
SendToAll(sBot,Msg)
return 1
end
end,
["lowerchatter"] = function(user, data)
if AllowedProfiles[user.iProfile] == 1 then
local s,e,name,chat = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(%d+)")
if name and chat then
if Chatstats[name] then
chat = tonumber(chat)
if Chatstats[name]["post"] <= chat then
user:SendData(sBot, "*** You can not raise the stats!")
else
local OldChat = Chatstats[name]["post"]
Chatstats[name]["post"] = chat
SendToOps(sBot, "*** CrimeLife stats crimes for " ..name.. " has been lowered to " ..chat.. " from " ..OldChat.. " by " ..string.lower(user.sName))
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end
else
user:SendData(sBot, "*** " ..name.. " is not in CrimeLife stats")
end
else
user:SendData(sBot, "*** Usage: !lowerchatter <name> <new posts>")
end
return 1
end
end,
["delchatter"] = function(user, data)
if AllowedProfiles[user.iProfile] == 1 then
local s,e,name = string.find(data, "%b<>%s+%S+%s+(%S+)" )
if name then
if Chatstats[name] then
Chatstats[name] = nil
SendToOps(sBot, "CrimeLife stats from user "..name.." are now removed!")
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
else
user:SendData(sBot, "*** CrimeLife stats from user "..name.." not found!")
end
else
user:SendData(sBot, "*** Usage: !delchatter <name>")
end
return 1
end
end,
["clearstats"] = function(user, data)
if AllowedProfiles[user.iProfile] == 1 then
Chatstats = {}
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
SendToAll(sBot, "CrimeLife stats are cleared by "..user.sName)
return 1
end
end,
}
if tCmds[cmd] then
return tCmds[cmd](user, data)
end
end
end
function Stats(Topic,Y,M)
if Chatstats then
if Y and M then
if loadfile("chatstats - " ..Y.. "-" ..M.. ".tbl") then
loadTableFromFile("chatstats - " ..Y.. "-" ..M.. ".tbl")
Table = ChatstatsMonth
else
return "That month has not been loged"
end
else
Table = Chatstats
end
TCopy={}
for i,v in pairs(Table) do
table.insert(TCopy,{i,v.post,v.chars,v.words,v.tot})
end
table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
local chat = Topic..":\r\n\r\n"
chat = chat.."\t -------------------------------------------------------------------------------------------------------------\r\n"
if UseTotal == 1 then
chat = chat.."\t Nr.\tCrimes:\tMoney:\tVehicles:\tTotal:\tName:\r\n"
else
chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
end
chat = chat.."\t -------------------------------------------------------------------------------------------------------------\r\n"
for i = 1,25 do
if TCopy[i] then
if UseTotal == 1 then
chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t ?"..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][5].."\t"..TCopy[i][1].."\r\n"
else
chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t "..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][1].."\r\n"
end
end
end
return chat
end
TCopy={}
end
function updStats(nick, str)
local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x"),["tot"]=0,}
tmp["post"], tmp["chars"], tmp["words"], tmp["time"], tmp["tot"] = tmp["post"]+1, tmp["chars"]+string.len(str), tmp["words"]+cntargs(str,"(%a+)"), os.date("%x"), tmp["tot"]+string.len(str)+cntargs(str,"(%a+)")+1
for posts,prof in pairs(rankProfiles) do
if tmp["post"] == tonumber(posts) then
user = GetItemByName(nick)
prof = tonumber(prof)
if user.iProfile == prof then
-- Do Nothing atm
else
if user.iProfile == -1 then
AddRegUser(user.sName,"temp",prof)
user:SendPM(sBot,"You have be regged as " ..GetProfileName(prof).. " with the pass temp, reconnect and then user !passwd <new password> to change it, then reconnect again, and login with the pass of you choise")
else
ChangeRegUser(user.sName,frmHub:GetUserPassword(user.sName),prof)
user:SendPM(sBot,"You have be upgraded to " ..GetProfileName(prof).. ". Please reconnect")
end
end
break
end
end
Chatstats[nick] = tmp
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
-- Update Monthfile
if UseMonthStats == 1 then
local tmpM = ChatstatsMonth[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x"),["tot"]=0}
tmpM["post"], tmpM["chars"], tmpM["words"], tmpM["time"], tmpM["tot"] = tmpM["post"]+1, tmpM["chars"]+string.len(str), tmpM["words"]+cntargs(str,"(%a+)"), os.date("%x"), tmpM["tot"]+string.len(str)+cntargs(str,"(%a+)")+1
ChatstatsMonth[nick] = tmpM
saveTableToFile(ChatStatsFileMonth,ChatstatsMonth,"ChatstatsMonth")
end
end
function cntargs(str, rule)
local s,n = string.gsub(str, rule, "")
return n
end
----------------------------------------------
-- load & save Tables
----------------------------------------------
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 saveTableToFile(file, table, tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
-----------------------------------------------------------
function loadTableFromFile(file)
local f = io.open(file)
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
-------------table checker by herodes
--- for an associative table, like ["smth"] = "smth else",
function isEmpty(t)
for i,v in pairs(t) do
return false;
end
return true;
end;
I got one more request with this script. I think its a little bit difficult. But asking is free.
I want that users can kill other users (so that they would be downgraded in ptokax)
Profile number //// Can kill till profile number //// Can kill not lower then profile
3 Can kill nobody
5 8
6 9
7 10
8 11 5
9 12 6
10 13 7
11 14 8
12 15 9
13 15 10
14 15 11
15 15 12
I want that it has a change like snowball war. That there is a change that he isnt killed. And that there is a change that hes killed?
But then i need to enable for all the profiles downgrade/upgrade function?
That has nothing to do with chatting what so ever, i would suggest makeing that request in a new topic, so you get a new script.
I tryed making a script myself but doesnt work im not good in scripting.
But i want to change my last request.
Can this be build in the script above:
Build in a command: !kill <nick>
What happens if user uses this command: If hes has a higher profile the command works if not lower profile then message: <nick> has a higher rank you cant kill him.
But if it works: Then a x of posts will be deleted. And X = 1 till 20 posts.
And then if user goes under the amount of set posts for his profile hes getting downgraded.
And if possible a delay time in hours (which can be set). So he cant kill another one a minute later
Kill command added
not tested at all...
i'm to lazy
and also to lazy to add that timer thing you wanted...
script in my previous post updated
Found an error:
tmp["posts"] - Posts
Needs to be:
tmp["posts"] = Posts
its in this peace:
if Z and u then
math.randomseed(os.date("%H%i%s"))
Hit = math.random(0,1)
if Hit == 1 then
Posts = math.random(1,20)
local tmp = ChatStats[Zombie.sName]
tmp["posts"] - Posts
for posts,prof in pairs(rankProfiles) do
if tmp["post"] == tonumber(posts) then
prof = tonumber(prof)
if Zombie.iProfile == prof then
-- Do Nothing atm
else
ChangeRegUser(Zombie.sName,frmHub:GetUserPassword(Zombie.sName),prof)
Zombie:SendPM(sBot,"You have be downgraded to " ..GetProfileName(prof).. ". Please reconnect")
end
break
end
end
Im getting everytime Sorry you cant play! why is this?
Beacuse a typo from me, fixed.
And cmd fixed and tested, works for me.
and you where almost right about the tmp["posts"] - Posts
it was suppos to be tmp["post"] = tmp["post"] - Posts
Wich means tmp["post"] equals tmp["post"] minus Posts
ok thx very very much :D
The script works perfect.
But i thought i add myself the waittime in it:
local start = os.clock()
if Zombie.sName then
local interval = Zombie.sName
if os.difftime(os.clock(), interval) < WaitTime then
local reply = "Take it easy. You must wait "..WaitTime.." seconds between kills."
user:SendData(sBot,reply)
return 1
end
end
I made it after this:
Zombie = GetItemByName(nick)
if Zombie then
if user.iProfile >= Zombie.iProfile then
for posts,prof in pairs(rankProfiles) do
prof = tonumber(prof)
if prof == Zombie.iProfile then
Z = 1
end
if prof == user.iProfile then
u = 1
end
end
Added on the top at the settings:
WaitTime = 86400
but getting this error:
bad argument #2 to 'difftime' (number expected, got string)
its this line:
if os.difftime(os.clock(), interval) < WaitTime then
Whats the problem?
You declared interval as Zombie.sName. Is it a number?
No its not a profile
In the script i see this:
ChangeRegUser(Zombie.sName,frmHub:GetUserPassword(Zombie.sName),prof)
local start = os.clock()
if Players[user.sName] then
local interval = Players[user.sName]
if os.difftime(os.clock(), interval) < WaitTime then
local reply = "Take it easy rookie. You must wait "..WaitTime.." seconds between shots in regulation play."
user:SendData(SnowBot,reply)
return 1
end
end
That was the original from the snowball script
i thought i change Players[user.sName] to Zombie.sName.
Zombie.sName is the victims username
So i have in the original:
Player[user.sName]
This is not correct anymore in my script.
So where do i need to change it to?