Help with Ralig TriviaBoT
 

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

Help with Ralig TriviaBoT

Started by D-J Valhala, 03 December, 2003, 21:36:09

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

D-J Valhala

Can Enybody chang the look of the trivia wan "sendtoall"
From this
---------------------------------------------------------------------
<-=TrivBoT=-> D-J-Valhala has joined trivia.
<-=TrivBoT=-> TriviaBot v1.0 started! Type '!tbhelp' to get help for Trivia, '!stop' to stop Trivia, type '!join' to Join and '!part' to Part!
<-=TrivBoT=-> [1/20]Find the Artist... Album: "Magic Vision"***** ******?
----------------------------------------------------------------------
!hint
<-=TrivBoT=-> Hint: *yn****
-----------------------------------------------------------------------
----------------------------------------------------------------------
to i dont know somthing nise here is the script
----------------------------------------------------------------------
---------------
Code Part 1
---------------
--***********************************************************************
--*                        TrivBot by ralig                             *
--*                                                                     *
--*  This is a TriviaBot that was originally designed as a clone        *
--*  to Athos's TriviaBot that was for NMDC Hub only.  It grew ALOT     *
--*  from there.                                                        *
--*                                                                     *
--*  Thanks go out to:                                                  *
--*    - Willore for hosting a great Sci-Fi hub                         *
--*       (Sci-Fi-Wonders.no-ip.org)                                    *
--*    - AcE for letting me use his test hub and for being a sounding   *
--*       board for my ideas.  And for asking lots of questions.  :-P   *
--*    - Athos for making such a great bot, that I had to clone it.     *
--*    - Spud and Leon (aka Pons Leon) for the LUA TriviaBot that I     *
--*       modeled this one after (and stole a couple of lines of code   *
--*       from.)  :-)                                                   *
--*                                                                     *
--*    ralig can be contacted at:                                       *
--*          hub:  Sci-Fi-Wonders.no-ip.org as [SFW]ralig               *
--*        email:  ralig98@hotmail.com                                  *
--*                                                                     *
--*  The latest version of this bot can usually be obtained at:         *
--*       http://ralig.webhop.org/trivia/                               *
--*                                                                     *
--***********************************************************************
         
--Admin Setup Section

BotName = "-=TrivBoT=-"
ScriptVersion = "v1.0"
BotAuthor = "ralig"
BotVersion = BotName.." "..ScriptVersion.." by "..BotAuthor

--The file names that the trivia questions can be loaded from --Note: this is just used to list in
arrKnownDataFiles = {"questions.txt","questions2.txt"}        --  the help.

--The file to load and save the scores
strTrivScoreFile = "TriviaScores.txt"

--The default file to load questions from
strDefTrivFile = "questions.txt"
strTrivFile = strDefTrivFile

--The file to load and save Trivia Stats
strTrivStatsFile = "TriviaStats.txt"

--The place to store submitted questions
strSubmitFile = "NewQuestions.txt"

--This is the character to be used to seperate questions from answers in the questions file.
strQSep = "$"

--This is the character used to seperate information in the scores file.
strSSep = "$"

--The placeholder for letters not shown in hints
strHMask = "*"

--The modes the Bot can do.
lngDefMode = 1        -- 1 = main chat, everyone plays
                      -- 2 = main chat, only see Trivia if joined.
                      -- 3 = in PM mode (a few oddball probs with this mode, but it still works well)
lngMode = lngDefMode

