• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

MoveEvent math quiz a simple task for any server

Slave Ots

LUA Newbie™
Joined
Jan 19, 2012
Messages
114
Reaction score
32
Location
/goto Slave Ots
hello Otlanders
today i present for YOU a simple task or a quiz..
it basicly depends on Teckman's http://otland.net/f81/teckmans-pop-quiz-140036/
i just made a little modification :p and its not bad
{TESTED AND WORKED IN TFS 0.3.7 SVN. REPORT HERE IF YOU FOUND BUGS}

so this will send each [config] time a message with a math equation
the first player solve it wons.. but if not one solve it on[config] time the quiz will be ended with no winner until the next question... so here we go
add in /mods;

PHP:
<?xml version = "1.0" encoding = "UTF-8"?>
	<mod name = "Pop quiz" version = "1.0" author = "Teckman" MODIFIED = "Slave Ots"  enabled = "yes">
		<config name = "config"><![CDATA[
		--[[
		keep the numbers of questions in this para ' and '  so that tfs didn't calculate it
		]]--
			config = {
				questions = {
					[1] = {question = "'2' * '2' + '2' / '2' + '5'", answer = '10'},
					[2] = {question = "'8' / '4' + '8' - '5'", answer = '5'},
					[3] = {question = "'60' / '30' + '28'", answer = '30'},
					[4] = {question = "'24' / '6' - '4' + '12'", answer = '12'},
					[5] = {question = "'6' * '6' + '4'", answer = '40'},		
					[5] = {question = "'50' / '10' + '20' - '25'", answer = '25'},
					[6] = {question = "'2' * '2' + '4' * '4'", answer = '20'},		
					[7] = {question = "'9' * '9' + '19'", answer = '100'},					
					[8] = {question = "'{8 * 8}' + '6' - '60'", answer = '10'},				
					[9] = {question = "'5' * '5' + '15'", answer = '40'},				
					[10] = {question = "'12' * '12' - '44'", answer = '100'},				
					[11] = {question = "'4' + '2' + '4' + '5' - '10' + '3'", answer = '8'},				
					[12] = {question = "'10' + '15' + '25' + '50", answer = '100'},					
					[13] = {question = "'10' + '20' + '30' + '40' + '50' + '100'", answer = '250'},					
					[14] = {question = "'8' + '2' - '5' + '6' + '9'", answer = '20'},					
					[15] = {question = "'{50 + 40 - 9}' / '9'", answer = '9'}
				},
				prize = 10 * 10000, -- 10 * crystal coins
				storage = 200, -- empty storage
				time = 30, -- time to end the question if not answer
				answered = 500 -- empty storage to check if question is answered or not
			}
		]]></config>
		<globalevent name="popquiz" interval="35000" event="script"><![CDATA[
			domodlib("config")
			function onThink(interval)
		for _, v in pairs(config.questions) do
		if not(v.question == getGlobalStorageValue(config.storage)) then
	setGlobalStorageValue(config.answered, 0)
	local random_question = config.questions[math.random(1, table.maxn(config.questions))].question
	local answer = config.questions[math.random(1, table.maxn(config.questions))].answer
	setGlobalStorageValue(cid, config.storage, random_question)
 doBroadcastMessage("[MATH QUIZ]: the question is "..random_question.." = ???!\n-- to answer the question type '/quiz ANSWER'.\nif no one send a correct answer in " .. config.time .. " seconds. the quiz will ended. ", MESSAGE_STATUS_CONSOLE_ORANGE)
addEvent(function()
	if getGlobalStorageValue(config.answered) == 0 then
		setGlobalStorageValue(config.answered, 1)
 doBroadcastMessage("[MATH QUIZ]: the quiz have been ended. no one answered a correct answe.", MESSAGE_STATUS_CONSOLE_ORANGE)
	return true
	end
	return true
	end, config.time*1000) 
				return true
			end
			end
			return true
			end
		]]></globalevent>
		<talkaction words = "/quiz" event = "script"><![CDATA[
			domodlib("config")
		function onSay(cid, words, param)
				if(param) then
					if(getGlobalStorageValue(config.storage)) or (not(getGlobalStorageValue(config.answered)) == 0) then
						for _, v in pairs(config.questions) do
							if(v.question == getGlobalStorageValue(config.storage)) then
								if(string.lower(param) == v.answer) then
									doBroadcastMessage("[MATH QUIZ]: " .. getPlayerName(cid) .. " has answered the MATH question. Congratulations to the winner!", MESSAGE_STATUS_CONSOLE_ORANGE)
									setGlobalStorageValue(config.answered, 1)
									doPlayerAddMoney(cid, type(config.prize) == "table" and math.random(config.prize[1], config.prize[2]) or config.prize)
									setGlobalStorageValue(config.storage, nil)
									doSendMagicEffect(getPlayerPosition(cid), 27)
									return true
									else
									doPlayerSendCancel(cid, "This answer is wrong.")
									doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
									return true
								end
			
							end
						end
					else
						doPlayerSendCancel(cid, "The MATH quiz has already ended.")
						doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
						return true
					end
				else
					doPlayerSendCancel(cid, "The answer must be stated in parameter.")
					doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
					return true
				end
				return TRUE
			end
		]]></talkaction>
	</mod>]

you also have to edit the interval if using TFS 0.3.6 from 35000 to 35
and dont remove ' ' from the questions or the TFS will calculate them in the broadcast message :D
hope to get REP++ if you like this script

Slave Ots​
 
Last edited:
Back
Top