<talkaction words="!merchant" event="script"><![CDATA[
domodlib('merchantSystem_conf')
function onSay(cid, words, param, channel)
if param:lower() == 'create' then
if getPlayerItemCount(cid, requiedItemToPutMerchant[1]) < requiedItemToPutMerchant[2] then
return doPlayerSendCancel(cid, 'You don\'t have enough '..getItemNameById(requiedItemToPutMerchant[1])..'s.')
end
if getPlayerItemCount(cid, writeableItem) < 1 then
return doPlayerSendCancel(cid, 'You need '..getItemNameById(writeableItem)..' to put merchant.')
end
local merchPlayer = getCreatureStorage(cid, merchantStorage)
if merchPlayer ~= -1 or isCreature(merchPlayer) then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendCancel(cid, 'Only one merchant at once!')
end
local greetMessage, itemOffert = doSearchWriteItem(cid, writeableItem)
if greetMessage and itemOffert then
local itemsExplode = itemOffert:explode('\n')
if #itemsExplode < 1 then
return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
end
local p = getThingPos(cid)
if getThingFromPos({x=p.x,y=p.y,z=p.z}, true).actionid ~= 123 then
return doPlayerSendCancel(cid, 'You can\'t create merchant here!')
end
local itemList, merchant = {}, doCreateNpc('merchant', getThingPos(cid), false)
for _, v in pairs(itemsExplode) do
local itemExplode = v:explode(',')
if #itemExplode < 2 then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
end
if #itemExplode > 3 then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
end
local itemId, itemCount = itemExplode[1], itemExplode[3] or 1
if type(tonumber(itemCount)) ~= 'number' or tonumber(itemCount) <= 0 then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'The amount must be a number greater than zero.')
end
if type(tonumber(itemExplode[2])) ~= 'number' or tonumber(itemExplode[2]) <= 0 then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Price must be a number greater than zero.')
end
if type(itemId) == 'string' then
itemId = getItemIdByName(itemExplode[1], false)
if not itemId then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Wrong item name!')
end
if getPlayerItemCount(cid, itemId) < tonumber(itemCount) then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You don\'t have these items.')
end
end
if getPlayerItemCount(cid, itemId) >= tonumber(itemCount) then
itemList[#itemList + 1] = {}
itemList[#itemList + 1] = {itemId = itemId, itemPrice = itemExplode[2], itemCount = itemCount}
end
end
for _, v in pairs(itemList) do
if v.itemId then
doPlayerRemoveItem(cid, v.itemId, v.itemCount)
end
end
addNewNpcItemList(cid, merchant, itemList)
doPlayerRemoveItem(cid, requiedItemToPutMerchant[1], requiedItemToPutMerchant[2])
doCreatureSetStorage(cid, merchantStorage, merchant)
doCreatureSetStorage(merchant, merchantStorage-2, '_'..cid)
doCreatureSetStorage(merchant, merchantStorage-1, '_' .. getCreatureName(cid) .. '_' .. getPlayerTown(cid))
doCreatureChangeOutfit(merchant, getCreatureOutfit(cid))
sayGreet(greetMessage, merchant)
return doCreatureSetStorage(merchant, cashStorage, 0)
end
end
return true
end
]]></talkaction>
<talkaction words="!merchant" event="script"><![CDATA[
domodlib('merchantSystem_conf')
function onSay(cid, words, param, channel)
if param:lower() == 'create' then
if getPlayerItemCount(cid, requiedItemToPutMerchant[1]) < requiedItemToPutMerchant[2] then
return doPlayerSendCancel(cid, 'You don\'t have enough '..getItemNameById(requiedItemToPutMerchant[1])..'s.')
end
if getPlayerItemCount(cid, writeableItem) < 1 then
return doPlayerSendCancel(cid, 'You need '..getItemNameById(writeableItem)..' to put merchant.')
end
local merchPlayer = getCreatureStorage(cid, merchantStorage)
if merchPlayer ~= -1 or isCreature(merchPlayer) then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendCancel(cid, 'Only one merchant at once!')
end
local greetMessage, itemOffert = doSearchWriteItem(cid, writeableItem)
if greetMessage and itemOffert then
local itemsExplode = itemOffert:explode('\n')
if #itemsExplode < 1 then
return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
end
local p = getThingPos(cid)
if getThingFromPos({x=p.x,y=p.y,z=p.z}, true).actionid ~= 123 then
return doPlayerSendCancel(cid, 'You can\'t create merchant here!')
end
local itemList, merchant = {}, doCreateNpc('Merchant ('..getCreatureName(cid)..')', getThingPos(cid), false)
for _, v in pairs(itemsExplode) do
local itemExplode = v:explode(',')
if #itemExplode < 2 then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
end
if #itemExplode > 3 then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
end
local itemId, itemCount = itemExplode[1], itemExplode[3] or 1
if type(tonumber(itemCount)) ~= 'number' or tonumber(itemCount) <= 0 then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'The amount must be a number greater than zero.')
end
if type(tonumber(itemExplode[2])) ~= 'number' or tonumber(itemExplode[2]) <= 0 then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Price must be a number greater than zero.')
end
if type(itemId) == 'string' then
itemId = getItemIdByName(itemExplode[1], false)
if not itemId then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Wrong item name!')
end
if getPlayerItemCount(cid, itemId) < tonumber(itemCount) then
doRemoveThing(merchant)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You don\'t have these items.')
end
end
if getPlayerItemCount(cid, itemId) >= tonumber(itemCount) then
itemList[#itemList + 1] = {}
itemList[#itemList + 1] = {itemId = itemId, itemPrice = itemExplode[2], itemCount = itemCount}
end
end
for _, v in pairs(itemList) do
if v.itemId then
doPlayerRemoveItem(cid, v.itemId, v.itemCount)
end
end
addNewNpcItemList(cid, merchant, itemList)
doPlayerRemoveItem(cid, requiedItemToPutMerchant[1], requiedItemToPutMerchant[2])
A nie ma takiej funkcji co zmienia nazwe gracza / npc w locie? wydaje mi sie ze byla.To nie może zadziałać bo nie mam npc o takiej nazwie: Merchant nick_garcza.Ale Dzięki za chęciCode:doCreateNpc('Merchant ('..getCreatureName(cid)..')', getThingPos(cid), false)![]()
local file = io.open("data/npc/merchants/Merchant "..getCreatureName(cid)..".xml", "w")
file:write('<?xml version="1.0" encoding="UTF-8"?><npc name="Merchant '..getCreatureName(cid)..'" script="merchant.lua" walkinterval="2000" floorchange="0"><health now="100" max="100"/><look type="133" head="57" body="113" legs="95" feet="113" addons="0"/><parameters></parameters></npc>')
file:close()