help converting script plz ........
---------------------------------------------------------------------------------------
-- 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 math.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 math.minutes between each score and player saving
--------------------------------------------
Max6 = 1 -- Smath.tands for how many chars are rvealed per hint.
Max8 = 6 -- Smath.tands 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) then
local num = Scores
Scores = {}
Scores.Score = num
Scores.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).." math.min.")
end
table.table.foreachi(trivtimerset, function(i,_) trivtimerset = trivtimerset + 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]
table.os.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
table.os.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 = openfile(TrivFolder.."/"..QFile,"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 = string.find(line,"(.*)"..DivideChar.."(.*)"..DivideChar.."(.*)")
if cat then
table.insert(curTrivQuestions,{cat,ques,ans,slinecount})
end
end
line = read(handle)
end
closefile(handle)
tTrivQuestions = {}
for _ = 1,table.getn(curTrivQuestions) do
local num = math.random(table.getn(curTrivQuestions))
table.insert(tTrivQuestions,curTrivQuestions[num])
table.os.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 = openfile(TrivFolder.."/"..QFile,"r")
if handle then
tTrivQuestions = {}
local slinecount = 0
local line = read(handle)
while line 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
line = read(handle)
end
closefile(handle)
end
getlines = {}
end
end
---------------------------------------------------------------------------------------
-- GET TOTAL QUESTIONS
---------------------------------------------------------------------------------------
function GetTotalQues()
local handle = io.open(TrivFolder.."/"..QFile,"r")
local count = 0
if handle then
local line = io.input(handle)
while line do
count = count + 1
line = io.input(handle)
end
closefile(handle)
end
return(count)
end
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
function WriteTable(table,tablename,file)
local handle = io.open(TrivFolder.."/"..file,"w")
Serialize(table,tablename,handle)
closefile(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 math.modes."
local trivcmdpm = "\t"..cmd7.." - Lets you math.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 then
msg = msg.."\t# "..i.." - "..TCopy[1]..", Points: "..TCopy[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[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
return("------ "..curUser.sName.."'s Player Stats. Total Players = "..table.getn(TCopy).." ------"..msg.."\r\n\r\n\t\t"..curUser.sName.."'s longest streak = "..TCopy[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 math.loged into Trivia.")
end
else
return("Trivia is played in Main Chat. You don't need to math.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 math.loged into Trivia.")
end
else
return("Trivia is played in Main Chat. You don't need to math.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 then
msg = msg.."\t# "..i.." - "..TCopy[1]..", Points: "..TCopy[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 then
msg = msg.."\t# "..i.." - "..TCopy[1]..", Streak: "..TCopy[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,
},
}
hi m8
if you are wanting help on a script of this size i suggest you Edit your posts adding the Code tags ...
[ code] <------ Without the Space
your code here
[ /code] <------ Without the Space
??????Hawk??????
Hi m8 not to sure what u mean by code tags .. but i think the prob is in this part .............
---------------------------------------------------------------------------------------
-- GET TOTAL QUESTIONS
---------------------------------------------------------------------------------------
function GetTotalQues()
local handle = io.open(TrivFolder.."/"..QFile,"r")
local count = 0
if handle then
local line = io.input(handle)
while line do
count = count + 1
line = io.input(handle)
end
closefile(handle)
end
return(count)
end
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
function WriteTable(table,tablename,file)
local handle = io.open(TrivFolder.."/"..file,"w")
Serialize(table,tablename,handle)
closefile(handle)
end
-----------------------------------------------------------------------------------------------------------------------------------
if thas is the only problem you had this should work:
---------------------------------------------------------------------------------------
-- GET TOTAL QUESTIONS
---------------------------------------------------------------------------------------
function GetTotalQues()
local handle = io.open(TrivFolder.."/"..QFile,"r")
local count = 0
if handle then
for line in handle:lines() do
count = count + 1
end
handle:close()
end
return count
end
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
function WriteTable(table,tablename,file)
local handle = io.open(TrivFolder.."/"..file,"w")
Serialize(table,tablename,handle)
handle:close()
end
Thx NL ...... i got probs here know can u help again plz .......
function GetQuestions(howmany)
if (HowToGetQuestions == 1) then
local getlines = {}
for _ = 1,howmany do
getlines[random(curTriv.QuestionsTotal)] = 1
end
local handle = openfile(TrivFolder.."/"..QFile,"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 = strfind(line,"(.*)"..DivideChar.."(.*)"..DivideChar.."(.*)")
if cat then
tinsert(curTrivQuestions,{cat,ques,ans,slinecount})
end
end
line = read(handle)
end
closefile(handle)
tTrivQuestions = {}
for _ = 1,getn(curTrivQuestions) do
local num = random(getn(curTrivQuestions))
tinsert(tTrivQuestions,curTrivQuestions[num])
tremove(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 = openfile(TrivFolder.."/"..QFile,"r")
if handle then
tTrivQuestions = {}
local slinecount = 0
local line = read(handle)
while line do
slinecount = slinecount + 1
if getlines[slinecount] then
local _,_,cat,ques,ans = strfind(line,"(.*)"..DivideChar.."(.*)"..DivideChar.."(.*)")
if cat then
tinsert(tTrivQuestions,{cat,ques,ans,slinecount})
end
end
line = read(handle)
end
closefile(handle)
end
getlines = {}
end
end
I think its all the file handles , i dont seem to be able to get them right :(
i'm getting this error with this part of script ........
trivia.lua5.lua:1176: `end' expected (to close `function' at line 615) near `'
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 handle:lines() do
while line 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
line = read(handle)
end
handle:close()
tTrivQuestions = {}
for _ = 1,table.getn(curTrivQuestions) do
local num = math.random(table.getn(curTrivQuestions))
table.insert(tTrivQuestions,curTrivQuestions[num])
table.os.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 = openfile(TrivFolder.."/"..QFile,"r")
if handle then
tTrivQuestions = {}
local slinecount = 0
local line = read(handle)
while line 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
line = read(handle)
end
handle:close()
end
getlines = {}
end
end
QuoteOriginally posted by ??????Hawk??????
hi m8
if you are wanting help on a script of this size i suggest you Edit your posts adding the Code tags ...
[ code] <------ Without the Space
your code here
[ /code] <------ Without the Space
??????Hawk??????
Listen HAWK.. you understand?
QuoteOriginally posted by (uk)jay
Hi m8 not to sure what u mean by code tags .. but i think the prob is in this part .............
He means like this
[ code ]
your script
[ /code ]
without the spaces befor and after "code" and "/code" then it ends up like this
your script
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 handle:lines() do
while line 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
line = read(handle)
end
handle:close()
tTrivQuestions = {}
for _ = 1,table.getn(curTrivQuestions) do
local num = math.random(table.getn(curTrivQuestions))
table.insert(tTrivQuestions,curTrivQuestions[num])
table.os.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 = openfile(TrivFolder.."/"..QFile,"r")
if handle then
tTrivQuestions = {}
local slinecount = 0
local line = read(handle)
while line 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
line = read(handle)
end
handle:close()
end
getlines = {}
end
end
hehe ok i get it now ....... still need help with script
Post all script please :)
---------------------------------------------------------------------------------------
-- 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 math.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 math.minutes between each score and player saving
--------------------------------------------
Max6 = 1 -- Smath.tands for how many chars are rvealed per hint.
Max8 = 6 -- Smath.tands 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).." math.min.")
end
table.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]
table.os.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
table.os.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 = openfile(TrivFolder.."/"..QFile,"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 = string.find(line,"(.*)"..DivideChar.."(.*)"..DivideChar.."(.*)")
if cat then
table.insert(curTrivQuestions,{cat,ques,ans,slinecount})
end
end
line = read(handle)
end
closefile(handle)
tTrivQuestions = {}
for _ = 1,table.getn(curTrivQuestions) do
local num = math.random(table.getn(curTrivQuestions))
table.insert(tTrivQuestions,curTrivQuestions[num])
table.os.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 = openfile(TrivFolder.."/"..QFile,"r")
if handle then
tTrivQuestions = {}
local slinecount = 0
local line = read(handle)
while line 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
line = read(handle)
end
closefile(handle)
end
getlines = {}
end
end
---------------------------------------------------------------------------------------
-- GET TOTAL QUESTIONS
---------------------------------------------------------------------------------------
function GetTotalQues()
local handle = io.open(TrivFolder.."/"..QFile,"r")
local count = 0
if handle then
local line = io.input(handle)
while line do
count = count + 1
line = io.input(handle)
end
closefile(handle)
end
return(count)
end
---------------------------------------------------------------------------------------
-- Write Tables
---------------------------------------------------------------------------------------
function WriteTable(table,tablename,file)
local handle = io.open(TrivFolder.."/"..file,"w")
Serialize(table,tablename,handle)
closefile(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 math.modes."
local trivcmdpm = "\t"..cmd7.." - Lets you math.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.")
Sorry but.. you want it in LUA 4 or LUA 5?
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 math.loged into Trivia.")
end
else
return("Trivia is played in Main Chat. You don't need to math.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 math.loged into Trivia.")
end
else
return("Trivia is played in Main Chat. You don't need to math.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,
},
}
full script as requested
lua 5 plz thx very much :))
This Work In LUA 5:
-- Converted the script into LUA 5 by 6Marilyn6Manson6
---------------------------------------------------------------------------------------
-- GLOBALS
---------------------------------------------------------------------------------------
RevealChar = string.char(149) -- The revealchar: 149,164,1
QFile = "TriviaEx.Questions-1.txt" -- The name of the Questionfile Questiondefaultstring.string.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 math.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 math.minutes between each score and player saving
--------------------------------------------
Max6 = 1 -- Smath.tands for how many chars are rvealed per hint.
Max8 = 6 -- Smath.tands 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.dat")
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.table.foreach(PMPlayers,function(a,_)
if not GetItemByName(a) then
PMPlayers[a] = nil
end
end)
else
frmHub:UnregBot(trivbot)
end
curTriv.QuestionsTotal = GetTotalQues()
os.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.dat")
if PMPlayers then
WriteTable(PMPlayers, "PMPlayers", "PMPlayers.txt")
end
end
---------------------------------------------------------------------------------------
function OnTimer()
if table.table.getn(tTrivQuestions) == 0 and Trivbreak == 1 and curTriv.GetQues == 1 then
GetQues = 3
trivtimerset[4] = 0
SendDataMP("Short Trivia break for "..(Max7/6).." math.min.")
end
table.table.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.dat")
end
if trivtimerset[2] >= Max4 and curTriv.GetQues == 1 then
trivtimerset[2] = 0
if table.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]
table.os.os.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.math.floor(curTriv.Points/Max8)) >= 0.5) then
curTriv.RevealHowMany = math.math.floor(curTriv.Points/Max8) + 1
elseif (math.math.floor(curTriv.Points/Max8) == 0) then
curTriv.RevealHowMany = 1
else
curTriv.RevealHowMany = math.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.dat")
end
end
end
OpDisconnected = UserDisconnected
function doCheckPlayers()
return(table.table.foreach(PMPlayers,function(a,_)
if a then
return("PLAY")
end
end))
end
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
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
bye bye
Thx m8 ...... i got this error when i loaded it
scripts\trivia.lua5.lua:122: attempt to index field `string' (a nil value)
QuoteOriginally posted by (uk)jay
Thx m8 ...... i got this error when i loaded it
scripts\trivia.lua5.lua:122: attempt to index field `string' (a nil value)
I have fixed it and i have update script but for work made file Scores.dat in dir with script :)
i think it's this part
DisplTrivPrefix = string.string.gsub(TrivPrefix,"%%"," ")
QuoteOriginally posted by (uk)jay
i think it's this part
DisplTrivPrefix = string.string.gsub(TrivPrefix,"%%"," ")
I have update it but change this line
QuoteDisplTrivPrefix = string.string.gsub(TrivPrefix,"%%"," ")
to
QuoteDisplTrivPrefix = string.gsub(TrivPrefix,"%%"," ")
bye bye
Thx m8 working great :))
hmmmmm getting this now......
trivia.lua5.lua:67: bad argument #1 to `gsub' (string expected, got nil)
QuoteOriginally posted by (uk)jay
hmmmmm getting this now......
trivia.lua5.lua:67: bad argument #1 to `gsub' (string expected, got nil)
Sorry I have see now your post. Change in line 135:
QuotecurTriv.curHint = string.string.gsub(curTriv.curAnswer,"(%S)",function (w) curTriv.Points = curTriv.Points + 1 return(RevealChar) end)
to
QuotecurTriv.curHint = string.gsub(curTriv.curAnswer,"(%S)",function (w) curTriv.Points = curTriv.Points + 1 return(RevealChar) end)
bye bye
still geting the same error
attempt to call global `GetTotalQues' (a nil value)
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.table.foreach(PMPlayers,function(a,_)
if not GetItemByName(a) then
PMPlayers[a] = nil
end
end)
else
frmHub:UnregBot(trivbot)
end
curTriv.QuestionsTotal = GetTotalQues()
os.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
think it's this line
curTriv.QuestionsTotal = GetTotalQues()
-- Converted the script into LUA 5 by 6Marilyn6Manson6
---------------------------------------------------------------------------------------
-- GLOBALS
---------------------------------------------------------------------------------------
RevealChar = string.char(149) -- The revealchar: 149,164,1
QFile = "TriviaEx.Questions-1.txt" -- The name of the Questionfile Questiondefaultstring.string.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 math.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 math.minutes between each score and player saving
--------------------------------------------
Max6 = 1 -- Smath.tands for how many chars are rvealed per hint.
Max8 = 6 -- Smath.tands 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.dat")
trivtimerset = { 0,0,0,0 }
UnRevealed = {}
curTriv = {
GetQues = 0,
Points = 0,
curNum = 0,
curCat = "",
curQues = "",
curAnswer = "",
curHint = "",
QuestionsTotal = 0,
GetTotalQues = 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.table.foreach(PMPlayers,function(a,_)
if not GetItemByName(a) then
PMPlayers[a] = nil
end
end)
else
frmHub:UnregBot(trivbot)
end
curTriv.QuestionsTotal = GetTotalQues()
os.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.dat")
if PMPlayers then
WriteTable(PMPlayers, "PMPlayers", "PMPlayers.txt")
end
end
---------------------------------------------------------------------------------------
function OnTimer()
if table.table.getn(tTrivQuestions) == 0 and Trivbreak == 1 and curTriv.GetQues == 1 then
GetQues = 3
trivtimerset[4] = 0
SendDataMP("Short Trivia break for "..(Max7/6).." math.min.")
end
table.table.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.dat")
end
if trivtimerset[2] >= Max4 and curTriv.GetQues == 1 then
trivtimerset[2] = 0
if table.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]
table.os.os.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.math.floor(curTriv.Points/Max8)) >= 0.5) then
curTriv.RevealHowMany = math.math.floor(curTriv.Points/Max8) + 1
elseif (math.math.floor(curTriv.Points/Max8) == 0) then
curTriv.RevealHowMany = 1
else
curTriv.RevealHowMany = math.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.dat")
end
end
end
OpDisconnected = UserDisconnected
function doCheckPlayers()
return(table.table.foreach(PMPlayers,function(a,_)
if a then
return("PLAY")
end
end))
end
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
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
Test it please, bye bye
Hi m8 error again ......
68: bad argument #1 to `gsub' (string expected, got nil)
Line 68 is ok i don't understand error.... because this line is LUA 4:
QuoteDisplTrivPrefix = gsub(TrivPrefix,"%%"," ")
and this in LUA 5:
QuoteDisplTrivPrefix = string.gsub(TrivPrefix,"%%"," ")
... but have error..... is it impossible
no idea m8 ..... is there a hub i can get u in and ill give u all my triv folder (questions .ect...)
TrivPrefix is nil. Post your file reading routine.
?(
The script u r trying to convert to lua 5 is the
Trivia Ex by chilla
Im getting simular probs ?(