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

Lua NPC respond to conversation but not to trading? (Avesta)

auda

Advanced OT User
Joined
Jun 29, 2014
Messages
273
Reaction score
233
Location
Sweden
This NPC system is based on Ferrus 7.40 Avesta.
The confusing part is that my other NPC which sell blank runes and fluids based on the exact same script, but with other items to sell and other conversations. Can anyone see why he does this? Thanks!

Code:
<?xml version="1.0"?>
<npc name="Conny" script="conny.lua" walkinterval="2000" floorchange="0" idleinterval="30">
    <health now="100" max="100"/>
    <look type="129" head="79" body="76" legs="58" feet="20"/>
</npc>

Code:
_state = 0
_count = 0
_index = 0
_delay = 1000

items = {}
items[0] = {name = 'bag', id = 1987, subtype = -1, sell = 5}
items[1] = {name = 'backpack', id = 1988, subtype = -1, sell = 15}
items[2] = {name = 'fishing rod', id = 2580, subtype = -1, sell = 35}
items[3] = {name = 'rope', id = 2120, subtype = -1, sell = 40}
items[4] = {name = 'shovel', id = 2554, subtype = -1, sell= 55}
items[5] = {name = 'pick', id = 2553, subtype = -1, sell = 70}
items[6] = {name = 'machete', id = 2420, subtype = -1, sell = 55}
items[7] = {name = 'scythe', id = 2550, subtype = -1, sell = 20}
items[8] = {name = 'basket', id = 1989, subtype = -1, sell = 10}
items[9] = {name = 'torch', id = 2050, subtype = -1, sell = 3}

function getNext()
    nextPlayer = getQueuedPlayer()
    if (nextPlayer ~= nil) then
        if (getDistanceToCreature(nextPlayer) <= 10) then
            updateNpcIdle()
            setNpcFocus(nextPlayer)
            greet(nextPlayer, _delay * 3)
            return
        else
            getNext()
        end
    end


    setNpcFocus(0)
    resetNpcIdle()
end

local function onActionItem(action)
    if ((action == 'buy' and items[_index].sell == -1) or
        (action == 'sell' and items[_index].buy == -1)) then
        return
    end
   
    amount = ''
    suffix = ''
    plural = 'a'
   
    if (_count > 1) then
        amount = ' ' .. tostring(_count)
        suffix = 's'
        plural = ''
    end
   
    cost = items[_index].buy
    if (action == 'buy') then
        cost = items[_index].sell
    end
   
    selfSay('Do you want to ' .. action .. ' ' .. plural .. amount .. ' ' .. items[_index].name .. suffix .. ' for ' .. cost .. ' gold?')
end

function _selfSay(message)
    selfSay(message, _delay)
    updateNpcIdle()
end

local function greet(cid, delay)
    selfSay('Greetings, ' .. getCreatureName(cid) .. '.', delay)
end

function onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    if (getNpcFocus() == cid) then
        selfSay('See you.', _delay)
        getNext()
    else
        unqueuePlayer(cid)
    end
end

function onCreatureMove(cid, oldPos, newPos)
    if (getNpcFocus() == cid) then
        faceCreature(cid)
    end
end

