adding colour? is this possible
 

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

adding colour? is this possible

Started by Tw?sT?d-d?v, 23 January, 2005, 14:13:46

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tw?sT?d-d?v

Hi, this might sound like a silly request, but is there any way to add colour to scripts??

i.e I run to games (triv and anagrams) would it be possible to have 1 game in a differant colour?


Sedulus

if everyone runs bcdc++ and a modified version of formatting.lua that recognises and colorizes your two games, it's possible

Tw?sT?d-d?v

hi  i found this script,is there any way it can be altered to work on sorton scripts and on all clients??


code:--------------------------------------------------------------------------------
--// vim:ts=4:sw=4:noet

-- use a namespace because we are in a global environment
formatting = {}
formatting.color = {}

--// ** edit below this line ** //-

-- set this to something other than nil if you have a dark background (it will invert the colors below)
formatting.background_is_dark = nil
-- use the following colors
formatting.color.normal   = "cyan";    -- someone else's line
formatting.color.nick   = "red";    -- my line: nick color
formatting.color.myline = "red";   -- my line: text color
formatting.color.mynick = "yellow";   -- someone else's line (contains my nick)
formatting.color.time   = "gray";
formatting.color.link   = "blue";
formatting.color.op   = "darkyellow";
-- use this to match other nicknames than your own
formatting.also_match_nicks = {  }; -- { "other", "nicks" }

--// ** do not edit below this line ** //--
-- heh!

function FormatChatText( hub, text )
   local txtcolor = formatting.color.normal
   local timecolor = formatting.color.time
   local namecolor = formatting.color.normal

   if (not text) then
      DC():PrintDebug("FormatChatText: text == nil");
      return nil;
   end

   -- escape chars
   text = string.gsub( string.gsub( text, "([{}\\])", "\\%1" ), "\n", "\\line\n" )

   if dcpp:hasHub( hub ) and dcpp:getHub( hub ):hasOwnNick() then
      local hub = dcpp:getHub( hub )
      local mynick = hub:getOwnNick()
      local sNickOutput = "";

      -- capture normal chat
      local ret,c,pre,nick,post = string.find( text, "^(.-)<([^> ]+)>(.*)$" );

      if (not ret) then -- capture !me speak
         ret,c,pre,nick,post = string.find( text, "^(.-)%*%s*(%S+)(.*)$");
         sNickOutput = "* \\b "..nick.."\\b0 ";
      else
         sNickOutput = "<\\b "..nick.."\\b0 >";
      end

      if (ret) then -- chat and !me, nothing abnormal
         if mynick == nick then   -- my line
            txtcolor = formatting.color.myline
            namecolor = formatting.color.nick;
         elseif formatting.testMyNick( post, mynick ) then -- not my line, contains my nick
            txtcolor = formatting.color.mynick
            timecolor = formatting.color.mynick
         end

         if mynick ~= nick and hub:isOp( nick ) then
            namecolor = formatting.color.op;
         end

         text = pre.."\\cf3 "..sNickOutput.."\\cf1 "..post;
      end
   end
   
   -- colorize timestamp
   text = string.gsub( text, "^(.\\line\n)(%[[0-9:]+%])", "%1\\cf4 %2\\cf1 " )
   -- em
   text = string.gsub( text, "(%s)(_%S+_)$", "%1\\ul %2\\ul0 " )
   text = string.gsub( text, "(%s)(_%S+_)(%s)", "%1\\ul %2\\ul0 %3" )

   text = string.gsub( text, "(%s)(*%S+*)$", "%1\\b %2\\b0 " )
   text = string.gsub( text, "(%s)(*%S+*)(%s)", "%1\\b %2\\b0 %3" )

   text = string.gsub( text, "(%s)(/[^/]+/)$", "%1\\i %2\\i0 " )
   text = string.gsub( text, "(%s)(/[^/]+/)(%s)", "%1\\i %2\\i0 %3" )

   -- colorize links
   text = string.gsub( text, "([ <\t\r\n])(dchub://[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   text = string.gsub( text, "([ <\t\r\n])(//http://[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   text = string.gsub( text, "([ <\t\r\n])(www\.[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   text = string.gsub( text, "([ <\t\r\n])(//ftp://[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   --
   DC():PrintDebug( "3>"..text )
      
   return "{\\rtf1\\ansi\\deff0\\plain0\n"..
         "{\\colortbl ;"..txtcolor..formatting.color.link..namecolor..timecolor.."}\n"..
         "\\cf1 "..text.."}\n"
end

-- color conversion types
formatting.color_conversion = {}
formatting.color_conversion.black   = {0, 0, 0}
formatting.color_conversion.white   = {255, 255, 255}
formatting.color_conversion.gray   = {127, 127, 127}
formatting.color_conversion.red      = {255, 0, 0}
formatting.color_conversion.green   = {0, 255, 0}
formatting.color_conversion.blue   = {0, 0, 255}
formatting.color_conversion.yellow   = {255, 255, 0}
formatting.color_conversion.magenta   = {255, 0, 255}
formatting.color_conversion.cyan   = {0, 255, 255}
-- dark variants
formatting.color_conversion.darkgray   = {63, 63, 63}
formatting.color_conversion.darkred   = {127, 0, 0}
formatting.color_conversion.darkgreen   = {0, 127, 0}
formatting.color_conversion.darkblue   = {0, 0, 127}
formatting.color_conversion.darkyellow   = {127, 127, 0}
formatting.color_conversion.darkmagenta   = {127, 0, 127}
formatting.color_conversion.darkcyan   = {0, 127, 127}
-- aliases
formatting.color_conversion.brown      = formatting.color_conversion.darkyellow
formatting.color_conversion.grey      = formatting.color_conversion.gray
formatting.color_conversion.darkgrey   = formatting.color_conversion.darkgray

-- convert colors..
for k,v in formatting.color do
   if formatting.color_conversion[v] then
      local c = formatting.color_conversion[v]
      formatting.color[k] = "\\red"..c[1].."\\green"..c[2].."\\blue"..c[3]..";"
   end
end

-- invert colors..
if formatting.background_is_dark then
   DC():PrintDebug( "hier" )
   for k,v in formatting.color do
      DC():PrintDebug( "hierv:"..v )
      local ret,c,r,g,b = string.find( v, "^\\red(%d+)\\green(%d+)\\blue(%d+);$" )
      if ret then
         formatting.color[k] = "\\red"..(255-tonumber(r))..
                           "\\green"..(255-tonumber(g))..
                           "\\blue"..(255-tonumber(b))..";"
         DC():PrintDebug( "hierv="..formatting.color[k] )   
      end
   end
end

-- escape also_match_nicks
for k,v in formatting.also_match_nicks do
   formatting.also_match_nicks[k] = string.gsub( string.lower( v ), "([^a-z0-9])", "%%%1" )
end

function formatting.testMyNick( text, nick )
   text = string.lower( text )

   -- test also_match_nicks first
   for k,v in formatting.also_match_nicks do
      if string.find( text, "[^a-z]"..v.."[^a-z]" ) or string.find( text, "[^a-z]"..v.."$" ) then
         return 1
      end
   end
   
   -- ok.. not found.. try our hub specific nick
   nick = string.lower( nick )
   local enick = nil
   local enick_notag = string.gsub( nick, "%[.*%]", "" )
   if enick_notag ~= "" then
      enick = string.gsub( enick_notag, "([^a-z0-9])", "%%%1" )
   else
      enick = string.gsub( nick, "([^a-z0-9])", "%%%1" )
   end

   if string.find( text, "[^a-z]"..enick.."[^a-z]" ) or string.find( text, "[^a-z]"..enick.."$" ) then
      return 1
   end
end
   

DC():PrintDebug( "  ** Loaded formatting.lua **" )

bastya_elvtars

formatting.also_match_nicks = { }; -- { "other", "nicks" }

this colorizes the line same as your nick

Sed, shouldn't this be a

{["[HUN]bastya_elvtars"]="blue"}


for example?
Everything could have been anything else and it would have just as much meaning.

Tw?sT?d-d?v

let's say i want to add colour to the following script;

1 colour for the question and 1 for the answer how could i do this,

and also so all clients can see them?

-- Ragaman.lua, created by Antony Warbrooke (antw@ihug.co.nz) 14 Aug 2003
-- is an anagram bot for use with PtokaX hub software. Tested on 0.326 td4
-- This has a similar look to the bot created by FLiXD for the nmdc hub software.

-- V1.3 REVISION BY REMASTER-IT

-- Global variables set here
-- These control the bot
botname = "(JAY'S)WORD-SCRAMBLE" -- Name of bot in user list
bothandle = "a." -- How to talk to the bot in chat
tickmax = 10 -- Number of five second ticks per question
bonusmax = 10 -- Maximum bonus points for speed
wordfile = "abtext/engwords.txt" -- Words file
scorefile = "abtext/scores.txt" -- Scores file
vernum = "1.3" -- Bot version number

-- These are general global variables
wordlist = {} -- The word list table
ticknum = 10 -- Number of timer ticks used for current anagram
bonusnum = 10 -- Bonus points for answering faster
currentword = "" -- Current scrambled answer
currentclue = "" -- Current half unscrambled answer
currentanswer = "" -- Current unscrambled answer
PlayerScore = {} -- Table of players and scores
RankPlayerScore = {} -- Table of ranks, player names and scores
AnaBotState = 0 -- Current state of bot. 0 = stopped, 1 = started
otherspelling = {} -- Table of possible answers to anagram

-- This is run when the script is started
function Main()
AnaBotLoadScores()
AnaBotLoadWords()
frmHub:RegBot(botname)
end

-- This is run when ever someone types something
function DataArrival(user, data)
-- If message from user
if( strsub(data, 1, 1) == "<" ) then
-- get the msg only using regular expression
s,e,msg = strfind(data, "%b<>%s*(.*)|$")
msg = strlower(msg) -- Convert to lower case
-- If a command to bot
if(strsub(msg,1,strlen(bothandle)) == bothandle) then
s,e,msg = strfind (msg, bothandle.."(.*)")
if(msg == "start") then
AnaBotStart ()
elseif(msg == "stop") then
AnaBotStop ()
elseif(msg == "help") then
AnaBotHelp ()
elseif(msg == "topten") then
AnaBotTopTen()
elseif(msg == "scores") then
AnaBotScores(user.sName)
elseif(msg == "pass") then
AnaBotPass()
elseif(msg == "resetscores") then
if (user.bOperator) then
AnaBotResetScores()
else
SendToAll("This command is for ops only!")
end
end
elseif (AnaBotState == 1) then
-- Check answer
AnaBotCheck (user.sName)
end
end
end

-- This is when the timer has reached it's set time
function OnTimer()
ticknum = ticknum + 1
if (bonusnum > 0) then
bonusnum = bonusnum - 1
end
if (ticknum == (tickmax / 2)) then
AnaBotClue () -- Display help if half way through time
elseif (ticknum == tickmax - 2) then
SendToAll(botname,"10 seconds left to solve anagram...")
elseif (ticknum == tickmax) then
AnaBotSolve () -- Show answer if full time
AnaBotNew () -- Pick a new word
end
end

function AnaBotStart()
if (getn(wordlist) == 0) then
SendToAll(botname,"There are no words loaded")
return
end
SetTimer(1000*15) -- Set timer to fifteen seconds
SendToAll(botname,botname.." Anagram. "..vernum.." is starting.")
AnaBotNew() -- Get a new word
StartTimer()
AnaBotState = 1
end

function AnaBotStop()
SendToAll(botname,botname.." Anagram. "..vernum.." is stopping.")
AnaBotSolve()
StopTimer()
AnaBotState = 0
end

function AnaBotHelp()
TextToSend = botname.." Ver. "..vernum.." has a few simple commands.\r\n"
TextToSend = TextToSend.." ?"..bothandle.."help To display this help\r\n"
TextToSend = TextToSend.." ?"..bothandle.."scores To display all scores\r\n"
TextToSend = TextToSend.." ?"..bothandle.."topten To display the top ten scores\r\n"
TextToSend = TextToSend.." ?"..bothandle.."pass To skip current anagram\r\n"
TextToSend = TextToSend.." ?"..bothandle.."start To start the game\r\n"
TextToSend = TextToSend.." ?"..bothandle.."stop To stop the game"
SendToAll (botname,TextToSend)
end

function AnaBotNew()
SendToAll(botname,"Next Anagram")
ticknum = 0 -- Reset tick counter
bonusnum = bonusmax -- Reset bonus amount
currentword = ""
otherspelling = {} -- Reset list of words with same letters
tempword1 = {}

local i = random(getn(wordlist)) -- Index into wordlist
currentanswer = wordlist
-- Put word into a table so we can use each letter (faster than gsub)
for i=1,strlen(currentanswer) do
tempword1 = strsub(currentanswer,i,i)
end
-- Get other spellings of the chosen letters
for i=1,getn(wordlist) do
if (strlen(currentanswer) == strlen(wordlist)) then
--Split word to use each letter
tempword2 = {}
for j=1, strlen(wordlist) do
tempword2[j] = strsub(wordlist,j,j)
end
-- Check each letter
for j=1, getn(tempword1) do
for k=1, getn(tempword2) do
if (tempword1[j] == tempword2[k]) then
tremove(tempword2,k)
break -- skip to next letter in j
end
end
end
if (getn(tempword2) == 0) then
-- Create entry in other spelling table
otherspelling[wordlist] = 1
end
end
end
-- Mix up letters to make anagram
while getn(tempword1) > 0 do
i = random(getn(tempword1))
currentword = currentword..tremove(tempword1,i)
end
-- Check to see that mixed up letters are not a valid word
-- Still to be done

-- Add spaces inbetween letters of anagram
tempword1 = {}
for i=1,strlen(currentword) do
tempword1 = strsub(currentword,i,i)
end
currentword = tempword1[1]
for i=2, getn(tempword1) do
currentword = currentword.." "..tempword1
end
currentclue = strsub(currentanswer,1,strlen(currentanswer)/2) -- Clue is first half of answer
SendToAll(botname,strupper(currentword))
end

function AnaBotSolve()
SendToAll(botname,"Time's up. The answer was: "..strupper(currentanswer)..".")
end

function AnaBotCheck(username)
if (otherspelling[msg]) then
--if exist add points
if (PlayerScore[username]) then
PlayerScore[username][2] = PlayerScore[username][2] + strlen(currentanswer) + bonusnum
--else add player to tables
else
PlayerScore[username] = {username , strlen(currentanswer) + bonusnum}
tinsert (RankPlayerScore, PlayerScore[username])
end
-- sort by points
sort (RankPlayerScore, function(a,b) return a[2] > b[2];end)
-- save scores
AnaBotSaveScores()
-- get rank
rank = 0
for i = 1, getn(RankPlayerScore) do
if (RankPlayerScore == PlayerScore[username]) then
rank = i
break
end
end

TextToSend = "Correct. "..username.." gets "..strlen(currentanswer).." points"
if (bonusnum > 0) then
TextToSend = TextToSend.." + "..bonusnum.." time bonus"
end
TextToSend = TextToSend..". Total: "..PlayerScore[username][2]..". Rank: "..rank.."/"..getn(RankPlayerScore).."."
-- Work out points gap to next person
if (rank == 1) then
-- If only player, say nothing
if (getn(RankPlayerScore) == 1) then
elseif (RankPlayerScore[1][2] == RankPlayerScore[2][2]) then
TextToSend = TextToSend.." Tied with "..RankPlayerScore[2][1]
else
TextToSend = TextToSend.." "..(RankPlayerScore[1][2] - RankPlayerScore[2][2]).." in front of "..RankPlayerScore[2][1]
end
elseif (RankPlayerScore[rank][2] == RankPlayerScore[rank-1][2]) then
TextToSend = TextToSend.." Tied with "..RankPlayerScore[rank-1][1]
else
TextToSend = TextToSend.." "..(RankPlayerScore[rank-1][2] - RankPlayerScore[rank][2]).." behind "..RankPlayerScore[rank-1][1]
end

SendToAll(botname,TextToSend)

AnaBotNew()
end
end

function AnaBotClue()
SendToAll(botname,"Current Anagram: "..strupper(currentword))
SendToAll(botname,"Tip: "..strupper(currentclue).."...")
end

function AnaBotLoadWords()
wordlist = {} -- blank word list
readfrom(wordfile) -- open file for read
while 1 do
local line = read()
if line == nil then
break
else
tinsert(wordlist, line)
end
end
readfrom() -- close file
SendToAll("I know of "..getn(wordlist).." words.")
end

function AnaBotSaveScores()
writeto(scorefile) -- open file for writing
-- write each user name and their score to the file
foreach (PlayerScore, function (name,score) write (name.."=="..score[2].."\r\n");end)
writeto() -- close file
end

function AnaBotLoadScores()
readfrom(scorefile) -- open file for read
while 1 do
local line = read()
if line == nil then
break
else
-- break line into username and score
s,e,user,score = strfind(line, "(.+)==(%d+)$")
-- add user to score tables
PlayerScore[user] = {user, tonumber(score)}
tinsert(RankPlayerScore, PlayerScore[user])
end
end
readfrom() -- close file
-- sort scores
sort (RankPlayerScore, function(a,b) return a[2] > b[2];end)
end

function AnaBotScores(username)
TextToSend = "<"..botname.."> These are the scores:"
for i = 1, getn(RankPlayerScore) do
TextToSend = TextToSend.."\r\nRank: "..i.." - Name: "..RankPlayerScore[1].." - Score: "..RankPlayerScore[2]
end
SendToNick(username, TextToSend)
end

function AnaBotTopTen()
TextToSend = "Top Ten: "
for i = 1, min(10,getn(RankPlayerScore)) do
TextToSend = TextToSend .. RankPlayerScore[1].." in "..AnaBotEnglishPlace(i).." with "..RankPlayerScore[2].." points, "
end
TextToSend = TextToSend.."there are "..getn(RankPlayerScore).." people with points."
SendToAll(botname, TextToSend)

end

function AnaBotEnglishPlace(place)
if (place == 1) then
return "1st"
elseif (place == 2) then
return "2nd"
elseif (place == 3) then
return "3rd"
else
return place.."th"
end
end

function AnaBotPass()
-- If bot running then show answer and get new anagram
if (AnaBotState == 1) then
AnaBotSolve()
AnaBotNew()
end
end

function AnaBotResetScores()
-- Rename the scores file to a backup file. If backup file exists, make backup of backup.
if (not readfrom(scorefile)) then
SendToAll("No "..scorefile.." file")
return
end
readfrom()
x = 1
while (readfrom(scorefile..x)) do
x=x+1
readfrom()
end
if (x>1) then
for y=x,2,-1 do
if (not rename (scorefile..(y-1),scorefile..y)) then
SendToAll ("Problem renaming "..scorefile..(y-1).." to "..scorefile..y.."!")
return
end
end
end
if (not rename (scorefile,scorefile.."1")) then
SendToAll ("Problem renaming "..scorefile.." to "..scorefile.."1!")
return
end
RankPlayerScore = {}
PlayerScore = {}
SendToAll ("Scores have been reset.")
end

Sedulus

that's a really old version of formatting.lua you got there. I suggest you fetch a newer one first.

after that, it's a matter of:

1) adding something unique to the output of the question and the answer
e.g. for every SendToAll and SendToNick, prepend either "[AnaQue]" or "[AnaAns]".

2) adding a check in formatting.lua for these strings,
e.g.
Index: formatting.lua
===================================================================
--- formatting.lua      (revision 623)
+++ formatting.lua      (working copy)
@@ -52,6 +52,10 @@
                        end
                elseif formatting.testPartnerLine( text ) then
                        txtcolor = formatting.color.partner