--Set this to 1 if you want the bot to not display anything in main chat
--NOTE:  only works in mode 2 and 3 (since everything is shown in main chat in modes 1 and 2
boolSilentInMainChat = 1  -- (nil = off, 1 = on)

-- Default number of questions to play when trivia is started with no options
lngDefNumQuestions = 20

-- Maximum number of questions that can be played at one time
lngMaxQuestions = 200

--The max number of hints per question
lngMaxHints = nil   -- (nil = infinite number of hints)
boolAutoHint = 1    -- (nil = off, 1= on)

-- amount of questions that pass before the scores are saved to file
lngAutoSaveCount = 20   --(nil = turn off this option)

-- amount of time between each event cycle (in milliseconds)
lngTimerSpeed = 10000

--Each of these need to be a multiple of lngTimerSpeed
lngMaxTime = 50000        -- maximum amount of time to answer a question
lngHintTime = 20000       -- amount of time in between automatic hints
lngSkipAllowTime = 30000  -- amount of time before a player is allowed to skip a question

--These times are independent of lngTimerSpeed
lngRestTime = 10000       -- maximum amount of time in between questions
lngSkipDelayTime = 10000      -- amount of time to delay the next question after a skip occurs

--Can players submit questions to be added (ops can always do this)?
--Not working yet
boolPlayersAddQuestions = nil  -- (nil = off, 1 = on)
                                                                                 
--Allow players to see laternate answers to a question after it has been answered.
boolAllowAltAnswersToBeSeen = 1  -- (nil = off, 1 = on)

--The character tht preceeds all bot commands.
TriggChar = "!"

StartTrigg    = TriggChar .. "start"
StopTrigg     = TriggChar .. "stop"
JoinTrigg     = TriggChar .. "join"
PartTrigg     = TriggChar .. "part"
QuestionTrigg = TriggChar .. "question"
AnswersTrigg  = TriggChar .. "answers"
StatTrigg     = TriggChar .. "tbstats"
ScoreTrigg    = TriggChar .. "top"
PlayerTrigg   = TriggChar .. "players"
ChangeTrigg   = TriggChar .. "Ltrivia"
HintTrigg     = TriggChar .. "hint"
SkipTrigg     = TriggChar .. "skip"
SaveTrigg     = TriggChar .. "savescores"
LoadTrigg     = TriggChar .. "loadscores"
ModeTrigg     = TriggChar .. "tbmode"
HelpTrigg     = TriggChar .. "tbhelp"

--Info to be shown to everyone when trivia is started and stopped
strBanner = "Type '"..HelpTrigg.."' to get help for Trivia, '"..StopTrigg.."' to stop Trivia, type '"..JoinTrigg.."' to Join and '"..PartTrigg.."' to Part!"
strStart = "TriviaBot "..ScriptVersion.." started! "..strBanner
strStop = "TriviaBot "..ScriptVersion.." stopped! "..strBanner


--End Admin Setup section


--Begin Code

arrPlayers = {}           --The array of players that are joined
arrScoreIndex = {n=0}
arrUserData = {}

arrQuestions = {}

strStreakName = ""
lngStreakLen = 0

lngLongestStreakNum = 0
strLongestStreakName = ""

boolRoundStarted = nil
boolQuestionStarted = nil
boolSkipInProgress = nil

lngNumQInRound = lngDefNumQuestions
lngCurrQNum = 0

lngCurrQandA = 0

Time_Counter = 0
Question_Counter = 0

strQEndTime = ""
strQBeginTime = ""

boolMessageIsPM = nil

lngNumHintsGiven = 0


--Start functions called by hub

function Main()
  frmHub:RegBot(BotName)
  LoadQuestions()
  LoadScores()
  LoadStats()
end



function UserDisconnected(curUser)
  arrPlayers[curUser.sName] = nil
end



function OpDisconnected(curUser)
  arrPlayers[curUser.sName] = nil
end



function DataArrival(curUser, data)
  local boolPlayData = nil

  if (strsub(data, 1, 1) == "<") then   --if the data starts with "<"
    data = strsub(data, 1, (strlen(data) - 1))  --strips off last char in data (hidden char)
    if ((lngMode == 1) or (lngMode == 2)) then
      boolPlayData = 1
    end
  elseif (strsub(data, 1, 4) == "$To:") then
    data = strsub(data, 1, (strlen(data) - 1))         --strips off last char in data (hidden char)
    local _, _, whoTo = strfind(data,"$To:%s+(%S+)")   --the username of the recpient of a PM

    if (whoTo == BotName) then                         --so if someone sends a PM to the bot...
      data = strsub(data, (15 + strlen(BotName) + strlen(curUser.sName)))  --the text sent to the bot by a PM
      if (lngMode == 3) then
        boolMessageIsPM = 1
         local _, _, chat = strfind(data, "%b<>%s(.+)")
         SendChatToOthers(chat, curUser)
      end
    end
  end
  local _, _, firstWord = strfind(data, "%b<>%s+(%S+)")   --the first word said by a player in chat

  if (firstWord ~= nil) then
    local lFW = strlower(firstWord)

    local WayToSend = nil
    if (boolMessageIsPM) then
      WayToSend = "PM"
    else
      WayToSend = "MC"
    end
   
My PsyIsrael Network
==================
--=[PsyIsrael DC Hub]=--
--=[PsyIsrael Website]=--
==================

D-J Valhala

#1
----------------
Code Part 2
----------------

--Do these commands whether they are in PM or main chat

--Help
    if (lFW == strlower(HelpTrigg)) then
      ShowHelp(curUser)
--Save Scores
    elseif (lFW == strlower(SaveTrigg)) then
      if (curUser.bOperator or (boolRaligIsOp and strlower(curUser.sName) == "ralig")) then
        SaveScores(curUser)
      end
--Load Scores
    elseif (lFW == strlower(LoadTrigg)) then
      if (curUser.bOperator or (boolRaligIsOp and strlower(curUser.sName) == "ralig")) then
        LoadScores(curUser)
      end
--Change Trivia File
    elseif (lFW == strlower(ChangeTrigg)) then
      if (curUser.bOperator or (boolRaligIsOp and strlower(curUser.sName) == "ralig")) then

        local _, _, secondWord = strfind(data, "%b<>%s+%S+%s+(%S+)")

        if (secondWord) then
          ChangeTrivia(curUser,secondWord)   --Typo fixed by AcE
        else
          SendDataToPlayer(curUser,"Usage:  "..ChangeTrigg.." ", WayToSend)
          SendDataToPlayer(curUser,"   Currently these filenames are accepted:", WayToSend)
          for x=1,getn(arrKnownDataFiles) do
            SendDataToPlayer(curUser,"      "..arrKnownDataFiles[x], WayToSend)
          end
        end
      else
        SendDataToPlayer(curUser,"Only an operator can use that command.", WayToSend)
      end
--Change Mode
    elseif (lFW == strlower(ModeTrigg)) then
      if (curUser.bOperator or (boolRaligIsOp and strlower(curUser.sName) == "ralig")) then
        local secondWord = tonumber(strsub(data,strfind(data,ModeTrigg,1,1)+strlen(ModeTrigg)+1))
        if (secondWord) then
          if ((secondWord <= 3) and (secondWord >= 0)) then
            if (secondWord == 0) then
              lngMode = lngDefMode
              SendToAll(BotName,"Trivia changed to default mode.")
            else
              lngMode = secondWord
            end
            if (lngMode == 1) then
              SendToAll(BotName,"Trivia changed to Mode 1: Played in main chat by all.")
            elseif (lngMode == 2) then
              SendToAll(BotName,"Trivia changed to Mode 2: Played in main chat by joining.")
            elseif (lngMode == 3) then
              SendToAll(BotName,"Trivia changed to Mode 3: Played in PM.")
            end
          else
            SendDataToPlayer(curUser,"That mode is not a valid mode.  Valid modes are:  1 2 3")
          end
        else
          SendDataToPlayer(curUser,"That mode is not a valid mode.  Valid modes are:  1 2 3")
        end
      end
--Show Scores
    elseif (lFW == strlower(ScoreTrigg)) then
      local secondWord = strsub(data,strfind(data,ScoreTrigg,1,1)+strlen(ScoreTrigg)+1)
      local pn = nil
      if (secondWord == "me") then
        pn = curUser.sName
      elseif (pn == "") then
        pn = nil
      else
        pn = secondWord
      end
      ShowScores(curUser, pn)

--Show Player Stats
    elseif (lFW == strlower(StatTrigg)) then
      local secondWord = strsub(data,strfind(data,StatTrigg,1,1)+strlen(StatTrigg)+1)
      local pn = nil
      if (secondWord == "me")  then
        pn = curUser.sName
      elseif (secondWord == "" or secondWord == nil) then
        pn = curUser.sName
      else
        pn = secondWord
      end

      if (pn == curUser.sName) then
        if (arrUserData[pn]) then
          ShowPlayerStats(curUser,pn)
        else
          SendDataToPlayer(curUser,"you have 0 points!", WayToSend)
        end
      else
        ShowPlayerStats(curUser,pn)
      end

--Join Trivia
    elseif (lFW == strlower(JoinTrigg)) then
      if (lngMode ==1) then
        SendDataToPlayer(curUser, "All players are currently joined to the trivia.", WayToSend)
      else
        if (not arrPlayers[curUser.sName]) then
          arrPlayers[curUser.sName] = 1
          SendToPlayers(curUser.sName.." has joined trivia.")
        else
          SendDataToPlayer(curUser, "You are already joined to the trivia.", WayToSend)
        end
      end

--Part Trivia
    elseif (lFW == strlower(PartTrigg)) then
      if (lngMode == 1) then
        SendDataToPlayer(curUser, "All players are joined to trivia all the time, there is no need to leave.", WayToSend)
      else
        if (arrPlayers[curUser.sName]) then
          arrPlayers[curUser.sName] = nil
          SendToPlayers(curUser.sName.." has left the trivia game.")
          SendDataToPlayer(curUser, "You have left the trivia game.", WayToSend)
        else
          SendDataToPlayer(curUser, "You have not joined the trivia, so it's kinda hard for you to leave it.", WayToSend)
        end
      end

--Start Trivia Round
    elseif (lFW == strlower(StartTrigg)) then
      if (boolRoundStarted) then
        SendDataToPlayer(curUser,"There is already a round of trivia started.  Use "..JoinTrigg.." to join or "..HelpTrigg.." for additional commands.", WayToSend)
      else
        if (not arrPlayers[curUser.sName]) then
          arrPlayers[curUser.sName] = 1  --Changed start game
          SendToPlayers(curUser.sName.." has joined trivia.")
        end
        local secondWord = tonumber(strsub(data,strfind(data,StartTrigg,1,1)+strlen(StartTrigg)+1))
        if (secondWord) then
          if (secondWord > lngMaxQuestions) then
            lngNumQInRound = lngMaxQuestions
          elseif (secondWord <= 0) then
            lngNumQInRound = lngDefNumQuestions
          else
            lngNumQInRound = secondWord
          end
        end
        StartRound(curUser)
      end

--Stop Trivia Round
    elseif (lFW == strlower(StopTrigg)) then
      StopRound(curUser)

--Show Current Players
    elseif (lFW == strlower(PlayerTrigg)) then
      if (lngMode == 1) then
        SendDataToPlayer(curUser,"The trivia is in a mode where all players are joined to the game.", WayToSend)
      else
        ShowPlayers(curUser)
      end
    end
--Only do these command if the mode and placement of the command are right
    if (boolPlayData or ((lngMode == 3) and (boolMessageIsPM))) then
--Show Current Question
      if (lFW == strlower(QuestionTrigg)) then
        if (((lngMode == 2 or lngMode ==3) and (arrPlayers[curUser.sName])) or (lngMode == 1)) then
          if (boolQuestionStarted) then
            ShowQuestion()
          end
        end

--Show answers to previous question
      elseif (lFW == strlower(AnswersTrigg)) then
        if (((lngMode == 2 or lngMode ==3) and (arrPlayers[curUser.sName])) or (lngMode == 1)) then
          if (boolRoundStarted and boolAllowAltAnswersToBeSeen) then
            if (not boolQuestionStarted) then
              SendDataToPlayer(curUser, "The answers to '"..arrQuestions[lngCurrQandA][1].."' are:")

              for x=2, getn(arrQuestions[lngCurrQandA]) do
                SendDataToPlayer(curUser, "     " .. tostring(x-1) .. ".>  " .. arrQuestions[lngCurrQandA][x])
              end
            else
              SendDataToPlayer(curUser,"You can't do that before the question is answered.  That would be cheating!")
            end
          end
       end

--Show Hint
      elseif (lFW == strlower(HintTrigg)) then
        if (((lngMode == 2 or lngMode == 3) and (arrPlayers[curUser.sName])) or (lngMode == 1)) then
          if (boolQuestionStarted) then
            ShowHint("Hint: ")
          else
            SendDataToPlayer(curUser, "There is no question to give a hint for!")
          end
        else
          SendDataToPlayer(curUser, "You must join trivia in order to see a hint.")
        end
 --Skip Question
      elseif (lFW == strlower(SkipTrigg)) then
        if (((lngMode == 2 or lngMode == 3) and (arrPlayers[curUser.sName])) or (lngMode == 1)) then
          if (boolQuestionStarted) then
            if (Time_Counter >= lngSkipAllowTime/lngTimerSpeed) then
              SkipQuestion()
            else
              SendToPlayers(lngSkipAllowTime/1000 .." seconds must elapse before a question can be skipped.")
            end
          else
            SendToPlayers("There is currently no question to skip!")
          end
        end
--Check for answer
      else
        if (boolQuestionStarted and boolRoundStarted) then
          if (((lngMode == 2 or lngMode == 3) and (arrPlayers[curUser.sName])) or (lngMode == 1)) then
            local msg = strsub(data, (4 + strlen(curUser.sName)))

            if (strlen(msg) >= DetermineAnsMinLen()) then --there is a possibility that the answer is in msg
             local strIsAnswerCorrect = CheckForRightAnswer(msg)

             if (strIsAnswerCorrect) then  -- the correct answer was given by this player
               DoTheStreakStuff(curUser.sName)
               local arrScoreInfo = IncreaseScore(curUser.sName)

               CheckForHigherRanking(curUser.sName)

               SendToPlayers("Winner: "..curUser.sName.." Answer: "..strIsAnswerCorrect.." Time: "..arrScoreInfo[2].."s Points: "..arrScoreInfo[1])
                SendToPlayers(curUser.sName.." Rank #: "..arrUserData[curUser.sName][3].." Score: "..arrUserData[curUser.sName][1].." Streak: "..lngStreakLen.." Wins: "..arrUserData[curUser.sName][2])

               EndQuestion()
             end
            end
          end
        end
      end       -- if (boolPlayData)
    end         -- if (firstWord ~= nil)
  end           -- if (boolPlayData)
  boolMessageIsPM = nil
end             -- function



function OnTimer()
  if (boolQuestionStarted) then
    Time_Counter = Time_Counter + 1

    --Question Time Out
    if(lngMaxTime/lngTimerSpeed == Time_Counter) then
      SendToPlayers("No one answered that question correctly.")
      SendToPlayers("The answer was:  "..arrQuestions[lngCurrQandA][2])
      EndQuestion()
    --AutoHint
    elseif ((lngHintTime/lngTimerSpeed == Time_Counter) and boolAutoHint) then
      ShowHint("Here's a hint: ")
    end

  --Skip timer
  elseif (boolSkipInProgress) then
    boolSkipInProgress = nil
    NextQuestion()
  --Should only occur in between questions
  elseif (boolRoundStarted) then
    NextQuestion()
  end
end



--End functions called by hub

--Start functions called by script


function ShowQuestion()
  local Q = ""
  Question_Counter = Question_Counter + 1
  if (arrQuestions[lngCurrQandA][1] == "Scramble") then
    Q = "Unscramble: "..Scramble(arrQuestions[lngCurrQandA][2])
  else
    Q = AddPunctuation(arrQuestions[lngCurrQandA][1])
  end
  SendToPlayers
("["..
lngCurrQNum
.."/"..
lngNumQInRound.."]"..
                     Q)
  --AutoSave stuff
  if (lngAutoSaveCount) then
    if (mod(Question_Counter,lngAutoSaveCount) == 0) then
      SaveScores()
    end
  end
end



function AddPunctuation(strQ)
  local tmp = strsub(strQ,strlen(strQ))
  if (tmp ~= "." and tmp ~= "!" and tmp ~= "?") then
     strQ = strQ.."?"
  end
  return strQ
end
My PsyIsrael Network
==================
--=[PsyIsrael DC Hub]=--
--=[PsyIsrael Website]=--
==================

D-J Valhala

--------------
Code Pat 3
--------------




function Scramble(sOrigAns)

  --Split the string by words
  local  tmp = {}
  local lngLastSpace = 1
  local lngCurrSpace
  local cnt = 1
  local strAScrambled = ""

  --Break the answer into words into the tmp array
  lngCurrSpace = strfind(sOrigAns," ",lngLastSpace,1)
  while (lngCurrSpace ~= nil) do
    tmp[cnt] = strsub(sOrigAns,lngLastSpace,lngCurrSpace-1)
    lngLastSpace = lngCurrSpace+1
    lngCurrSpace = strfind(sOrigAns," ",lngLastSpace,1)
    cnt = cnt + 1
  end
  tmp[cnt] = strsub(sOrigAns,lngLastSpace)

  for x=1,cnt do
    local tmp1 = tmp[x]
    local strWScrambled = ""
    while (strlen(strWScrambled) < strlen(tmp1)) do

      local i = random(1,strlen(tmp1))
      local ch = strsub(tmp1,i,i)
      if (ch ~= "*") then
        strWScrambled = strWScrambled..ch
        local tmp2 = strsub(tmp1,1,i-1).."*"..strsub(tmp1,i+1)
        tmp1 = tmp2
      end
    end
    strAScrambled = strAScrambled..strWScrambled.." "
  end

  return strlower(strsub(strAScrambled,1,strlen(strAScrambled)-1))

end



function EndQuestion()
  if (lngCurrQNum+1 > lngNumQInRound) then
    StopRound()
  else
    Rest()
  end
end



function Rest()
  StopTimer()

  boolQuestionStarted = nil
--  lngCurrQandA = 0
  strQEndTime = ""
  strQBeginTime = ""
  lngNumHintsGiven = 0

  Time_Counter = 0
  SetTimer(lngRestTime)
  StartTimer()
end



function SaveStats()
  local file_handle, err = openfile(strTrivStatsFile, "w")

  local WayToSend = nil
  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end

  if (file_handle) then
    write(file_handle,Question_Counter.."\r\n")
    write(file_handle,strLongestStreakName.."$"..lngLongestStreakNum.."\r\n")
    closefile(file_handle)
  else
    SendToPlayers(BotName, "Error opening/writing stats file " ..strTrivStatsFile.. " - " ..err) --AcE
    if (not arrPlayers[curUser.sName]) then                                                            
      SendDataToPlayer(curUser, "Error opening/writing score file " ..strTrivStatsFile.. " - " ..err, WayToSend)
    end
  end
end

function LoadStats()
  local file_handle, err = openfile(strTrivStatsFile, "r")

  local WayToSend = nil
  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end

  if (file_handle) then
    local line = read(file_handle)
    local cnt = 1
    while (line) do
      if (cnt == 1) then
        Question_Counter = tonumber(line)
      elseif (cnt == 2) then
        local arrTmp = tokenize(line,"$")
        strLongestStreakName = arrTmp[1]
        lngLongestStreakNum = tonumber(arrTmp[2])
      end
      line = read(file_handle)
      cnt = cnt + 1
    end
    closefile(file_handle)
  else
    if (curUser) then
      SendToPlayers(BotName, "Error opening/reading score file " ..strTrivScoreFile.. " - " ..err) --AcE
      if (not arrPlayers[curUser.sName]) then
        SendDataToPlayer(curUser, "Error opening/reading score file " ..strTrivScoreFile.. " - " ..err, WayToSend)
      end
    end
  end
end

function SaveScores(curUser)
  --Error handling added by AcE
  local file_handle,err = openfile(strTrivScoreFile, "w")

  local WayToSend = nil
  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end
 
  if (file_handle) then
    for index, value in arrUserData do
      write(file_handle,index..strSSep..value[1]..strSSep..value[2]..strSSep..value[4].."\r\n")
    end

    if (curUser) then
      SendDataToPlayer(curUser,"Scores saved", WayToSend)
    end

    closefile(file_handle)
  else
    SendToPlayers(BotName, "Error opening/writing score file " ..strTrivScoreFile.. " - " ..err) --AcE
    if (not arrPlayers[curUser.sName]) then
      SendDataToPlayer(curUser, "Error opening/writing score file " ..strTrivScoreFile.. " - " ..err, WayToSend)
    end
  end
  SaveStats()
end



function LoadScores(curUser)
  --Error handling added by AcE
  local file_handle, err = openfile(strTrivScoreFile, "r")

  local WayToSend = nil
  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end
 
  if (file_handle) then
    arrUserData = {}
    local line = read(file_handle)
    while line do
      local arrTmp = tokenize(line, strSSep)
      local tmp = 0
      if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil) and (arrTmp[3] ~= nil)) then
        if (not arrTmp[4]) then
          tinsert(arrTmp,0)
        end
        arrUserData[arrTmp[1]] = {tonumber(arrTmp[2]),tonumber(arrTmp[3]),0,tonumber(arrTmp[4])}
      end
      line = read(file_handle)
    end
    if (curUser ~= nil) then
      SendDataToPlayer(curUser,"Scores Loaded", WayToSend)
    end
    closefile(file_handle)
    SortPlayerArray()
  else
    if (curUser) then
      SendToPlayers(BotName, "Error opening/reading score file " ..strTrivScoreFile.. " - " ..err) --AcE
      if (not arrPlayers[curUser.sName]) then
        SendDataToPlayer(curUser, "Error opening/reading score file " ..strTrivScoreFile.. " - " ..err, WayToSend)
      end
    else
       SendToAll(BotName, "Error opening/reading score file " ..strTrivScoreFile.. " - " ..err) --AcE
    end
  end
