Lua:
local itemIdToEffectId = {
[365] = 40,
[370] = 41,
[375] = 42,
[380] = 43,
[385] = 44
}
local itemIdToTime = {
[365] = 299, -- Time for item with ID 365
[370] = 299, -- Time for item with ID 370
[375] = 299, -- Time for item with ID 375
[380] = 399, -- Time for item with ID 380
[385] = 399 -- Time for item with ID 385
}
local itemIdToAssignedId = {
[365] = 367, -- Assigned ID for item with ID 365
[370] = 372, -- Assigned ID for item with ID 370
[375] = 377, -- Assigned ID for item with ID 375
[380] = 382, -- Assigned ID for item with ID 380
[385] = 387 -- Assigned ID for item with ID 385
}
local itemIdToDissapearEffect = {
[365] = 45, -- Assigned EffectID for item with ID 365
[370] = 46, -- Assigned EffectID for item with ID 370
[375] = 47, -- Assigned EffectID for item with ID 375
[380] = 48, -- Assigned EffectID for item with ID 380
[385] = 49 -- Assigned EffectID for item with ID 385
}
local action = Action()
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local storedBagItems = item:getItems()
local itemPos = item:getPosition()
local itemId = item:getId()
local effectId = itemIdToEffectId[itemId]
local time = itemIdToTime[itemId]
local openedBag = itemIdToAssignedId[itemId]
local dissapearEffect = itemIdToDissapearEffect[itemId]
item:remove()
itemPos:sendMagicEffect(effectId)
addEvent(function()
local bag = Game.createItem(openedBag, 1, itemPos)
for i = 1, #storedBagItems do
bag:addItem(storedBagItems[i]:getId(), storedBagItems[i]:getCount())
end
addEvent(function()
bag:remove()
itemPos:sendMagicEffect(dissapearEffect)
end, 120000)
end, time)
end
action:id(365, 370, 375, 380, 385)
action:register()
My question is how likely this code is to break/crash something
I have a feeling like the addEvent might be a problem since they hold the info about items without passing them as arguments
Also if it happends like its not a problem then its might be a performence problem since this script will hang around for 2 minutes so the last addevent will execute
Could somebody provide me with some information ?