D
Deleted member 141899
Guest
Hello friends, im using TFS 1.1, and im have a problem with my Grizzly Adams script, that the player can open multiples shop windows in same window, if he talks trade many times as him want in the same session...
Here are the part of the grizzly adams trade:
Please help!
Here are the part of the grizzly adams trade:
Code:
if isInArray({"offer", "trade"}, msg:lower()) then
if getPlayerRank(cid) >= 2 then
if getPlayerRank(cid) == 2 or getPlayerRank(cid) == 3 then
tradeRank = grizzlyAdamsConfig.ranks.huntsMan_rank
elseif getPlayerRank(cid) == 4 then
tradeRank = grizzlyAdamsConfig.ranks.bigGameHunter_rank
setNewLineTable(grizzlyAdamsConfig.ranks.huntsMan_rank, grizzlyAdamsConfig.ranks.bigGameHunter_rank)
elseif getPlayerRank(cid) == 5 or getPlayerRank(cid) == 6 then
tradeRank = grizzlyAdamsConfig.ranks.trophyHunter_rank
setNewLineTable(grizzlyAdamsConfig.ranks.huntsMan_rank, grizzlyAdamsConfig.ranks.bigGameHunter_rank)
setNewLineTable(grizzlyAdamsConfig.ranks.huntsMan_rank, grizzlyAdamsConfig.ranks.trophyHunter_rank)
end
local items = setNewTradeTable(tradeRank)
local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
if ignoreCap == false and (player:getFreeCapacity() < getItemWeight(items[item].itemId, amount) or inBackpacks and player:getFreeCap() < (getItemWeight(items[item].itemId, amount) + getItemWeight(1988, 1))) then
return player:sendTextMessage(MESSAGE_INFO_DESCR, 'You don\'t have enough cap.')
end
if items[item].buyPrice then
player:removeMoney(amount * items[item].buyPrice)
for i = 1, amount do
if inBackpacks then
local backpack = doCreateItemEx(1988, 1)
doAddContainerItem(backpack, items[item].itemId, amount)
else
player:addItem(items[item].itemId, amount, true)
end
end
return player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.')
end
return true
end
local function onSell(cid, item, subType, amount, ignoreCap, inBackpacks)
if items[item].sellPrice then
player:addMoney(items[item].sellPrice * amount)
player:removeItem(items[item].itemId, amount)
return player:sendTextMessage(cid, MESSAGE_INFO_DESCR, 'You sold '..amount..'x '..items[item].realName..' for '..items[item].sellPrice * amount..' gold coins.')
end
return true
end
openShopWindow(cid, tradeRank, onBuy, onSell)
return npcHandler:say('It\'s my offer.', player)
else
return npcHandler:say('You don\'t have any rank.', player)
end
end
Code:
local function setNewTradeTable(table)
local items = {}
for _, v in ipairs(table) do
items[v.id] = {itemId = v.id, buyPrice = v.buy, sellPrice = v.sell, subType = 0, realName = v.name}
end
return items
end
local function setNewLineTable(oldTable, newTable)
for k, v in pairs(oldTable) do
table.insert(newTable, k, v)
end
return true
end