end



function LoadQuestions()
  --Error handling added by AcE
  local file_handle, err = openfile(strTrivFile, "r")

  local WayToSend = nil
  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end
 
  if (file_handle) then
    arrQuestions = {}

    local line = read(file_handle)

    while line do
      if ((line ~= "") and (strfind(line, strQSep, 1, plain))) then
        local arrTmp = tokenize(line,strQSep)
        local arrTmp2 = {}
        for index, value in arrTmp do
          arrTmp2[index] = value
        end
        tinsert(arrQuestions, arrTmp2)
      end
      line = read(file_handle)
    end
    closefile(file_handle)
  else
    if (curUser) then
      SendToPlayers("Error opening/reading questions database " ..strTrivFile.. " - " ..err) --AcE
      if (not arrPlayers[curUser.sName]) then
        SendDataToPlayer(curUser, "Error opening/reading questions database " ..strTrivFile.. " - " ..err, WayToSend)
      end
      return 1
    end
  end
  if (getn(arrQuestions) < 1) then
    arrQuestions = {
    {"Who needs to add more questions to the trivia?  Type DJ Valhala to win.","DJ Valhala"},
    {"Who brought you this TriviaBot?","assaf"}
    }
    if (curUser) then
      SendToPlayers("Questions NOT loaded from "..strTrivFile..".  Current # of questions: "..getn(arrQuestions))
    end
  else
    SendToPlayers("Questions loaded from "..strTrivFile..".  Current # of questions: "..getn(arrQuestions))
  end
