• 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!

TFS 1.X+ Oracle with Vocation Items and Player Choice

aalqaq2

Trying to help, but I'm not too good at it.
Joined
Apr 10, 2017
Messages
111
Solutions
3
Reaction score
8
Hey guys,

What is the best way to save player choices into an array and add the items later? I want to give the players the ability to choose a secondary weapon and choose between a spellbook or shield when they enter the mainland. I thought about using a secondary table and
Lua:
local a = table.insert(a, item)
but I'm not sure if that's the best way. I'm also pretty sure I'm handling the implementation in the worst possible manner.

The code is below. Any feedback is appreciated.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local vocation = {}
local town = {}
local destination = {}
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
--Equipment Upon Arrival to Mainland
--{8601, 1}, {2439, 1}, {8602, 1}, {2175, 1} | steel axe, daramian mace, jagged sword, spellbook
local config = {
    [1] = { -- Sorcerer
            --Equipment: wand of vortex, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2190, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potions, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2525, 1}}
    },
    [2] = { -- Druid
            --Equipment: snakebite rod, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2182, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}}
    },
    [3] = { -- Paladin
            --Equipment: dwarven shield, 1 spear, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2389, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms, bow, 50 arrows
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2456, 1}, {2544, 50}}
    },
    [4] = { -- Knight
            --Equipment: dwarven shield, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5} ,{2160, 1}, {5022, 10}, {2789,100}} 
    }
} 
--End--
local function greetCallback(cid)
    local player = Player(cid)
    local level = player:getLevel()
    if level < 8 then
        npcHandler:say("CHILD! COME BACK WHEN YOU HAVE GROWN UP!", cid)
        return false
    elseif level > 9 then
        npcHandler:say(player:getName() .. ", I CAN'T LET YOU LEAVE - YOU ARE TOO STRONG ALREADY! YOU CAN ONLY LEAVE WITH LEVEL 9 OR LOWER.", cid)
        return false
    elseif player:getVocation():getId() > 0 then
        npcHandler:say("YOU ALREADY HAVE A VOCATION!", cid)
        return false
    end
    return true
