READ THE RULES
0 Members and 1 Guest are viewing this topic.
--Trivia Ex by chill--Ex = Expert and not experimental, although its still the other way around.------------------------------------------------------------------------------------------------------------------------------------------------------------------------------trivbot = "RasTriv"--149--164--1----------------------------------------------------------------------------------------- GLOBALS---------------------------------------------------------------------------------------RevealChar = strchar(149)ReggaeTrivQues = {}QFile = "fullques.txt"Scores = {}seeks = {}Max1 = 10GetQues = 1trivtimerset = { 0,0,0 }curTriv = 0curCat = ""curQues = ""curAnswer = ""TrivFolder = "txt"TrivPrefix = "+"cmd1 = "score"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function Main() dofile(TrivFolder.."/seeks.txt") QuestionsTotal = getn(seeks) dofile(TrivFolder.."/Scores.txt") SetTimer(25*1000) StartTimer()end---------------------------------------------------------------------------------------function OnTimer() foreachi(trivtimerset, function(i,_) trivtimerset[i] = trivtimerset[i] + 1 end) if trivtimerset[2] >= 3 then if GetQues == 1 then WriteScore(Scores, "Scores", "Scores.txt") if getn(ReggaeTrivQues) == 0 then GetQuestions(Max1) end curTriv = ReggaeTrivQues[1][4] curCat = ReggaeTrivQues[1][1] curQues = ReggaeTrivQues[1][2] curAnswer = ReggaeTrivQues[1][3] tremove(ReggaeTrivQues,1) points = 0 curHint = gsub(curAnswer,"(%S)",function (w) points = points + 1 return(RevealChar) end) SendQuestion(curCat,curQues,curHint) trivtimerset[1] = 1 GetQues = 0 end if trivtimerset[1] > 1 then curHint = RevealOneChar(curAnswer,curHint) if curAnswer ~= curHint then SendQuestion(curCat,curQues,curHint) else SendToAll(trivbot,"Okey smokeys it was: "..curHint) GetQues = 1 trivtimerset = { 0,0,0 } end end endend---------------------------------------------------------------------------------------function DataArrival(curUser,data) if (strsub(data,1,1) == "<") then local _,_,sdata = strfind( data, "%b<>%s(.*)%|$") if curAnswer and strlower(sdata) == strlower(curAnswer) then SendToAll(trivbot,"Correct "..curUser.sName.." the answer was \""..curAnswer.."\", You get "..points.." Points.") Scores[strlower(curUser.sName)] = Scores[strlower(curUser.sName)] or 0 Scores[strlower(curUser.sName)] = Scores[strlower(curUser.sName)] + points SendToAll(trivbot,"That gives you a total score of "..Scores[strlower(curUser.sName)].." Points.") trivtimerset = { 0,0,0 } GetQues = 1 elseif TrivFuncs[strlower(sdata)] then curUser:SendData(trivbot,TrivFuncs[strlower(sdata)]()) end endend----------------------------------------------------------------------------------------- Send a question---------------------------------------------------------------------------------------function SendQuestion(curCat,curQues,curHint) SendToAll(trivbot,"QUESTION - Nr. "..curTriv.." from "..QuestionsTotal.." Questions.\r\n".. "\t----------------------------------------------------------------------\r\n".. "\t- Category: "..curCat.." - Points: "..points.."\r\n".. "\tQUESTION: "..curQues.."\r\n".. "\tHINT: "..curHint.."\r\n".. "\t----------------------------------------------------------------------")end----------------------------------------------------------------------------------------- Reveal a char---------------------------------------------------------------------------------------function RevealOneChar(answer,toreveal) local Revealed,revealchar,ctoreveal = {},0,toreveal for i = 1,strlen(toreveal) do if strsub(toreveal,i,i) == RevealChar then tinsert(Revealed,i) end end if getn(Revealed) == 0 then SendToAll(answer.." "..toreveal) end revealchar,toreveal = Revealed[random(getn(Revealed))],"" for i = 1,strlen(answer) do if i == revealchar then toreveal = toreveal..strsub(answer,i,i) else toreveal = toreveal..strsub(ctoreveal,i,i) end end points = points - 1 return(toreveal)end----------------------------------------------------------------------------------------- Get a bunch of questions---------------------------------------------------------------------------------------function GetQuestions(howmany) local handle = openfile(TrivFolder.."/"..QFile,"r") if handle then for i = 1,howmany do local num = random(getn(seeks)) seek(handle,"set",seeks[num]) local line = read(handle) local _,_,cat,ques,ans = strfind(line,"(.*)%$%$(.*)%$%$(.*)") if cat then tinsert(ReggaeTrivQues,{cat,ques,ans,num}) end end closefile(handle) endend----------------------------------------------------------------------------------------- Write Score---------------------------------------------------------------------------------------function WriteScore(table, tablename, file) local handle = openfile(TrivFolder.."/"..file, "w") write(handle,tablename.." = {\r\n") for i,v in table do write(handle,"\t["..format('%q',i).."] = "..v..",\r\n") end write(handle,"}") closefile(handle)end----------------------------------------------------------------------------------------- TRIVFUNCS---------------------------------------------------------------------------------------TrivFuncs = { [tostring(TrivPrefix..strlower(cmd1))] = function() TCopy = {} for i,v in Scores do tinsert(TCopy,{i,v}) end sort(TCopy,function(a,b) return(a[2]>b[2]) end) local msg = " -- Trivia Scores --\r\n\r\n" for i = 1,getn(TCopy) do msg = msg.."\t# "..i.." - "..TCopy[i][1].." Points: "..TCopy[i][2].."\r\n" end return msg end,}
Originally posted by c h i l l a lets see how long this one holds :)my first trivia bothttp://mitglied.lycos.de/shashamane/
Originally posted by c h i l l a -- 28.1.04 : V0.6411. Hopefully fixed revealing of chars.2. Added User Stats ). Like longest Streak and so on.3. Also changed the trivmyscore, you'll see.trivia ex 0.641