Lava Titan
Developer
So I got this very old TFS 0.4 MOD that works perfectely but I'm trying to make it work with math.random instead of text questions and answers..
Example:
instead of
I made the tests in lua demo console and it works fine, I'm not sure what I missed so I ask for a extra pair of eyes to look at the script and tell me what am I doing wrong xd
Here's the full script:
Example:
Lua:
[1] = {question = "How much is "..number1.." + "..number2.."?", answer = ""..number1+number2..""}
instead of
Lua:
[1] = {question = "How much is 1 + 1?", answer = "2"}
I made the tests in lua demo console and it works fine, I'm not sure what I missed so I ask for a extra pair of eyes to look at the script and tell me what am I doing wrong xd
Here's the full script:
Lua:
<?xml version = "1.0" encoding = "UTF-8"?>
<mod name = "Pop quiz" version = "1.0" author = "Teckman" enabled = "yes">
<config name = "config"><![CDATA[
config = {
local number1 = math.random(1,10)
local number2 = math.random(1,10)
questions = {
[1] = {question = "How much is "..number1.." + "..number2.."?", answer = ""..number1+number2..""}, -- this doesnt work
[2] = {question = "What is the name of this game?", answer = "Tibia"}
}, -- this works
newItem = {2160, 1}, -- reward
storage = 400
}
]]></config>
<globalevent name="popquiz" interval="60000" event="script"><![CDATA[
domodlib("config")
function onThink(interval)
setGlobalStorageValue(cid, config.storage, config.questions[math.random(1, table.maxn(config.questions))].question)
doBroadcastMessage("[QUIZ]: " .. getGlobalStorageValue(config.storage) .. " - to answer the question type '/quiz ANSWER'.", MESSAGE_EVENT_ADVANCE)
return true
end
]]></globalevent>
<talkaction words = "/quiz" event = "script"><![CDATA[
domodlib("config")
function onSay(cid, words, param)
if(param) then
if(getGlobalStorageValue(config.storage)) then
for _, v in pairs(config.questions) do
if(v.question == getGlobalStorageValue(config.storage)) then
if(string.lower(param) == v.answer) then
doBroadcastMessage("[QUIZ]: " .. getPlayerName(cid) .. " has answered the question: " .. v.question .. ", with answer: " .. v.answer .. ". Congratulations to the winner!", MESSAGE_EVENT_ADVANCE)
doPlayerAddItem(cid, config.newItem[1], config.newItem[2])
setGlobalStorageValue(config.storage, nil)
doSendMagicEffect(getPlayerPosition(cid), 40)
return true
end
end
end
else
doPlayerSendCancel(cid, "The 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
doPlayerSendCancel(cid, "This answer is wrong.")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
return true
end
]]></talkaction>
</mod>