All pastes #814378 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-12-13 06:52 UTC
rendered paste body
include('TBQuestions.lua')
local TB = {}
TB.QTimeLimit = 25
function TB.Init(ply, txt, toall)
	if string.lower(txt) == "/tb start" then
		if !ply:IsAdmin() then return end
		TB.QuestCount = 1
		TB.CurQuest = ""
		TB.CurAns = ""
		TB.PrevQuests = {}
		for k,v in pairs(player.GetAll()) do
			v:ChatPrint("[TriviaBot]: Trivia Bot initialized! First question coming up in 10 seconds!")
			v:ChatPrint("[TriviaBot]: Get ready!")
		end	
		timer.Create("TriviaTimer", 10, 1, TB.Generate)
	end
end 
hook.Add("PlayerSay", "StartTriviaBot", TB.Init)

function TB.Generate()
	local rand = math.random(1, #TB_QUESTIONS)
	if table.HasValue(TB.PrevQuests, rand) then
		rand = math.random(1, #TB_QUESTIONS)
	end
	TB.CurQuest = TB_QUESTIONS[rand]
	TB.CurAns = TB_ANSWER1[rand]
	for k,v in pairs(player.GetAll()) do
		v:ChatPrint("[TriviaBot]: Question " .. TB.QuestCount)
		v:ChatPrint("[TriviaBot]: " .. TB.CurQuest)
	end
	timer.Create("TBQuestionTimer", TB.QTimeLimit, 1, TB.NextQuestion)
end

function TB.NextQuestion()
	TB.QuestCount = TB.QuestCount + 1
	for k,v in pairs(player.GetAll()) do
		v:ChatPrint("[TriviaBot]: No correct answer was given.")
		v:ChatPrint("[TriviaBot]: The correct answer is: " .. TB.CurAns)
	end
	timer.Simple(5, function() 
						for k,v in pairs(player.GetAll()) do
							v:ChatPrint("[TriviaBot]: Next question coming up in " .. TB.QTimeLimit .. " seconds.")
						end
						timer.Create("TBQuestionTimer", TB.QTimeLimit, 1, TB.Generate)
					end
				)
end