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.)
And while trying to buy
Thanks.
Edit:
To make it a bit easier. if (count > 1) then is line 178
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
And while trying to buy
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