Postado Julho 29, 2018 6 anos Olá galera, estou utilizando um sistema de task system simples, aonde você pede a task para o NPC, mata os monstros e volta para pegar a recompensa. Peguei um script base do @Vodkart e alterei para as minhas necessidades. Como faz tempo que não faço scripts, estou enfrentando um problema onde no meu script está configurado o ganho de experiência, dinheiro e itens quando dizer "reward" para o NPC, ao dizer "reward" o jogador recebe apenas a experiência e o dinheiro, os itens não, e está gerando o seguinte erro no console: Outro problema que eu enfrento é que sempre que eu falar "reward" eu recebo a recompensa novamente, sendo que só pode receber apenas uma vez. Utilizo a base TFS 0.4 simpletask.xml <?xml version="1.0" encoding="UTF-8"?> <mod name="Simple Task" version="1.0" enabled="yes"> <config name="task_func"> <![CDATA[ monstertable = { ["troll"] = {monster = {"troll", "frost troll", "furious troll", "island troll", "swamp troll", "troll champion", "troll legionnaire"}, startStorage = 200201, storage = 91001, count = 20, experience = 150, money = 300, reward = {{2160, 2}, {2389, 10}}}, ["goblin"] = {monster = {"goblin", "goblin assassin", "goblin leader"}, startStorage = 200202, storage = 91002, count = 30, experience = 200, money = 150, reward = {{1294, 20}}}, } function isSummon(cid) return getCreatureMaster(cid); end function checkTask(cid) for k, v in pairs(monstertable) do if getPlayerStorageValue(cid, v.startStorage) >= 1 then return true end end return false end function HavePlayerPosition(cid, from, to) return isInRange(getPlayerPosition(cid), from, to) and true or false end function getItemsInContainerById(container, itemid) local items = {} if isContainer(container) and getContainerSize(container) > 0 then for slot = 0, (getContainerSize(container)-1) do local item = getContainerItem(container, slot) if isContainer(item.uid) then local itemsbag = getItemsInContainerById(item.uid, itemid) for i = 0, #itemsbag do table.insert(items, itemsbag[i]) end else if itemid == item.itemid then table.insert(items, item.uid) end end end end return items end function doPlayerAddItemStacking(cid, itemid, quant) local item = getItemsInContainerById(getPlayerSlotItem(cid, 3).uid, itemid) local piles = 0 if #item > 0 then for i, x in pairs(item) do if getThing(x).type < 100 then local it = getThing(x) doTransformItem(it.uid, itemid, it.type+quant) if it.type+quant > 100 then doPlayerAddItem(cid, itemid, it.type+quant-100) end else piles = piles+1 end end else return doPlayerAddItem(cid, itemid, quant) end if piles == #item then doPlayerAddItem(cid, itemid, quant) end end function getItemsFromList(items) local str = '' if table.maxn(items) > 0 then for i = 1, table.maxn(items) do str = str .. items[i][2] .. ' ' .. getItemNameById(items[i][1]) if i ~= table.maxn(items) then str = str .. ', ' end end end return str end function doAddItemsFromList(cid,items) if table.maxn(items) > 0 then for i = 1, table.maxn(items) do local count = items[i][2] while count > 0 do if isItemStackable(items[i][1]) then doPlayerAddItemStacking(cid, items[i][1], 1) else doPlayerAddItem(cid, items[i][1],1) end count = count - 1 end end end end ]]> </config> <event type="login" name="TaskLogin" event="script"> <![CDATA[ function onLogin(cid) registerCreatureEvent(cid, "KillTask") return true end ]]> </event> <event type="kill" name="KillTask" event="script"> <![CDATA[ domodlib('task_func') function onKill(cid, target, lastHit) if isMonster(target) and not isSummon(target) then local n = string.lower(getCreatureName(target)) for task, mob in pairs(monstertable) do if getPlayerStorageValue(cid, mob.startStorage) >= 1 then for i = 1, #mob.monster do if n == mob.monster[i] and getPlayerStorageValue(cid, mob.startStorage) >= 1 then local contagem = getPlayerStorageValue(cid, mob.storage) if (contagem == -1) then contagem = 1 end if not tonumber(contagem) then return true end if contagem > mob.count then return true end setPlayerStorageValue(cid, mob.storage, contagem+1) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, ""..(contagem == mob.count and "Congratulations! You finished the task of "..task.."." or "defeated. Total ["..contagem.."/"..mob.count.."] "..task..".").."") end end end end end return true end ]]> </event> </mod> simpletask.lua(NPC) domodlib('task_func') local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} 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 function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid local msg = string.lower(msg) if isInArray({"task", "tasks"}, msg) then selfSay("Tell me what the monster's name wants to do the task?", cid) talkState[talkUser] = 1 elseif talkState[talkUser] == 1 then if monstertable[msg] then if checkTask(cid) ~= true then local contagem = getPlayerStorageValue(cid, monstertable[msg].storage) if(contagem == -1) then contagem = 1 end if not tonumber(contagem) then selfSay("Sorry, but you're done with the "..msg..".", cid) talkState[talkUser] = 0 return true end setPlayerStorageValue(cid, monstertable[msg].startStorage, 1) selfSay("Congratulations, you are now participating in the "..msg.." task, "..monstertable[msg].count.." "..msg.." left for you to kill.", cid) talkState[talkUser] = 0 else selfSay("Sorry, but you are already part of a task.", cid) talkState[talkUser] = 0 end else selfSay("Enter the correct task name.", cid) talkState[talkUser] = 0 end elseif msgcontains(msg, "reward") then if checkTask(cid) then for k, v in pairs(monstertable) do if getPlayerStorageValue(cid, v.startStorage) >= 1 then local contagem = getPlayerStorageValue(cid, v.storage) if (contagem == -1) then contagem = 1 end if not tonumber(contagem) then selfSay("You can only receive items only once.", cid) return true end if (((contagem) -1) >= v.count) then local str = "" if v.experience ~= nil then doPlayerAddExp(cid, v.experience) str = str.."".. (str == "" and "" or ",").. " "..v.experience.." of experience" end if v.money ~= nil then doPlayerAddMoney(cid, v.money) str = str.."".. (str == "" and "" or ",").." "..v.money.." golds" end if v.reward ~= nil then doAddItemsFromList(cid, v.reward) str = str.."".. (str == "" and "" or ",").." "..getItemsFromList(v.reward).."" end selfSay("Thanks for your help, you received "..(str == "" and "none" or ""..str.."").." for completing the task of the "..k..".", cid) setPlayerStorageValue(cid, v.storage, "Finished") setPlayerStorageValue(cid, v.startStorage, 0) setPlayerStorageValue(cid, 521456, getPlayerStorageValue(cid, 521456) == -1 and 1 or getPlayerStorageValue(cid, 521456) + 1) else selfSay("Sorry, but you only killed "..((contagem)-1).." of "..v.count.." "..k..".", cid) end end end else selfSay("You are not participating in any task.", cid) end elseif msgcontains(msg, "leave") then if checkTask(cid) then talkState[talkUser] = 2 for k, v in pairs(monstertable) do if getPlayerStorageValue(cid, v.startStorage) >= 1 then storagesair = v.startStorage local contagem = getPlayerStorageValue(cid, v.storage) if (contagem == -1) then contagem = 1 end if not tonumber(contagem) then selfSay("You are not participating in any task.", cid) else selfSay("You are participating in a "..k.." and already has "..((contagem)-1).." dead "..k..", do you really want to leave?", cid) end end end else selfSay("You are not on any task.", cid) end elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then setPlayerStorageValue(cid, storagesair, 0) selfSay("You were successfully removed from the task!", cid) elseif msgcontains(msg, "no") then selfSay("Okay then.", cid) talkState[talkUser] = 0 npcHandler:releaseFocus(cid) end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Scripts atualizados, problema corrgido, task funcionando 100% euacho Editado Julho 30, 2018 6 anos por GiovaniRodrigo (veja o histórico de edições) Spoiler local config = { delrey = getPlayerCarValue(cid, DELREY), cigarro = getPlayerCancer(cid, DERBY), prostituta = getPlayerAIDS(cid, cracuda), tresOitao = getPlayerRevorvi(cid, 38) } if(delrey == "Ligado" and cigarro == "Aceso" and prostituta == "No Colo" and tresOitao == "Carregado") then doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Começou o fim de semana. #PAS") end
Postado Julho 30, 2018 6 anos Solução <?xml version="1.0" encoding="UTF-8"?> <mod name="Simple Task" version="1.0" enabled="yes"> <config name="task_func"> <![CDATA[ monstertable = { ["troll"] = {monster = {"troll", "frost troll", "furious troll", "island troll", "swamp troll", "troll champion", "troll legionnaire"}, startStorage = 200201, storage = 91001, count = 20, experience = 150, money = 300, reward = {{2160, 2}, {2389, 10}}}, ["goblin"] = {monster = {"goblin", "goblin assassin", "goblin leader"}, startStorage = 200202, storage = 91002, count = 30, experience = 200, money = 150, reward = {{1294, 20}}} } function isSummon(cid) return getCreatureMaster(cid); end function checkTask(cid) for k, v in pairs(monstertable) do if getPlayerStorageValue(cid, v.startStorage) >= 1 then return true end end return false end function getItemsFromList(items) local str = '' if table.maxn(items) > 0 then for i = 1, table.maxn(items) do str = str .. items[i][2] .. ' ' .. getItemNameById(items[i][1]) if i ~= table.maxn(items) then str = str .. ', ' end end end return str end function GiveRewardsTask(cid, items) local backpack = doPlayerAddItem(cid, 1999, 1) -- backpackID for _, i_i in ipairs(items) do local item, amount = i_i[1],i_i[2] if isItemStackable(item) or amount == 1 then doAddContainerItem(backpack, item, amount) else for i = 1, amount do doAddContainerItem(backpack, item, 1) end end end end function HavePlayerPosition(cid, from, to) return isInRange(getPlayerPosition(cid), from, to) and true or false end ]]> </config> <event type="login" name="TaskLogin" event="script"> <![CDATA[ function onLogin(cid) registerCreatureEvent(cid, "KillTask") return true end ]]> </event> <event type="kill" name="KillTask" event="script"> <![CDATA[ domodlib('task_func') function onKill(cid, target, lastHit) if isMonster(target) and not isSummon(target) then local n = string.lower(getCreatureName(target)) for task, mob in pairs(monstertable) do if getPlayerStorageValue(cid, mob.startStorage) >= 1 then for i = 1, #mob.monster do if n == mob.monster[i] and getPlayerStorageValue(cid, mob.startStorage) >= 1 then local contagem = getPlayerStorageValue(cid, mob.storage) if (contagem == -1) then contagem = 1 end if not tonumber(contagem) then return true end if contagem > mob.count then return true end setPlayerStorageValue(cid, mob.storage, contagem+1) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, ""..(contagem == mob.count and "Congratulations! You finished the task of "..task.."." or "defeated. Total ["..contagem.."/"..mob.count.."] "..task..".").."") end end end end end return true end ]]> </event> </mod> ------------------ domodlib('task_func') local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} 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 function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid local msg = string.lower(msg) if isInArray({"task", "tasks"}, msg) then selfSay("Tell me what the monster's name wants to do the task?", cid) talkState[talkUser] = 1 elseif talkState[talkUser] == 1 then if monstertable[msg] then if checkTask(cid) ~= true then local contagem = getPlayerStorageValue(cid, monstertable[msg].storage) if(contagem == -1) then contagem = 1 end if not tonumber(contagem) then selfSay("Sorry, but you're done with the "..msg..".", cid) talkState[talkUser] = 0 return true end setPlayerStorageValue(cid, monstertable[msg].startStorage, 1) selfSay("Congratulations, you are now participating in the "..msg.." task, "..monstertable[msg].count.." "..msg.." left for you to kill.", cid) talkState[talkUser] = 0 else selfSay("Sorry, but you are already part of a task.", cid) talkState[talkUser] = 0 end else selfSay("Enter the correct task name.", cid) talkState[talkUser] = 0 end elseif msgcontains(msg, "reward") then if checkTask(cid) then for k, v in pairs(monstertable) do if getPlayerStorageValue(cid, v.startStorage) >= 1 then local contagem = getPlayerStorageValue(cid, v.storage) if (contagem == -1) then contagem = 1 end if not tonumber(contagem) then selfSay("You can only receive items only once.", cid) return true end if (((contagem) -1) >= v.count) then local str = "" if v.experience ~= nil then doPlayerAddExp(cid, v.experience) str = str.."".. (str == "" and "" or ",").. " "..v.experience.." of experience" end if v.money ~= nil then doPlayerAddMoney(cid, v.money) str = str.."".. (str == "" and "" or ",").." "..v.money.." golds" end if v.reward ~= nil then GiveRewardsTask(cid, v.reward) str = str.."".. (str == "" and "" or ", ") ..""..getItemsFromList(v.reward) end selfSay("Thanks for your help, you received "..(str == "" and "none" or ""..str.."").." for completing the task of the "..k..".", cid) setPlayerStorageValue(cid, v.storage, "Finished") setPlayerStorageValue(cid, v.startStorage, 0) setPlayerStorageValue(cid, 521456, getPlayerStorageValue(cid, 521456) == -1 and 1 or getPlayerStorageValue(cid, 521456) + 1) else selfSay("Sorry, but you only killed "..((contagem)-1).." of "..v.count.." "..k..".", cid) end end end else selfSay("You are not participating in any task.", cid) end elseif msgcontains(msg, "leave") then if checkTask(cid) then talkState[talkUser] = 2 for k, v in pairs(monstertable) do if getPlayerStorageValue(cid, v.startStorage) >= 1 then storagesair = v.startStorage local contagem = getPlayerStorageValue(cid, v.storage) if (contagem == -1) then contagem = 1 end if not tonumber(contagem) then selfSay("You are not participating in any task.", cid) else selfSay("You are participating in a "..k.." and already has "..((contagem)-1).." dead "..k..", do you really want to leave?", cid) end end end else selfSay("You are not on any task.", cid) end elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then setPlayerStorageValue(cid, storagesair, 0) selfSay("You were successfully removed from the task!", cid) elseif msgcontains(msg, "no") then selfSay("Okay then.", cid) talkState[talkUser] = 0 npcHandler:releaseFocus(cid) end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) [*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*] DISCORD: vodkart#6090
Postado Julho 30, 2018 6 anos Autor @Vodkart, obrigado príncipe encantado ❤️ Spoiler local config = { delrey = getPlayerCarValue(cid, DELREY), cigarro = getPlayerCancer(cid, DERBY), prostituta = getPlayerAIDS(cid, cracuda), tresOitao = getPlayerRevorvi(cid, 38) } if(delrey == "Ligado" and cigarro == "Aceso" and prostituta == "No Colo" and tresOitao == "Carregado") then doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Começou o fim de semana. #PAS") end
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.