+               elseif string.find( text, "[AnaAns]", 1, 1 ) then
+                       txtcolor = formatting.color.anaans
+               elseif string.find( text, "[AnaQue]", 1, 1 ) then
+                       txtcolor = formatting.color.anaque
                end
                -- escape chars
                text = string.gsub( text, "([{}\\])", "\\%1" )
@@ -216,6 +220,8 @@
        if not formatting_opt.color.nick then formatting_opt.color.nick = "darkred" end
        if not formatting_opt.color.partner then formatting_opt.color.partner = "darkmagenta" end
        if not formatting_opt.color.noise then formatting_opt.color.noise = "darkgray" end
+       if not formatting_opt.color.anaans then formatting_opt.color.anaans = "darkgreen" end
+       if not formatting_opt.color.anaque then formatting_opt.color.anaque = "blue" end
        if not formatting_opt.also_match_nicks then formatting_opt.also_match_nicks = {} end
 end

Tw?sT?d-d?v

thx for your help m8,  but im not very good at putting scripts together any chance someone could help me out here.......i want the game scripted altered or redone so that questions and answers appear in differant colours



help is most appreciated : ))

Tw?sT?d-d?v

mmmm    cant find a new formatting.lua any1 help?

bastya_elvtars

what about the one shipped with latest BCDC?

or

http://bottledhate.webhop.org
Everything could have been anything else and it would have just as much meaning.

Tw?sT?d-d?v

ok thx bastya_elvtars got that ...

so how do i compille this to add colours to the game i asked about before cause i dont have a clue on where i would start such a thing??

Ubikk

Hi guys. I also got a trivia bot and I want to know how to enable colors too.
Here is the script
Quote
-- Trivia Ex V 0.67 by chill
-- Serialisation by RabidWombat, modded to exclude functions

-- This script is opensource, that means that anybody may edit/copy this code
-- and I will not come and cry for money, if you take bits to make a even more useless script
-- then leave a note over it with my name, would be cool :).

-- Lucida Console, Courier New


--------
-- PTOKAX FUNCS
--------

function Main()
   TrivEx:Main()

end


function OnExit()

   TrivEx:OnExit()

end

