Postado Dezembro 22, 2015 9 anos Autor 7 horas atrás, Azhaurn disse: @brendoonh http://www.tibiaking.com/forum/topic/65860-npc-que-troque-3-itens-por-uma-chave/#comment-375394 O que eu fiz de errado?? Spoiler 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 local items = { item1 = {2177}, -- Item que vai pedir na troca item2 = {2425, 2516, 3983} -- Item que vai pedir na troca } local counts = { count1 = {10}, -- Quantidade do ITEM1 count2 = {1, 1, 3} -- Quantidade do ITEM2 } function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, 'flawless ice crystal') then selfSay('You want to swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.',cid) talkState[talkUser] = 1 elseif talkState[talkUser] == 1 then if msgcontains(msg, 'yes') then if getPlayerItemCount(cid, items.item1[1]) >= counts.count1[1] then doPlayerRemoveItem(cid, items.item1[1], counts.count1[1]) doPlayerAddItem(cid, items.item1[2], counts.count1[2]) selfSay('You just swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.', cid) talkState[talkUser] = 0 else selfSay('You need '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..'.', cid) end else selSay('Ok then!', cid) talkState[talkUser] = 0 end elseif msgcontains(msg, 'obsidian knife') then selfSay('You want to swap '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..' for '.. counts.count2[2] ..' '.. getItemNameById(items.item2[2]) ..'.', cid) talkState[talkUser] = 2 elseif talkSate[talkUser] == 2 if msgcontains(msg, 'yes') then if getPlayerItemCount(cid, items.item2[1]) >= counts.count2[1] then doPlayerRemoveItem(cid, items.item2[1], counts.count2[1]) doPlayerAddItem(cid, items.item2[2], counts.count2[2]) selfSay('You just swap '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..' for '.. counts.count2[2] ..' '.. getItemNameById(items.item2[2]) ..'.', cid) talkState[talkUser] = 0 else selfSay('You need '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..'.', cid) end else selfSay('Ok then!', cid) talkState[talkUser] = 0 end end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Spoiler <?xml version="1.0" encoding="UTF-8"?> <npc name="Sweet Ciclops" script="sweet.lua" walkinterval="2000" floorchange="0"> <health now="150" max="150" /> <look type="22" head="57" body="59" legs="40" feet="76" corpse="2212" /> <parameters> <parameter key="message_greet" value="Hello |PLAYERNAME|. Do not want to make an exchange? I have {flawless ice crystal} and {obsidian knife}." /> <parameter key="message_farewell" value="Bye bye!" /> </parameters> </npc> Editado Dezembro 22, 2015 9 anos por brendoonh Adicionando foto (veja o histórico de edições)
Postado Dezembro 22, 2015 9 anos Tente assim: Spoiler 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 local items = { item1 = {2177}, -- Item que vai pedir na troca item2 = {2425, 2516, 3983} -- Item que vai pedir na troca } local counts = { count1 = {10}, -- Quantidade do ITEM1 count2 = {1, 1, 3} -- Quantidade do ITEM2 } function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, 'flawless ice crystal') then selfSay('You want to swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.',cid) talkState[talkUser] = 1 elseif talkState[talkUser] == 1 then if msgcontains(msg, 'yes') then if getPlayerItemCount(cid, items.item1[1]) >= counts.count1[1] then doPlayerRemoveItem(cid, items.item1[1], counts.count1[1]) doPlayerAddItem(cid, items.item1[2], counts.count1[2]) selfSay('You just swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.', cid) talkState[talkUser] = 0 else selfSay('You need '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..'.', cid) end else selSay('Ok then!', cid) talkState[talkUser] = 0 end elseif msgcontains(msg, 'obsidian knife') then selfSay('You want to swap '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..' for '.. counts.count2[2] ..' '.. getItemNameById(items.item2[2]) ..'.', cid) talkState[talkUser] = 2 elseif talkSate[talkUser] == 2 then if msgcontains(msg, 'yes') then if getPlayerItemCount(cid, items.item2[1]) >= counts.count2[1] then doPlayerRemoveItem(cid, items.item2[1], counts.count2[1]) doPlayerAddItem(cid, items.item2[2], counts.count2[2]) selfSay('You just swap '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..' for '.. counts.count2[2] ..' '.. getItemNameById(items.item2[2]) ..'.', cid) talkState[talkUser] = 0 else selfSay('You need '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..'.', cid) end else selfSay('Ok then!', cid) talkState[talkUser] = 0 end end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) ➥ Regras | Seções OTServ | Seções BOT
Postado Dezembro 22, 2015 9 anos Autor 1 hora atrás, Wakon disse: Tente assim: Ocultar conteúdo 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 local items = { item1 = {2177}, -- Item que vai pedir na troca item2 = {2425, 2516, 3983} -- Item que vai pedir na troca } local counts = { count1 = {10}, -- Quantidade do ITEM1 count2 = {1, 1, 3} -- Quantidade do ITEM2 } function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, 'flawless ice crystal') then selfSay('You want to swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.',cid) talkState[talkUser] = 1 elseif talkState[talkUser] == 1 then if msgcontains(msg, 'yes') then if getPlayerItemCount(cid, items.item1[1]) >= counts.count1[1] then doPlayerRemoveItem(cid, items.item1[1], counts.count1[1]) doPlayerAddItem(cid, items.item1[2], counts.count1[2]) selfSay('You just swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.', cid) talkState[talkUser] = 0 else selfSay('You need '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..'.', cid) end else selSay('Ok then!', cid) talkState[talkUser] = 0 end elseif msgcontains(msg, 'obsidian knife') then selfSay('You want to swap '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..' for '.. counts.count2[2] ..' '.. getItemNameById(items.item2[2]) ..'.', cid) talkState[talkUser] = 2 elseif talkSate[talkUser] == 2 then if msgcontains(msg, 'yes') then if getPlayerItemCount(cid, items.item2[1]) >= counts.count2[1] then doPlayerRemoveItem(cid, items.item2[1], counts.count2[1]) doPlayerAddItem(cid, items.item2[2], counts.count2[2]) selfSay('You just swap '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..' for '.. counts.count2[2] ..' '.. getItemNameById(items.item2[2]) ..'.', cid) talkState[talkUser] = 0 else selfSay('You need '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..'.', cid) end else selfSay('Ok then!', cid) talkState[talkUser] = 0 end end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Valeu.. Funcionou ! Estou com uma duvida, nessa parte dos items, item2 = {2425, 2516, 3983} -- Item que vai pedir na troca Eu achava que seria assim, esses 3 ids, trocaria pelo Obsidian Knife, só que nao ta assim, na verdade isso so funciona assim, por ex: {2425, 5805} Nao ta tendo como colocar 3 items para trocar por 1, esse exemplo que citei, ele recebe o ID 2425, e troca pelo 5805... Eu iria por diversos itens na troca, só que eu nao to conseguindo.. 10 life crystal = 1 flawless ice crystal 1 dragon shield + 1 obsidian lance + 3 bast skirt = obsidian knife 100 soul orb = 100 infernal bolt 3 devil helmet = 1 magic sulphur 1 small ruby + 1 diamond = fire bug Nao teria um modo mais simples de fazer??
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.