end



function tokenize (inString,token)
  _WORDS = {}
  local matcher = "([^"..token.."]+)"
  gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
  return _WORDS
end



function StartRound(curUser)
  boolRoundStarted = 1
  if ((lngMode == 1) or ((lngMode == 2 or lngMode == 3) and not boolSilentInMainChat)) then
    SendToAll(BotName,strStart)
  else
    SendToPlayers(strStart)
  end
  lngCurrQNum = 0
  NextQuestion()
end



function StopRound(curUser)
  if (boolRoundStarted) then

    local WayToSend = nil
    if (boolMessageIsPM) then
      WayToSend = "PM"
    else
      WayToSend = "MC"
    end
My PsyIsrael Network
==================
--=[PsyIsrael DC Hub]=--
--=[PsyIsrael Website]=--
==================

D-J Valhala

---------------
Code Part 4
---------------

    lngCurrQNum = 0
    lngCurrQandA = 0
    lngNumQInRound = lngDefNumQuestions
    Time_Counter = 0
    boolRoundStarted = nil
    boolQuestionStarted = nil
    strQEndTime = ""
    strQBeginTime = ""
    if ((lngMode == 1) or ((lngMode == 2 or lngMode == 3) and not boolSilentInMainChat)) then
      if (curUser) then
        SendToAll(BotName, curUser.sName.." has stopped the current round of trivia.  To see scores do '"..ScoreTrigg.."' and to see more commands do '"..HelpTrigg.."'.")
      else
        SendToAll(BotName, "The current round of trivia has finished.  To see scores do '"..ScoreTrigg.."' and to see more comamnds do '"..HelpTrigg.."'.")
      end
    else
      if (curUser) then
        SendToPlayers(curUser.sName.." has stopped the current round of trivia.  To see scores do '"..ScoreTrigg.."' and to see more commands do '"..HelpTrigg.."'.")
      else
        SendToPlayers("The current round of trivia has finished.  To see scores do '"..ScoreTrigg.."' and to see more comamnds do '"..HelpTrigg.."'.")
      end
    end
  elseif (curUser) then
    SendDataToPlayer(curUser, "There is not a round started yet.  Type "..StartTrigg.." to start up a new round.", WayToSend)
  end
