• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Adding more vocations in this script?

julhinhuu

New Member
Joined
Jul 16, 2011
Messages
35
Reaction score
0
As the topic already said , I would like to help me in this script to add more calling this npc .

Code:
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())

I wish all vocations buy is magic. Thanks in advance.
I've tried so and does not work:
vocation = 1,2,3,4,
and
vocation = {1,2,3,4},
 
vocation = {1,2,3,4},
this should do the job....

post your /lib/npcsystem/modules~~ maybe module learnSpell doesnt check for an array
or give us the error printout from your server console
 
Modules:
Code:
    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

I put so and gave the error:
vocation = {1,2,3,4},

cKUs8qQ


Link image:
https://imgur.com/cKUs8qQ
 
make a backup of your modules.lua

then test this:
Code:
            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)

change it to:
Code:
elseif (not isInArray(parameters.vocation, player:getVocation():getId())) then
    npcHandler:say("This spell is not for your vocation", cid)
 
Back
Top