Postado Novembro 29, 2012 12 anos Este é um post popular. Olá galera do TibiaKing, a um tempo eu estava querendo um NPC que vendia spells (magias) Porém, eu não achava, na época não tinha, então, eu fui no ##### e pedi lá esse NPC que vendia spells pelo NPC, ai o "VODKART", postou esse NPC lá e me ajudou, e se não me engano, não existe esse NPC aqui no TK, então agora irá ter. Chega de papo/enrolação e vamos para o que interessa. Abra a pasta do seu OT/data/npc/NOME DO SEU NPC.xml e coloque isso: <?xml version="1.0"?> <npc name="NOME DO SEU NPC" script="data/npc/scripts/spell_seller.lua" walkinterval="50000" floorchange="0"> <health now="100" max="100"/> <look type="129" head="95" body="116" legs="121" feet="115" addons="3"/> <parameters> <parameter key="message_greet" value="Hello |PLAYERNAME|. Quer comprar algumas {spells} ?" /> </parameters> </npc> Agora abra a pasta do seu OT/data/npc/scripts/spell_seller.lua e coloque isso: 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 moeda = 2157 local t = { ["light healing"] = {price = 15,vocations = {1,2,3,4},level = 9}, ["find person"] = {price = 25,vocations = {3,4},level = 8}, ["light magic missile"] = {price =30,vocations = {1,5,7,8},level = 15}, ["energy strike"] = {price =20,vocations = {1,2,5,6},level = 12}, ["flame strike"] = {price =100,vocations = {1,2,5,6},level = 12} } if (msgcontains(msg, 'SPELLS') or msgcontains(msg, 'spells'))then local str = "" str = str .. "Eu vendo estas Magias: " for name, pos in pairs(t) do str = str.." {"..name.."} = "..pos.price.." Moedas /" end str = str .. "." npcHandler:say(str, cid) elseif t[msg] then if not getPlayerLearnedInstantSpell(cid, msg) then if getPlayerLevel(cid) >= t[msg].level then if isInArray(t[msg].vocations, getPlayerVocation(cid)) then if doPlayerRemoveItem(cid,moeda,t[msg].price) then doPlayerLearnInstantSpell(cid, msg) npcHandler:say("Você aprendeu uma nova magia chamada ".. msg .."!", cid) else npcHandler:say("você não tem "..t[msg].price.." ".. getItemNameById(moeda), cid) end else npcHandler:say("você não tem a vocação para comprar está spell.", cid) end else npcHandler:say("você precisa ter level "..t[msg].level.." ou mais para comprar essa magia.", cid) end else npcHandler:say("você já aprendeu essa magia.", cid) end end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Configurando as spells que serão vendidas é aqui: local t = { ["light Healing"] = {price = 15,vocations = {1,2,3,4},level = 9}, ["find person"] = {price = 25,vocations = {3,4},level = 8}, ["light magic missile"] = {price =30,vocations = {1,5,7,8},level = 15}, ["energy strike"] = {price =20,vocations = {1,2,5,6},level = 12}, ["flame strike"] = {price =100,vocations = {1,2,5,6},level = 12} } ["Nome da Spells"] ={price = Quantos Coins (NO CASO ESTÁ COINS) irá custar. Vocations ={ID DAS VOC},level = level para poder usar a magia} E para usar a magia só quem comprou você faz o seguinte vai em spells.xml e na tag da magia nessa parte: needlearn="0" Você coloca assim: needlearn="1" EXPLICANDO SOBRE O NEEDLEARN: needlearn="1" -- Aqui está que precisa comprar a magia no NPC para poder usa-la. needlearn="0" -- Aqui está que não precisa comprar a magia no NPC para poder usa-la. CRÉDITOS: Vodkart (Pelo Script) Thiagobji (Pelo Tópico, Pelo Pedido e por postar no TibiaKing.com) É ISSO GALERA, QUALQUER DÚVIDA SÓ POSTAR.
Postado Novembro 29, 2012 12 anos Autor Legal e bem útil a script, gostei. Rep+ Valeu Carlos. Qualquer dúvida só postar.
Postado Setembro 27, 2013 11 anos E se eu quisesse configurar para que o parâmetro da compra fosse magic level ao invés de level? É só mudar o parâmetro "level" para "magiclevel" ou "maglevel"? Se alguém puder responder PS: excelente tutorial! Editado Setembro 27, 2013 11 anos por Inthus (veja o histórico de edições)
Postado Setembro 27, 2013 11 anos Gostei, o npc é bastante rpg e útil. (: Ot Design: https://discord.gg/VgtVRNmCD7
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.