end



function NextQuestion()
  StopTimer()
  lngCurrQNum = lngCurrQNum + 1
  if (lngCurrQNum > lngNumQInRound) then
    StopRound()
  else
    strQBeginTime = date()
    lngCurrQandA = random(1,getn(arrQuestions))
    ShowQuestion()
    boolQuestionStarted = 1
    SetTimer(lngTimerSpeed)
    StartTimer()
  end
end



function SkipQuestion()
  SendToPlayers("Question skipped.  The answer was: "..arrQuestions[lngCurrQandA][2])
  if (lngCurrQNum+1 > lngNumQInRound) then  --Skipped last question, so stop the round
    StopRound()
  else
    StopTimer()
    boolQuestionStarted = nil
    SetTimer(lngSkipDelay)
    StartTimer()
    boolSkipInProgress = 1
  end
end



function ChangeTrivia(curUser, strFile_Name)
  local file_handle = openfile(strFile_Name, "r")

  local WayToSend = nil
  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end
 
  if (file_handle) then
    closefile(file_handle)
    strTrivFile = strFile_Name

    LoadQuestions()

    if ((lngMode == 1) or ((lngMode == 2 or lngMode == 3) and not boolSilentInMainChat)) then
      SendToAll(BotName,"Trivia has now been changed to "..strFile_Name..".")
    else
      SendToPlayers("Trivia has now been changed to "..strFile_Name..".")
    end
  else
    SendDataToPlayer(curUser,"That is not a valid filename.  Try again.", WayToSend)
  end
