ive try'd converting triv game (by chilla)using NL's converter ......... and i get this error
scripts\trivia.lua5.lua:619: bad argument #1 to `random' (interval is empty)
here is that part of script...
-- Get a bunch of questions
---------------------------------------------------------------------------------------
function GetQuestions(howmany)
if (HowToGetQuestions == 1) then
local getlines = {}
for _ = 1,howmany do
getlines[math.random(curTriv.QuestionsTotal)] = 1 << end
local handle = io.open(TrivFolder.."/"..QFile,"r")
if handle then
local curTrivQuestions = {}
local slinecount = 0
for line in io.lines() do
slinecount = slinecount + 1
if getlines[slinecount] then
local _,_,cat,ques,ans = string.find(line,"(.*)"..DivideChar.."(.*)"..DivideChar.."(.*)")
if cat then
table.insert(curTrivQuestions,{cat,ques,ans,slinecount})
end
end
end
io.close(handle)
tTrivQuestions = {}
for _ = 1,table.getn(curTrivQuestions) do
local num = math.random(table.getn(curTrivQuestions))
table.insert(tTrivQuestions,curTrivQuestions[num])
tos.remove(curTrivQuestions,num)
end
end
getlines = {}
elseif (HowToGetQuestions == 2) then
curTriv.LinearNum = curTriv.LinearNum or 0
if curTriv.LinearNum >= curTriv.QuestionsTotal then
curTriv.LinearNum = 0
end
local getlines = {}
for _ = 1,howmany do
curTriv.LinearNum = curTriv.LinearNum + 1
end
getlines[curTriv.LinearNum] = 1
local handle = io.open(TrivFolder.."/"..QFile,"r")
if handle then
tTrivQuestions = {}
local slinecount = 0
for line in io.lines() do
slinecount = slinecount + 1
if getlines[slinecount] then
local _,_,cat,ques,ans = string.find(line,"(.*)"..DivideChar.."(.*)"..DivideChar.."(.*)")
if cat then
table.insert(tTrivQuestions,{cat,ques,ans,slinecount})
end
end
end
io.close(handle)
end
getlines = {}
end
end
Instead of..
io.close(handle)
replace it (both times) with..
handle:close()
still same error m8 :((
This is all i get on my hub ........
Short Trivia break for 1 min.
[22:10] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:10] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:11] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:11] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:11] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:11] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:11] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:11] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:12] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:12] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:12] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:12] <(JAY's)MIND-GAMES> Short Trivia break for 1 min.
[22:12] <(JAY's)MIND-GAMES> Short Trivia break for 1 min
for some reason it wont find the questions :((
Could you post the whole script please?
nps ...........
-- HIDE AND SEEK TRIVIA VER 1.02 REVISION BY REMASTER-IT ORIGINAL by chilla
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
trivbot = "(JAY's)MIND-GAMES" -- The botname
---------------------------------------------------------------------------------------
-- COMMANDS
---------------------------------------------------------------------------------------
TrivPrefix = "%+%-%!" -- TriviaPrefix
cmd0 = "trivhelp" -- Trivia Help
cmd1 = "trivscore" -- Shows the Ranking of the best Max3
cmd4 = "trivmyscore" -- Shows only your score
cmd16 = "trivstats" -- Shows the top "Max9" player stats.
cmd7 = "login" -- Allows you to login to Trivia
cmd8 = "logout" -- Allows you to logout of Trivia
cmd10 = "trivplayers" -- Show's the Trivia Players
--------------------------------------------
cmd9 = "trivscorereset" -- Resets the Trivia Score
--------------------------------------------
cmd2 = "trivstart" -- Strats Trivia
cmd3 = "trivstop" -- Stops Trivia
cmd5 = "trivmain" -- Allows you to play in Main
cmd6 = "trivpm" -- Allows you to play in PM, implements the regging of a bot
--------------------------------------------
cmd11 = "trivskip" -- Lets you skip a question, trivskip
cmd12 = "triviaskip" -- Enables/Diables cmd11
--------------------------------------------
cmd13 = "trivhint" -- Gives you a Hint
cmd14 = "triviahint" -- Enables/Disables cmd14
--------------------------------------------
cmd15 = "triviashowhint" -- Switches between the Hint Modes.
---------------------------------------------------------------------------------------
trivbotmyinfo = "$MyINFO $ALL "..trivbot.." GAME BOT: +"..cmd0.."$ $TRIVIA$$0$"
---------------------------------------------------------------------------------------
-- GLOBALS
---------------------------------------------------------------------------------------
RevealChar = string.char(149) -- The revealchar: 149,164,1
QFile = "TriviaEx.Questions-1.txt" -- The name of the Questionfile Questiondefaultstring.format = category$$questions$$answer)
TrivFolder = "TRIVIA" -- The name of the Folder, for the Questionfile.
DivideChar = "%$%$" -- The Divied Char whitch divides the Category,Questions and Answer
HowToGetQuestions = 1 -- Questions Mode 1 = Random, 2 = Linear (e.g. 1,2,3)
--------------------------------------------
showPM = 1 -- 1 = Pm data from other players is seen, 2 = Pm data isn't seen
--------------------------------------------
Max1 = 30 -- How many questions are loaded into Memory
Max7 = 1 -- Trivia Break Time in minutes, between each question reload
Trivbreak = 1 -- 1 = do a triviabreak between each reload, 2 == no triviabreak
--------------------------------------------
Max2 = 30 -- Time between each hint in seconds
Max4 = 15 -- Time in seconds between each question
--------------------------------------------
Max3 = 100 -- The number of trivia scores shown
Max9 = 10 -- Number of top trivias shown
Max5 = 30 -- Time in minutes between each score and player saving
--------------------------------------------
Max6 = 1 -- Stands for how many chars are rvealed per hint.
Max8 = 6 -- Stands for how mayn Hints are displayed. This overruns Max6 (May not be totally accurate)
--------------------------------------------
StartOnMain = 1 -- 1 = Trivia starts on Main(), 0 = Trivia doesn't start on Main()
--------------------------------------------
TriviaConfig = {
TrivMainPM = 1, -- 1 = Trivia is played in MainChat, 2 = Trivia is played in PM
TrivSkip = 1, -- 1 = cmd11 enabled, 2 = disabled
TrivHint = 1, -- 1 = cmd14 enabled, 2 = disabled
TrivShowHint = 1, -- 1 = regular Hints, 2 = showing Maximal number of Hints (Max8)
}
dofile(TrivFolder.."/TriviaConfig.txt")
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--// MAIN SCRIPT
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
tTrivQuestions = {}
Scores = {}
dofile(TrivFolder.."/Scores.txt")
trivtimerset = { 0,0,0,0 }
UnRevealed = {}
curTriv = {
GetQues = 0,
Points = 0,
curNum = 0,
curCat = "",
curQues = "",
curAnswer = "",
curHint = "",
QuestionsTotal = 0,
RevealHowMany = 0,
LinearNum = 0,
curStreak = {
curNick = "",
curStreak = 0,
set = 0,
},
}
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
Max2 = Max2/10
Max4 = Max4/10
Max5 = Max5*6
Max7 = Max7*6
---------------------------------------------------------------------------------------
DisplTrivPrefix = string.gsub(TrivPrefix,"%%"," ")
---------------------------------------------------------------------------------------
function Main()
for i,v in Scores do
if tonumber(Scores[i]) then
local num = Scores[i]
Scores[i] = {}
Scores[i].Score = num
Scores[i].Streak = 1
end
end
if TriviaConfig.TrivMainPM == 2 then
frmHub:RegBot(trivbot)
PMPlayers = {}
SendToAll(trivbotmyinfo)
dofile(TrivFolder.."/PMPlayers.txt")
table.foreach(PMPlayers,function(a,_)
if not GetItemByName(a) then
PMPlayers[a] = nil
end
end)
else
frmHub:UnregBot(trivbot)
end
curTriv.QuestionsTotal = GetTotalQues()
os.remove(TrivFolder.."/PMPlayers.txt")
SetTimer(10*1000)
if StartOnMain == 1 and (TriviaConfig.TrivMainPM == 1 or doCheckPlayers() == "PLAY") then
curTriv.GetQues = 1
StartTimer()
GetQuestions(Max1)
end
end
---------------------------------------------------------------------------------------
function OnExit()
WriteTable(Scores, "Scores", "Scores.txt")
if PMPlayers then
WriteTable(PMPlayers, "PMPlayers", "PMPlayers.txt")
end
end
---------------------------------------------------------------------------------------
function OnTimer()
if table.getn(tTrivQuestions) == 0 and Trivbreak == 1 and curTriv.GetQues == 1 then
GetQues = 3
trivtimerset[4] = 0
SendDataMP("Short Trivia break for "..(Max7/6).." min.")
end
table.foreachi(trivtimerset, function(i,_) trivtimerset[i] = trivtimerset[i] + 1 end)
if trivtimerset[4] == Max7 and curTriv.GetQues == 3 then
curTriv.GetQues = 1
GetQuestions(Max1)
end
if trivtimerset[3] >= Max5 then
trivtimerset[3] = 0
WriteTable(Scores, "Scores", "Scores.txt")
end
if trivtimerset[2] >= Max4 and curTriv.GetQues == 1 then
trivtimerset[2] = 0
if table.getn(tTrivQuestions) == 0 then
GetQuestions(Max1)
end
curTriv.curNum = tTrivQuestions[1][4]
curTriv.curCat = tTrivQuestions[1][1]
curTriv.curQues = tTrivQuestions[1][2]
curTriv.curAnswer = tTrivQuestions[1][3]
tos.remove(tTrivQuestions,1)
curTriv.Points = 0
UnRevealed = {}
curTriv.curHint = string.gsub(curTriv.curAnswer,"(%S)",function (w) curTriv.Points = curTriv.Points + 1 return(RevealChar) end)
if TriviaConfig.TrivShowHint == 2 then
if ((curTriv.Points/Max8 - math.floor(curTriv.Points/Max8)) >= 0.5) then
curTriv.RevealHowMany = math.floor(curTriv.Points/Max8) + 1
elseif (math.floor(curTriv.Points/Max8) == 0) then
curTriv.RevealHowMany = 1
else
curTriv.RevealHowMany = math.floor(curTriv.Points/Max8)
end
else
curTriv.RevealHowMany = Max6
end
SendQuestion(curTriv.curCat,curTriv.curQues,curTriv.curHint,curTriv.Points,curTriv.curNum,curTriv.QuestionsTotal)
trivtimerset[1] = 0
curTriv.GetQues = 0
end
if trivtimerset[1] >= Max2 and curTriv.GetQues == 0 then
trivtimerset[1] = 0
curTriv.curHint = RevealChars(curTriv.curAnswer,curTriv.curHint)
if curTriv.curAnswer ~= curTriv.curHint then
SendQuestion(curTriv.curCat,curTriv.curQues,curTriv.curHint,curTriv.Points,curTriv.curNum,curTriv.QuestionsTotal)
else
curTriv.GetQues,curTriv.curAnswer = 1,nil
SendDataMP("The right answer was: "..curTriv.curHint)
if curTriv.curStreak.curStreak >= 3 then
SendDataMP("There goes "..curTriv.curStreak.curNick.."'s streak of "..curTriv.curStreak.curStreak)
end
curTriv.curStreak.curNick,curTriv.curStreak.curStreak,curTriv.curStreak.set = "",0,0
trivtimerset = { 0,0,trivtimerset[3],0 }
end
end
end
---------------------------------------------------------------------------------------
function DataArrival(curUser,data)
if (string.sub(data,1,1) == "<") then
if ParseData(curUser,data) == 1 then
return 1
end
elseif (TriviaConfig.TrivMainPM == 2 and string.sub(data,1,4) == "$To:") then
local _,_,whoTo,mes = string.find(data,"$To:%s+(%S+)%s+From:%s+%S+%s+$(.*)$")
if whoTo == trivbot then
ParseData(curUser,mes,1)
end
end
end
---------------------------------------------------------------------------------------
function NewUserConnected(curUser)
if TriviaConfig.TrivMainPM == 2 then
curUser:SendData(trivbotmyinfo)
end
end
OpConnected = NewUserConnected
---------------------------------------------------------------------------------------
function UserDisconnected(curUser)
if TriviaConfig.TrivMainPM == 2 and PMPlayers[curUser.sName] then
PMPlayers[curUser.sName] = nil
if doCheckPlayers() ~= "PLAY" then
StopTimer()
curAnswer = nil
WriteTable(Scores, "Scores", "Scores.txt")
end
end
end
OpDisconnected = UserDisconnected
---------------------------------------------------------------------------------------
-- Check for Players
---------------------------------------------------------------------------------------
function doCheckPlayers()
return(table.foreach(PMPlayers,function(a,_)
if a then
return("PLAY")
end
end))
end
---------------------------------------------------------------------------------------
-- Parse the Data
---------------------------------------------------------------------------------------
function ParseData(curUser,data,pm)
local _,_,sdata = string.find( data, "%b<>%s(.*)|$")
local _,_,cmd = string.find( data, "^%b<>%s["..TrivPrefix.."](%w+)")
if curTriv.curAnswer and string.lower(sdata) == string.lower(curTriv.curAnswer) then
SendDataMP("Correct "..curUser.sName.." the answer was \""..curTriv.curAnswer.."\", You get "..curTriv.Points.." Point(s).")
if Scores[curUser.sName] then
Scores[curUser.sName].Score = Scores[curUser.sName].Score + curTriv.Points
else
Scores[curUser.sName] = {}
Scores[curUser.sName].Score = curTriv.Points
Scores[curUser.sName].Streak = 1
end
SendDataMP("That gives you a total score of "..Scores[curUser.sName].Score.." Point(s).")
if (curTriv.curStreak.curNick ~= curUser.sName) then
if curTriv.curStreak.curStreak >= 3 then
SendDataMP("There goes "..curTriv.curStreak.curNick.."'s streak of "..curTriv.curStreak.curStreak)
curTriv.curStreak.curNick = curUser.sName
curTriv.curStreak.curStreak = 1
curTriv.curStreak.set = 1
else
curTriv.curStreak.curNick = curUser.sName
curTriv.curStreak.curStreak = 1
curTriv.curStreak.set = 1
end
elseif (curTriv.curStreak.curNick == curUser.sName) then
curTriv.curStreak.curStreak = curTriv.curStreak.curStreak + 1
if curTriv.curStreak.curStreak > Scores[curUser.sName].Streak then
if curTriv.curStreak.set == 1 then
SendDataMP(curUser.sName..", you broke your current streak of "..Scores[curUser.sName].Streak..".")
curTriv.curStreak.set = 0
end
Scores[curUser.sName].Streak = curTriv.curStreak.curStreak
end
if curTriv.curStreak.curStreak >= 3 then
SendDataMP(curUser.sName..", that makes "..curTriv.curStreak.curStreak.." streaks in a row.")
end
end
trivtimerset = { 0,0,trivtimerset[3],0 }
curTriv.GetQues,curTriv.curAnswer = 1,nil
elseif cmd then
if TrivFuncs[string.lower(cmd)] then
SendDataMP(TrivFuncs[string.lower(cmd)](curUser),curUser)
return 1
elseif TrivConfs[string.lower(cmd)] then
local _,_,status = string.find( data, "^%b<>%s["..TrivPrefix.."]%w+%s+(%w+)")
if status and TrivConfs[string.lower(cmd)][string.lower(status)] then
SendDataMP(TrivConfs[string.lower(cmd)][string.lower(status)](curUser),curUser)
return 1
else
SendDataMP(TrivConfs[string.lower(cmd)].help,curUser)
return 1
end
end
elseif pm and showPM == 1 then
SendDataMP(data,curUser,1)
end
end
---------------------------------------------------------------------------------------
-- Send Data To Players
---------------------------------------------------------------------------------------
function SendDataMP(data,curUser,sd)
if data then
if curUser then
if not sd then
if TriviaConfig.TrivMainPM == 2 then
curUser:SendPM(trivbot,data)
else
curUser:SendData(trivbot,data)
end
else
for i,_ in PMPlayers do
if i ~= curUser.sName and GetItemByName(i) then
GetItemByName(i):SendData("$To: "..i.." From: "..trivbot.." $"..data)
end
end
end
else
if TriviaConfig.TrivMainPM == 2 then
for i,_ in PMPlayers do
SendPmToNick(i,trivbot,data)
end
else
SendToAll(trivbot,data)
end
end
end
end
---------------------------------------------------------------------------------------
-- Send a question
---------------------------------------------------------------------------------------
function SendQuestion(curCat,curQues,curHint,points,number,totalques)
SendDataMP("QUESTION - Nr. "..number.." from "..totalques.." Questions.\r\n"..
"\t----------------------------------------------------------------------\r\n"..
"\t> Category: "..curCat.." - Point(s): "..points.."\r\n"..
"\tQUESTION: "..curQues.."\r\n"..
"\tHINT: "..curHint.."\r\n"..
"\t----------------------------------------------------------------------")
end
---------------------------------------------------------------------------------------
-- Reveal char(s)
---------------------------------------------------------------------------------------
function RevealChars(answer,toreveal)
if table.getn(UnRevealed) == 0 then
for i = 1,string.len(toreveal) do
if string.sub(toreveal,i,i) == RevealChar then
table.insert(UnRevealed,i)
end
end
end
for _ = 1,curTriv.RevealHowMany do
if table.getn(UnRevealed) ~= 0 then
local ctoreveal,revealnum = toreveal,math.random(table.getn(UnRevealed))
toreveal = ""
for i = 1,string.len(answer) do
if i == UnRevealed[revealnum] then
toreveal = toreveal..string.sub(answer,i,i)
else
toreveal = toreveal..string.sub(ctoreveal,i,i)
end
end
tos.remove(UnRevealed,revealnum)
curTriv.Points = curTriv.Points - 1
end
end
return(toreveal)
end
---------------------------------------------------------------------------------------
-- Get a bunch of questions
---------------------------------------------------------------------------------------
function GetQuestions(howmany)
if (HowToGetQuestions == 1) then
local getlines = {}
for _ = 1,howmany do
getlines[math.random(curTriv.QuestionsTotal)] = 1
end
local handle = io.open(TrivFolder.."/"..QFile,"r")
if handle then
local curTrivQuestions = {}
local slinecount = 0
for line in io.lines() do
slinecount = slinecount + 1
if getlines[slinecount] then
local _,_,cat,ques,ans = string.find(line,"(.*)"..DivideChar.."(.*)"..DivideChar.."(.*)")
if cat then
table.insert(curTrivQuestions,{cat,ques,ans,slinecount})
end
end
end
handle:close()
tTrivQuestions = {}
for _ = 1,table.getn(curTrivQuestions) do
local num = math.random(table.getn(curTrivQuestions))
table.insert(tTrivQuestions,curTrivQuestions[num])
tos.remove(curTrivQuestions,num)
end
end
getlines = {}
elseif (HowToGetQuestions == 2) then
curTriv.LinearNum = curTriv.LinearNum or 0
if curTriv.LinearNum >= curTriv.QuestionsTotal then
curTriv.LinearNum = 0
end
local getlines = {}
for _ = 1,howmany do
curTriv.LinearNum = curTriv.LinearNum + 1
end
getlines[curTriv.LinearNum] = 1
local handle = io.open(TrivFolder.."/"..QFile,"r")
if handle then
tTrivQuestions = {}
local slinecount = 0
for line in io.lines() do
slinecount = slinecount + 1
if getlines[slinecount] then
local _,_,cat,ques,ans = string.find(line,"(.*)"..DivideChar.."(.*)"..DivideChar.."(.*)")
if cat then
table.insert(tTrivQuestions,{cat,ques,ans,slinecount})
end
end
end
handle:close()
end
getlines = {}
end
end
---------------------------------------------------------------------------------------
-- GET TOTAL QUESTIONS
---------------------------------------------------------------------------------------
function GetTotalQues()
local handle = io.open(TrivFolder.."/"..QFile,"r")
local count = 0
if handle then
for line in io.lines() do
count = count + 1
end
io.close(handle)
end
return(count)
end
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
function WriteTable(table,tablename,file)
local handle = io.open(TrivFolder.."/"..file,"w")
Serialize(table,tablename,handle)
io.close(handle)
end
--------------------------------------------
function Serialize(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
write(hFile,sTab..sTableName.." = {\n");
for key,value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
write(hFile,sTab.."\t"..sKey.." = "..sValue);
end
write(hFile,",\n");
end
write(hFile,sTab.."}");
end
---------------------------------------------------------------------------------------
-- TRIVFUNCS
---------------------------------------------------------------------------------------
TrivFuncs = {
[tostring(string.lower(cmd0))] = function(curUser)
local trivhtop = "-- Trivia Help --\r\n\r\n\tPrefixes: "..DisplTrivPrefix.."\r\n"
local sline = "\t------------------------"
local trivcmd = "\t"..cmd1.." - Shows the top "..Max3.." scorers.\r\n"..
"\t"..cmd4.." - Shows your score.\r\n"..
"\t"..cmd16.." - Shows the top "..Max9.." player stats.\r\n"..
"\t"..cmd10.." - Shows you the Trivia Players.\r\n"..
"\t"..cmd11.." - Lets you skipp the current question.\r\n"..
"\t"..cmd13.." - Gives you a hint."
local trivconfig = "\t"..cmd2.." - Start the Trivia.\r\n"..
"\t"..cmd3.." - Stop the Trivia.\r\n"..
"\t"..cmd5.." - Plays Trivia in Main Chat.\r\n"..
"\t"..cmd6.." - Plays Trivia in PM to the bot.\r\n"..
"\t"..cmd12.." on/off - Enables/Disables TriviaSkip.\r\n"..
"\t"..cmd14.." on/off - Enables/Disables TrivHint.\r\n"..
"\t"..cmd15.." - Switches between the 2 hint modes."
local trivcmdpm = "\t"..cmd7.." - Lets you login.\r\n"..
"\t"..cmd8.." - Logs you out."
local trivcmdscorere = "\t"..cmd9.." - Lets you reset the score."
local trivhelp = "\t"..cmd0.." - Shows you this help."
if curUser.bOperator then
return(trivhtop.."\r\n"..trivcmd.."\r\n"..sline.."\r\n"..trivcmdpm.."\r\n"..sline.."\r\n"..trivconfig.."\r\n"..sline.."\r\n"..trivcmdscorere.."\r\n"..sline.."\r\n"..trivhelp.."\r\n")
else
return(trivhtop.."\r\n"..trivcmd.."\r\n"..sline.."\r\n"..trivcmdpm.."\r\n"..sline.."\r\n"..trivhelp.."\r\n")
end
end,
[tostring(string.lower(cmd1))] = function()
TCopy = {}
for i,v in Scores do
table.insert(TCopy,{i,v})
end
table.sort(TCopy,function(a,b) return(a[2].Score>b[2].Score) end)
local msg = " -- Top "..Max3.." Trivia Scorers --\r\n\r\n"
for i = 1,Max3 do
if TCopy[i] then
msg = msg.."\t# "..i.." - "..TCopy[i][1]..", Points: "..TCopy[i][2].Score.."\r\n"
end
end
return msg
end,
[tostring(string.lower(cmd2))] = function(curUser)
if curUser.bOperator then
trivtimerset = { 0,0,trivtimerset[3],0 }
curTriv.GetQues = 1
StartTimer()
GetQuestions(Max1)
return("Trivia is started.")
else
return("You are not authorized to use this command.")
end
end,
[tostring(string.lower(cmd3))] = function(curUser)
if curUser.bOperator then
StopTimer()
curTriv.curAnswer = nil
WriteTable(Scores, "Scores", "Scores.txt")
return("Trivia is stopped.")
else
return("You are not authorized to use this command.")
end
end,
[tostring(string.lower(cmd4))] = function(curUser)
TCopy = {}
for i,v in Scores do
table.insert(TCopy,{i,v})
end
table.sort(TCopy,function(a,b) return(a[2].Score>b[2].Score) end)
for i = 1,table.getn(TCopy) do
if TCopy[i][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[i][2].Score).." Point(s)."..
"\r\n\t---->\t# "..i.." - "..TCopy[i][1]..", Points: "..TCopy[i][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[i][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[i][2].Score).." Point(s)."..
"\r\n\t--->\t# "..i.." - "..TCopy[i][1]..", Points: "..TCopy[i][2].Score.."."
elseif TCopy[(i+1)] then
msg = "\r\n\r\n\t--->\t# "..i.." - "..TCopy[i][1]..", Points: "..TCopy[i][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[i][2].Score).." Point(s)."
end
return("------ "..curUser.sName.."'s Player Stats. Total Players = "..table.getn(TCopy).." ------"..msg.."\r\n\r\n\t\t"..curUser.sName.."'s longest streak = "..TCopy[i][2].Streak..".\r\n")
end
end
return("Your current score is : 0 Point(s).")
end,
[tostring(string.lower(cmd5))] = function(curUser)
if curUser.bOperator then
TriviaConfig.TrivMainPM = 1
PMPlayers = nil
frmHub:UnregBot(trivbot)
os.remove(TrivFolder.."/PMPlayers.txt")
WriteTable(TriviaConfig, "TriviaConfig", "TriviaConfig.txt")
StartTimer()
return("Trivia is now played in MainChat.")
else
return("You are not authorized to use this command.")
end
end,
[tostring(string.lower(cmd6))] = function(curUser)
if curUser.bOperator then
TriviaConfig.TrivMainPM = 2
PMPlayers = {}
frmHub:RegBot(trivbot)
SendToAll(trivbotmyinfo)
WriteTable(TriviaConfig, "TriviaConfig", "TriviaConfig.txt")
return("Trivia is now played in PM.")
else
return("You are not authorized to use this command.")
end
end,
[tostring(string.lower(cmd7))] = function(curUser)
if TriviaConfig.TrivMainPM == 2 then
if not PMPlayers[curUser.sName] then
if doCheckPlayers() ~= "PLAY" then
StartTimer()
trivtimerset = { 0,0,trivtimerset[3],0 }
curTriv.GetQues = 1
end
PMPlayers[curUser.sName] = 1
SendDataMP("\""..curUser.sName.."\" has joined the trivia.")
else
return("You are already loged into Trivia.")
end
else
return("Trivia is played in Main Chat. You don't need to login.")
end
end,
[tostring(string.lower(cmd8))] = function(curUser)
if TriviaConfig.TrivMainPM == 2 then
if PMPlayers[curUser.sName] then
SendDataMP("\""..curUser.sName.."\" has parted the trivia..")
PMPlayers[curUser.sName] = nil
if doCheckPlayers() ~= "PLAY" then
StopTimer()
curTriv.curAnswer = nil
WriteTable(Scores, "Scores", "Scores.txt")
end
else
return("You are not loged into Trivia.")
end
else
return("Trivia is played in Main Chat. You don't need to logout.")
end
end,
[tostring(string.lower(cmd9))] = function(curUser)
if curUser.bOperator then
Scores = {}
WriteTable(Scores, "Scores", "Scores.txt")
return("The scores have been reseted.")
else
return("You are not authorized to use this command.")
end
end,
[tostring(string.lower(cmd10))] = function()
if TriviaConfig.TrivMainPM == 2 then
local players = ""
for i,_ in PMPlayers do
players = players.."\r\n\t- "..i
end
return("Currently Loged In:\r\n"..players.."\r\n")
else
return("Trivia is played in Main Chat. Everybody is a player.")
end
end,
[tostring(string.lower(cmd11))] = function(curUser)
if TriviaConfig.TrivSkip == 1 then
SendDataMP("\""..curUser.sName.."\" has skipped this question.")
trivtimerset = { 0,0,trivtimerset[3],0 }
curTriv.GetQues = 1
curTriv.curAnswer = nil
else
return("TriviaSkip is currently disabled.")
end
end,
[tostring(string.lower(cmd13))] = function(curUser)
if TriviaConfig.TrivHint == 1 then
if curTriv.GetQues == 0 then
SendDataMP("\""..curUser.sName.."\" needs a hint.")
trivtimerset[1] = 0
curTriv.curHint = RevealChars(curTriv.curAnswer,curTriv.curHint)
if curTriv.curAnswer ~= curTriv.curHint then
SendQuestion(curTriv.curCat,curTriv.curQues,curTriv.curHint,curTriv.Points,curTriv.curNum,curTriv.QuestionsTotal)
else
SendDataMP("The right answer was: "..curTriv.curHint)
curTriv.GetQues,curTriv.curAnswer = 1,nil
trivtimerset = { 0,0,trivtimerset[3],0 }
end
else
return("No Question given")
end
else
return("TriviaHint is currently disabled.")
end
end,
[tostring(string.lower(cmd15))] = function(curUser)
if curUser.bOperator then
if TriviaConfig.TrivShowHint == 1 then
TriviaConfig.TrivShowHint = 2
WriteTable(TriviaConfig, "TriviaConfig", "TriviaConfig.txt")
return("Trivia Hints will be displayed in Mode 2. Beginning next Question")
else
TriviaConfig.TrivShowHint = 1
WriteTable(TriviaConfig, "TriviaConfig", "TriviaConfig.txt")
return("Trivia Hints will be displayed in Mode 1. Beginning next Question")
end
else
return("You are not authorized to use this command.")
end
end,
[tostring(string.lower(cmd16))] = function(curUser)
TCopy = {}
for i,v in Scores do
table.insert(TCopy,{i,v})
end
table.sort(TCopy,function(a,b) return(a[2].Score>b[2].Score) end)
local msg = "----- Top "..Max9.." Player Stats -----\r\n\r\n\tTop "..Max9.." Scorer's.\r\n\r\n"
for i = 1,Max9 do
if TCopy[i] then
msg = msg.."\t# "..i.." - "..TCopy[i][1]..", Points: "..TCopy[i][2].Score.."\r\n"
end
end
table.sort(TCopy,function(a,b) return(a[2].Streak>b[2].Streak) end)
local msg = msg.."\r\n\tTop "..Max9.." Streaker's.\r\n\r\n"
for i = 1,Max9 do
if TCopy[i] then
msg = msg.."\t# "..i.." - "..TCopy[i][1]..", Streak: "..TCopy[i][2].Streak.."\r\n"
end
end
return(msg)
end,
}
-------------------------------------------------
-- TRIVCONFIGS
-------------------------------------------------
TrivConfs = {
[tostring(string.lower(cmd12))] = {
on = function(curUser)
if curUser.bOperator then
TriviaConfig.TrivSkip = 1
WriteTable(TriviaConfig, "TriviaConfig", "TriviaConfig.txt")
return("TriviaSkip is now enabled.")
end
end,
off = function(curUser)
if curUser.bOperator then
TriviaConfig.TrivSkip = 2
WriteTable(TriviaConfig, "TriviaConfig", "TriviaConfig.txt")
return("TriviaSkip is now disabled.")
end
end,
help = "Syntax: Prefix\""..cmd12.."\" on/off :: Prefixes: "..DisplTrivPrefix,
},
[tostring(string.lower(cmd14))] = {
on = function(curUser)
if curUser.bOperator then
TriviaConfig.TrivHint = 1
WriteTable(TriviaConfig, "TriviaConfig", "TriviaConfig.txt")
return("TriviaHint is now enabled.")
end
end,
off = function(curUser)
if curUser.bOperator then
TriviaConfig.TrivHint = 2
WriteTable(TriviaConfig, "TriviaConfig", "TriviaConfig.txt")
return("TriviaHint is now disabled.")
end
end,
help = "Syntax: Prefix\""..cmd14.."\" on/off :: Prefixes: "..DisplTrivPrefix,
},
}