function onCreatureSay(cid, type, msg)
    if (getNpcFocus() == 0) then
        if ((msgcontains(msg, 'hi') or msgcontains(msg, 'hello')) and getDistanceToCreature(cid) <= 4) then
            updateNpcIdle()
            setNpcFocus(cid)
            greet(cid, _delay)
        end
       
    elseif (getNpcFocus() ~= cid) then
        if ((msgcontains(msg, 'hi') or msgcontains(msg, 'hello')) and getDistanceToCreature(cid) <= 4) then
            selfSay('Wait for your turn, ' .. getCreatureName(cid) .. '.', _delay)
            queuePlayer(cid)
        end
       
    else
        if (msgcontains(msg, 'bye')) then
            selfSay('Bye!', _delay)
            getNext()
       
        elseif (msgcontains(msg, 'conny')) then
            _selfSay('My name is Conny and I recently moved here from Priory.')
       
        elseif (msgcontains(msg, 'priory')) then
            _selfSay('A dangerous continent. For a toolsman, that is.')
       
        elseif (msgcontains(msg, 'king') or msgcontains(msg, 'calvin')) then
            _selfSay('Such welcoming!')
       
        elseif (msgcontains(msg, 'meadowfield')) then
            _selfSay('Seems to be peaceful.')
       
        elseif (msgcontains(msg, 'offer') or msgcontains(msg, 'goods')) then
            _selfSay('I\'m offering the finest tools!')
           
        elseif (_state == 1) then
            if (msgcontains(msg, 'yes')) then
                if (doPlayerRemoveMoney(cid, items[_index].sell * _count) == 1) then
                    for i = 1, _count do
                        doPlayerAddItem(cid, items[_index].id, items[_index].subtype)
                    end
               
                    selfSay('Thank you!', _delay)
                else
                    selfSay('You\'re welcome whenever you can afford to it.', _delay)
                end
               
                updateNpcIdle()
            else
                selfSay('Hmm.', _delay)
            end
           
            _state = 0
           
        elseif (_state == 2) then
            if (msgcontains(msg, 'yes')) then
                if (doPlayerRemoveItem(cid, items[_index].id, _count, items[_index].subtype) == 1) then
                    doPlayerAddMoney(cid, items[_index].buy * _count)
                    selfSay('Great! Here is your money.')
                else
                    if (count > 1) then
                        selfSay('Sorry, you do not have so many.', _delay)
                    else
                        selfSay('Sorry, you do not have one.', _delay)
                    end
                end
               
                updateNpcIdle()
            else
                selfSay('Maybe another time?', _delay)
            end
       
            _state = 0
           
        else
            for n = 0, table.getn(items) do
                if (msgcontains(msg, items[n].name) or msgcontains(msg, items[n].name .. "s")) then
                    _count = getCount(msg)
                    _index = n
                   
                    if (msgcontains(msg, 'sell')) then
                        onActionItem('sell')
                        _state = 2
                    else
                        onActionItem('buy')
                        _state = 1
                    end
                   
                    updateNpcIdle()
                    break
                end
            end
        end
    end
end

function onThink()
    if (getNpcFocus() ~= 0) then
        if (isNpcIdle() or getDistanceToCreature(getNpcFocus()) > 4) then
            selfSay('Bye!', _delay)
            getNext()
        end
    end
end
 
Looked through some NPCs in Avesta 7.4 and this should work.
Code:
items = {}
items[0] = {name = 'bag', id = 1987, subtype = -1, sell = 5, buy = -1}
items[1] = {name = 'backpack', id = 1988, subtype = -1, sell = 15, buy = -1}
items[2] = {name = 'fishing rod', id = 2580, subtype = -1, sell = 35, buy = -1}
items[3] = {name = 'rope', id = 2120, subtype = -1, sell = 40, buy = -1}
items[4] = {name = 'shovel', id = 2554, subtype = -1, sell= 55, buy = -1}
items[5] = {name = 'pick', id = 2553, subtype = -1, sell = 70, buy = -1}
items[6] = {name = 'machete', id = 2420, subtype = -1, sell = 55, buy = -1}
items[7] = {name = 'scythe', id = 2550, subtype = -1, sell = 20, buy = -1}
items[8] = {name = 'basket', id = 1989, subtype = -1, sell = 10, buy = -1}
items[9] = {name = 'torch', id = 2050, subtype = -1, sell = 3, buy = -1}
 
I used your code and inserted it into my NPC. What really confuses me is that I ask to buy for a shovel - doesn't respond. But when I ask to buy a mana fluid, which he should not sell - HE SELL it anyways. I copied the script from my magic NPC, but do have changed everything and the I've connected my npcs to separate scripts, so no bugs there...wtf.png
 
Back
Top