I got several issues with my NPC and the system Ferrus wrote (or added).
ICARUS:
CONNY:
[/CODE]
ICARUS WITH CONNY CONNY WITH ICARUS CONNY WITH ICARUS CONNY WITHOUT ICARUS
- NPC Icarus is supposed to sell mana & life fluids as well as blank runes.
- NPC Conny is supposed to sell tools including bags and backpacks.
- NPC Icarus work almost perfectly, except that he doesn't count when trying to buy several items at once. For example he replies after you told him "Buy 2 mana fluids.". He simply replies "Do you wish to buy 2 mana fluids for 50 gold coins?", when it's actually 50 GP each. You pay 100 GP but he keeps saying the standard price per one item.
- NPC Conny works definately perfecly... when NPC Icarus isn't added in the game.
ICARUS:
Code:
_state = 0
_count = 0
_index = 0
_delay = 1500
items = {}
items[0] = {name = 'blank rune', id = 2260, subtype = -1, sell = 10, buy = -1}
items[1] = {name = 'mana fluid', id = 2006, subtype = 7, sell = 50, buy = -1}
items[2] = {name = 'life fluid', id = 2006, subtype = 10, sell = 45, buy = -1}
items[3] = {name = 'vial', id = 2006, subtype =-1, sell = -1, buy = 5}
function getNext()
nextPlayer = getQueuedPlayer()
if (nextPlayer ~= nil) then
if (getDistanceToCreature(nextPlayer) <= 0) 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('Welcome ' .. 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('Just wait, ' .. getCreatureName(cid) .. '.', _delay)
queuePlayer(cid)
end
else
if (msgcontains(msg, 'bye')) then
selfSay('See you.', _delay)
getNext()
elseif (msgcontains(msg, 'name')) then
_selfSay('I am Icarus')
elseif (msgcontains(msg, 'job')) then
_selfSay('I study the art of spellcasting and conjuring.')
elseif (msgcontains(msg, 'king') or msgcontains(msg, 'calvin')) then
_selfSay('I was kicked out of the city castle by Calvin himself for one slight miscalculation!')
elseif (msgcontains(msg, 'meadowfield')) then
_selfSay('Hmpf!')
elseif (msgcontains(msg, 'offer') or msgcontains(msg, 'goods')) then
_selfSay('I\'m selling runes and fluids.')
elseif (msgcontains(msg, 'rune') and not(msgcontains(msg, 'blank'))) then
_selfSay('I only sell blank runes, for the sake of security.')
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('Come back down here when you have money.', _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('Ok. 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('Perhaps 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('See you.', _delay)
getNext()
end
end
end
CONNY:
Code:
_state = 0
_count = 0
_index = 0
_delay = 1500
items = {}
items[0] = {name = 'bag', id = 1987, sell = 5, buy = -1}
items[1] = {name = 'backpack', id = 1988, sell = 15, buy = -1}
items[2] = {name = 'fishing rod', id = 2580, sell = 35, buy = -1}
items[3] = {name = 'rope', id = 2120, sell = 40, buy = -1}
items[4] = {name = 'shovel', id = 2554, sell= 55, buy = -1}
items[5] = {name = 'pick', id = 2553, sell = 70, buy = -1}
items[6] = {name = 'machete', id = 2420, sell = 55, buy = -1}
items[7] = {name = 'scythe', id = 2550, sell = 20, buy = -1}
items[8] = {name = 'basket', id = 1989, sell = 10, buy = -1}
items[9] = {name = 'torch', id = 2050, sell = 3, buy = -1}
function getNext()
nextPlayer = getQueuedPlayer()
if (nextPlayer ~= nil) then
if (getDistanceToCreature(nextPlayer) <= 0) 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('You have to wait, ' .. getCreatureName(cid) .. '.', _delay)
queuePlayer(cid)
end
else
if (msgcontains(msg, 'bye')) then
selfSay('Goodbye.', _delay)
getNext()
elseif (msgcontains(msg, 'conny')) then
_selfSay('Conny here.')
elseif (msgcontains(msg, 'where did you come from')) then
_selfSay('I entered these city gates a few weeks ago. Priory is the past.')
elseif (msgcontains(msg, 'priory')) then
_selfSay('A dangerous place. For a toolsman, that is.')
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('Come back when you have enough money.', _delay)
end
updateNpcIdle()
else
selfSay('Hmm, next time.', _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('Ok. 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 next 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('See you.', _delay)
getNext()
end
end
end
ICARUS WITH CONNY CONNY WITH ICARUS CONNY WITH ICARUS CONNY WITHOUT ICARUS
Last edited by a moderator: