From 4852db8c7bcec6f60d7d8396a506e4f072d9dcfb Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 2 Mar 2024 03:38:53 -0300 Subject: [PATCH] refactor: aniversary reward boxes to core --- .../actions/items}/anniversary_reward_boxes.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) rename {data-otservbr-global/scripts/actions/other => data/scripts/actions/items}/anniversary_reward_boxes.lua (92%) diff --git a/data-otservbr-global/scripts/actions/other/anniversary_reward_boxes.lua b/data/scripts/actions/items/anniversary_reward_boxes.lua similarity index 92% rename from data-otservbr-global/scripts/actions/other/anniversary_reward_boxes.lua rename to data/scripts/actions/items/anniversary_reward_boxes.lua index 8327222a570..d5d36bb7455 100644 --- a/data-otservbr-global/scripts/actions/other/anniversary_reward_boxes.lua +++ b/data/scripts/actions/items/anniversary_reward_boxes.lua @@ -55,22 +55,24 @@ local config = { } local rewardBox = Action() + function rewardBox.onUse(player, item, fromPosition, itemEx, toPosition) local box = config[item:getId()] - if not box or not player then + if not box then return false end - for i = 1, #box do - if box[i] then - player:addItem(box[i].id, box[i].count) - player:getPosition():sendMagicEffect(CONST_ME_PRISMATIC_SPARK) - end + + for _, reward in ipairs(box) do + player:addItem(reward.id, reward.count) + player:getPosition():sendMagicEffect(CONST_ME_PRISMATIC_SPARK) end + item:remove() return true end -for index, value in pairs(config) do +for index, _ in pairs(config) do rewardBox:id(index) end + rewardBox:register()