elnelson
Lunaria World Dev
Good afternoon, im trying to upgrade this script to make it work on TFS 1.X.
The objective of this script is to sell lootbags inside a box after pulling a lever.
I will appreciate a lot your help
The objective of this script is to sell lootbags inside a box after pulling a lever.
I will appreciate a lot your help
Lua:
local items = { -- you need to set up all items here where :
[2466] = {cost = 100},
[2446] = {cost = 3000},
[2470] = {cost = 4000},
}
local box = {x=999,y=1001,z=7,stackpos = 1} -- box pos
-- // SCRIPT START \\ --
function getContentDescription(uid, li) -- credits to Cyko for main form of this function
local ret, i, containers,removes, left = {}, 0, {}, {}, {}
while i <= getContainerSize(uid) do
local v = getContainerItem(uid, i)
local k = v.uid
local k2 = v.itemid
local check = items[k2]
if check then
table.insert(ret, k2)
table.insert(removes,k)
end
if isContainer(k) then
table.insert(containers, k)
end
i = i + 1
end
for i = 1, #containers do
local bah = getContentDescription(containers[i], li)
for i = 1,#bah do
if li == 1 then
table.insert(removes,bah[i])
elseif li == 2 then
table.insert(ret,bah[i])
end
end
end
return li== 1 and removes or ret
end
function getKey(t)
local s = {}
for k,v in pairs(t) do
table.insert(s,k)
end
return s
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local exist = getThingFromPos(box).uid
local itm = getThingFromPos(box).itemid
if isContainer(exist) then
local t = getContentDescription(exist,2)
local t2 = getContentDescription(exist,1)
if #t > 0 then
local f = {}
for i = 1,#t do
if not isInArray(getKey(f),t[i]) then
f[t[i]] = 1
else
f[t[i]] = f[t[i]] + 1
end
end
local str = "Sold items : "
local money = 0
for k,v in pairs(f) do
str = str.."\n".."•••• "..v.."x "..getItemNameById(k).." : ".. ( tonumber(items[k].cost) * tonumber(v) ) .. " gold coins."
money = money + tonumber(items[k].cost) * tonumber(v)
end
for i = 1,#t2 do
doRemoveItem(t2[i])
end
doPlayerSendTextMessage(cid,27,str)
doPlayerAddMoney(cid,money)
if #t > 1 then
doPlayerSendTextMessage(cid,19," Total money : ".. money.." gold coins.")
end
else
doPlayerSendTextMessage(cid,18,"Warning : Sold nothing --> either bag is empty or items included arn't sellable here.")
doSendMagicEffect(fromPosition,2)
end
else
local merge = items[itm]
if not merge then
doPlayerSendTextMessage(cid,18,"Warning : This item isn't sellable here.")
doSendMagicEffect(fromPosition,2)
else
doRemoveItem(exist)
doPlayerSendTextMessage(cid,27,"Sold item : \n •••• 1x "..getItemNameById(itm).." : "..merge.cost.."." )
doPlayerAddMoney(cid,merge.cost)
end
end
return doTransformItem(item.uid,item.uid == 1945 and 1946 or 1945)
end