diff --git a/data-otservbr-global/scripts/actions/other/glooth_bag.lua b/data-otservbr-global/scripts/actions/other/glooth_bag.lua deleted file mode 100644 index 382aa5ad447..00000000000 --- a/data-otservbr-global/scripts/actions/other/glooth_bag.lua +++ /dev/null @@ -1,47 +0,0 @@ -local items = { - glooth_spears = 21158, - glooth_amulet = 21183, - glooth_club = 21178, - glooth_axe = 21180, - glooth_blade = 21179, - glooth_backpack = 21295, - glooth_sandwiches = 21143, - glooth_soup = 21144, - glooth_steaks = 21146, - control_unit = 21186, -} - -local gloothBag = Action() - -function gloothBag.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local rand = math.random(1, 100) - - if rand <= 15 then - player:addItem(items.glooth_spears, 2) - elseif rand >= 16 and rand <= 23 then - player:addItem(items.glooth_amulet, 1) - elseif rand >= 24 and rand <= 32 then - player:addItem(items.glooth_club, 1) - elseif rand >= 33 and rand <= 50 then - player:addItem(items.glooth_axe, 1) - elseif rand >= 51 and rand <= 64 then - player:addItem(items.glooth_blade, 1) - elseif rand >= 65 and rand <= 75 then - player:addItem(items.glooth_backpack, 1) - elseif rand >= 76 and rand <= 86 then - player:addItem(items.glooth_sandwiches, 10) - elseif rand >= 87 and rand <= 96 then - player:addItem(items.glooth_soup, 10) - elseif rand >= 97 and rand <= 99 then - player:addItem(items.control_unit, 1) - elseif rand == 100 then - player:addItem(items.glooth_steaks, 10) - end - - item:remove(1) - - return true -end - -gloothBag:id(21203) -gloothBag:register() diff --git a/data/scripts/actions/items/glooth_bag.lua b/data/scripts/actions/items/glooth_bag.lua new file mode 100644 index 00000000000..a3703ea08dc --- /dev/null +++ b/data/scripts/actions/items/glooth_bag.lua @@ -0,0 +1,40 @@ +local config = { + { chanceFrom = 0, chanceTo = 1875, itemId = 21158, count = 2 }, -- glooth spear + { chanceFrom = 1876, chanceTo = 3418, itemId = 21183 }, -- glooth amulet + { chanceFrom = 3419, chanceTo = 4933, itemId = 21178 }, -- glooth club + { chanceFrom = 4934, chanceTo = 6397, itemId = 21180 }, -- glooth axe + { chanceFrom = 6398, chanceTo = 7829, itemId = 21179 }, -- glooth blade + { chanceFrom = 7830, chanceTo = 8462, itemId = 21295 }, -- glooth backpack + { chanceFrom = 8463, chanceTo = 8975, itemId = 21143, count = 10 }, -- glooth sandwich + { chanceFrom = 8976, chanceTo = 9469, itemId = 21144, count = 10 }, -- bowl of glooth soup + { chanceFrom = 9470, chanceTo = 9922, itemId = 21146, count = 10 }, -- glooth steak + { chanceFrom = 9923, chanceTo = 10000, itemId = 21186 }, -- control unit +} + +local gloothBag = Action() + +function gloothBag.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local chance = math.random(0, 10000) + for i = 1, #config do + local randomItem = config[i] + if chance >= randomItem.chanceFrom and chance <= randomItem.chanceTo then + if randomItem.itemId then + local gift = randomItem.itemId + local count = randomItem.count or 1 + if type(count) == "table" then + count = math.random(count[1], count[2]) + end + + player:addItem(gift, count) + end + + item:getPosition():sendMagicEffect(CONST_ME_HITBYPOISON) + item:remove(1) + return true + end + end + return false +end + +gloothBag:id(21203) +gloothBag:register()