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

Solved NPC doesn't cooperate while trying to sell (Avesta)

auda

Advanced OT User
Joined
Jun 29, 2014
Messages
273
Reaction score
233
Location
Sweden
My NPCs aren't stable at most of the time - and a few major problems I get and cannot solve is that when trying to sell and SOMETIMES tries to buy it ends up like this. I'm using Avesta 0.6.5.

NPC Script: (I've shortened it a bit due to 1000 letter cap.)
Code:
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('You have to wait, ' .. getCreatureName(cid) .. '.', _delay)
                        queuePlayer(cid)
                end
             
        else
                if (msgcontains(msg, 'bye')) then
                        selfSay('Bye.', _delay)
                        getNext()
             
                elseif (msgcontains(msg, 'otto')) then
                        _selfSay('What do you want?')
                elseif (msgcontains(msg, 'what do you sell')) then
                        _selfSay('I am the only blacksmith left and I smite every type of equipment and a lot of weapons.')
                elseif (msgcontains(msg, 'meadowfield')) then
                        _selfSay('Been here for as long as I can remember.')
                                             
                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('Here you are.', _delay)
                                else
                                        selfSay('Don\'t stumble in here without money.', _delay)
                                end
                             
                                updateNpcIdle()
                        elseif (msgcontains(msg, 'no')) then
                                selfSay('Maybe next time.', _delay)
                        else
                                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()
                                end
                        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 gold.')
                                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()
                        elseif (msgcontains(msg, 'no')) then
                                selfSay('Maybe next time.', _delay)
                        else
                                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()
                                end
                        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('See you.', _delay)
                        getNext()
                end
        end
end

error1.png
error2.png

And while trying to buy
error4.png
error3.png
Thanks.

Edit:
To make it a bit easier. if (count > 1) then is line 178
Code:
                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 gold.')
                                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
 
I'm not an expert, but

Code:
if (count > 1) then

Shouldn't it be
Code:
if (_count > 1) then

Oh my god, thanks guiismiti. I've made progress thanks to that, but a problem I stumble upon now is that the NPC keep saying that I don't have the certain item I do have and try to sell, will work on it. Thanks bud!
 
Back
Top