npc que troca item por spells
spell_seller.lua
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())
Você adiciona e configura as spells que serão trocadas 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 DO SEU NPC.xml
<?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>
e para usar a magia só quem comprou você faz o seguinte
vai em Spells.xml e na tag da sua magia vc coloca
needlearn="1"
needlearn="1" -- precisa aprender para usar a magia
needlearn="0" -- n precisa aprender para usar a magia



info
Grupo: Conde
Registrado: 18/07/08
Posts: 545
Reputação: +21
Char no Tibia: Nem eu sei
Queria 2 npcs, como fala no titulo:
1 - Voê da um item pro NPC e ganha uma spell.
2 - Se você tiver a storage X, é so ir no NPC e trocar por uma outra spell.