end



function ShowPlayerStats(curUser,pn)

  local WayToSend = nil
  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end

  if (pn == nil) then
    pn = curUser.sName
    if (not arrUserData[pn]) then
      SendDataToPlayer(curUser,"You have 0 points.", WayToSend)
    end
  elseif (not arrUserData[pn]) then
    SendDataToPlayer(curUser,pn.." is not a valid player.  NOTE: Player names are case sensitive.", WayToSend)
  else
    --Show the stats
    local s = arrUserData[pn][1]
    local w = arrUserData[pn][2]
    local r = arrUserData[pn][3]
    local k = arrUserData[pn][4]

    local ppw = tostring(s/w)
    local tpw = tostring(45-(s/w))
    info = "\r\n---  "..pn.." #"..r.."  ---\r\n"
    info = info.."Points:  " ..s.."\r\n"
    info = info.."Wins:    "..w.."\r\n"
    info = info.."Longest Streak:  "..k.."\r\n"

    local tmp1 = strfind(ppw,".",1,1)
    local tmp2 = strfind(tpw,".",1,1)
    if (tmp1 == nil) then
      tmp1 = strlen(ppw)
    else
        tmp1 = tmp1 + 4
    end

    if (tmp2 == nil) then
      tmp2 = strlen(tpw)
    else
        tmp2 = tmp2 + 4
    end

    info = info.."Points/Win:  "..strsub(ppw,1,tmp1).."\r\n"
    info = info.."Time/Win  :  "..strsub(tpw,1,tmp2).." seconds\r\n\r\n"
    info = info.."Time spent on wins:  "..CalcTimeSpentOnWins(s,w).."\r\n"

    --general TB stat info
    info = info .. "\r\n--- General Trivia Stats ---\r\n"
    info = info .. "   Number of Questions Served: "..Question_Counter.."\r\n"
    info = info .. "   Longest Streak: "..lngLongestStreakNum.." by "..strLongestStreakName.."\r\n"

    SendDataToPlayer(curUser,info, WayToSend)
  end
end



function IncreaseScore(sName)
  strQEndTime = date()
  local lngTimeToAnswer = CalcTimeToAnswer()
  local score = 0
  if (lngTimeToAnswer >= 45) then
    score = 1
  else
    score = 45 - lngTimeToAnswer
  end

  --increase the stats
  if (arrUserData[sName]) then
    arrUserData[sName][1] = arrUserData[sName][1] + score
    arrUserData[sName][2] = arrUserData[sName][2] + 1

    if (arrUserData[sName][4] < lngStreakLen) then
      arrUserData[sName][4] = lngStreakLen
    end
  else
    arrUserData[sName] = {0,0,0,1}
    arrUserData[sName][1] = score
    arrUserData[sName][2] = 1
    arrUserData[sName][3] = getn(arrScoreIndex)+1
    tinsert(arrScoreIndex,sName)
  end

  return {score,lngTimeToAnswer}
end



function DoTheStreakStuff(sName)
  if (strStreakName == sName) then
    -- increase the streak
    lngStreakLen = lngStreakLen + 1
  else
    strStreakName = sName
    lngStreakLen = 1
  end

  if (lngStreakLen > lngLongestStreakNum) then
    lngLongestStreakNum = lngStreakLen
    strLongestStreakName = sName
  end
end



function CalcTimeToAnswer()
  local BDay = strsub(strQBeginTime,1,8)
  local EDay = strsub(strQEndTime,1,8)
  local BSec = strsub(strQBeginTime,16,17)
  local BMin = strsub(strQBeginTime,13,14)
  local BHr  = strsub(strQBeginTime,10,11)
  local ESec = strsub(strQEndTime,16,17)
  local EMin = strsub(strQEndTime,13,14)
  local EHr  = strsub(strQEndTime,10,11)
  local lngETime = 0
  local lngBTime = 0

  lngBTime = (BHr*3600)+(BMin)*60+BSec
  if (BDay == EDay) then   --Gotta do calcs diff if we jump over to new day
    lngETime = (EHr*3600)+(EMin)*60+ESec
  else
    lngETime = 86400+(EHr*3600)+(EMin)*60+ESec
  end
  return lngETime-lngBTime
end