function DataArrival(curUser,data)

   if (strsub(data,1,1) == "<") then

      if TrivEx:ParseData("main",curUser,data) == 1 then

         return 1

      end

   elseif (strsub(data,1,4) == "$To:") then

      local _,_,whoTo,mes = strfind(data,"$To:%s+(%S+)%s+From:%s+%S+%s+$(.*)$")

      if (whoTo == TrivEx._Sets.bot) then

         TrivEx:ParseData("pm",curUser,mes)

      end

   end

end


function NewUserConnected(curUser)
   TrivEx:NewUserConnected(curUser)

end

OpConnected = NewUserConnected



function UserDisconnected(curUser)
   TrivEx:UserDisconnected(curUser)

end

OpDisconnected = UserDisconnected

function OnTimer()
   TrivEx:OnTimer()
end



---------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------

--            GLOBALS                       --

---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------

-- Main Table

TrivEx = {}

TrivEx._Profiles = {}

TrivEx._Profiles.Normal = {
   [0] = "Master",
   [1] = "Operator",
   [2] = "VIP",
   [3] = "Reg",
   [-1] = "Noobs",
}

TrivEx._Profiles.Config = {
   [0] = "Master",
   [1] = "Operator",
   [2] = "VIP",
   [3] = "Reg",
}

TrivEx._Profiles["Config+"] = {
   [0] = "Master",
   [1] = "Operator",
}


---------------------------------------------------------------------------------------

--   TRIVIA EX SETTINGS

---------------------------------------------------------------------------------------
TrivEx._Sets = {}

TrivEx._Sets.Version =    0.67               -- Script Version

TrivEx._Sets.StartOnMain = 1               -- 1 = Trivia starts on Main(), 0 = Trivia doesn't start on Main()

TrivEx._Sets.bot = "robotzel"               -- The botname
TrivEx._Sets.regbot = 0                  -- 0 = do not reg bot, 1 = reg bot

TrivEx._Sets.questionfile = "Intrebari.txt"      -- The name of the Questionfile Questiondefaultformat = category$questions$answer
TrivEx._Sets.addquestionfile = "AddQuesFile.txt"      -- The name of the file where ops can add a question

TrivEx._Sets.dividechar = "$"               -- The Divied Char whitch divides the Category,Questions and Answer, (Only one character, Questionfile specific)
TrivEx._Sets.quesmode = 1               -- 1 = Gets "Category,Question,Answer", 2 = Only Gets "Question,Answer" (Questionfile specific)

TrivEx._Sets.revealchar = "*"               -- The revealchar: 149,164,1

TrivEx._Sets.prefixes = "%+%-%!"            -- TriviaPrefix


TrivEx._Sets.savestats = 30               -- Time in minutes between each score and player saving, 0 = never save stats only OnExit()


--------------------------------------------------------------

TrivEx._Sets.folder = "TRIVIA"               -- The name of the Folder, for the Questionfile.

TrivEx._Sets.showcorrectanswer = 2            -- 1 = shows detailed stuff, 2 = only shows that it was the right answer
TrivEx._Sets.showquestion = 3               -- 1 = Shows "Question Number,Category,Question,Answer", 2 = Shows "Question Number,Question,Answer", 3 = Shows "Question,Answer"
TrivEx._Sets.showquesmode = 1               -- Questions Mode 1 = Random, 2 = Sequential (e.g. 1,2,3)
TrivEx._Sets.revealques = 2               -- 1 = Random displaying of hints, 2 = Displays the first letters of the hint first (Grands Trivia).
TrivEx._Sets.trivshowhint = 2               -- 1 = reveal by number of chars 2 = reveal by number of hints

TrivEx._Sets.autostop = 10               -- nil when no autostop, 1 - endless, when you want the script to stop after a certain number of unanswered questions

TrivEx._Sets.splitques = 90               -- After how many chars the question is splitted


TrivEx._Sets.memques = 50               -- How many questions are loaded into Memory

TrivEx._Sets.breaktime = 4               -- Trivia Break Time in minutes
TrivEx._Sets.timebreak = 30               -- Time in minutes till Trivia Break

TrivEx._Sets.dobreak = 1               -- 1 = do a triviabreak between 'TrivEx._Sets.timebreak' Minutes, 0 = no triviabreak



TrivEx._Sets.showques = 15               -- Time between each hint in seconds


TrivEx._Sets.displscorers = 25               -- The number of trivia scorers shown
TrivEx._Sets.displtoptrivs = 10               -- Number of top trivias shown


TrivEx._Sets.revealedchars = 2               -- Stands for how many chars are revealed per hint.
TrivEx._Sets.shownhints = 4               -- Stands for how many Hints are displayed (May not be totally accurate)
TrivEx._Sets.solveques = 2               -- The Question will be solved when there are only 'TrivEx._Sets.solveques' unrevealed chars left


--------------------------------------------------------------

TrivEx._Sets.botmyinfo = "$MyINFO $ALL "..TrivEx._Sets.bot.." TrivHelp: +trivhelp, -trivhelp, !trivhelp$ $TRIVIA$$0$"



--------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------
--//         MAIN SCRIPT

--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------

--   NO EDITING PAST THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING

---------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------
--   Adjust Timers to seconds

---------------------------------------------------------------------------------------
TrivEx._Sets.breaktime = TrivEx._Sets.breaktime * 60
TrivEx._Sets.timebreak = TrivEx._Sets.timebreak * 60


TrivEx._Sets.TrivConfigFile = "TriviaExConfig.txt"

TrivEx._Sets.ScoresFile = "TriviaExScores.txt"
TrivEx._Sets.PMPlayersFile = "TriviaExPMPlayers.txt"

TrivEx._datamode = ""

TrivEx._Questions = {n=0}

-- Scores
TrivEx._Scores = {}
dofile(TrivEx._Sets.folder.."/"..TrivEx._Sets.ScoresFile)

-- PM Players
TrivEx._PMPlayers = {}
dofile(TrivEx._Sets.folder.."/"..TrivEx._Sets.PMPlayersFile)
remove(TrivEx._Sets.folder.."/"..TrivEx._Sets.PMPlayersFile)

---------------------------------------------------------------------------------------

--   TRIVIA EX CONFIG

---------------------------------------------------------------------------------------
TrivEx._Config = {}


TrivEx._Config.mode =       "main"            -- "main" = Trivia is played in MainChat, "pm" = Trivia is played in PM

TrivEx._Config.trivskip =    1            -- 1 = trivskip enabled, 0 = disabled

TrivEx._Config.trivhint =    1            -- 1 = trivhint enabled, 0 = disabled
TrivEx._Config.sequentialnum =    0
dofile(TrivEx._Sets.folder.."/"..TrivEx._Sets.TrivConfigFile)

---------------------------------------------------------------------------------------

--   TRIVIA Data

---------------------------------------------------------------------------------------
TrivEx.Data = {}

TrivEx.Data.HelpNormal = "-- Trivia Ex V."..TrivEx._Sets.Version.." by chill --\r\n\r\n\tPrefixes: ! + -\r\n"..
   "\t------------------------\r\n"..
   "\ttrivhelp   - This Text\r\n"..
   "\t------------------------\r\n"..
   "\ttrivscore   - Shows the top "..TrivEx._Sets.displscorers.." scorers\r\n"..
   "\ttrivmyscore   - Shows your score\r\n"..
   "\ttrivstats   - Shows the top "..TrivEx._Sets.displtoptrivs.." player stats\r\n"..
   "\ttrivplayers   - Shows you the Trivia Players, if played in PM\r\n"..
   "\ttrivskip   - Lets you skipp the current question, if enabled\r\n"..
   "\ttrivhint   - Gives you a hint, if enabled\r\n"..
   "\tlogin   - Logs you in\r\n"..
   "\tlogout   - Log you out\r\n"..
   "\t------------------------\r\n"

TrivEx.Data.HelpConfig = TrivEx.Data.HelpNormal..
   "\ttrivstart  - Start the Trivia\r\n"..
   "\ttrivstop   - Stop the Trivia\r\n"..
   "\ttrivquestion   - Starts with questionNr.\r\n"
   if (TrivEx._Sets.quesmode == 1) then
      TrivEx.Data.HelpConfig = TrivEx.Data.HelpConfig.."\ttrivaddquestion   - Lets you add a question\r\n"
   elseif (TrivEx._Sets.quesmode == 2) then
      TrivEx.Data.HelpConfig = TrivEx.Data.HelpConfig.."\ttrivaddquestion   - Lets you add a question\r\n"
   end
   TrivEx.Data.HelpConfig = TrivEx.Data.HelpConfig.."\t------------------------\r\n"

TrivEx.Data["HelpConfig+"] = TrivEx.Data.HelpConfig..
   "\ttriviaskip   - Enables/Disables TriviaSkip\r\n"..
   "\ttriviahint   - Enables/Disables TrivHint\r\n"..
   "\ttriviamain   - Plays Trivia in Main Chat\r\n"..
   "\ttriviapm   - Plays Trivia in PM to the bot\r\n"..
   "\ttriviascorereset   - Lets you reset all scores\r\n"..
   "\t------------------------\r\n"

---------------------------------------------------------------------------------------

--   TRIVIA FUNCTIONS

---------------------------------------------------------------------------------------

function TrivEx:Main()

   if (self:GetPlayMode() == "pm") then
      frmHub:RegBot(self._Sets.bot)
      SendToAll(self._Sets.botmyinfo)
      
      foreach(self._PMPlayers,function(nick,_)
         if not GetItemByName(nick) then
            %self._PMPlayers[nick] = nil
         end
      end)

   elseif (self._Sets.regbot == 1) then
      frmHub:RegBot(self._Sets.bot)
      SendToAll(self._Sets.botmyinfo)
   elseif (self._Sets.regbot == 0) then

      frmHub:UnregBot(TrivEx._Sets.bot)

   end

   curTriv.totalques = TrivEx:GetTotalQues()


   SetTimer(1*1000)

   if (self._Sets.StartOnMain == 1) then
      StartTimer()

   end
end

function TrivEx:GetTotalQues()
   local handle = openfile(self._Sets.folder.."/"..self._Sets.questionfile,"r")
   local count = 0
   if handle then
      local line = read(handle)
      while line do
         count = count + 1
         line = read(handle)
      end
      closefile(handle)
   end
   return(count)
end

function TrivEx:OnExit()
   self:WriteTable(self._Scores,"TrivEx._Scores",self._Sets.folder.."/"..TrivEx._Sets.ScoresFile)
   self:WriteTable(self._Config,"TrivEx._Config",self._Sets.folder.."/"..self._Sets.TrivConfigFile)
   if (self:GetPlayMode() == "pm") then
      self:WriteTable(self._PMPlayers,"TrivEx._PMPlayers",self._Sets.folder.."/"..TrivEx._Sets.PMPlayersFile)
   end
end


