LuckinhaSan 191 Postado Maio 10, 2013 Share Postado Maio 10, 2013 TESTADO E FUNCIONANDO EM TFS 0.3.7 SVN. Hoje eu apresento para você uma tarefa simples ou um quiz. Isso irá enviar cada vez [configuração] uma mensagem com uma equação matemática. O primeiro jogador que resolver vence... Mas se não resolver [configuração] o questionário será terminado sem vencedor até a próxima pergunta... Então aqui vamos nós! Vá em data/mods, crie uma arquivo xml e adicione isso - {TESTED AND WORKED IN TFS 0.3.7 SVN. REPORT HERE IF YOU FOUND BUGS}<?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>] Você também tem que editar o intervalo se estiver usando TFS 0.3.6 de 35000 para 35 e não remover ' ' das questões ou o TFS irá calculá-los na mensagem de difusão. Créditos - Slave Ots Link para o comentário https://xtibia.com/forum/topic/214058-math-quiz-uma-tarefa-simples-para-qualquer-servidor/ Compartilhar em outros sites More sharing options...
Eventide 23 Postado Maio 12, 2013 Share Postado Maio 12, 2013 Caraaaalho, ninguém nesse fórum sabe identar um script? Bom, não vou ficar repetindo isso a cada postagem, eu gostei do seu script, a ideia é interessante, só gostaria de complementar que a função table.maxn está obsoleta e já não vem mais em Lua 5.2, use #tabela ao invés dela e seu código será mais portável no caso de alguma distro resolver usar Lua 5.2(o que não seria ruim). Link para o comentário https://xtibia.com/forum/topic/214058-math-quiz-uma-tarefa-simples-para-qualquer-servidor/#findComment-1519592 Compartilhar em outros sites More sharing options...
Visitante Umtiro Postado Maio 12, 2013 Share Postado Maio 12, 2013 Não adianta dar sugestões ao rapaz, já que ele não foi o criador do script, Eventide. Link para o comentário https://xtibia.com/forum/topic/214058-math-quiz-uma-tarefa-simples-para-qualquer-servidor/#findComment-1519612 Compartilhar em outros sites More sharing options...
Eventide 23 Postado Maio 12, 2013 Share Postado Maio 12, 2013 Desculpe, foi erro meu... Não notei que o nome dos créditos era diferente do criador do tópico. Link para o comentário https://xtibia.com/forum/topic/214058-math-quiz-uma-tarefa-simples-para-qualquer-servidor/#findComment-1519618 Compartilhar em outros sites More sharing options...
Posts Recomendados