Ir para conteúdo
  • 0

Colocando mais vocaçoes neste Script de NPC


julhinhuu

Pergunta

Olá galera do XT bom tempo sem pedir nada aqui, mais hoje estou aqui heehe.

O que eu realmente gostaria era de adicionar mais vocações neste npc de venda de Spells.

 

Segue ele ai:

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


-- OTServ event handling functions start
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
-- OTServ event handling functions end


local node1 = keywordHandler:addKeyword({'light healing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn light healing for 170 gp?'})
node1:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'light healing', vocation = 2, price = 170, level = 9})
node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())

Já tentei de varias formas mais ainda não consegui espero que me ajudem.

 

Link para o comentário
Compartilhar em outros sites

7 respostass a esta questão

Posts Recomendados

  • 0

Troque seu script do StdModule.learnSpell por esse :

function StdModule.learnSpell(cid, message, keywords, parameters, node)
local npcHandler = parameters.npcHandler
    if npcHandler == nil then
        error("StdModule.learnSpell called without any npcHandler instance.")
    end
    if not npcHandler:isFocused(cid) then
       return false
    end
local player = Player(cid)
    if parameters.premium and player:isPremium() then
        if player:hasLearnedSpell(parameters.spellName) then
            npcHandler:say("You already know this spell.", cid)
        elseif player:getLevel() < parameters.level then
            npcHandler:say("You need to obtain a level of " .. parameters.level .. " or higher to be able to learn " .. parameters.spellName .. ".", cid)
        elseif type(parameters.vocation) == "table" then
          	if not isInArray(parameters.vocation,  player:getVocation():getId()) then
          		npcHandler:say("This spell is not for your vocation", cid)
           	end
        elseif type(parameters.vocation) == "number" then
          	if player:getVocation():getId() ~= parameters.vocation and player:getVocation():getId() ~= parameters.vocation + 4 and vocation ~= 9 then
          		npcHandler:say("This spell is not for your vocation", cid)
           	end
        elseif not player:removeMoney(parameters.price) then
            npcHandler:say("You do not have enough money, this spell costs " .. parameters.price .. " gold.", cid)
        else
            npcHandler:say("You have learned " .. parameters.spellName .. ".", cid)
            player:learnSpell(parameters.spellName)
        end
    else
        npcHandler:say("You need a premium account in order to buy " .. parameters.spellName .. ".", cid)
    end
    npcHandler:resetNpc(cid)
    return true
end

e em vocation coloque :

 

vocation = {id_vocation, id_vocation, id_vocation}(Para mais de 1 vocação)

 

ou

 

vocation = id_vocation(Para apenas 1 vocação)

Editado por Kawoszin
Link para o comentário
Compartilhar em outros sites

  • 0

Tente:

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


-- OTServ event handling functions start
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
-- OTServ event handling functions end


local node1 = keywordHandler:addKeyword({'light healing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn light healing for 170 gp?'})
node1:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'light healing', vocation = 1,2,3,4 price = 170, level = 9})
node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())
Link para o comentário
Compartilhar em outros sites

  • 0

 

Tente:

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


-- OTServ event handling functions start
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
-- OTServ event handling functions end


local node1 = keywordHandler:addKeyword({'light healing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn light healing for 170 gp?'})
node1:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'light healing', vocation = 1,2,3,4 price = 170, level = 9})
node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())

Da erro sem parar, o erro só para após colocar ','

vocation = 1,2,3,4,

 

Após isso o npc só vende a spell para a 1ª vocação.

 

Link para o comentário
Compartilhar em outros sites

  • 0

Já tentou botar em tabela?

assim:

vocation = {1,2,3,4}

EDIT:

 

Caso do jeito acima não funcione, tente o script na seguinte forma:

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


-- OTServ event handling functions start
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(cid) 
local vocs = {1,2,3,4}
local player = Player(cid)
if isInArray(vocs, player:getVocation()) then
a = player:getVocation()
else
a = vocs[1]
end
npcHandler:onThink(cid) end
-- OTServ event handling functions end



local node1 = keywordHandler:addKeyword({'light healing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn light healing for 170 gp?'})
node1:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'light healing', vocation = a price = 170, level = 9})
node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())

*não tenho ctz se vai dar certo... mas ñ custa tentar

Editado por Danihcv
Link para o comentário
Compartilhar em outros sites

  • 0

Já tentou botar em tabela?

assim:

vocation = {1,2,3,4}

EDIT:

 

Caso do jeito acima não funcione, tente o script na seguinte forma:

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


-- OTServ event handling functions start
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(cid) 
local vocs = {1,2,3,4}
local player = Player(cid)
if isInArray(vocs, player:getVocation()) then
a = player:getVocation()
else
a = vocs[1]
end
npcHandler:onThink(cid) end
-- OTServ event handling functions end



local node1 = keywordHandler:addKeyword({'light healing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn light healing for 170 gp?'})
node1:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'light healing', vocation = a price = 170, level = 9})
node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())

*não tenho ctz se vai dar certo... mas ñ custa tentar

 

Dando este erro:

post-321783-0-95984300-1458423585_thumb.png

Coloquei ',' ficando assim vocation = a, e deu este erro antes dava erro em Price.

E tabela já havia tentando e da erro no npc também.

 

Modules desta função creio que seja essa:

function StdModule.learnSpell(cid, message, keywords, parameters, node)

local npcHandler = parameters.npcHandler

if npcHandler == nil then

error("StdModule.learnSpell called without any npcHandler instance.")

end

 

if not npcHandler:isFocused(cid) then

return false

end

 

local player = Player(cid)

if parameters.premium and player:isPremium() then

if player:hasLearnedSpell(parameters.spellName) then

npcHandler:say("You already know this spell.", cid)

elseif player:getLevel() < parameters.level then

npcHandler:say("You need to obtain a level of " .. parameters.level .. " or higher to be able to learn " .. parameters.spellName .. ".", cid)

elseif player:getVocation():getId() ~= parameters.vocation and player:getVocation():getId() ~= parameters.vocation + 4 and vocation ~= 9 then

npcHandler:say("This spell is not for your vocation", cid)

elseif not player:removeMoney(parameters.price) then

npcHandler:say("You do not have enough money, this spell costs " .. parameters.price .. " gold.", cid)

else

npcHandler:say("You have learned " .. parameters.spellName .. ".", cid)

player:learnSpell(parameters.spellName)

end

else

npcHandler:say("You need a premium account in order to buy " .. parameters.spellName .. ".", cid)

end

 

npcHandler:resetNpc(cid)

return true

end

Editado por julhinhokullitz
Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...