function TrivEx:ParseData(mode,curUser,data)

   self._datamode = mode

   data = strsub(data,1,strlen(data)-1)

   local _,_,sdata = strfind( data, "^%b<>%s(.*)$")
   
   local _,_,cmd = strfind( data, "^%b<>%s["..self._Sets.prefixes.."](%w+)")

   if cmd then
      cmd = strlower(cmd)

      if self._Cmds[cmd] then
         self._Cmds[cmd](self,curUser,data)
         return 1
      end

   elseif sdata then

      local corrans = foreachi(curTriv.ans, function(_,v)
         if strlower(%sdata) == strlower(v) then
            return (v)
         end
      end)
      if corrans and (not curTriv:GetGetQues()) then
         -- SetGetQues
         curTriv:SetGetQues(1)

         local ansTime = format("%.2f",(clock()-curTriv.start)) -- Get Answering Time in sec.

         if (TrivEx._Sets.showcorrectanswer == 1) then
            -- Show right answer
            self:SendToPlayers("Correct "..curUser.sName.." the answer was \""..corrans.."\", You get "..curTriv.points.." Point(s). Answer solved in "..ansTime.." sec.")
         elseif (TrivEx._Sets.showcorrectanswer == 2) then
            -- Show right answer
            self:SendToPlayers("Corect "..curUser.sName..". Raspunsul era \""..corrans.."\", Meriti "..curTriv.points.." Punct(e) pt efortul tau de "..ansTime.." secunde :)")
         end





Ubikk

Quote

   -- Show other answeres if present
         if curTriv.availans > 1 then
            curTriv:ShowAnswer()
         end

         -- Update Scores
         if self._Scores[curUser.sName] then
            self._Scores[curUser.sName].Score = self._Scores[curUser.sName].Score + curTriv.points
            self._Scores[curUser.sName].AvTime[1] = self._Scores[curUser.sName].AvTime[1] + ansTime
            self._Scores[curUser.sName].AvTime[2] = self._Scores[curUser.sName].AvTime[2] + 1
            self._Scores[curUser.sName].AvTime[3] = tonumber(format("%.2f",self._Scores[curUser.sName].AvTime[1]/self._Scores[curUser.sName].AvTime[2]))
         else
            self._Scores[curUser.sName] = {}
            self._Scores[curUser.sName].Score = curTriv.points
            self._Scores[curUser.sName].Streak = 1
            self._Scores[curUser.sName].AvTime = { tonumber(ansTime),1,tonumber(ansTime) }
         end

         if (self._Sets.showcorrectanswer == 1) then
            SendDataPlayers(curUser.sName.."'s Stats, Score: "..self._Scores[curUser.sName].Score.." Point(s), Answerd Questions: "..self._Scores[curUser.sName].AvTime[2]..", Average Answering Time: "..format("%.2f",self._Scores[curUser.sName].AvTime[3]).." sec.")
         end

         -- Check for Streak
         curTriv.streak:UpdStreak(curUser)

      elseif (self:GetPlayMode() == "pm") then

         self:SendToPlayers(data,curUser)
      end

   end

end

function TrivEx:NewUserConnected(curUser)
   if (self:GetPlayMode() == "pm") or (self._Sets.regbot == 1) then

      curUser:SendData(self._Sets.botmyinfo)

   end
end

function TrivEx:UserDisconnected(curUser)
   if (self:GetPlayMode() == "pm") and self._PMPlayers[curUser.sName] then
      self._PMPlayers[curUser.sName] = nil

   end
end

function TrivEx:OnTimer()

   -- Load Questions if needed
   if (getn(self._Questions) == 0) then
      self:LoadQuestions()
   end

   -- Check if Trivia should be paused
   if (self._Sets.dobreak == 1) then
      if (not curTriv:Pause()) then
         -- Update TimeBreak
         TrivTimers.timebreak = TrivTimers.timebreak + 1
         if (TrivTimers.timebreak >= self._Sets.timebreak) and curTriv:GetGetQues() then
            curTriv:SetPause(1)
            TrivTimers.timebreak = 0
            TrivTimers.breaktime = 0
            self:SendToPlayers("Short Trivia break for "..(self._Sets.breaktime/60).." min.")
         end
      end
      if curTriv:Pause() then
         -- Update BreakTime
         TrivTimers.breaktime = TrivTimers.breaktime + 1
         if (TrivTimers.breaktime >= self._Sets.breaktime) then
            curTriv:SetPause(0)
            TrivTimers.timebreak = 0
            TrivTimers.breaktime = 0
            TrivTimers.showques = 0
         end
      end
   end

   -- Check if Trivia should be Autostoped
   if curTriv:GetGetQues() then
      if self._Sets.autostop and (curTriv.unansques == self._Sets.autostop) then
         StopTimer()

         curTriv:SetGetQues(1)
         self:WriteTable(self._Scores,"TrivEx._Scores",self._Sets.folder.."/"..TrivEx._Sets.ScoresFile)
         self:SendToPlayers("Trivia stoped due to Autostop, "..self._Sets.autostop.." questions weren't answered in a row.")
         return
      end
   end

   if (not curTriv:Pause()) then
      --Update ShowQuestion Time
      TrivTimers.showques = TrivTimers.showques + 1
      if (TrivTimers.showques == self._Sets.showques) then
         TrivTimers.showques = 0
         -- Check if to get new question
         if curTriv:GetNewQues() then
            curTriv:SendQuestion()
            -- Count unsanswered questions one up
            curTriv.unansques = curTriv.unansques + 1
         else
            curTriv:UpdHint()
            if curTriv:GetGetQues() then
               -- Show the Answer
               curTriv:ShowAnswer()
               -- Check for Streak
               curTriv.streak:UpdStreak()
            else
               curTriv:SendQuestion()
            end
         end
      end
   end

   if (self._Sets.savestats ~= 0) then
      TrivTimers.savestats = TrivTimers.savestats + 1

      if TrivTimers.savestats >= self._Sets.savestats then

         TrivTimers.savestats = 0
         if (curTriv.streak.write_scores == 1) then
            self:WriteTable(self._Scores,"TrivEx._Scores",self._Sets.folder.."/"..TrivEx._Sets.ScoresFile)
            curTriv.streak.write_scores = 0
         end

      end
   end

end

function TrivEx:SendToUser(curUser,data)
   if (self._datamode == "main") then
      curUser:SendData(TrivEx._Sets.bot,data)
   else
      curUser:SendPM(TrivEx._Sets.bot,data)
   end
end

function TrivEx:SendToPlayers(data,curUser)
   if (self:GetPlayMode() == "main") then
      SendToAll(self._Sets.bot,data)
   else
      local snick = ""
      if curUser then
         snick = curUser.sName
      else
         data = "<"..self._Sets.bot.."> "..data
      end
      for i,_ in self._PMPlayers do
         local user = GetItemByName(i)

         if user then
            if (i ~= snick) then
               user:SendData("$To: "..i.." From: "..self._Sets.bot.." $"..data)
            end

         else
            self._PMPlayers = nil

         end

      end
   end
end

function TrivEx:AllowedProf(status,curUser)
   if self._Profiles[status] and self._Profiles[status][curUser.iProfile] then
      return 1
   end
end

function TrivEx:SetPlayMode(mode)
   if (mode == "main") then
      self._PMPlayers = {}
      if (self._Sets.regbot == 0) then
         frmHub:UnregBot(self._Sets.bot)
      end
      self:WriteTable(self._Config,"TrivEx._Config",self._Sets.folder.."/"..self._Sets.TrivConfigFile)
      StartTimer()
      curTriv:SetGetQues(1)
      self._Config.mode = mode
   elseif (mode == "pm") then
      self._PMPlayers = {}
      frmHub:RegBot(self._Sets.bot)

      SendToAll(self._Sets.botmyinfo)
      self:WriteTable(self._Config,"TrivEx._Config",self._Sets.folder.."/"..self._Sets.TrivConfigFile)
      self._Config.mode = mode
   end
end

function TrivEx:GetPlayMode()
   return self._Config.mode
end
--------------------------------------------
function TrivEx:LoadQuestions(getques)
   self._Questions = {n = 0}
   local howmany = self._Sets.memques
   if (self._Sets.showquesmode == 1) and (not getques) then
      local getlines = {}
      for _ = 1,howmany do
         getlines[random(curTriv.totalques)] = 1
      end
      local handle = openfile(self._Sets.folder.."/"..self._Sets.questionfile,"r")

      if handle then
         local curTrivQuestions = {}
         local slinecount = 0
         local line = read(handle)
         while line do
            slinecount = slinecount + 1
            if getlines[slinecount] then
               local cat,ques,ans = self:SplitLine(line)
               if (cat and ques and ans) then

                  tinsert(curTrivQuestions,{cat,ques,ans,slinecount})

               end
            end
            line = read(handle)

         end

         closefile(handle)
         for _ = 1,getn(curTrivQuestions) do
            local num = random(getn(curTrivQuestions))
            tinsert(self._Questions,curTrivQuestions[num])
            tremove(curTrivQuestions,num)
         end               

      end
   elseif (self._Sets.showquesmode == 2) or (getques) then
      self._Config.sequentialnum = self._Config.sequentialnum or 0
      local getlines = {}
      for _ = 1,howmany do
         self._Config.sequentialnum = self._Config.sequentialnum + 1
         if (self._Config.sequentialnum <= curTriv.totalques) then
            getlines[self._Config.sequentialnum] = 1
            if getques then
               break
            end
         else
            self._Config.sequentialnum = 0
         end
      end
      local handle = openfile(self._Sets.folder.."/"..self._Sets.questionfile,"r")
      if handle then
         local slinecount = 0
         local line = read(handle)
         while line do
            slinecount = slinecount + 1
            if getlines[slinecount] then
               local cat,ques,ans = self:SplitLine(line)
               if (cat and ques and ans) then

                  tinsert(self._Questions,{cat,ques,ans,slinecount})

               end
            end
            line = read(handle)

         end

         closefile(handle)
      end
      if (not getques) or (self._Sets.showquesmode == 2) then
         TrivEx:WriteTable(self._Config,"TrivEx._Config",self._Sets.folder.."/"..TrivEx._Sets.TrivConfigFile)
      end
   end   

end
function TrivEx:SplitLine(line,dividechar)

   local dividechar = dividechar or self._Sets.dividechar

   local set,cat,ques,ans = {0,1},"","",{n=0}
   for i = 1,strlen(line) do
      if (strsub(line,i,i) == dividechar) then
         if (self._Sets.quesmode == 1) then
            if (set[1] == 0) then
               cat = strsub(line,set[2],(i-1))
               set = { 1,(i+1) }
            elseif (set[1] == 1) then
               ques = strsub(line,set[2],(i-1))
               ans = strsub(line,(i+1),strlen(line))
               ans = self:SplitAnswer(ans,dividechar)
               return cat,ques,ans
            end
         elseif (self._Sets.quesmode == 2) then
            ques = strsub(line,1,(i-1))
            ans = strsub(line,(i+1),strlen(line))
            ans = self:SplitAnswer(ans,dividechar)
            return cat,ques,ans
         end
      end
   end
end
function TrivEx:SplitAnswer(ans,dividechar)
   local set1,anst = 1,{n=0}
   for i = 1,strlen(ans) do
      if (strsub(ans,i,i) == dividechar) then
         tinsert(anst,strsub(ans,set1,(i-1)))
         set1 = (i+1)
      elseif i == strlen(ans) then
         tinsert(anst,strsub(ans,set1,strlen(ans)))
      end
   end
   return anst
