• 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!

TFS 1.X+ [TFS1.4.2]HELP! Can anyone rate this script? (Quest Script .lua)

Zarosiano

New Member
Joined
Dec 9, 2022
Messages
21
Reaction score
1
This is a quest script from an NPC, everything works normally, however, when killing the mob, the message does not appear in the chat, and I also checked that it is not counting. I use the same script (changed storages) in other quests, and it works.
Lua:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local storage = 60001

local monsters = {
   ["Werewolf"] = {storage = 5050, mstorage = 19010, amount = 50, exp = 12000, items = {{id = 24790, count = 5}, {id = 24740, count = 1}}},
   ["Giant Spider"] = {storage = 5051, mstorage = 19011, amount = 100, exp = 150000, items = {{id = 26398, count = 1}, {id = 2160, count = 30}}},
   ["Ancient Scarab"] = {storage = 5052, mstorage = 19012, amount = 100, exp = 14000, items = {{id = 8882, count = 1}, {id = 7865, count = 1}}},
   ["Bog Raider"] = {storage = 5053, mstorage = 19013, amount = 100, exp = 13000, items = {{id = 8909, count = 1}, {id = 18411, count = 1}}}
}


local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " e "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end

local function Cptl(f, r)
     return f:upper()..r:lower()
end

function creatureSayCallback(cid, type, msg)

     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     if not npcHandler:isFocused(cid) then
         if msg == "oi" or msg == "hi" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
                 if n > 1 then
                     npcHandler:say("Eu sou o prefeito de Kalista, e preciso de pessoas que saibam lutar! Veja as tarefas que tenho a oferecer"..text.." ou use /listar", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("A prefeitura de Kalista agradece os seu trabalho! mas ainda falta "..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("Por enquanto, tudo certo!", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Voce eliminou "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) == -1 then
             npcHandler:say("Boa sorte! Volte quando tiver terminado "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("Voce ja fez essa "..cmsg.." tarefa.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "sim") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Bom trabalho! Aqui esta sua recompensa, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, 2)
             player:setStorageValue(storage, -1)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("Voce nao matou todos eles, voce ainda precisa matar "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "tarefa") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Otimo! Ainda temos mais algumas criaturas. "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("Voce ja me ajudou bastante.", cid)
         end
     elseif msgcontains(msg, "nao") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok, tudo bem", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "parar") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Tudo bem"..text..".", cid)
         else
             npcHandler:say("Voce ainda nao iniciou nenhuma nova tarefa, se quiser iniciar uma, pode escolher"..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "listar") then
         local text = "Tarefas\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Recompensa:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experiencia \n\n"
             else
                 text = text .. k .." [FEITO]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Aqui esta.", cid)
     elseif msgcontains(msg, "Adeus") then
         npcHandler:say("Tchau.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("O que ²", cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Back
Top