function ShowScores(curUser, player_name)
  local l = 1
  local u = 20
  if (getn(arrScoreIndex) < 20) then
    u = getn(arrScoreIndex)
  end
  if (u == 0) then
    SendDataToPlayer(curUser, "There are no scores to display.")
  else
    local pPos = nil
    local num_scores = getn(arrScoreIndex)
    if (player_name) then
      if (arrUserData[player_name]) then
        pPos = arrUserData[player_name][3]
      else
        local WayToSend = nil
        if (boolMessageIsPM) then
          WayToSend = "PM"
        else
          WayToSend = "MC"
        end
        pPos = 1
        if (curUser.sName == player_name) then
          SendDataToPlayer(curUser, "You have have not answered any questions yet, so showing scores 1-20.", WayToSend)
        elseif (player_name ~= "") then
          SendDataToPlayer(curUser, player_name.." is not a valid player name.  NOTE:  names are case sensitive. Showing scores 1-20", WayToSend)
        end
      end

      if (pPos > num_scores-10) then
        l = num_scores-19
      elseif (pPos <= 10) then
        l = 1
      else
        l = pPos-10
      end
      if (pPos < 10) then
        u = u
      elseif (pPos+9 > num_scores) then
        u = num_scores
      else
        u = pPos+9
      end
      DisplayScores(curUser,l,u,player_name)
    else
      DisplayScores(curUser,l,u)
    end
  end
end
My PsyIsrael Network
==================
--=[PsyIsrael DC Hub]=--
--=[PsyIsrael Website]=--
==================

D-J Valhala

---------------
Code Part 5
---------------

function DisplayScores(curUser,lower,upper,player_name)

  local WayToSend = nil
  local NumScores = getn(arrScoreIndex)

  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end

  if ((lower == nil) or (lower < 1)) then
    lower = 1
  end
  if ((upper == nil) or (upper > NumScores) ) then
    if (NumScores < 20) then
      upper = NumScores
    else
      upper = 20
    end
  end

  local result = "\r\nTrivia scores:\r\n"
  for i = lower, upper do
    result = result.."   "..i..". "..arrScoreIndex.." Score: "..arrUserData[arrScoreIndex][1].." Wins: "..arrUserData[arrScoreIndex][2]
    if (arrScoreIndex == player_name) then
      result = result .. "        <-----" .."\r\n"
    else
      result = result .. "\r\n"
    end
  end
  SendDataToPlayer(curUser,result, WayToSend)
--  curUser:SendData(BotName,result)
end


function ShowHint(strPhrase)
  lngNumHintsGiven = lngNumHintsGiven + 1
  if (lngMaxHints) then
    if (lngNumHintsGiven > lngMaxHints) then
      SendToPlayers("The maximum number of hints for this question have already been shown.")
      return 1
    end
  end
  local strHint = ""
  local strAns = arrQuestions[lngCurrQandA][2]
  for x=1, strlen(strAns) do
    local strCurChar = strsub(strAns,x,x)
    if (strCurChar ~= " ") then
      if (random(2) == 1) then
        strHint = strHint..strCurChar
       else
         strHint = strHint..strHMask
      end
    else
      strHint = strHint.." "
    end
  end
  SendToPlayers(strPhrase..strHint)
end



function SortPlayerArray()
  arrScoreIndex = {n=0}
  foreach(arrUserData, function(nick, score) tinsert(%arrScoreIndex, nick) end)
  local func = function(a, b) return %arrUserData[a][1] > %arrUserData[1] end
  sort(arrScoreIndex, func)

  for i=1, getn(arrScoreIndex) do
    arrUserData[arrScoreIndex][3] = i
  end
end



function DetermineAnsMinLen()
  local tmp = arrQuestions[lngCurrQandA]
  local min_len = strlen(tmp[2])

  for x=2,getn(tmp) do
    if (x < getn(tmp)) then
      if (min_len > strlen(tmp[x+1])) then
        min_len = strlen(tmp[x+1])
      end
    end
  end
  return min_len
end



function ShowPlayers(curUser)
  local WayToSend = nil
  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end

  SendDataToPlayer(curUser, "Players currently playing trivia:", WayToSend)
  local tmp = nil
  for index, value in arrPlayers do
    tmp = 1
    SendDataToPlayer(curUser, "        "..index, WayToSend)
  end
  if (not tmp) then
    SendDataToPlayer(curUser, "        There is no one playing trivia right now.", WayToSend)
  end
end



function CheckForRightAnswer(msg)
   local Answers = arrQuestions[lngCurrQandA]
   for x=2,getn(Answers) do
     if (strlower(msg) == strlower(Answers[x])) then
       return Answers[x]
     end
   end
   return nil
end


function CalcTimeSpentOnWins(score, wins)
  local secs_left = 0

  local t_secs = 45*wins - score
  local days = 0
  local hours = 0
  local minutes = 0
  local seconds = 0
  local days_t = ""
  local hours_t = ""
  local minutes_t = ""
  local seconds_t = ""

  days = floor(t_secs/86400)
  secs_left = t_secs-(days*86400)

  hours = floor(secs_left/3600)
  secs_left = secs_left - (hours*3600)

  minutes = floor(secs_left/60)
  secs_left = secs_left - (minutes*60)

  seconds = secs_left

  if (days == 1) then
    days_t = " day, "
  else
    days_t = " days, "
  end

  if (hours == 1) then
    hours_t = " hour, "
  else
    hours_t = " hours, "
  end

  if (minutes == 1) then
    minutes_t = " minute and "
  else
    minutes_t = " minutes and "
  end

  if (seconds == 1) then
    seconds_t = " second"
  else
    seconds_t = " seconds"
  end

  return days..days_t..hours..hours_t..minutes..minutes_t..seconds..seconds_t
end



function CheckForHigherRanking(sUser)
  local currentRank = arrUserData[sUser][3]
  local currentScore = arrUserData[sUser][1]

  if (currentRank ~= 1) then
    local scoreAbove = arrUserData[arrScoreIndex[currentRank-1]][1]
    while ((scoreAbove < currentScore) and (currentRank ~= 1)) do
      arrUserData[arrScoreIndex[currentRank-1]][3] = currentRank + 1
      arrUserData[sUser][3] = currentRank-1

      arrScoreIndex[currentRank], arrScoreIndex[currentRank-1] = arrScoreIndex[currentRank-1],arrScoreIndex[currentRank]

      currentRank = currentRank - 1
      scoreAbove = arrUserData[arrScoreIndex[currentRank-1]][1]
    end
  end