end
--------------------------------------------
function TrivEx:WriteTable(table,tablename,file)
   local handle = openfile(file,"w")
   self:Serialize(table,tablename,handle)
     closefile(handle)
end
function TrivEx:Serialize(tTable,sTableName,hFile,sTab)
   sTab = sTab or "";
   write(hFile,sTab..sTableName.." = {\n");
   for key,value in tTable do
      if (type(value) ~= "function") then
         local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
         if(type(value) == "table") then
            self:Serialize(value,sKey,hFile,sTab.."\t");
         else
            local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
            write(hFile,sTab.."\t"..sKey.." = "..sValue);
         end
         write(hFile,",\n");
      end
   end
   write(hFile,sTab.."}");
end
--------------------------------------------

[/size]

Ubikk

Quote


------------------------
function TrivEx:TrivHelp(curUser)
   if (self:AllowedProf("Config+",curUser)) then
      self:SendToUser(curUser,TrivEx.Data["HelpConfig+"])
   elseif self:AllowedProf("Config",curUser) then
      self:SendToUser(curUser,TrivEx.Data.HelpConfig)
   elseif self:AllowedProf("Normal",curUser) then
      self:SendToUser(curUser,TrivEx.Data.HelpNormal)
   end
end

function TrivEx:TrivScore(curUser)
   if self:AllowedProf("Normal",curUser) then
      local TCopy = {}

      foreach(self._Scores, function(i,v) tinsert(%TCopy, {i,v}) end)

      sort(TCopy,function(a,b) return(a[2].Score>b[2].Score) end)

      local msg = " -- Top "..self._Sets.displscorers.." Trivia Scorers --\r\n\r\n"

      for i = 1,TrivEx._Sets.displscorers do

         if TCopy then

            msg = msg.."\t# "..i.."  -  "..TCopy[1]..",  Points: "..TCopy[2].Score.."\r\n"

         end

      end

      self:SendToUser(curUser,msg)
   end
end

function TrivEx:TrivMyScore(curUser)
   if self:AllowedProf("Normal",curUser) then
      if self._Scores[curUser.sName] then
         local TCopy = {}
         foreach(self._Scores, function(i,v) tinsert(%TCopy, {i,v}) end)
         sort(TCopy,function(a,b) return(a[2].Score>b[2].Score) end)
         for i = 1,getn(TCopy) do
            if TCopy[1] == curUser.sName then
               local msg = ""
               if TCopy[(i+1)] and TCopy[(i-1)] then
                  msg = "\r\n\r\n\t\t# "..(i-1).." - "..TCopy[(i-1)][1]..",  Points: "..TCopy[(i-1)][2].Score..".  Diff = "..(TCopy[(i-1)][2].Score-TCopy[2].Score).." Point(s)."..
                  "\r\n\t---->\t# "..i.." - "..TCopy[1]..",  Points: "..TCopy[2].Score.."."..
                  "\r\n\t\t# "..(i+1).." - "..TCopy[(i+1)][1]..",  Points: "..TCopy[(i+1)][2].Score..".  Diff = "..(TCopy[(i+1)][2].Score-TCopy[2].Score).." Point(s)."
               elseif TCopy[(i-1)] then
                  msg = "\r\n\r\n\t\t# "..(i-1).." - "..TCopy[(i-1)][1]..",  Points: "..TCopy[(i-1)][2].Score..".  Diff = "..(TCopy[(i-1)][2].Score-TCopy[2].Score).." Point(s)."..
                  "\r\n\t--->\t# "..i.." - "..TCopy[1]..",  Points: "..TCopy[2].Score.."."
               elseif TCopy[(i+1)] then
                  msg = "\r\n\r\n\t--->\t# "..i.." - "..TCopy[1]..",  Points: "..TCopy[2].Score.."."..
                  "\r\n\t\t# "..(i+1).." - "..TCopy[(i+1)][1]..",  Points: "..TCopy[(i+1)][2].Score..".  Diff = "..(TCopy[(i+1)][2].Score-TCopy[2].Score).." Point(s)."
               end
               self:SendToUser(curUser,"------ "..curUser.sName.."'s Player Stats. Total Players = "..getn(TCopy).." ------"..msg.."\r\n\r\n"..
               "\t\t"..curUser.sName.."'s longest run = "..TCopy[2].Streak..".\r\n")
            end
         end
      else
         self:SendToUser(curUser,"Your current score is : 0 Point(s).")
      end
   end
end
      

