NPC X:
Kod:
_state = 0
_count = 0
_index = 0
_delay = 500
items = {}
--runes
items[0] = {name = 'aol', id = 2173, subtype = -1, sell = 10000, buy = 0}
items[1] = {name = 'scarf', id = 2661, subtype = -1, sell = 1000, buy = 0}
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 getNext()
nextPlayer = getQueuedPlayer()
if (nextPlayer ~= nil) then
if (getDistanceToCreature(nextPlayer) <= 4) then
updateNpcIdle()
setNpcFocus(nextPlayer)
selfSay('Hi there ' .. getCreatureName(nextPlayer) .. '.', _delay * 3)
return
else
getNext()
end
end
setNpcFocus(0)
resetNpcIdle()
end
function _selfSay(message)
selfSay(message, _delay)
updateNpcIdle()
end
--
function onCreatureAppear(cid)
return true
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)
if (oldPos.z ~= newPos.z or getDistanceToCreature(cid) > 4) then
selfSay('See you.', _delay)
getNext()
end
else
if (oldPos.z ~= newPos.z or getDistanceToCreature(cid) > 4) then
unqueuePlayer(cid)
end
end
return true
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)
selfSay('Welcome ' .. getCreatureName(cid) .. ' in the name of the gods, pilgrim', _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
elseif (msgcontains(msg, 'offer')) then
_selfSay('I sell aol (10k) and scarf(1k).')
_state = 1
else
if (msgcontains(msg, 'bye')) then
selfSay('Good bye ' ..getCreatureName(cid).. '.May the gods be with you to guard and guide you, my child!', _delay)
getNext()
elseif (_state == 1) then
if (msgcontains(msg, 'yes')) then
if(doPlayerRemoveMoney(cid, items[_index].sell*_count)) then
for i = 1, _count do
if items[_index].subtype < 1 then
costam = 1
else
costam = items[_index].subtype
end
doPlayerAddItem(cid, items[_index].id, costam)
end
selfSay('Here you are.', _delay)
else
selfSay('Come back, when you have enough money.', _delay)
end
updateNpcIdle()
else
selfSay('Hmm, but next time.', _delay)
end
_state = 0
elseif (_state == 2) then
if (msgcontains(msg, 'yes')) then
if (doPlayerRemoveItem(cid, items[_index].id, _count)) then
local mon = items[_index].buy *_count
doPlayerAddMoney(cid, mon)
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, 'buy')) then
onActionItem('buy')
_state = 1
else
_state = 0
end
updateNpcIdle()
break
end
end
end
end
return true
end
function onThink()
if (getNpcFocus() ~= 0) then
if (isNpcIdle()) then
selfSay('See you.', _delay)
getNext()
end
end
return true
end
Kod:
_state = 0
_count = 0
_index = 0
_delay = 500
items = {}
--helmets
items[0] = {name = 'royal helmet', id = 2498, subtype = -1, sell = 0, buy = 30000}
items[1] = {name = 'warrior helmet', id = 2475, subtype = -1, sell = 0, buy = 3000}
items[2] = {name = 'crusader helmet', id = 2497, subtype = -1, sell = 0, buy = 3500}
items[3] = {name = 'crown helmet', id = 2491, subtype = -1, sell = 0, buy = 2000}
items[4] = {name = 'devil helmet', id = 2462, subtype = -1, sell = 0, buy = 1500}
items[5] = {name = 'mystic turban', id = 2663, subtype = -1, sell = 0, buy = 500}
items[6] = {name = 'chain helmet', id = 2458, subtype = -1, sell = 0, buy = 35}
items[7] = {name = 'iron helmet', id = 2459, subtype = -1, sell = 0, buy = 30}
--boots
items[8] = {name = 'boots of haste', id = 2195, subtype = -1, sell = 0, buy = 20000}
items[9] = {name = 'steel boots', id = 2645, subtype = -1, sell = 0, buy = 10000}
--armor
items[10] = {name = 'mpa', id = 2472, subtype = -1, sell = 0, buy = 80000}
items[11] = {name = 'magic plate armor', id = 2472, subtype = -1, sell = 0, buy = 80000}
items[12] = {name = 'dragon scale mail', id = 2492, subtype = -1, sell = 0, buy = 50000}
items[13] = {name = 'dsm', id = 2492, subtype = -1, sell = 0, buy = 50000}
items[14] = {name = 'golden armor', id = 2466, subtype = -1, sell = 0, buy = 25000}
items[15] = {name = 'crown armor', id = 2487, subtype = -1, sell = 0, buy = 5000}
items[16] = {name = 'knight armor', id = 2476, subtype = -1, sell = 0, buy = 3000}
items[17] = {name = 'blue robe', id = 2656, subtype = -1, sell = 0, buy = 10000}
items[18] = {name = 'lady armor', id = 2500, subtype = -1, sell = 0, buy = 1000}
items[19] = {name = 'plate armor', id = 2463, subtype = -1, sell = 0, buy = 300}
items[20] = {name = 'brass armor', id = 2465, subtype = -1, sell = 0, buy = 200}
items[21] = {name = 'chain armor', id = 2464, subtype = -1, sell = 0, buy = 100}
local function onActionItem(action)
if ((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
selfSay('Do you want to ' .. action .. ' ' .. plural .. amount .. ' ' .. items[_index].name .. suffix .. ' for ' .. cost .. ' gold?')
end
function getNext()
nextPlayer = getQueuedPlayer()
if (nextPlayer ~= nil) then
if (getDistanceToCreature(nextPlayer) <= 4) then
updateNpcIdle()
setNpcFocus(nextPlayer)
selfSay('Hi there ' .. getCreatureName(nextPlayer) .. '.', _delay * 3)
return
else
getNext()
end
end
setNpcFocus(0)
resetNpcIdle()
end
function _selfSay(message)
selfSay(message, _delay)
updateNpcIdle()
end
--
function onCreatureAppear(cid)
return true
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)
if (oldPos.z ~= newPos.z or getDistanceToCreature(cid) > 4) then
selfSay('See you.', _delay)
getNext()
end
else
if (oldPos.z ~= newPos.z or getDistanceToCreature(cid) > 4) then
unqueuePlayer(cid)
end
end
return true
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)
selfSay('Hi there ' .. getCreatureName(cid) .. '! Do you need my services? I buy some equipment.', _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
elseif (msgcontains(msg, 'helmets')) then
_selfSay('I buy royal (30k), warrior (3k), crusader (3,5k), crown (2k), devil (1,5k), chain (35gp) and iron helmets (30gp), also mystic turbans (500gp).')
elseif (msgcontains(msg, 'offer')) then
_selfSay('Say swords, clubs, axes, helmets, boots, legs, shields and armors for more info.')
elseif (msgcontains(msg, 'swords')) then
_selfSay('I buy giant (10k), bright (6k), fire (3k) serpent (1.5k), spike (800gp) and two handed swords (400gp), also ice rapiers (4k), broad swords (70gp), short swords (30gp), sabres (25gp) and swords (25gp).')
elseif (msgcontains(msg, 'clubs')) then
_selfSay('I buy war (4k), dragon (2k) and battle hammers (60gp), also skull staffs (4k) and clerical maces (200gp).')
elseif (msgcontains(msg, 'axes')) then
_selfSay('I buy fire (10k), knight (2k), double (200gp) and battle axes (100gp), also dragon lances (10k), halberds (200gp) and hatchets (20gp).')
elseif (msgcontains(msg, 'boots')) then
_selfSay('I buy steel boots (25k) and boots of haste (10k).')
elseif (msgcontains(msg, 'legs')) then
_selfSay('I buy golden (100k), crown (7k), knight (4k), plate (500gp), brass (100gp) and chain legs (50gp).')
elseif (msgcontains(msg, 'shields')) then
_selfSay('I buy demon (50k), vampire (5,5k), medusa (4k), amazon (3k), crown (3k), tower (3k), dragon (2k), guardian (1.5k), beholder (1k), and dwarven shields (100gp), also mms (100k)')
elseif (msgcontains(msg, 'armors')) then
_selfSay('I buy golden (25k), crown (5k), knight (3k), lady (1k), plate (300gp), brass (200gp) and chain armors (100gp), also mpa (200k), dsm (50k) and blue robes (10k).')
_state = 1
else
if (msgcontains(msg, 'bye')) then
selfSay('Good bye, ' .. getCreatureName(cid) .. 'Visit me whenever you want to sell something.', _delay)
getNext()
_state = 0
elseif (_state == 2) then
if (msgcontains(msg, 'yes')) then
if (doPlayerRemoveItem(cid, items[_index].id, _count)) then
local mon = items[_index].buy *_count
doPlayerAddMoney(cid, mon)
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
end
updateNpcIdle()
break
end
end
end
end
return 1
end
function onThink()
if (getNpcFocus() ~= 0) then
if (isNpcIdle()) then
selfSay('See you.', _delay)
getNext()
end
end
return true
end
Zakładki