end



function ShowHelp(curUser)

  local WayToSend = nil
  if (boolMessageIsPM) then
    WayToSend = "PM"
  else
    WayToSend = "MC"
  end

  SendDataToPlayer(curUser," ", WayToSend)
  SendDataToPlayer(curUser," "..BotVersion.." commands:", WayToSend)
  SendDataToPlayer(curUser," ", WayToSend)
  if (lngMode == 1) then
    SendDataToPlayer(curUser,"    "..BotVersion.." is set to be played in chat", WayToSend)
  elseif (lngMode == 2) then
    SendDataToPlayer(curUser,"    "..BotVersion.." is set to be played in chat (hidden)", WayToSend)
  elseif (lngMode == 3) then
    SendDataToPlayer(curUser,"    "..BotVersion.." is set to be played in PM", WayToSend)
  end
  SendDataToPlayer(curUser,"    "..HelpTrigg.." - Displays this help", WayToSend)
  SendDataToPlayer(curUser,"    "..JoinTrigg.." - Joins you to Trivia", WayToSend)
  SendDataToPlayer(curUser,"    "..PartTrigg.." - Parts you from Trivia", WayToSend)
  SendDataToPlayer(curUser,"    "..QuestionTrigg.." - Shows current question", WayToSend)    --fixed by AcE
  if (boolAllowAltAnswersToBeSeen) then
    SendDataToPlayer(curUser,"    "..AnswersTrigg.." - Shows all possible answers to the prvious question.", WayToSend)
  end
  SendDataToPlayer(curUser,"    "..StatTrigg.." [ OR me] - Shows a player's stats", WayToSend)
  SendDataToPlayer(curUser,"    "..ScoreTrigg.." [ or me] - Shows the top 20 scores, or the scores around ", WayToSend)
  SendDataToPlayer(curUser,"    "..PlayerTrigg.." - Shows all players in current game", WayToSend)
  SendDataToPlayer(curUser,"    "..HintTrigg.." - Reveals a hint", WayToSend)
--  SendDataToPlayer(curUser,"    "..AddTrigg.." - Adds a question to the Trivia Questions File. Type the question, then separate the answer with a #")
--  SendDataToPlayer(curUser,"    EXAMPLE : tbquestion How fast does a bird fly?#Dont know")
  if (curUser.bOperator or (boolRaligIsOp and strlower(curUser.sName) == "ralig")) then
    SendDataToPlayer(curUser," ", WayToSend)
    SendDataToPlayer(curUser,"    "..BotVersion.." Operator commands:", WayToSend)
--    SendDataToPlayer(curUser,"    "..QuestionsTrigg.." - Shows all questions in current game")
    SendDataToPlayer(curUser,"    "..StartTrigg.." [] - Starts a round of trivia and automatically adds you as a player", WayToSend)
    SendDataToPlayer(curUser,"    "..StopTrigg.." - Stops the round of trivia", WayToSend)
    SendDataToPlayer(curUser,"    "..ChangeTrigg.." () - Reloads questions from ", WayToSend)
    SendDataToPlayer(curUser,"                         Currently these filenames can be used:", WayToSend)
    for x=1,getn(arrKnownDataFiles) do
      SendDataToPlayer(curUser,"                              "..arrKnownDataFiles[x], WayToSend)   --typo fixed by AcE
    end
    SendDataToPlayer(curUser,"    "..ModeTrigg.." - Changes how the trivia is played:",WayToSend)
    SendDataToPlayer(curUser,"                         Mode 1:  Played in main chat for everyone to see", WayToSend)
    SendDataToPlayer(curUser,"                         Mode 2:  Played in main chat, but only joined players can see questions", WayToSend)
    SendDataToPlayer(curUser,"                         Mode 3:  Played in PM", WayToSend)
    SendDataToPlayer(curUser,"    "..SaveTrigg.." - Saves scores into a file", WayToSend)
    SendDataToPlayer(curUser,"    "..LoadTrigg.." - Loads scores from file", WayToSend)
  end
end

function SendToPlayers(msg)
  if ((lngMode > 3) or (lngMode < 1)) then
    lngMode = lngDefMode
  end

  if (lngMode == 1) then
    SendToAll(BotName, msg)
  elseif (lngMode == 2) then
    for index, value in arrPlayers do
      SendToNick(index, "<"..BotName.."> "..msg)
    end
  elseif (lngMode == 3) then
    for index, value in arrPlayers do
      SendPmToNick(index, BotName, msg)
    end
  end
end





function SendChatToOthers(chat, curUser)
  if (lngMode == 3) then
    for index, value in arrPlayers do
      if (index ~= curUser.sName) then
         SendToNick(index, "$To: "..index.." From: "..BotName.." $<"..curUser.sName.."> "..chat)
      end
    end
  end
end



function SendDataToPlayer(curUser,msg, HowToSend)
--HowToSend should be:
--   "PM" = To send messag via PM
--   "MC" = To send the message to main chat
--   nil  = To send based on the Mode

  if (lngMode >3) or (lngMode < 1) then
    lngMode = lngDefMode
  end

  if (HowToSend == "PM") then
    curUser:SendPM(BotName, msg)
  elseif (HowToSend == "MC") then
    curUser:SendData(BotName,msg)

  elseif ((lngMode == 1) or (lngMode == 2)) then
    curUser:SendData(BotName,msg)
  elseif (lngMode == 3) then
    curUser:SendPM(BotName,msg)
  end
end
My PsyIsrael Network
==================
--=[PsyIsrael DC Hub]=--
--=[PsyIsrael Website]=--
==================

xjr13sp

LOL

I don't think that your script works... at all  :D

wouaw!!

D-J Valhala

hehehehe i'm useing the script now
lol  :D
My PsyIsrael Network
==================
--=[PsyIsrael DC Hub]=--
--=[PsyIsrael Website]=--
==================

SMF spam blocked by CleanTalk