I have a code I tried to change the code to be able to use the lever I needed to have 5 units of item 18423, but it didn't work, can someone help me with this, the default code is working normally, but I just wanted this, and if I didn't have the item he couldn't use it. I use TFS 1.4x 10.98.
code is this.
second code
code is this.
Code:
-- Legendary Lever was developed by lyu (Legendary Lever now is public)
if not randomitems then
randomitems = {}
function randomitems:saveLog(...)
local message = '[%s] %s has found %s %s\n'
local file = io.open('data/logs/randomitems/' .. ... .. '.log', 'a')
if not file then
return
end
io.output(file)
io.write(message:format(os.date('%d/%m/%Y %H:%M'), ...))
io.close(file)
end
function randomitems:random(p, obj, exhaust, item)
if not rawequal(type(obj), 'table') then
return error('table of items not found.')
end
if not p:getGroup():getAccess() then
-- double-click protect
if obj.exhaust and obj.exhaust > os.time() then
return p:getMoney() >= obj.coust and p:sendCancelMessage('Lever exhausted for ' .. obj.exhaust - os.time() ..' seconds.') or true
end
-- the exhaust of x object is global for all players
obj.exhaust = os.time() + (not exhaust and 2 or exhaust)
if obj.onlypremium and not p:isPremium() then
return p:say('Sorry, only premium players can use this lever.', TALKTYPE_MONSTER_SAY)
end
if not p:removeMoney(obj.coust) then
return p:say('Payment fail, you need ' .. obj.coust .. ' gold coins.', TALKTYPE_MONSTER_SAY)
end
if exhaust > 1 then
item:transform(item.itemid + 1)
addEvent(function()
item:transform(item.itemid - 1)
end, ((obj.exhaust - os.time())-1) * 1000)
end
end
-- this function is necessary to repeat the loop if the result was nil
local function randomize()
for _, it in ipairs(obj) do
if it.chance>=100-(math.random()*100) then
local item = p:addItem(it.itemid, it.amount)
local name = not rawequal(type(item), 'table') and item:getName() or item[1]:getName()
self:saveLog(p:getName(), it.amount, name)
p:save() -- [security] save player
if it.broadcast then
local msg = '[Legendary Levers] %s has found %s %s.'
if not p:getGroup():getAccess() then
Game.broadcastMessage(msg:format(p:getName(), rawequal(it.amount, 1) and 'a' or it.amount, name .. '' .. (it.amount > 1 and 's' or '')), MESSAGE_EVENT_ADVANCE)
end
end
p:sendTextMessage(MESSAGE_INFO_DESCR, 'Congratulations, you have found ' .. (rawequal(it.amount, 1) and 'a' or it.amount) .. ' ' .. name .. '' .. (it.amount > 1 and 's.' or '.'))
return not p:isInGhostMode() and p:getPosition():sendMagicEffect(it.broadcast and 7 or 15)
end
end
-- repeat
randomize()
end
-- called by self:random(...)
randomize()
return true
end
else
error('>> randomitems/lib.lua loading failed.')
end
second code
Code:
-- Legendary Lever was developed by lyu (Legendary Lever now is public)
local lever = {
{itemid = 8851, amount = 1, chance = 5, broadcast = true},
{itemid = 8300, amount = 1, chance = 12, broadcast = false},
{itemid = 9971, amount = 50, chance = 25, broadcast = false},
{itemid = 7253, amount = 1, chance = 65, broadcast = false},
}
lever.onlypremium = false
lever.coust = 10000
function onUse(player, item) return randomitems:random(player, lever, 2, item) end