function TrivEx:TrivStats(curUser)
   if self:AllowedProf("Normal",curUser) then
      local TCopy = {}

      foreach(self._Scores, function(i,v) tinsert(%TCopy, {i,v}) end)


      sort(TCopy,function(a,b) return(a[2].Score>b[2].Score) end)
      local msg = "----- Top "..self._Sets.displtoptrivs.." Player Stats -----\r\n\r\n\tTop "..self._Sets.displtoptrivs.." Scorers.\r\n\r\n"
      for i = 1,self._Sets.displtoptrivs do
         if TCopy then
            msg = msg.."\t# "..i.."  -  "..TCopy[1]..",  Points: "..TCopy[2].Score.."\r\n"
         end
      end

      sort(TCopy,function(a,b) return(a[2].Streak>b[2].Streak) end)
      local msg = msg.."\r\n\tTop "..self._Sets.displtoptrivs.." Runners.\r\n\r\n"
      for i = 1,self._Sets.displtoptrivs do
         if TCopy then
            msg = msg.."\t# "..i.."  -  "..TCopy[1]..",  Run: "..TCopy[2].Streak.."\r\n"
         end
      end

      sort(TCopy,function(a,b) return(a[2].AvTime[3]      local msg = msg.."\r\n\tTop "..self._Sets.displtoptrivs.." Typos.\r\n\r\n"
      for i = 1,self._Sets.displtoptrivs do
         if TCopy then
            msg = msg.."\t# "..i.."  -  "..TCopy[1]..", Average Answering Time: "..TCopy[2].AvTime[3].." sec.\r\n"
         end
      end

      sort(TCopy,function(a,b) return(a[2].AvTime[2]>b[2].AvTime[2]) end)
      local msg = msg.."\r\n\tTop "..self._Sets.displtoptrivs.." Wizos.\r\n\r\n"
      for i = 1,self._Sets.displtoptrivs do
         if TCopy then
            msg = msg.."\t# "..i.."  -  "..TCopy[1]..", Answered Questions: "..TCopy[2].AvTime[2].."\r\n"
         end
      end
      self:SendToUser(curUser,msg)
   end
end

function TrivEx:Login(curUser)
   if self:AllowedProf("Normal",curUser) then
      if (self:GetPlayMode() == "pm") then
         if not self._PMPlayers[curUser.sName] then
            self._PMPlayers[curUser.sName] = 1

            self:SendToPlayers("\""..curUser.sName.."\" has joined the Trivia.")
         else
            self:SendToUser(curUser,"You are already loged into Trivia.")
         end
      else

         self:SendToUser(curUser,"Trivia is played in Main Chat. You don't need to login.")

      end
   end
end

function TrivEx:Logout(curUser)
   if self:AllowedProf("Normal",curUser) then
      if (self:GetPlayMode() == "pm") then
         if self._PMPlayers[curUser.sName] then
            self:SendToPlayers("\""..curUser.sName.."\" has parted the trivia..")
            self._PMPlayers[curUser.sName] = nil
         else
            self:SendToUser(curUser,mode,"You are not loged into Trivia.")
         end
      else

         self:SendToUser(curUser,"Trivia is played in Main Chat. You don't need to logout.")

      end
   end
end

function TrivEx:ShowTrivPlayers(curUser)
   if self:AllowedProf("Normal",curUser) then
      if (self:GetPlayMode() == "pm") then
         local players = ""

         for i,_ in self._PMPlayers do

            players = players.."\r\n\t-  "..i

         end
         self:SendToUser(curUser,"Currently Loged In:\r\n"..players.."\r\n")
      else
         self:SendToUser(curUser,"Trivia is played in Main Chat. Everybody is a player.")
      end

   end
end

function TrivEx:DoTrivSkip(curUser)
   if self:AllowedProf("Normal",curUser) then
      if (self._Config.trivskip == 1) then
         if not curTriv:GetGetQues() then
            self:SendToPlayers("\""..curUser.sName.."\" a sarit peste aceasta intrebare :(")

            curTriv:SetGetQues(1)
         else
            self:SendToUser(curUser,"No question to skip")
         end
      else

         self:SendToUser(curUser,"TriviaSkip is currently disabled.")
      end
   end
end

function TrivEx:DoTrivHint(curUser)
   if self:AllowedProf("Normal",curUser) then
      if (self._Config.trivhint == 1) then
         if not curTriv:GetGetQues() then

            self:SendToPlayers("\""..curUser.sName.."\" are nevoie de niste indicii :P")

            curTriv:UpdHint()
            if curTriv:GetGetQues() then
               curTriv:ShowAnswer()
            else
               curTriv:SendQuestion()
            end
         else

            self:SendToUser(curUser,"No question given")

         end
      else

         self:SendToUser(curUser,"TriviaHint is currently disabled.")

      end
   end
end
------------------------
------------------------
function TrivEx:TrivStart(curUser)
   if self:AllowedProf("Config",curUser) then
      curTriv.unansques = 0
      curTriv:SetGetQues(1)
      StartTimer()

      self:SendToUser(curUser,"Trivia is started.")
      self:SendToPlayers("Trivia a fost pornita de "..curUser.sName)
   end

end


function TrivEx:TrivStop(curUser)
   if self:AllowedProf("Config",curUser) then
      StopTimer()

      curTriv:SetGetQues(1)
      self:WriteTable(self._Scores,"TrivEx._Scores",self._Sets.folder.."/"..self._Sets.ScoresFile)
      self:SendToUser(curUser,"Trivia is stoped.")
      self:SendToPlayers("Trivia a fost oprita de "..curUser.sName)
   end

end

function TrivEx:LoadQuestion(curUser,data)
   if self:AllowedProf("Config",curUser) then
      local _,_,arg1 = strfind(data,"^%b<>%s+%S+%s+(%d+)")
      local num = tonumber(arg1) or 1
      self._Config.sequentialnum = num-1
      self:LoadQuestions(1)
      curTriv:SetGetQues(1)
      self:SendToUser(curUser,"Trying to load QuestionNr. "..num)
   end
end   



[/size]

Ubikk

Quote

function TrivEx:AddQuestion(curUser,data)
   if self:AllowedProf("Config",curUser) then
      local _,_,newquestion = strfind(data,"^%b<>%s+%S+%s+(.*)")
      if newquestion then
         local Cat,Ques,tAns = self:SplitLine(newquestion,"/")
         if Ques and Ques ~= "" then
            local handle = openfile(self._Sets.folder.."/"..self._Sets.addquestionfile,"a")
            if (self._Sets.quesmode == 1) then
               local msg = ""
               msg = msg.."Category: "..Cat..", Question: "..Ques..", Answers: "
               write(handle,Cat..self._Sets.dividechar..Ques)
               for i = 1,getn(tAns) do
                  msg = msg..tAns..", "
                  write(handle,self._Sets.dividechar..tAns)
               end
               write(handle,"\n")
               self:SendToUser(curUser,"Added Question: "..msg)
            elseif (self._Sets.quesmode == 2) then
               local msg = ""
               local handle = openfile(self._Sets.folder.."/"..self._Sets.addquestionfile,"a")
               msg = msg.."Question: "..Ques..", Answers: "
               write(handle,Ques)
               for i = 1,getn(tAns) do
                  msg = msg..tAns..", "
                  write(handle,self._Sets.dividechar..tAns)
               end
               write(handle,"\n")
               self:SendToUser(curUser,"Added Question: "..msg)
            end
            closefile(handle)
         else
            self:SendToUser(curUser,"Couldn't parse Question: "..newquestion)
         end
      else
         self:SendToUser(curUser,"No Question given!")
      end
   end
end



function TrivEx:ConfTrivSkip(curUser)
   if self:AllowedProf("Config+",curUser) then
      if (self._Config.trivskip == 1) then
         self._Config.trivskip = 0
         self:WriteTable(self._Config,"TrivEx._Config",self._Sets.folder.."/"..self._Sets.TrivConfigFile)
         self:SendToUser(curUser,"TriviaSkip is now disabled.")
      elseif (self._Config.trivskip == 0) then
         self._Config.trivskip = 1
         self:WriteTable(self._Config,"TrivEx._Config",self._Sets.folder.."/"..self._Sets.TrivConfigFile)
         self:SendToUser(curUser,"TriviaSkip is now enabled.")
      end
   end
end

function TrivEx:ConfTrivHint(curUser)
   if self:AllowedProf("Config+",curUser) then
      if (self._Config.trivhint == 1) then
         self._Config.trivhint = 0
         self:WriteTable(self._Config,"TrivEx._Config",self._Sets.folder.."/"..self._Sets.TrivConfigFile)
         self:SendToUser(curUser,"TriviaHint is now disabled.")
      elseif (self._Config.trivhint == 0) then
         self._Config.trivhint = 1
         self:WriteTable(self._Config,"TrivEx._Config",self._Sets.folder.."/"..self._Sets.TrivConfigFile)
         self:SendToUser(curUser,"TriviaHint is now enabled.")
      end
   end
end

function TrivEx:PlayTrivMain(curUser)
   if self:AllowedProf("Config+",curUser) then
      self:SetPlayMode("main")
      self:SendToUser(curUser,"Trivia is now played in MainChat.")
   end

end

function TrivEx:PlayTrivPM(curUser)
   if self:AllowedProf("Config+",curUser) then
      self:SetPlayMode("pm")

      self:SendToUser(curUser,"Trivia is now played in PM.")
   end

end

function TrivEx:ResetScore(curUser)
   if self:AllowedProf("Config+",curUser) then
      self._Scores = {}

      self:WriteTable(self._Scores,"TrivEx._Scores",self._Sets.folder.."/"..self._Sets.ScoresFile)

      self:SendToUser(curUser,"The scores have been reseted.")
   end

end

--   TRIVIA EX COMMANDS

TrivEx._Cmds = {}

-- Normal Commands

TrivEx._Cmds.trivhelp = TrivEx.TrivHelp         

TrivEx._Cmds.score = TrivEx.TrivScore
TrivEx._Cmds.trivmyscore = TrivEx.TrivMyScore      
TrivEx._Cmds.trivstats = TrivEx.TrivStats

TrivEx._Cmds.login = TrivEx.Login         
TrivEx._Cmds.logout = TrivEx.Logout

TrivEx._Cmds.trivplayers = TrivEx.ShowTrivPlayers   
TrivEx._Cmds.next =   TrivEx.DoTrivSkip      
TrivEx._Cmds.hint =   TrivEx.DoTrivHint      
-- Configure Commands

TrivEx._Cmds.trivstart = TrivEx.TrivStart      -- Strats Trivia

TrivEx._Cmds.trivstop =   TrivEx.TrivStop         -- Stops Trivia

TrivEx._Cmds.trivquestion = TrivEx.LoadQuestion      -- Expects a number as argument, e.g. +trivquestion 111
TrivEx._Cmds.trivaddquestion = TrivEx.AddQuestion   -- Lets you add a question to a file

-- Configure+ Commands

TrivEx._Cmds.triviaskip = TrivEx.ConfTrivSkip      -- Enables/Disables triviaskip

TrivEx._Cmds.triviahint = TrivEx.ConfTrivHint      
TrivEx._Cmds.triviamain = TrivEx.PlayTrivMain
TrivEx._Cmds.triviapm = TrivEx.PlayTrivPM      
TrivEx._Cmds.triviascorereset =   TrivEx.ResetScore   



--   TRIVIA GAME

-- Timers
TrivTimers = {}
TrivTimers.timebreak = 0
TrivTimers.breaktime = 0
TrivTimers.showques = 0
TrivTimers.savestats = 0

UnRevealed = {}
FirstLetters = {}

-- Current TriviaGame
curTriv = {}

curTriv.unansques = 0

curTriv.totalques = 0
curTriv.pause = 0
curTriv.getques = 1

curTriv.quesnum = 0
curTriv.cat = ""
curTriv.ques = ""
curTriv.ans = {}
curTriv.availans = 0
curTriv.points = 0
curTriv.hint = ""

curTriv.unrevealed = {}
curTriv.unrevealed.fl = {n = 0}
curTriv.unrevealed.ol = {n = 0}

curTriv.revealnum = 0

curTriv.streak = {}
curTriv.streak.nick = ""
curTriv.streak.streak = 0
curTriv.streak.write_scores = 0

-- funcs curTriv.streak
curTriv.streak.UpdStreak = function(self,curUser)

   if curUser then

      -- Write Scores by next saving
      curTriv.streak.write_scores = 1

      -- Set Unanswered Questions to zero
      curTriv.unansques = 0

      local nick = curUser.sName
      if (self.nick == nick) then
         self.streak = self.streak + 1
         if (self.streak > TrivEx._Scores[curUser.sName].Streak)  then
            TrivEx:SendToPlayers(nick..", tocmai ti-ai autodepasit recordul de "..TrivEx._Scores[curUser.sName].Streak.." raspunsuri consecutive :)")
            TrivEx._Scores[curUser.sName].Streak = self.streak
         end
         if (self.streak == 12) then
            TrivEx:SendToPlayers(" WOOOOOOOOW !!! Felicitari "..nick.." pentru cele "..self.streak.." raspunsuri consecutive :P Tocmai ai castigat o bere din partea mea :D")
         elseif (self.streak == 9) then
            TrivEx:SendToPlayers(nick.." a devenit un pericol pt societate :)) "..self.streak.." raspunsuri unul dupa altul :(((")
         elseif (self.streak == 6) then
            TrivEx:SendToPlayers("Miracolul numit "..nick.." continua .. "..self.streak.." raspunsuri la rand :D")
         elseif (self.streak == 3) then
            TrivEx:SendToPlayers("Bravo "..nick..", "..self.streak.." raspunsuri consecutive... esti tare  :)")
         end
      else

         if (self.streak >= 12) then
            TrivEx:SendToPlayers("And "..nick.." ends "..self.nick.." miracle of "..self.streak.." runs in a row. Ole!")
         elseif (self.streak >= 9) then
            TrivEx:SendToPlayers(nick.." *applause*, was about time to break, "..self.nick.."'s "..self.streak.." runs in a row.")
         elseif (self.streak >= 6) then
            TrivEx:SendToPlayers("Beat it "..self.nick..", "..nick.." just set and end to your "..self.streak.." runs in a row.")
         elseif (self.streak >= 3) then
            TrivEx:SendToPlayers("There goes "..self.nick.."'s run of "..self.streak)
         end
         self.nick = nick
         self.streak = 1
      end

   else
      if (self.nick ~= "") then
         if (self.streak >= 12) then
            TrivEx:SendToPlayers("Well that was obvious, that this questions would end "..self.nick.."'s run of "..self.streak.." ;)")
         elseif (self.streak >= 9) then
            TrivEx:SendToPlayers(self.nick..", deja ti s-a dus inspiratia dupa doar "..self.streak.." raspunsuri consecutive? :)")
         elseif (self.streak >= 3) then
            TrivEx:SendToPlayers("There goes "..self.nick.."'s run of "..self.streak)
         end
      end
      self.nick = ""
      self.streak = 0
   end
end

-- funcs curTriv
function curTriv:Pause()
   if (self.pause == 1) then
      return 1
   end
end

function curTriv:SetPause(arg)
   self.pause = arg
end

function curTriv:GetNewQues()
   if (self.getques == 1) then
      self:GetQuestion()
      return 1
   end
end

function curTriv:GetQuestion()
   self.quesnum = TrivEx._Questions[1][4]

   self.cat = TrivEx._Questions[1][1]
   self.ques = TrivEx._Questions[1][2]
   self.ans = TrivEx._Questions[1][3]
   self.availans = getn(self.ans)

   tremove(TrivEx._Questions,1)

   self.points = 0
   self.hint = gsub(self.ans[1],"(%S)",function (w)  %self.points = %self.points + 1 return(TrivEx._Sets.revealchar) end)

   self.unrevealed.fl = {n = 0}
   self.unrevealed.ol = {n = 0}
   for i = 1,strlen(self.hint) do
      if (strsub(self.hint,i,i) == TrivEx._Sets.revealchar) then
         if (TrivEx._Sets.revealques == 2) and ((i == 1) or (strsub(self.hint,(i-1),(i-1)) == " ")) then
            tinsert(self.unrevealed.fl,i)
         else
            tinsert(self.unrevealed.ol,i)
         end
      end
   end
            
   if (TrivEx._Sets.trivshowhint == 2) then
      if ((self.points/TrivEx._Sets.shownhints - floor(self.points/TrivEx._Sets.shownhints)) >= 0.5) then
         self.revealnum = floor(self.points/TrivEx._Sets.shownhints) + 1
      elseif (floor(self.points/TrivEx._Sets.shownhints) == 0) then
         self.revealnum = 1
      else
         self.revealnum = floor(self.points/TrivEx._Sets.shownhints)
      end
   else
      self.revealnum = TrivEx._Sets.revealedchars
   end
   self.start = clock()
   self:SetGetQues(0)

end

function curTriv:SetGetQues(arg)
   TrivTimers.showques = 0
   self.getques = arg
end

function curTriv:GetGetQues()
   if (self.getques == 1) then   
      return 1
   end
end

function curTriv:SendQuestion()
   if (TrivEx._Sets.showquestion == 1) then
      TrivEx:SendToPlayers("QUESTION - Nr. "..self.quesnum.." from "..self.totalques.." Questions.\r\n"..

      "\t----------------------------------------------------------------------\r\n"..

      "\t> Category: "..self.cat.." - Point(s): "..self.points.." - Total Answers: "..self.availans.."\r\n"..

      "\t"..self:doSplitQuestion("QUESTION: "..self.ques).."\r\n"..

      "\tHINT:  "..self.hint.."\r\n"..

      "\t----------------------------------------------------------------------")
   elseif (TrivEx._Sets.showquestion == 2) then
      TrivEx:SendToPlayers("QUESTION - Nr. "..self.quesnum.." from "..self.totalques.." Questions.\r\n"..

      "\t----------------------------------------------------------------------\r\n"..

      "\t> Point(s): "..self.points.." - Total Answers: "..self.availans.."\r\n"..

      "\t"..self:doSplitQuestion("QUESTION: "..self.ques).."\r\n"..

      "\tHINT:  "..self.hint.."\r\n"..

      "\t----------------------------------------------------------------------")
   elseif (TrivEx._Sets.showquestion == 3) then
      TrivEx:SendToPlayers("\r\n"..

      "\r\n"..

      "\t"..self:doSplitQuestion("QUESTION: "..self.ques).."\r\n"..

      "\tHINT:  "..self.hint.."\r\n"..

      "")
   end

end

function curTriv:doSplitQuestion(sQues)
   for i = TrivEx._Sets.splitques,strlen(sQues) do
      if (strsub(sQues,i,i) == " ") then
         local srest = strsub(sQues,(i+1),strlen(sQues))
         srest = self:doSplitQuestion(srest)
         return (strsub(sQues,1,(i-1)).."\r\n\t "..srest)
      end
   end
   return(sQues)
end

function curTriv:UpdHint()
   local thint = self:toTable(self.hint)
   if (TrivEx._Sets.revealques == 1) then
      for _ = 1,curTriv.revealnum do
         if (getn(curTriv.unrevealed.ol) ~= 0) then
            local rannum = random(getn(curTriv.unrevealed.ol))
            local strnum = curTriv.unrevealed.ol[rannum]
            thint[strnum] = strsub(self.ans[1],strnum,strnum)
            curTriv.points = curTriv.points - 1
            tremove(curTriv.unrevealed.ol,rannum)
         end
      end
   elseif(TrivEx._Sets.revealques == 2) then
      for _ = 1,curTriv.revealnum do
         if (getn(curTriv.unrevealed.fl) ~= 0) then
            local rannum = random(getn(curTriv.unrevealed.fl))
            local strnum = curTriv.unrevealed.fl[rannum]
            thint[strnum] = strsub(self.ans[1],strnum,strnum)
            curTriv.points = curTriv.points - 1
            tremove(curTriv.unrevealed.fl,rannum)
         elseif (getn(curTriv.unrevealed.ol) ~= 0) then
            local rannum = random(getn(curTriv.unrevealed.ol))
            local strnum = curTriv.unrevealed.ol[rannum]
            thint[strnum] = strsub(self.ans[1],strnum,strnum)
            curTriv.points = curTriv.points - 1
            tremove(curTriv.unrevealed.ol,rannum)
         end
      end
   end
   self.hint = self:toString(thint)
   if ((getn(curTriv.unrevealed.fl)+getn(curTriv.unrevealed.ol)) <= TrivEx._Sets.solveques) then
      self.hint = self.ans[1]
      self:SetGetQues(1)
   end
end

function curTriv:toTable(string)
   local table = {n = 0}
   for i = 1,strlen(string) do
      tinsert(table,strsub(string,i,i))
   end
   return table
end

function curTriv:toString(table)
   local string = ""
   for i = 1,getn(table) do
      string = string..table
   end
   return(string)
end

function curTriv:ShowAnswer()
   TrivEx:SendToPlayers("The answer is:  "..curTriv.ans[1])
   if curTriv.availans > 1 then
      local msg = ""
      for i = 2,curTriv.availans do
         msg = msg..curTriv.ans..", "
      end
      msg = strsub(msg,1,strlen(msg)-2)
      curTriv:SendToPlayers("Other answers were: "..msg..".")
   end
end

[/size]

Ubikk

That's the hole script.

I hope you guys can help :)

Tw?sT?d-d?v

I was told that this formating lua could be altered so for dc++ ..... can some1 help me out here plz    

i have no idea where to start

--// vim:ts=4:sw=4:noet

-- use a namespace because we are in a global environment
formatting = {}

-- load pickle functions
dofile("scripts/libsimplepickle.lua")
formatting.settings_file = "scripts/formatting_settings.txt"
   
-- every new line starts with the following, because of the multiline-URL-fix-hack
formatting.input_start = " "

-- regexes that should be considered noise
formatting.noise = {
   -- NMDC Kick
   "^"..formatting.input_start.."\r\n[0-9:%[%] ]*<[^> ]+> [^ ]+ is kicking [^ ]+ because",
   -- DCH++ Banuser/Bannick/Banip
   "^"..formatting.input_start.."\r\n[0-9:%[%] ]*<[^> ]+> [^ ]+ banned [^ ]+ by ip [^ ]+ and nick %(",
   "^"..formatting.input_start.."\r\n[0-9:%[%] ]*<[^> ]+> [^ ]+ banned [0-9.]+ %(",
   "^"..formatting.input_start.."\r\n[0-9:%[%] ]*<[^> ]+> [^ ]+ banned [^ ]+ by nick %(",
   -- YHub Kick
   "^"..formatting.input_start.."\r\n[0-9:%[%] ]*<[^> ]+> [^ ]+, IP: [0-9.]+ was kicked",
   -- ADC test commands
   "^"..formatting.input_start.."\r\n[0-9:%[%] ]*.*$",
   -- p14nd4's join/part noise add
   "^"..formatting.input_start.."\r\n[0-9:%[%] ]*** Joins: [^ ]",
   "^"..formatting.input_start.."\r\n[0-9:%[%] ]*** Parts: [^ ]",
}

function dcpp.FormatChatText( hub, text )
   local txtcolor = formatting.color.normal
   local timecolor = formatting.color.time
   local nickcolor = formatting.color.nick

   if formatting.isNoise( text ) then
      -- escape chars
      text = string.gsub( text, "([{}\\])", "\\%1" )
      text = string.gsub( text, "\r\n", "\n" )
      text = string.gsub( text, "\n", "\\line\n" )
      txtcolor = formatting.color.noise
   elseif dcpp:hasHub( hub ) and dcpp:getHub( hub ):getOwnNick() then
      local hub = dcpp:getHub( hub )
      local mynick = hub:getOwnNick()
      if formatting.testMyLine( text, mynick ) then
         txtcolor = formatting.color.self
         formatting.findChatPartner( hub, text )
      elseif formatting.testMyNick( text, mynick ) then
         txtcolor = formatting.color.myname
         timecolor = formatting.color.myname
         if formatting.flash_on_myname then
            hub:attention()
         end
      elseif formatting.testPartnerLine( text ) then
         txtcolor = formatting.color.partner
      end
      -- escape chars
      text = string.gsub( text, "([{}\\])", "\\%1" )
      text = string.gsub( text, "\r\n", "\n" )
      text = string.gsub( text, "\n", "\\line\n" )
      -- colorize OPs
      local ret,c,pre,nick,post = string.find( text,
            "^("..formatting.input_start.."\\line\n[0-9:,%a%s%[%]]*<)([^> ]+)(>.*)$" )
      if ret then
         text = string.sub( pre, 1, -2 ).."\\cf3 <"..nick..">\\cf1 "..string.sub( post, 2 )
         --text = string.sub( pre, 1, -2 ).."\\cf3 <\\b "..nick.."\\b0 >\\cf1 "..string.sub( post, 2 )
         if hub:isOp( nick ) then
            nickcolor = formatting.color.op
         end
      end
   else
      -- escape chars
      text = string.gsub( text, "([{}\\])", "\\%1" )
      text = string.gsub( text, "\r\n", "\n" )
      text = string.gsub( text, "\n", "\\line\n" )
   end
   
   -- colorize timestamp
   text = string.gsub( text, "^("..formatting.input_start.."\\line\n)(%[[0-9:,%s%a]*%])", "%1\\cf4 %2\\cf1 " )
   -- em
   text = string.gsub( text, "(%s)(_%S+_)$", "%1\\ul %2\\ul0 " )
   text = string.gsub( text, "(%s)(_%S+_)(%s)", "%1\\ul %2\\ul0 %3" )

   text = string.gsub( text, "(%s)(*%S+*)$", "%1\\b %2\\b0 " )
   text = string.gsub( text, "(%s)(*%S+*)(%s)", "%1\\b %2\\b0 %3" )

   text = string.gsub( text, "(%s)(/[^/\r\n\t]+/)$", "%1\\i %2\\i0 " )
   text = string.gsub( text, "(%s)(/[^/\n\n\t]+/)(%s)", "%1\\i %2\\i0 %3" )

   -- colorize links
   text = string.gsub( text, "([ <\t\r\n])(dchub://[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   text = string.gsub( text, "([ <\t\r\n])(//http://[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   text = string.gsub( text, "([ <\t\r\n])(//https://[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   text = string.gsub( text, "([ <\t\r\n])(www\.[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   text = string.gsub( text, "([ <\t\r\n])(//ftp://[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   text = string.gsub( text, "([ <\t\r\n])(magnet:%?[^ \t\\>]+)", "%1\\ul\\cf2 %2\\cf1\\ul0 " )
   text = string.gsub( text, "([ <\t\r\n])(irc://[^ \t\\>]+)","%1\\ul\\cf2 %2\\cf1\\ul0 " )
      
   return "{\\urtf1\\ansi\\ansicpg1252\\deff0\\plain0\n"..
         "{\\colortbl ;"..txtcolor..formatting.color.link..nickcolor..timecolor.."}\n"..
         "\\cf1 "..text.."}\n"
end

-- time data
formatting.time = {}
formatting.time.partners = {}

-- color conversion types
formatting.color_conversion = {}
formatting.color_conversion.black   = {0, 0, 0}
formatting.color_conversion.white   = {255, 255, 255}
formatting.color_conversion.gray   = {127, 127, 127}
formatting.color_conversion.red      = {255, 0, 0}
formatting.color_conversion.green   = {0, 255, 0}
formatting.color_conversion.blue   = {0, 0, 255}
formatting.color_conversion.yellow   = {255, 255, 0}
formatting.color_conversion.magenta   = {255, 0, 255}
formatting.color_conversion.cyan   = {0, 255, 255}
-- dark variants
formatting.color_conversion.darkgray   = {63, 63, 63}
formatting.color_conversion.darkred      = {127, 0, 0}
formatting.color_conversion.darkgreen   = {0, 127, 0}
formatting.color_conversion.darkblue   = {0, 0, 127}
formatting.color_conversion.darkyellow   = {127, 127, 0}
formatting.color_conversion.darkmagenta   = {127, 0, 127}
formatting.color_conversion.darkcyan   = {0, 127, 127}
-- aliases
formatting.color_conversion.brown      = formatting.color_conversion.darkyellow
formatting.color_conversion.grey      = formatting.color_conversion.gray
formatting.color_conversion.darkgrey   = formatting.color_conversion.darkgray
formatting.color_conversion.lightgrey  = formatting.color_conversion.lightgray

-- convert colors..
function formatting.setColors()
   formatting.color = {}
   for k,v in formatting_opt.color do
      if formatting.color_conversion[v] then
         local c = formatting.color_conversion[v]
         formatting.color[k] = "\\red"..c[1].."\\green"..c[2].."\\blue"..c[3]..";"
      else
         formatting.color[k] = v
      end
      -- optionally invert color
      if formatting.background_is_dark then
         local ret,c,r,g,b = string.find( formatting.color[k], "^\\red(%d+)\\green(%d+)\\blue(%d+);$" )
         if ret then
            formatting.color[k] = "\\red"..(255-tonumber(r))..
                              "\\green"..(255-tonumber(g))..
                              "\\blue"..(255-tonumber(b))..";"
         end
      end
   end
end

-- set "also match nicks"
function formatting.setAlsoMatchNicks()
   formatting.also_match_nicks = {}
   for k,v in formatting_opt.also_match_nicks do
      formatting.also_match_nicks[k] = string.gsub( string.lower( v ), "([^%l%d])", "%%%1" )
   end
end

-- set other options
function formatting.setOtherOptions()
   local function test( b )
      b = string.lower( tostring( b ) )
      if b == "nil" or b == "0" or b == "off" or b == "no" then return nil
      else return 1
      end
   end
   formatting.flash_on_myname = test( formatting_opt.flash_on_myname )
   formatting.background_is_dark = test( formatting_opt.background_is_dark )
end

function formatting.setOptions()
   formatting.setDefaultOptions()
   formatting.setOtherOptions()
   formatting.setColors()
   formatting.setAlsoMatchNicks()
end

function formatting.setDefaultOptions()
   if not formatting_opt then formatting_opt = {} end
   if not formatting_opt.background_is_dark then
      local bgcolor = DC():GetSetting( "BackgroundColor" ) -- BACKGROUND_COLOR (IntSetting)
      local R = math.mod( bgcolor, 256 )
      local G = math.mod( bgcolor / 256, 256 )
      local B = math.mod( bgcolor / 256 / 256, 256 )
      if R + G + B < 384 then
         formatting_opt.background_is_dark = 1
      else
         formatting_opt.background_is_dark = 0
      end
   end
   if not formatting_opt.flash_on_myname then formatting_opt.flash_on_myname = 0 end
   if not formatting_opt.color then formatting_opt.color = {} end
   if not formatting_opt.color.normal then formatting_opt.color.normal = "black" end
   if not formatting_opt.color.self then formatting_opt.color.self = "red" end
   if not formatting_opt.color.myname then formatting_opt.color.myname = "darkgreen" end
   if not formatting_opt.color.time then formatting_opt.color.time = "darkgray" end
   if not formatting_opt.color.link then formatting_opt.color.link = "blue" end
   if not formatting_opt.color.op then formatting_opt.color.op = "blue" end
   if not formatting_opt.color.nick then formatting_opt.color.nick = "darkred" end
   if not formatting_opt.color.partner then formatting_opt.color.partner = "darkmagenta" end
   if not formatting_opt.color.noise then formatting_opt.color.noise = "darkgray" end
   if not formatting_opt.also_match_nicks then formatting_opt.also_match_nicks = {} end
end

function formatting.save()
   formatting.setOptions()
   pickle.store( formatting.settings_file, {formatting_opt = formatting_opt} )
end

function formatting.load()
   local o = io.open( formatting.settings_file, "r" )
   if o then
      dofile( formatting.settings_file )
      o:close()
   end
   formatting.setOptions()
end

--/////////////////////////////////--
--// chatline matching functions //--
--/////////////////////////////////--

function formatting.testMyLine( text, nick )
   if string.find( text, "<"..nick.."> ", 1, 1 ) then
      return 1
   end
end
function formatting.testPartnerLine( text )
   local now = os.time()
   local ret = nil
   for k,v in formatting.time.partners do
      if string.find( text, "<"..k.."> ", 1, 1 ) then
         ret = 1
         formatting.time.partners[k] = now -- re-enforce user speaking
      else
         if now - v > 60*10 then -- expire after 10 mins
            formatting.time.partners[k] = nil
         end
      end
   end
   return ret
end
function formatting.testMyNick( text, nick )
   text = string.lower( text )

   -- test also_match_nicks first
   for k,v in formatting.also_match_nicks do
      if string.find( text, "[^%l]"..v.."[^%l]" ) or string.find( text, "[^%l]"..v.."$" ) then
         return 1
      end
   end
   
   -- ok.. not found.. try our hub specific nick
   nick = string.lower( nick )
   local enick = nil
   local enick_notag = string.gsub( nick, "%[.*%]", "" )
   if enick_notag ~= "" then
      enick = string.gsub( enick_notag, "([^a-z0-9])", "%%%1" )
   else
      enick = string.gsub( nick, "([^a-z0-9])", "%%%1" )
   end

   if string.find( text, "[^a-z]"..enick.."[^a-z]" ) or string.find( text, "[^a-z]"..enick.."$" ) then
      return 1
   end
end
function formatting.findChatPartner( hub, text )
   local ret,c,nick = string.find( text, "> ([%[%]%a%d_-]+)" )
   if not ret then return end
   local notag = nil
   if not string.find( nick, "[%[%]]" ) then notag = 1 end
   -- iterate through hub nicks to find someone,
   -- if we didn't check user existence, we'd store a heck of a lot of words
   local list = hub:findUsers( nick, notag )
   local now = os.time()
   for k,v in list do
      formatting.time.partners[v:getNick()] = now
   end
end
function formatting.isNoise( text )
   for k,v in formatting.noise do
      if string.find( text, v ) then
         return 1
      end
   end
end


--//////////////////////////////--


function formatting.tokenize( str )
   local ret = {}
   string.gsub( str, "(%w+)", function( s ) table.insert( ret, s ) end )
   return ret
end

Tw?sT?d-d?v

here is rest of that script  ......




dcpp:setListener( "ownChatOut", "formatting",
   function( hub, text )
      if string.sub( text, 1, 1 ) ~= "/" then return end
      parms = formatting.tokenize( string.sub( string.lower( text ), 2 ) )
      if parms[1] == "help" then
         hub:injectChat( "*** (formatting.lua) /color [what] [color], /flash [on/off], "..
                     "/highlight [add/del] [nick], /invert [on/off]" )
         return 1
      elseif parms[1] == "flash" then
         if parms[2] == "on" then
            formatting_opt.flash_on_myname = 1
            formatting.save()
            hub:injectChat( "*** Flash on your nick enabled" )
         elseif parms[2] == "off" then
            formatting_opt.flash_on_myname = 0
            formatting.save()
            hub:injectChat( "*** Flash on your nick disabled" )
         else
            hub:injectChat( "*** /flash (parameters: 'on' or 'off'): "..
                        "When enabled, the BCDC++ window flashes when someone calls you in main chat." )
         end
         return 1
      elseif parms[1] == "invert" then
         if parms[2] == "on" then
            formatting_opt.background_is_dark = 1
            formatting.save()
            hub:injectChat( "*** Invert colors enabled")
         elseif parms[2] == "off" then
            formatting_opt.background_is_dark = 0
            formatting.save()
            hub:injectChat( "*** Invert colors disabled" )
         else
            hub:injectChat( "*** /invert (parameters: 'on' or 'off'): "..
                        "When enabled, the main chat colors are inverted, useful when there's "..
                        "low contrast between the chat colors and background (e.g. if you have a "..
                        "black background). "..
                        "As an alternate option, you can set the colors manually as you like by "..
                        "using /color, see /help." )
         end
         return 1
      elseif parms[1] == "color" then
         if parms[2] == "show" then
            -- show current settings
            local msg = "*** The current color set is the following:"
            for k,v in formatting_opt.color do
               msg = msg.. "\r\n*"..k..":* "..v
            end
            hub:injectChat( msg )
         elseif not parms[2] or not parms[3] then
            local msg = "*** /color (parameters: and ): "..
                     "Use this to change the colors used in the chat.\r\n"..
                     "Available color-identifiers to set ():\r\n"..
                     "  normal = the normal text color\r\n"..
                     "  self = lines you speak\r\n"..
                     "  myname = lines where your name is used (someone calling you)\r\n"..
                     "  time = the timestamp\r\n"..
                     "  link = URLs (clickable links)\r\n"..
                     "  op = the nickname of an operator (the one between angle brackets)\r\n"..
                     "  nick = the nickname of normal people\r\n"..
                     "  partner = lines someone with whom you spoke recently\r\n"..
                     "  noise = kick messages\r\n"..
                     "Available colors ():\r\n  "
            for k,v in formatting.color_conversion do
               msg = msg..k..", "
            end
            msg = string.sub( msg, 1, -3 )
            msg = msg.."\r\nUse \"/color show\" to get the current color set displayed."
            hub:injectChat( msg )
         else
            if formatting_opt.color[parms[2]] then
               if formatting.color_conversion[parms[3]] then
                  formatting_opt.color[parms[2]] = parms[3];
                  formatting.save()
                  hub:injectChat( "*** /color -- set "..parms[2].." to "..parms[3] )   
               else
                  hub:injectChat( "*** /color -- invalid " )
               end
            else
               hub:injectChat( "*** /color -- invalid " )
            end
         end
         return 1
      elseif parms[1] == "highlight" then
         if not parms[2] or not parms[3] then
            local msg = "*** /highlight (parameters: 'add' or 'del' and ): "..
                     "Adds or removes words to match for highlighting besides your own name. "..
                     "E.g. use \"/highlight add operator\" to let BCDC++ highlight lines that "..
                     "include the word \"operator\".\r\n"..
                     "Currently matched words:\r\n  "
            for k,v in formatting_opt.also_match_nicks do
               msg = msg..v..", "
            end
            hub:injectChat( string.sub( msg, 1, -3 ) )
         elseif parms[2] == "add" then
            for k,v in formatting_opt.also_match_nicks do
               if string.lower( v ) == parms[3] then
                  hub:injectChat( "*** /highlight -- "..parms[3].." exists already" )
                  return 1
               end
            end
            table.insert( formatting_opt.also_match_nicks, parms[3] )
            formatting.save()
            hub:injectChat( "*** Highlight, added: "..parms[3] )
         elseif parms[2] == "del" then
            local rm = nil
            for k,v in formatting_opt.also_match_nicks do
               if string.lower( v ) == parms[3] then
                  table.remove( formatting_opt.also_match_nicks, k )
                  rm = 1
               end
            end
            if rm then
               formatting.save()
               hub:injectChat( "*** Highlight, removed: "..parms[3] )
            else
               hub:injectChat( "*** /highlight -- "..parms[3].." didn't exist" )
            end
         else
            hub:injectChat( "*** /highlight -- "..parms[2].." is not a switch" )
         end   
         return 1
      end
   end
)

-- load saved settings
formatting.load()
formatting.save() -- recreate settings file

DC():PrintDebug( "  ** Loaded formatting.lua **" )

SMF spam blocked by CleanTalk