end
local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    if msgcontains(msg, "yes") and npcHandler.topic[cid] == 0 then
        npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}, {EDRON}, {YALAHAR}, {SVARGROND}, {FARMINE}, {ROSHAMUUL}, {LIBERTY BAY}, {PORT HOPE}, {ANKRAHMUN}, {DARASHIA}, {RATHLETON}?", cid)
        npcHandler.topic[cid] = 1
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "thais") then
            town[cid] = 2
            destination[cid] = Position(32369, 32241, 7) 
            npcHandler:say("IN THAIS! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "carlin") then
            town[cid] = 4
            destination[cid] = Position(32360, 31782, 7) 
            npcHandler:say("IN CARLIN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "venore") then
            town[cid] = 1
            destination[cid] = Position(32957, 32076, 7) 
            npcHandler:say("IN VENORE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ab'dendriel") then
            town[cid] = 5
            destination[cid] = Position(32732, 31634, 7) 
            npcHandler:say("IN AB'DENDRIEL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "edron") then
            town[cid] = 11
            destination[cid] = Position(33217, 31814, 8) 
            npcHandler:say("IN EDRON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "yalahar") then
            town[cid] = 13
            destination[cid] = Position(32787, 31276, 7) 
            npcHandler:say("IN YALAHAR! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "svargrond") then
            town[cid] = 12
            destination[cid] = Position(32212, 31132, 7) 
            npcHandler:say("IN SVARGROND! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "farmine") then
            town[cid] = 14
            destination[cid] = Position(33023, 31525, 11) 
            npcHandler:say("IN FARMINE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "roshamuul") then
            town[cid] = 29
            destination[cid] = Position(33513, 32363, 6) 
            npcHandler:say("IN ROSHAMUUL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "liberty bay") then
            town[cid] = 7
            destination[cid] = Position(32317, 32826, 7) 
            npcHandler:say("IN LIBERTY BAY! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "port hope") then
            town[cid] = 8
            destination[cid] = Position(32594, 32745, 7) 
            npcHandler:say("IN PORT HOPE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ankrahmun") then
            town[cid] = 9
            destination[cid] = Position(33194, 32853, 8) 
            npcHandler:say("IN ANKRAHMUN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "darashia") then
            town[cid] = 10
            destination[cid] = Position(33213, 32454, 1) 
            npcHandler:say("IN DARASHIA! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "rathleton") then
            town[cid] = 33
            destination[cid] = Position(33594, 31899, 6) 
            npcHandler:say("IN RATHLETON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        else
            npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}?", cid)
        end
    elseif npcHandler.topic[cid] == 2 then
        if msgcontains(msg, "sorcerer") then
            npcHandler:say("YOU WILL BE GIVEN A WAND OF VORTEX. WOULD YOU LIKE TO CHOOSE A SECONDARY {WEAPON}?", cid)
            if isInArray({"weapon", "yes"}, msg:lower()) then
                npcHandler:say("WOULD YOU LIKE A {SWORD} WEAPON, {AXE} WEAPON, OR {CLUB} WEAPON?", cid)
                if msgcontains(msg, "sword") then
                    --Add Sword Here {8602, 1}
                    npcHandler:say("YOU WILL RECEIVE A SWORD WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                elseif msgcontains(msg, "axe") then
                    --Add Axe Here {8601, 1}
                    npcHandler:say("YOU WILL RECEIVE AN AXE WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                elseif msgcontains(msg, "club") then
                    --Add Club Here {2439, 1}
                    npcHandler:say("YOU WILL RECEIVE A CLUB WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add Error handler here
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                else
                    npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
                end
            else
                npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
            end
            npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 1
        elseif msgcontains(msg, "druid") then
            npcHandler:say("YOU WILL BE GIVEN A SNAKEBITE ROD. WOULD YOU LIKE TO CHOOSE A SECONDARY {WEAPON}?", cid)
            if isInArray({"weapon", "yes"}, msg:lower()) then
                npcHandler:say("WOULD YOU LIKE A {SWORD} WEAPON, {AXE} WEAPON, OR {CLUB} WEAPON?", cid)
                if msgcontains(msg, "sword") then
                    --Add Sword Here {8602, 1}
                    npcHandler:say("YOU WILL RECEIVE A SWORD WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                elseif msgcontains(msg, "axe") then
                    --Add Axe Here {8601, 1}
                    npcHandler:say("YOU WILL RECEIVE AN AXE WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                elseif msgcontains(msg, "club") then
                    --Add Club Here {2439, 1}
                    npcHandler:say("YOU WILL RECEIVE A CLUB WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add Error handler here
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                else
                    npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
                end
            else
                npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
            end
            npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 2
        elseif msgcontains(msg, "paladin") then
            npcHandler:say("YOU WILL BE GIVEN A BOW, ARROWS, AND A SPEAR. WOULD YOU LIKE TO CHOOSE A MELEE {WEAPON}?", cid)
            if isInArray({"weapon", "yes"}, msg:lower()) then
                npcHandler:say("WOULD YOU LIKE A {SWORD} WEAPON, {AXE} WEAPON, OR {CLUB} WEAPON?", cid)
                if msgcontains(msg, "sword") then
                    --Add Sword Here {8602, 1}
                    npcHandler:say("YOU WILL RECEIVE A SWORD WEAPON!", cid)
                elseif msgcontains(msg, "axe") then
                    --Add Axe Here {8601, 1}
                    npcHandler:say("YOU WILL RECEIVE AN AXE WEAPON!", cid)
                elseif msgcontains(msg, "club") then
                    --Add Club Here {2439, 1}
                    npcHandler:say("YOU WILL RECEIVE A CLUB WEAPON!", cid)
                else
                    npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
                end
            else
                npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
            end
            npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 3
        elseif msgcontains(msg, "knight") then
            npcHandler:say("THE DEFAULT WEAPON IS A SWORD. WOULD YOU LIKE TO CHOOSE A DIFFERENT {WEAPON}?", cid)
            if isInArray({"weapon", "yes"}, msg:lower()) then
                npcHandler:say("WOULD YOU LIKE A {SWORD} WEAPON, {AXE} WEAPON, OR {CLUB} WEAPON?", cid)
                if msgcontains(msg, "sword") then
                    --Add Sword Here {8602, 1}
                    npcHandler:say("YOU WILL RECEIVE A SWORD WEAPON!", cid)
                elseif msgcontains(msg, "axe") then
                    --Add Axe Here {8601, 1}
                    npcHandler:say("YOU WILL RECEIVE AN AXE WEAPON!", cid)
                elseif msgcontains(msg, "club") then
                    --Add Club Here {2439, 1}
                    npcHandler:say("YOU WILL RECEIVE A CLUB WEAPON!", cid)
                else
                    npcHandler:say("YOU WILL RECEIVE A SWORD!", cid)
                end
            else
                npcHandler:say("YOU WILL RECEIVE A SWORD!", cid)
            end
            npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 4
        else
            npcHandler:say("{KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
        end
    elseif npcHandler.topic[cid] == 3 then
        if msgcontains(msg, "yes") then
            local player = Player(cid)
            npcHandler:say("SO BE IT!", cid)
            player:setVocation(Vocation(vocation[cid]))
            player:setTown(Town(town[cid]))
            local destination = destination[cid]
            npcHandler:releaseFocus(cid)
            player:teleportTo(destination)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            destination:sendMagicEffect(CONST_ME_TELEPORT)
            --------------------------------------
            --Equipment Upon Arrival to Mainland--
            --------------------------------------
            
            local firstItems = {2480, 2464, 2468, 2643, 2530, 2383} 
            local player = Player(cid)
            
            -- Remove rook items from player inventory
            for i = 1, #firstItems do
                player:removeItem(firstItems[i], 1) 
            end
                
            local player = Player(cid)
            local targetVocation = config[player:getVocation():getId()]
                
            if not targetVocation then
            return true
            end
            
            -- Add Mainland items to player inventory
            for i = 1, #targetVocation.items do
                player:addItem(targetVocation.items[i][1], targetVocation.items[i][2])
            end
            
            local backpack = player:addItem(1988)
            
            if not backpack then
            return true
            end
            
            for i = 1, #targetVocation.container do
                backpack:addItem(targetVocation.container[i][1], targetVocation.container[i][2])
            end
                
            --------------------------------------
            ----------End Custom Section----------
            --------------------------------------
        else
            npcHandler:say("THEN WHAT? {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        end
    end
    return true
end
local function onAddFocus(cid)
    town[cid] = 0
    vocation[cid] = 0
    destination[cid] = 0
end
local function onReleaseFocus(cid)
    town[cid] = nil
    vocation[cid] = nil
    destination[cid] = nil
end
npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Hey guys,

What is the best way to save player choices into an array and add the items later? I want to give the players the ability to choose a secondary weapon and choose between a spellbook or shield when they enter the mainland. I thought about using a secondary table and
Lua:
local a = table.insert(a, item)
but I'm not sure if that's the best way. I'm also pretty sure I'm handling the implementation in the worst possible manner.
What you're doing is this
Lua:
local a = {}
table.insert(a, item)

-- now the table a looks like this..
local a = {item}

Instead, just input into the table directly. (using your already known index)
Lua:
local a = {}
a[item] = 0

-- now the table a looks like this..
local a = {
    [item] = 0...

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,522
Solutions
378
Reaction score
3,638
Hey guys,

What is the best way to save player choices into an array and add the items later? I want to give the players the ability to choose a secondary weapon and choose between a spellbook or shield when they enter the mainland. I thought about using a secondary table and
Lua:
local a = table.insert(a, item)
but I'm not sure if that's the best way. I'm also pretty sure I'm handling the implementation in the worst possible manner.
What you're doing is this
Lua:
local a = {}
table.insert(a, item)

-- now the table a looks like this..
local a = {item}

Instead, just input into the table directly. (using your already known index)
Lua:
local a = {}
a[item] = 0

-- now the table a looks like this..
local a = {
    [item] = 0
}

Of course this example is already in your code, but you kind of stopped using it.
Lua:
local town = {}
town[cid] = 2

-- now the table a looks like this..
local town = {
    [cid] = 2
}

Realistically, you should just continue holding all of the information like that, ideally inside of 1 array instead of 2+ arrays, but both would work, and ensure that the information is cleared away after use, or at the start of use. (which you seem to be doing already)
Lua:
town[cid] = nil
or
town[cid] = 0

--
Inside the code, you could probably just take all the town names, secondary weapons, shields.. and put them into their own tables.
That way you can just verify if the information exists inside of the table, instead of doing endless elseif's.

--
If you need more feedback / help, let me know.
 
Solution
OP
aalqaq2

aalqaq2

Trying to help, but I'm not too good at it.
Joined
Apr 10, 2017
Messages
111
Solutions
3
Reaction score
8
I think I'm following...

If I declare a table
Lua:
 local items = {}
I should be able to add the items like this?
Lua:
if msgcontains(msg, "sorcerer") then
            npcHandler:say("YOU WILL BE GIVEN A WAND OF VORTEX. WOULD YOU LIKE TO CHOOSE A SECONDARY {WEAPON}?", cid)
            if isInArray({"weapon", "yes"}, msg:lower()) then
                npcHandler:say("WOULD YOU LIKE A {SWORD} WEAPON, {AXE} WEAPON, OR {CLUB} WEAPON?", cid)
                if msgcontains(msg, "sword") then
                    --Add Sword Here {8602, 1}
                    items[1] = {8602, 1}
                    npcHandler:say("YOU WILL RECEIVE A SWORD WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        items[2] = {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                elseif msgcontains(msg, "axe") then
                    --Add Axe Here {8601, 1}
                    items[1] = {8601, 1}
                    npcHandler:say("YOU WILL RECEIVE AN AXE WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        items[2] = {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                elseif msgcontains(msg, "club") then
                    --Add Club Here {2439, 1}
                    items[1] = {2439, 1}
                    npcHandler:say("YOU WILL RECEIVE A CLUB WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        items[2] = {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add Error handler here
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                else
                    npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
                end
            else
                npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
            end

and iterate through the table like this right?

Lua:
for i = 1, #items do
      player:addItem(items[i][1], items[i][2])
end
Post automatically merged:

Inside the code, you could probably just take all the town names, secondary weapons, shields.. and put them into their own tables.
That way you can just verify if the information exists inside of the table, instead of doing endless elseif's.
I am curious to know what you mean by this? It's probably what I'm wanting to do, but I lack the knowledge to do so.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,522
Solutions
378
Reaction score
3,638
I think I'm following...

If I declare a table
Lua:
 local items = {}
I should be able to add the items like this?
Lua:
if msgcontains(msg, "sorcerer") then
            npcHandler:say("YOU WILL BE GIVEN A WAND OF VORTEX. WOULD YOU LIKE TO CHOOSE A SECONDARY {WEAPON}?", cid)
            if isInArray({"weapon", "yes"}, msg:lower()) then
                npcHandler:say("WOULD YOU LIKE A {SWORD} WEAPON, {AXE} WEAPON, OR {CLUB} WEAPON?", cid)
                if msgcontains(msg, "sword") then
                    --Add Sword Here {8602, 1}
                    items[1] = {8602, 1}
                    npcHandler:say("YOU WILL RECEIVE A SWORD WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        items[2] = {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                elseif msgcontains(msg, "axe") then
                    --Add Axe Here {8601, 1}
                    items[1] = {8601, 1}
                    npcHandler:say("YOU WILL RECEIVE AN AXE WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        items[2] = {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                elseif msgcontains(msg, "club") then
                    --Add Club Here {2439, 1}
                    items[1] = {2439, 1}
                    npcHandler:say("YOU WILL RECEIVE A CLUB WEAPON!", cid)
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    if msgcontains(msg, "spellbook") then
                        --Add spellbook here {2175, 1}
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    elseif msgcontains(msg, "shield") then
                        --Add shield here {2525, 1}
                        items[2] = {2525, 1}
                        npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
                    else
                        --Add Error handler here
                        items[2] = {2175, 1}
                        npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
                    end
                else
                    npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
                end
            else
                npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
            end

and iterate through the table like this right?

Lua:
for i = 1, #items do
      player:addItem(items[i][1], items[i][2])
end
As you currently have it... the additional questions are hidden behind other if statements.. so it's impossible for a person to answer them.

You need to separate your questions from one another using the built-in npc topic table.
That way the npc knows what questions you are at.

Code:
If topic == 0 then
    if yes then
        what town?
        set topic 1
    else
        huh?
    end


elseif topic == 1 then
    if townName is valid then
        -- store town information
        what vocations?
        set topic 2
    else
        townName is invalid..
    end


elseif topic == 2 then
    if vocation is valid then
        -- store vocation information
        would you like a secondary weapon?
        set topic 3
    else
        vocation is invalid..
    end


elseif topic == 3 then
    if yes then
        what secondary weapon?
        set topic 4
    elseif no then
        -- store secondary weapon information
        Shield or spellbook?
        set topic 5
    else
        -- didn't give yes or no answer
    end


elseif topic == 4 then
    if secondary weapon is valid then
        -- store secondary weapon information
        Shield or spellbook?
        set topic 5
    else
        secondary weapon is invalid ..
    end


elseif topic == 5 then
    if shield or spellbook then
        -- store information
        Are you ready to go to the mainland?
        set topic 6
    else
        didn't give a valid response..
    end

 
elseif topic == 6 then
    if yes then
        -- take stored information and use it. (give items, teleport player, whatever else)
    else
        -- does not want to go.. reset all information?
    end
   
end

Post automatically merged:


I am curious to know what you mean by this? It's probably what I'm wanting to do, but I lack the knowledge to do so.
You'll get there.
You just need to understand tables better.

Read about Lua tables, then just start testing stuff.
"The master has failed more times then the apprentice has even tried."
 
OP
aalqaq2

aalqaq2

Trying to help, but I'm not too good at it.
Joined
Apr 10, 2017
Messages
111
Solutions
3
Reaction score
8
I think I got it! Can you take a look? I just want to make sure I haven't made any obvious mistakes. I also want to release it to the public after I completely fail-safe it.

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

local vocation = {}
local town = {}
local destination = {}
local items = {}

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

--Equipment Upon Arrival to Mainland
--{8601, 1}, {2439, 1}, {8602, 1}, {2175, 1} | steel axe, daramian mace, jagged sword, spellbook
local config = {
    [1] = { -- Sorcerer
            --Equipment: wand of vortex, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2190, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potions, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2525, 1}}
    },
    [2] = { -- Druid
            --Equipment: snakebite rod, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2182, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}}
    },
    [3] = { -- Paladin
            --Equipment: dwarven shield, 1 spear, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2389, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms, bow, 50 arrows
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2456, 1}, {2544, 50}}
    },
    [4] = { -- Knight
            --Equipment: dwarven shield, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5} ,{2160, 1}, {5022, 10}, {2789,100}}
    }
}
--End--

local function greetCallback(cid)
    local player = Player(cid)
    local level = player:getLevel()
    if level < 8 then
        npcHandler:say("CHILD! COME BACK WHEN YOU HAVE GROWN UP!", cid)
        return false
    elseif level > 9 then
        npcHandler:say(player:getName() .. ", I CAN'T LET YOU LEAVE - YOU ARE TOO STRONG ALREADY! YOU CAN ONLY LEAVE WITH LEVEL 9 OR LOWER.", cid)
        return false
    elseif player:getVocation():getId() > 0 then
        npcHandler:say("YOU ALREADY HAVE A VOCATION!", cid)
        return false
    end
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains(msg, "yes") and npcHandler.topic[cid] == 0 then
        npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}, {EDRON}, {YALAHAR}, {SVARGROND}, {FARMINE}, {ROSHAMUUL}, {LIBERTY BAY}, {PORT HOPE}, {ANKRAHMUN}, {DARASHIA}, {RATHLETON}?", cid)
        npcHandler.topic[cid] = 1
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "thais") then
            town[cid] = 2
            destination[cid] = Position(32369, 32241, 7)
            npcHandler:say("IN THAIS! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "carlin") then
            town[cid] = 4
            destination[cid] = Position(32360, 31782, 7)
            npcHandler:say("IN CARLIN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "venore") then
            town[cid] = 1
            destination[cid] = Position(32957, 32076, 7)
            npcHandler:say("IN VENORE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ab'dendriel") then
            town[cid] = 5
            destination[cid] = Position(32732, 31634, 7)
            npcHandler:say("IN AB'DENDRIEL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "edron") then
            town[cid] = 11
            destination[cid] = Position(33217, 31814, 8)
            npcHandler:say("IN EDRON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "yalahar") then
            town[cid] = 13
            destination[cid] = Position(32787, 31276, 7)
            npcHandler:say("IN YALAHAR! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "svargrond") then
            town[cid] = 12
            destination[cid] = Position(32212, 31132, 7)
            npcHandler:say("IN SVARGROND! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "farmine") then
            town[cid] = 14
            destination[cid] = Position(33023, 31525, 11)
            npcHandler:say("IN FARMINE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "roshamuul") then
            town[cid] = 29
            destination[cid] = Position(33513, 32363, 6)
            npcHandler:say("IN ROSHAMUUL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "liberty bay") then
            town[cid] = 7
            destination[cid] = Position(32317, 32826, 7)
            npcHandler:say("IN LIBERTY BAY! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "port hope") then
            town[cid] = 8
            destination[cid] = Position(32594, 32745, 7)
            npcHandler:say("IN PORT HOPE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ankrahmun") then
            town[cid] = 9
            destination[cid] = Position(33194, 32853, 8)
            npcHandler:say("IN ANKRAHMUN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "darashia") then
            town[cid] = 10
            destination[cid] = Position(33213, 32454, 1)
            npcHandler:say("IN DARASHIA! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "rathleton") then
            town[cid] = 33
            destination[cid] = Position(33594, 31899, 6)
            npcHandler:say("IN RATHLETON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        else
            npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}, {EDRON}, {YALAHAR}, {SVARGROND}, {FARMINE}, {ROSHAMUUL}, {LIBERTY BAY}, {PORT HOPE}, {ANKRAHMUN}, {DARASHIA}, {RATHLETON}?", cid)
        end
    elseif npcHandler.topic[cid] == 2 then
        if msgcontains(msg, "sorcerer") then
            npcHandler:say("YOU WILL BE GIVEN A WAND OF VORTEX. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 1
        elseif msgcontains(msg, "druid") then
            npcHandler:say("YOU WILL BE GIVEN A SNAKEBITE ROD. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 2
        elseif msgcontains(msg, "paladin") then
            npcHandler:say("YOU WILL BE GIVEN A BOW, ARROWS, AND A SPEAR. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 3
        elseif msgcontains(msg, "knight") then
            npcHandler:say("YOU WILL BE GIVEN A SWORD. WOULD YOU LIKE TO CHOOSE A DIFFERENT {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 4
        else
            npcHandler:say("{KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
        end
    elseif npcHandler.topic[cid] == 3 then
        if isInArray({"weapon", "yes"}, msg:lower()) then
            npcHandler:say("WOULD YOU LIKE A JAGGED {SWORD}, STEEL {AXE}, DARAMIAN {MACE}?", cid)
            npcHandler.topic[cid] = 4
        elseif msgcontains(msg, "no") then
            items[1] = nil
            npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
            npcHandler.topic[cid] = 5
        else
            npcHandler:say("WOULD YOU LIKE TO CHOOSE A DIFFERENT {WEAPON}?", cid)
        end
    elseif npcHandler.topic[cid] == 4 then
        if msgcontains(msg, "sword") then
            npcHandler:say("YOU WILL RECEIVE A JAGGED SWORD!", cid)
            items[1] = {8602, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                end
        elseif msgcontains(msg, "axe") then
            npcHandler:say("YOU WILL RECEIVE A STEEL AXE!", cid)
            items[1] = {8601, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                end
        elseif msgcontains(msg, "mace") then
            npcHandler:say("YOU WILL RECEIVE A DARAMIAN MACE!", cid)
            items[1] = {2439, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                end
        else
            npcHandler:say("WELL?! WOULD YOU LIKE A JAGGED {SWORD}, STEEL {AXE}, DARAMIAN {MACE}?", cid)
        end
    elseif npcHandler.topic[cid] == 5 then
        if msgcontains(msg, "spellbook") then
            items[2] = {2175, 1}
            npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
            npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 6
        elseif msgcontains(msg, "shield") then
            items[2] = {2525, 1}
            npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
            npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 6
        else
            npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
        end
    elseif npcHandler.topic[cid] == 6 then
        if msgcontains(msg, "yes") then
            local player = Player(cid)
            npcHandler:say("SO BE IT!", cid)
            player:setVocation(Vocation(vocation[cid]))
            player:setTown(Town(town[cid]))

            local destination = destination[cid]
            npcHandler:releaseFocus(cid)
            player:teleportTo(destination)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            destination:sendMagicEffect(CONST_ME_TELEPORT)

            --------------------------------------
            --Equipment Upon Arrival to Mainland--
            --------------------------------------
           
            local firstItems = {2480, 2464, 2468, 2643, 2530, 2383}
            local player = Player(cid)
           
            -- Remove rook items from player inventory
            for i = 1, #firstItems do
                player:removeItem(firstItems[i], 1)
            end
               
            local player = Player(cid)
            local targetVocation = config[player:getVocation():getId()]
               
            if not targetVocation then
            return true
            end
           
            -- Add Mainland items to player inventory
            for i = 1, #targetVocation.items do
                player:addItem(targetVocation.items[i][1], targetVocation.items[i][2])
            end
           
            local backpack = player:addItem(1988)
           
            if not backpack then
            return true
            end
           
            -- Add Mainland items to player backpack
            for i = 1, #targetVocation.container do
                backpack:addItem(targetVocation.container[i][1], targetVocation.container[i][2])
            end
           
            -- Add custom items to player inventory
            for i = 1, #items do
                player:addItem(items[i][1], items[i][2])
            end
               
            --------------------------------------
            ----------End Custom Section----------
            --------------------------------------
        else
            npcHandler:say("COME BACK WHEN YOU ARE READY CHILD!!!", cid)
            npcHandler.topic[cid] = 0
        end
    end
    return true
end

local function onAddFocus(cid)
    town[cid] = 0
    vocation[cid] = 0
    destination[cid] = 0
    items[cid] = 0
end

local function onReleaseFocus(cid)
    town[cid] = nil
    vocation[cid] = nil
    destination[cid] = nil
    items[cid] = nil
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,522
Solutions
378
Reaction score
3,638
I think I got it! Can you take a look? I just want to make sure I haven't made any obvious mistakes.

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

local vocation = {}
local town = {}
local destination = {}
local items = {}

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

--Equipment Upon Arrival to Mainland
--{8601, 1}, {2439, 1}, {8602, 1}, {2175, 1} | steel axe, daramian mace, jagged sword, spellbook
local config = {
    [1] = { -- Sorcerer
            --Equipment: wand of vortex, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2190, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potions, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2525, 1}}
    },
    [2] = { -- Druid
            --Equipment: snakebite rod, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2182, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}}
    },
    [3] = { -- Paladin
            --Equipment: dwarven shield, 1 spear, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2389, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms, bow, 50 arrows
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2456, 1}, {2544, 50}}
    },
    [4] = { -- Knight
            --Equipment: dwarven shield, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5} ,{2160, 1}, {5022, 10}, {2789,100}}
    }
}
--End--

local function greetCallback(cid)
    local player = Player(cid)
    local level = player:getLevel()
    if level < 8 then
        npcHandler:say("CHILD! COME BACK WHEN YOU HAVE GROWN UP!", cid)
        return false
    elseif level > 9 then
        npcHandler:say(player:getName() .. ", I CAN'T LET YOU LEAVE - YOU ARE TOO STRONG ALREADY! YOU CAN ONLY LEAVE WITH LEVEL 9 OR LOWER.", cid)
        return false
    elseif player:getVocation():getId() > 0 then
        npcHandler:say("YOU ALREADY HAVE A VOCATION!", cid)
        return false
    end
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains(msg, "yes") and npcHandler.topic[cid] == 0 then
        npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}, {EDRON}, {YALAHAR}, {SVARGROND}, {FARMINE}, {ROSHAMUUL}, {LIBERTY BAY}, {PORT HOPE}, {ANKRAHMUN}, {DARASHIA}, {RATHLETON}?", cid)
        npcHandler.topic[cid] = 1
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "thais") then
            town[cid] = 2
            destination[cid] = Position(32369, 32241, 7)
            npcHandler:say("IN THAIS! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "carlin") then
            town[cid] = 4
            destination[cid] = Position(32360, 31782, 7)
            npcHandler:say("IN CARLIN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "venore") then
            town[cid] = 1
            destination[cid] = Position(32957, 32076, 7)
            npcHandler:say("IN VENORE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ab'dendriel") then
            town[cid] = 5
            destination[cid] = Position(32732, 31634, 7)
            npcHandler:say("IN AB'DENDRIEL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "edron") then
            town[cid] = 11
            destination[cid] = Position(33217, 31814, 8)
            npcHandler:say("IN EDRON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "yalahar") then
            town[cid] = 13
            destination[cid] = Position(32787, 31276, 7)
            npcHandler:say("IN YALAHAR! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "svargrond") then
            town[cid] = 12
            destination[cid] = Position(32212, 31132, 7)
            npcHandler:say("IN SVARGROND! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "farmine") then
            town[cid] = 14
            destination[cid] = Position(33023, 31525, 11)
            npcHandler:say("IN FARMINE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "roshamuul") then
            town[cid] = 29
            destination[cid] = Position(33513, 32363, 6)
            npcHandler:say("IN ROSHAMUUL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "liberty bay") then
            town[cid] = 7
            destination[cid] = Position(32317, 32826, 7)
            npcHandler:say("IN LIBERTY BAY! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "port hope") then
            town[cid] = 8
            destination[cid] = Position(32594, 32745, 7)
            npcHandler:say("IN PORT HOPE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ankrahmun") then
            town[cid] = 9
            destination[cid] = Position(33194, 32853, 8)
            npcHandler:say("IN ANKRAHMUN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "darashia") then
            town[cid] = 10
            destination[cid] = Position(33213, 32454, 1)
            npcHandler:say("IN DARASHIA! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "rathleton") then
            town[cid] = 33
            destination[cid] = Position(33594, 31899, 6)
            npcHandler:say("IN RATHLETON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        else
            npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}, {EDRON}, {YALAHAR}, {SVARGROND}, {FARMINE}, {ROSHAMUUL}, {LIBERTY BAY}, {PORT HOPE}, {ANKRAHMUN}, {DARASHIA}, {RATHLETON}?", cid)
        end
    elseif npcHandler.topic[cid] == 2 then
        if msgcontains(msg, "sorcerer") then
            npcHandler:say("YOU WILL BE GIVEN A WAND OF VORTEX. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 1
        elseif msgcontains(msg, "druid") then
            npcHandler:say("YOU WILL BE GIVEN A SNAKEBITE ROD. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 2
        elseif msgcontains(msg, "paladin") then
            npcHandler:say("YOU WILL BE GIVEN A BOW, ARROWS, AND A SPEAR. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 3
        elseif msgcontains(msg, "knight") then
            npcHandler:say("YOU WILL BE GIVEN A SWORD. WOULD YOU LIKE TO CHOOSE A DIFFERENT {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 4
        else
            npcHandler:say("{KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
        end
    elseif npcHandler.topic[cid] == 3 then
        if isInArray({"weapon", "yes"}, msg:lower()) then
            npcHandler:say("WOULD YOU LIKE A JAGGED {SWORD}, STEEL {AXE}, DARAMIAN {MACE}?", cid)
            npcHandler.topic[cid] = 4
        elseif msgcontains(msg, "no") then
            items[1] = nil
            npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
            npcHandler.topic[cid] = 5
        else
            npcHandler:say("WOULD YOU LIKE TO CHOOSE A DIFFERENT {WEAPON}?", cid)
        end
    elseif npcHandler.topic[cid] == 4 then
        if msgcontains(msg, "sword") then
            npcHandler:say("YOU WILL RECEIVE A JAGGED SWORD!", cid)
            items[1] = {8602, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                end
        elseif msgcontains(msg, "axe") then
            npcHandler:say("YOU WILL RECEIVE A STEEL AXE!", cid)
            items[1] = {8601, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                end
        elseif msgcontains(msg, "mace") then
            npcHandler:say("YOU WILL RECEIVE A DARAMIAN MACE!", cid)
            items[1] = {2439, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                end
        else
            npcHandler:say("WELL?! WOULD YOU LIKE A JAGGED {SWORD}, STEEL {AXE}, DARAMIAN {MACE}?", cid)
        end
    elseif npcHandler.topic[cid] == 5 then
        if msgcontains(msg, "spellbook") then
            items[2] = {2175, 1}
            npcHandler:say("YOU WILL RECEIVE A SPELLBOOK!", cid)
            npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 6
        elseif msgcontains(msg, "shield") then
            items[2] = {2525, 1}
            npcHandler:say("YOU WILL RECEIVE A SHIELD!", cid)
            npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 6
        else
            npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
        end
    elseif npcHandler.topic[cid] == 6 then
        if msgcontains(msg, "yes") then
            local player = Player(cid)
            npcHandler:say("SO BE IT!", cid)
            player:setVocation(Vocation(vocation[cid]))
            player:setTown(Town(town[cid]))

            local destination = destination[cid]
            npcHandler:releaseFocus(cid)
            player:teleportTo(destination)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            destination:sendMagicEffect(CONST_ME_TELEPORT)

            --------------------------------------
            --Equipment Upon Arrival to Mainland--
            --------------------------------------
         
            local firstItems = {2480, 2464, 2468, 2643, 2530, 2383}
            local player = Player(cid)
         
            -- Remove rook items from player inventory
            for i = 1, #firstItems do
                player:removeItem(firstItems[i], 1)
            end
             
            local player = Player(cid)
            local targetVocation = config[player:getVocation():getId()]
             
            if not targetVocation then
            return true
            end
         
            -- Add Mainland items to player inventory
            for i = 1, #targetVocation.items do
                player:addItem(targetVocation.items[i][1], targetVocation.items[i][2])
            end
         
            local backpack = player:addItem(1988)
         
            if not backpack then
            return true
            end
         
            -- Add Mainland items to player backpack
            for i = 1, #targetVocation.container do
                backpack:addItem(targetVocation.container[i][1], targetVocation.container[i][2])
            end
         
            -- Add custom items to player inventory
            for i = 1, #items do
                player:addItem(items[i][1], items[i][2])
            end
             
            --------------------------------------
            ----------End Custom Section----------
            --------------------------------------
        else
            npcHandler:say("COME BACK WHEN YOU ARE READY CHILD!!!", cid)
            npcHandler.topic[cid] = 0
        end
    end
    return true
end

local function onAddFocus(cid)
    town[cid] = 0
    vocation[cid] = 0
    destination[cid] = 0
    items[cid] = 0
end

local function onReleaseFocus(cid)
    town[cid] = nil
    vocation[cid] = nil
    destination[cid] = nil
    items[cid] = nil
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Everything looks good up until line 174
elseif npcHandler.topic[cid] == 4 then

Then it get's a bit blurry.

items[1] = {8602, 1}
If multiple people are talking to the npc at the same time, this will update with each of their answers.

cid = creatureid, which is different and unique for every player, which is why we use it to identify and distinguish the players from one another in the table.

So first, you'd want to create the index.
Lua:
elseif npcHandler.topic[cid] == 4 then
    items[cid] = {}

Then add items into it, kind of like what you were doing before.
So instead of
items[1] = {8602, 1}
use
items[cid][1] = {8602, 1}

You wont need to re-create the index when asking for the shield/spellbook, so just add those directly into the same table the same way.

And of course change your loop for giving the players the items, to account for the new index.

Lua:
for i = 1, #items do
    player:addItem(items[i][1], items[i][2])
end
Lua:
for i = 1, #items[cid] do
    player:addItem(items[cid][i][1], items[cid][i][2])
end

One last minor thing, is that you'll want to teleport the player as the Very last thing you do.
Otherwise it's possible that some of the functions / adding items won't happen, since the npc will lose focus of the player and clear the tables.
----

You're doing a good job. đź‘Ť
 
OP
aalqaq2

aalqaq2

Trying to help, but I'm not too good at it.
Joined
Apr 10, 2017
Messages
111
Solutions
3
Reaction score
8
I guess the custom Items are not being saved now? The NPC interaction is working fine, but the player is not given any of the items from the NPC interaction. I've tried moving the release focus to the end as you suggested and that didn't change anything. I'm sure it's an easy fix too. I'm just overlooking it, right? Would you mind looking at it again?

Console Log
Code:
Adding Backpack Items:
2120        1
2554        1
7620        5
7618        5
2160        1
5022        10
2789        100
Adding Custom Items:
God Fabled has logged out.

NPC Interaction Log
Code:
14:26 Testera [8]: hi
14:26 The Oracle: Testera, ARE YOU PREPARED TO FACE YOUR DESTINY?
14:26 Testera [8]: yes
14:26 The Oracle: IN WHICH TOWN DO YOU WANT TO LIVE: THAIS, CARLIN, VENORE, AB'DENRIEL, EDRON, YALAHAR, SVARGROND, FARMINE, ROSHAMUUL, LIBERTY BAY, PORT HOPE, ANKRAHMUN, DARASHIA, RATHLETON?
14:26 Testera [8]: thais
14:26 The Oracle: IN THAIS! AND WHAT PROFESSION HAVE YOU CHOSEN: KNIGHT, PALADIN, SORCERER, OR DRUID?
14:27 Testera [8]: druid
14:27 The Oracle: YOU WILL BE GIVEN A SNAKEBITE ROD. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE WEAPON?
14:27 Testera [8]: yes
14:27 The Oracle: WOULD YOU LIKE A JAGGED SWORD, STEEL AXE, DARAMIAN MACE?
14:27 Testera [8]: axe
14:27 The Oracle: WOULD YOU LIKE A SPELLBOOK OR A SHIELD?
14:27 Testera [8]: shield
14:27 The Oracle: YOU WILL RECEIVE A SHIELD! ARE YOU READY TO ENTER THE MAINLAND?!
14:27 Testera [8]: yes
14:27 The Oracle: SO BE IT!

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

local vocation = {}
local town = {}
local destination = {}
local items = {}

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

--Equipment Upon Arrival to Mainland
--{8601, 1}, {2439, 1}, {8602, 1}, {2175, 1} | steel axe, daramian mace, jagged sword, spellbook
local config = {
    [1] = { -- Sorcerer
            --Equipment: wand of vortex, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2190, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potions, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2525, 1}}
    },
    [2] = { -- Druid
            --Equipment: snakebite rod, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2182, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}}
    },
    [3] = { -- Paladin
            --Equipment: dwarven shield, 1 spear, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2389, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms, bow, 50 arrows
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2456, 1}, {2544, 50}}
    },
    [4] = { -- Knight
            --Equipment: dwarven shield, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5} ,{2160, 1}, {5022, 10}, {2789,100}}
    }
}
--End--

local function greetCallback(cid)
    local player = Player(cid)
    local level = player:getLevel()
    if level < 8 then
        npcHandler:say("CHILD! COME BACK WHEN YOU HAVE GROWN UP!", cid)
        return false
    elseif level > 9 then
        npcHandler:say(player:getName() .. ", I CAN'T LET YOU LEAVE - YOU ARE TOO STRONG ALREADY! YOU CAN ONLY LEAVE WITH LEVEL 9 OR LOWER.", cid)
        return false
    elseif player:getVocation():getId() > 0 then
        npcHandler:say("YOU ALREADY HAVE A VOCATION!", cid)
        return false
    end
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains(msg, "yes") and npcHandler.topic[cid] == 0 then
        npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}, {EDRON}, {YALAHAR}, {SVARGROND}, {FARMINE}, {ROSHAMUUL}, {LIBERTY BAY}, {PORT HOPE}, {ANKRAHMUN}, {DARASHIA}, {RATHLETON}?", cid)
        npcHandler.topic[cid] = 1
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "thais") then
            town[cid] = 2
            destination[cid] = Position(32369, 32241, 7)
            npcHandler:say("IN THAIS! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "carlin") then
            town[cid] = 4
            destination[cid] = Position(32360, 31782, 7)
            npcHandler:say("IN CARLIN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "venore") then
            town[cid] = 1
            destination[cid] = Position(32957, 32076, 7)
            npcHandler:say("IN VENORE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ab'dendriel") then
            town[cid] = 5
            destination[cid] = Position(32732, 31634, 7)
            npcHandler:say("IN AB'DENDRIEL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "edron") then
            town[cid] = 11
            destination[cid] = Position(33217, 31814, 8)
            npcHandler:say("IN EDRON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "yalahar") then
            town[cid] = 13
            destination[cid] = Position(32787, 31276, 7)
            npcHandler:say("IN YALAHAR! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "svargrond") then
            town[cid] = 12
            destination[cid] = Position(32212, 31132, 7)
            npcHandler:say("IN SVARGROND! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "farmine") then
            town[cid] = 14
            destination[cid] = Position(33023, 31525, 11)
            npcHandler:say("IN FARMINE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "roshamuul") then
            town[cid] = 29
            destination[cid] = Position(33513, 32363, 6)
            npcHandler:say("IN ROSHAMUUL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "liberty bay") then
            town[cid] = 7
            destination[cid] = Position(32317, 32826, 7)
            npcHandler:say("IN LIBERTY BAY! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "port hope") then
            town[cid] = 8
            destination[cid] = Position(32594, 32745, 7)
            npcHandler:say("IN PORT HOPE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ankrahmun") then
            town[cid] = 9
            destination[cid] = Position(33194, 32853, 8)
            npcHandler:say("IN ANKRAHMUN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "darashia") then
            town[cid] = 10
            destination[cid] = Position(33213, 32454, 1)
            npcHandler:say("IN DARASHIA! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "rathleton") then
            town[cid] = 33
            destination[cid] = Position(33594, 31899, 6)
            npcHandler:say("IN RATHLETON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        else
            npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}, {EDRON}, {YALAHAR}, {SVARGROND}, {FARMINE}, {ROSHAMUUL}, {LIBERTY BAY}, {PORT HOPE}, {ANKRAHMUN}, {DARASHIA}, {RATHLETON}?", cid)
        end
    elseif npcHandler.topic[cid] == 2 then
        if msgcontains(msg, "sorcerer") then
            npcHandler:say("YOU WILL BE GIVEN A WAND OF VORTEX. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 1
        elseif msgcontains(msg, "druid") then
            npcHandler:say("YOU WILL BE GIVEN A SNAKEBITE ROD. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 2
        elseif msgcontains(msg, "paladin") then
            npcHandler:say("YOU WILL BE GIVEN A BOW, ARROWS, AND A SPEAR. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 3
        elseif msgcontains(msg, "knight") then
            npcHandler:say("YOU WILL BE GIVEN A SWORD. WOULD YOU LIKE TO CHOOSE A DIFFERENT {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 4
        else
            npcHandler:say("{KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
        end
    elseif npcHandler.topic[cid] == 3 then
        cItems[cid] = {}
        if isInArray({"weapon", "yes"}, msg:lower()) then
            npcHandler:say("WOULD YOU LIKE A JAGGED {SWORD}, STEEL {AXE}, DARAMIAN {MACE}?", cid)
            npcHandler.topic[cid] = 4
        elseif msgcontains(msg, "no") then
            npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
            cItems[cid][1] = {2112, 0}
            if vocation[cid] == 1 or vocation[cid] == 2 then
                npcHandler:say("OKAY! WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                npcHandler.topic[cid] = 5
            elseif vocation[cid] == 3 or vocation[cid] == 4 then
                npcHandler:say("OKAY! ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                npcHandler.topic[cid] = 6
            else
                npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                npcHandler.topic[cid] = 0
                npcHandler:releaseFocus(cid)
            end
        else
            npcHandler:say("WOULD YOU LIKE TO CHOOSE A DIFFERENT {WEAPON}?", cid)
        end
    elseif npcHandler.topic[cid] == 4 then
        if msgcontains(msg, "sword") then
            npcHandler:say("YOU WILL RECEIVE A JAGGED SWORD!", cid)
            cItems[cid][1] = {8602, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("OKAY! WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("OKAY! ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                    npcHandler:releaseFocus(cid)
                end
        elseif msgcontains(msg, "axe") then
            npcHandler:say("YOU WILL RECEIVE A STEEL AXE!", cid)
            cItems[cid][1] = {8601, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                    npcHandler:releaseFocus(cid)
                end
        elseif msgcontains(msg, "mace") then
            npcHandler:say("YOU WILL RECEIVE A DARAMIAN MACE!", cid)
            cItems[cid][1] = {2439, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                    npcHandler:releaseFocus(cid)
                end
        else
            npcHandler:say("WELL?! WOULD YOU LIKE A JAGGED {SWORD}, STEEL {AXE}, DARAMIAN {MACE}?", cid)
        end
    elseif npcHandler.topic[cid] == 5 then
        if msgcontains(msg, "spellbook") then
            cItems[cid][2] = {2175, 1}
            npcHandler:say("YOU WILL RECEIVE A SPELLBOOK! ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 6
        elseif msgcontains(msg, "shield") then
            cItems[cid][2] = {2525, 1}
            npcHandler:say("YOU WILL RECEIVE A SHIELD! ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 6
        else
            npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
        end
    elseif npcHandler.topic[cid] == 6 then
        if msgcontains(msg, "yes") then
            local player = Player(cid)
            npcHandler:say("SO BE IT!", cid)
            player:setVocation(Vocation(vocation[cid]))
            player:setTown(Town(town[cid]))
            local destination = destination[cid]
            npcHandler:releaseFocus(cid)
            player:teleportTo(destination)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            destination:sendMagicEffect(CONST_ME_TELEPORT)
           
            --------------------------------------
            --Equipment Upon Arrival to Mainland--
            --------------------------------------
           
            local firstItems = {2480, 2464, 2468, 2643, 2530, 2383}
            local player = Player(cid)
           
            -- Remove rook items from player inventory
            for i = 1, #firstItems do
                player:removeItem(firstItems[i], 1)
            end
               
            local player = Player(cid)
            local targetVocation = config[player:getVocation():getId()]
               
            if not targetVocation then
            return true
            end
           
            -- Add Mainland items to player inventory
            for i = 1, #targetVocation.items do
                player:addItem(targetVocation.items[i][1], targetVocation.items[i][2])
            end
           
            local backpack = player:addItem(1988)
           
            if not backpack then
            return true
            end
           
            -- Add Mainland items to player backpack
            print("Adding Backpack Items:\n")
            for i = 1, #targetVocation.container do
                print(targetVocation.container[i][1], targetVocation.container[i][2])
                backpack:addItem(targetVocation.container[i][1], targetVocation.container[i][2])
            end
           
            -- Add custom items to player inventory
            print("Adding Custom Items:\n")
            for i = 1, #cItems do
                print(cItems[cid][i][1], cItems[cid][i][2])
               backpack:addItem(cItems[cid][i][1], cItems[cid][i][2])
            end
               
            --------------------------------------
            ----------End Custom Section----------
            --------------------------------------
        else
            npcHandler:say("COME BACK WHEN YOU ARE READY CHILD!!!", cid)
            npcHandler.topic[cid] = 0
            npcHandler:releaseFocus(cid)
        end
    end
    return true
end

local function onAddFocus(cid)
    town[cid] = 0
    vocation[cid] = 0
    destination[cid] = 0
end

local function onReleaseFocus(cid)
    town[cid] = nil
    vocation[cid] = nil
    destination[cid] = nil
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Post automatically merged:

Disregard that previous post. I found out the issue is in the for loop and changed it. It's only two items so I took out the loop and explicitly added the items by index. Why isn't that working though? I can't remember the other variant of the for loop size.
Lua:
            for i = 1, #cItems do
                print(cItems[cid][i][1], cItems[cid][i][2])
               backpack:addItem(cItems[cid][i][1], cItems[cid][i][2])
            end,
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,522
Solutions
378
Reaction score
3,638
I guess the custom Items are not being saved now? The NPC interaction is working fine, but the player is not given any of the items from the NPC interaction. I've tried moving the release focus to the end as you suggested and that didn't change anything. I'm sure it's an easy fix too. I'm just overlooking it, right? Would you mind looking at it again?

Console Log
Code:
Adding Backpack Items:
2120        1
2554        1
7620        5
7618        5
2160        1
5022        10
2789        100
Adding Custom Items:
God Fabled has logged out.

NPC Interaction Log
Code:
14:26 Testera [8]: hi
14:26 The Oracle: Testera, ARE YOU PREPARED TO FACE YOUR DESTINY?
14:26 Testera [8]: yes
14:26 The Oracle: IN WHICH TOWN DO YOU WANT TO LIVE: THAIS, CARLIN, VENORE, AB'DENRIEL, EDRON, YALAHAR, SVARGROND, FARMINE, ROSHAMUUL, LIBERTY BAY, PORT HOPE, ANKRAHMUN, DARASHIA, RATHLETON?
14:26 Testera [8]: thais
14:26 The Oracle: IN THAIS! AND WHAT PROFESSION HAVE YOU CHOSEN: KNIGHT, PALADIN, SORCERER, OR DRUID?
14:27 Testera [8]: druid
14:27 The Oracle: YOU WILL BE GIVEN A SNAKEBITE ROD. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE WEAPON?
14:27 Testera [8]: yes
14:27 The Oracle: WOULD YOU LIKE A JAGGED SWORD, STEEL AXE, DARAMIAN MACE?
14:27 Testera [8]: axe
14:27 The Oracle: WOULD YOU LIKE A SPELLBOOK OR A SHIELD?
14:27 Testera [8]: shield
14:27 The Oracle: YOU WILL RECEIVE A SHIELD! ARE YOU READY TO ENTER THE MAINLAND?!
14:27 Testera [8]: yes
14:27 The Oracle: SO BE IT!

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

local vocation = {}
local town = {}
local destination = {}
local items = {}

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

--Equipment Upon Arrival to Mainland
--{8601, 1}, {2439, 1}, {8602, 1}, {2175, 1} | steel axe, daramian mace, jagged sword, spellbook
local config = {
    [1] = { -- Sorcerer
            --Equipment: wand of vortex, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2190, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potions, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2525, 1}}
    },
    [2] = { -- Druid
            --Equipment: snakebite rod, spirit cloak, plate legs, soldier helmet, scarf, leather boots
            items = {{2182, 1}, {8870, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}}
    },
    [3] = { -- Paladin
            --Equipment: dwarven shield, 1 spear, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2389, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms, bow, 50 arrows
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5}, {2160, 1}, {5022, 10}, {2789,100}, {2456, 1}, {2544, 50}}
    },
    [4] = { -- Knight
            --Equipment: dwarven shield, scale armor, plate legs, soldier helmet, scarf, leather boots
            items = {{2525, 1}, {2483, 1}, {2647, 1}, {2481, 1}, {2661, 1}, {2643, 1}},
            --Backpack: rope, shovel, 5 mana potion, 5 health potion, 1 crystal coin, 10 orichalcum pearls, 100 brown mushrooms
            container = {{2120, 1}, {2554, 1}, {7620, 5}, {7618, 5} ,{2160, 1}, {5022, 10}, {2789,100}}
    }
}
--End--

local function greetCallback(cid)
    local player = Player(cid)
    local level = player:getLevel()
    if level < 8 then
        npcHandler:say("CHILD! COME BACK WHEN YOU HAVE GROWN UP!", cid)
        return false
    elseif level > 9 then
        npcHandler:say(player:getName() .. ", I CAN'T LET YOU LEAVE - YOU ARE TOO STRONG ALREADY! YOU CAN ONLY LEAVE WITH LEVEL 9 OR LOWER.", cid)
        return false
    elseif player:getVocation():getId() > 0 then
        npcHandler:say("YOU ALREADY HAVE A VOCATION!", cid)
        return false
    end
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains(msg, "yes") and npcHandler.topic[cid] == 0 then
        npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}, {EDRON}, {YALAHAR}, {SVARGROND}, {FARMINE}, {ROSHAMUUL}, {LIBERTY BAY}, {PORT HOPE}, {ANKRAHMUN}, {DARASHIA}, {RATHLETON}?", cid)
        npcHandler.topic[cid] = 1
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "thais") then
            town[cid] = 2
            destination[cid] = Position(32369, 32241, 7)
            npcHandler:say("IN THAIS! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "carlin") then
            town[cid] = 4
            destination[cid] = Position(32360, 31782, 7)
            npcHandler:say("IN CARLIN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "venore") then
            town[cid] = 1
            destination[cid] = Position(32957, 32076, 7)
            npcHandler:say("IN VENORE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ab'dendriel") then
            town[cid] = 5
            destination[cid] = Position(32732, 31634, 7)
            npcHandler:say("IN AB'DENDRIEL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "edron") then
            town[cid] = 11
            destination[cid] = Position(33217, 31814, 8)
            npcHandler:say("IN EDRON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "yalahar") then
            town[cid] = 13
            destination[cid] = Position(32787, 31276, 7)
            npcHandler:say("IN YALAHAR! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "svargrond") then
            town[cid] = 12
            destination[cid] = Position(32212, 31132, 7)
            npcHandler:say("IN SVARGROND! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "farmine") then
            town[cid] = 14
            destination[cid] = Position(33023, 31525, 11)
            npcHandler:say("IN FARMINE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "roshamuul") then
            town[cid] = 29
            destination[cid] = Position(33513, 32363, 6)
            npcHandler:say("IN ROSHAMUUL! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "liberty bay") then
            town[cid] = 7
            destination[cid] = Position(32317, 32826, 7)
            npcHandler:say("IN LIBERTY BAY! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "port hope") then
            town[cid] = 8
            destination[cid] = Position(32594, 32745, 7)
            npcHandler:say("IN PORT HOPE! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "ankrahmun") then
            town[cid] = 9
            destination[cid] = Position(33194, 32853, 8)
            npcHandler:say("IN ANKRAHMUN! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "darashia") then
            town[cid] = 10
            destination[cid] = Position(33213, 32454, 1)
            npcHandler:say("IN DARASHIA! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        elseif msgcontains(msg, "rathleton") then
            town[cid] = 33
            destination[cid] = Position(33594, 31899, 6)
            npcHandler:say("IN RATHLETON! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
            npcHandler.topic[cid] = 2
        else
            npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {THAIS}, {CARLIN}, {VENORE}, {AB'DENRIEL}, {EDRON}, {YALAHAR}, {SVARGROND}, {FARMINE}, {ROSHAMUUL}, {LIBERTY BAY}, {PORT HOPE}, {ANKRAHMUN}, {DARASHIA}, {RATHLETON}?", cid)
        end
    elseif npcHandler.topic[cid] == 2 then
        if msgcontains(msg, "sorcerer") then
            npcHandler:say("YOU WILL BE GIVEN A WAND OF VORTEX. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 1
        elseif msgcontains(msg, "druid") then
            npcHandler:say("YOU WILL BE GIVEN A SNAKEBITE ROD. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 2
        elseif msgcontains(msg, "paladin") then
            npcHandler:say("YOU WILL BE GIVEN A BOW, ARROWS, AND A SPEAR. WOULD YOU LIKE TO CHOOSE AN ADDITIONAL MELEE {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 3
        elseif msgcontains(msg, "knight") then
            npcHandler:say("YOU WILL BE GIVEN A SWORD. WOULD YOU LIKE TO CHOOSE A DIFFERENT {WEAPON}?", cid)
            npcHandler.topic[cid] = 3
            vocation[cid] = 4
        else
            npcHandler:say("{KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid)
        end
    elseif npcHandler.topic[cid] == 3 then
        cItems[cid] = {}
        if isInArray({"weapon", "yes"}, msg:lower()) then
            npcHandler:say("WOULD YOU LIKE A JAGGED {SWORD}, STEEL {AXE}, DARAMIAN {MACE}?", cid)
            npcHandler.topic[cid] = 4
        elseif msgcontains(msg, "no") then
            npcHandler:say("YOU WILL NOT RECEIVE A SECONDARY WEAPON!", cid)
            cItems[cid][1] = {2112, 0}
            if vocation[cid] == 1 or vocation[cid] == 2 then
                npcHandler:say("OKAY! WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                npcHandler.topic[cid] = 5
            elseif vocation[cid] == 3 or vocation[cid] == 4 then
                npcHandler:say("OKAY! ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                npcHandler.topic[cid] = 6
            else
                npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                npcHandler.topic[cid] = 0
                npcHandler:releaseFocus(cid)
            end
        else
            npcHandler:say("WOULD YOU LIKE TO CHOOSE A DIFFERENT {WEAPON}?", cid)
        end
    elseif npcHandler.topic[cid] == 4 then
        if msgcontains(msg, "sword") then
            npcHandler:say("YOU WILL RECEIVE A JAGGED SWORD!", cid)
            cItems[cid][1] = {8602, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("OKAY! WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("OKAY! ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                    npcHandler:releaseFocus(cid)
                end
        elseif msgcontains(msg, "axe") then
            npcHandler:say("YOU WILL RECEIVE A STEEL AXE!", cid)
            cItems[cid][1] = {8601, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                    npcHandler:releaseFocus(cid)
                end
        elseif msgcontains(msg, "mace") then
            npcHandler:say("YOU WILL RECEIVE A DARAMIAN MACE!", cid)
            cItems[cid][1] = {2439, 1}
                if vocation[cid] == 1 or vocation[cid] == 2 then
                    npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
                    npcHandler.topic[cid] = 5
                elseif vocation[cid] == 3 or vocation[cid] == 4 then
                    npcHandler:say("ARE YOU READY TO ENTER THE MAINLAND?!", cid)
                    npcHandler.topic[cid] = 6
                else
                    npcHandler:say("COME BACK WHEN YOU KNOW WHAT YOU WANT!", cid)
                    npcHandler.topic[cid] = 0
                    npcHandler:releaseFocus(cid)
                end
        else
            npcHandler:say("WELL?! WOULD YOU LIKE A JAGGED {SWORD}, STEEL {AXE}, DARAMIAN {MACE}?", cid)
        end
    elseif npcHandler.topic[cid] == 5 then
        if msgcontains(msg, "spellbook") then
            cItems[cid][2] = {2175, 1}
            npcHandler:say("YOU WILL RECEIVE A SPELLBOOK! ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 6
        elseif msgcontains(msg, "shield") then
            cItems[cid][2] = {2525, 1}
            npcHandler:say("YOU WILL RECEIVE A SHIELD! ARE YOU READY TO ENTER THE MAINLAND?!", cid)
            npcHandler.topic[cid] = 6
        else
            npcHandler:say("WOULD YOU LIKE A {SPELLBOOK} OR A {SHIELD}?", cid)
        end
    elseif npcHandler.topic[cid] == 6 then
        if msgcontains(msg, "yes") then
            local player = Player(cid)
            npcHandler:say("SO BE IT!", cid)
            player:setVocation(Vocation(vocation[cid]))
            player:setTown(Town(town[cid]))
            local destination = destination[cid]
            npcHandler:releaseFocus(cid)
            player:teleportTo(destination)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            destination:sendMagicEffect(CONST_ME_TELEPORT)
          
            --------------------------------------
            --Equipment Upon Arrival to Mainland--
            --------------------------------------
          
            local firstItems = {2480, 2464, 2468, 2643, 2530, 2383}
            local player = Player(cid)
          
            -- Remove rook items from player inventory
            for i = 1, #firstItems do
                player:removeItem(firstItems[i], 1)
            end
              
            local player = Player(cid)
            local targetVocation = config[player:getVocation():getId()]
              
            if not targetVocation then
            return true
            end
          
            -- Add Mainland items to player inventory
            for i = 1, #targetVocation.items do
                player:addItem(targetVocation.items[i][1], targetVocation.items[i][2])
            end
          
            local backpack = player:addItem(1988)
          
            if not backpack then
            return true
            end
          
            -- Add Mainland items to player backpack
            print("Adding Backpack Items:\n")
            for i = 1, #targetVocation.container do
                print(targetVocation.container[i][1], targetVocation.container[i][2])
                backpack:addItem(targetVocation.container[i][1], targetVocation.container[i][2])
            end
          
            -- Add custom items to player inventory
            print("Adding Custom Items:\n")
            for i = 1, #cItems do
                print(cItems[cid][i][1], cItems[cid][i][2])
               backpack:addItem(cItems[cid][i][1], cItems[cid][i][2])
            end
              
            --------------------------------------
            ----------End Custom Section----------
            --------------------------------------
        else
            npcHandler:say("COME BACK WHEN YOU ARE READY CHILD!!!", cid)
            npcHandler.topic[cid] = 0
            npcHandler:releaseFocus(cid)
        end
    end
    return true
end

local function onAddFocus(cid)
    town[cid] = 0
    vocation[cid] = 0
    destination[cid] = 0
end

local function onReleaseFocus(cid)
    town[cid] = nil
    vocation[cid] = nil
    destination[cid] = nil
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Post automatically merged:

Disregard that previous post. I found out the issue is in the for loop and changed it. It's only two items so I took out the loop and explicitly added the items by index. Why isn't that working though? I can't remember the other variant of the for loop size.
Lua:
            for i = 1, #cItems do
                print(cItems[cid][i][1], cItems[cid][i][2])
               backpack:addItem(cItems[cid][i][1], cItems[cid][i][2])
            end,
I would definitely suggest changing your items table to be cItems.. and making sure to clear it out inside of addFocus and ReleaseFocus.

It's not clear what your current issue is, though.

Can you be a little more explicit?
 
OP
aalqaq2

aalqaq2

Trying to help, but I'm not too good at it.
Joined
Apr 10, 2017
Messages
111
Solutions
3
Reaction score
8
I actually did change it to cItems and both clear and initialize it. Lol

This doesn't work
Lua:
for i = 1, #cItems do
     backpack:addItem(cItems[cid][i][1], cItems[cid][i][2])
end
This does:
Lua:
backpack:addItem(cItems[cid][1][1], cItems[cid][1][2])
backpack:addItem(cItems[cid][2][1], cItems[cid][2][2])

Something is wrong with the for loop but I'm not sure what it is
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,522
Solutions
378
Reaction score
3,638
I actually did change it to cItems and both clear and initialize it. Lol

This doesn't work
Lua:
for i = 1, #cItems do
     backpack:addItem(cItems[cid][i][1], cItems[cid][i][2])
end
This does:
Lua:
backpack:addItem(cItems[cid][1][1], cItems[cid][1][2])
backpack:addItem(cItems[cid][2][1], cItems[cid][2][2])

Something is wrong with the for loop but I'm not sure what it is
change to

Lua:
for i = 1, #cItems[cid] do
     backpack:addItem(cItems[cid][i][1], cItems[cid][i][2])
end
 
Top