function I1370074_GiftBag(MapID, InstanceID, TypeID, TargetID) local r = math.random(1, 3400) local temp = 0 local index = 1 local tbl = {} tbl[1] = {8099155, 1, 6, 100} tbl[2] = {8099156, 1, 6, 100} tbl[3] = {8099157, 1, 6, 100} tbl[4] = {8099159, 1, 6, 100} tbl[5] = {8099160, 1, 6, 100} tbl[6] = {8099161, 1, 6, 100} tbl[7] = {8099201, 1, 6, 100} tbl[8] = {8099202, 1, 6, 100} tbl[9] = {8099203, 1, 6, 100} tbl[10] = {8099212, 1, 6, 100} tbl[11] = {8099213, 1, 6, 100} tbl[12] = {8099214, 1, 6, 100} tbl[13] = {8099270, 1, 6, 100} tbl[14] = {8099271, 1, 6, 100} tbl[15] = {8099272, 1, 6, 100} tbl[16] = {8099439, 1, 6, 100} tbl[17] = {8099440, 1, 6, 100} tbl[18] = {8099441, 1, 6, 100} tbl[19] = {8099442, 1, 6, 100} tbl[20] = {8099443, 1, 6, 100} tbl[21] = {8099444, 1, 6, 100} tbl[22] = {8099515, 1, 6, 100} tbl[23] = {8099516, 1, 6, 100} tbl[24] = {8099517, 1, 6, 100} tbl[25] = {8099705, 1, 6, 100} tbl[26] = {8099706, 1, 6, 100} tbl[27] = {8099707, 1, 6, 100} tbl[28] = {8099820, 1, 6, 100} tbl[29] = {8099821, 1, 6, 100} tbl[30] = {8099822, 1, 6, 100} tbl[31] = {8099852, 1, 6, 100} tbl[32] = {8099853, 1, 6, 100} tbl[33] = {8099854, 1, 6, 100} for i = 1, 33 do temp = temp + tbl[i][4] if temp >= r then index = i break end end if index >= 1 then local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 100, 280) msg.AddMsgEvent(MsgID, 2, TargetID) msg.AddMsgEvent(MsgID, 4, TypeID) msg.AddMsgEvent(MsgID, 4, tbl[index][1]) msg.DispatchWorldMsgEvent(MsgID) end role.AddRoleItem(MapID, InstanceID, TargetID, tbl[index][1], tbl[index][2], tbl[index][3], 8, 420) end function I1370074_CanUseGiftBag(MapID, InstanceID, TypeID, TargetID) local bRet, bIgnore = 0, false local FreeSize = role.GetBagFreeSize(TargetID) if FreeSize < 1 then bRet = 40 end return bRet, bIgnore end aux.RegisterItemEvent(1370074, 1, "I1370074_GiftBag") aux.RegisterItemEvent(1370074, 0, "I1370074_CanUseGiftBag") function I6600972_CanUseGiftBag(MapID, InstanceID, TypeID, TargetID) local bRet, bIgnore = 0, false -- Check if there is enough free space in the bag local FreeSize = role.GetBagFreeSize(TargetID) if FreeSize < 1 then bRet = 40 -- Notify the player that the bag space is insufficient return bRet, bIgnore end -- Check if the player has at least one of the specific items local items = { {3020001, 340}, {3020058, 340}, {3020059, 340}, {3020060, 30}, {3050003, 1290}, {3050029, 810}, {3050029, 830}, {3050026, 850}, {3050027, 2400}, {3050028, 2600}, {3050029, 2800}, {3050109, 300}, {3500041, 150}, {3500042, 200}, {4010019, 2900}, {4010038, 900}, {4010323, 2200}, {4010324, 900}, {4080080, 40}, {4080081, 40}, {4080082, 40}, {4080083, 40}, {4080084, 40}, {4090018, 90}, {4400025, 25}, {4400026, 25}, {4400027, 25}, {4400028, 25}, {4400029, 25}, {4400030, 25}, {4810013, 1800}, {4810140, 1400}, {4820038, 620}, {4820078, 240}, {4820175, 690}, {4820230, 2000}, {4820231, 2000}, {4820232, 250}, {4820233, 250}, {4820273, 400}, {5802142, 35}, {5802143, 40}, {6600289, 600}, {6600916, 1000}, {6600917, 1100}, {6600918, 600}, {6600919, 2200} } local hasItem = false local itemToRemove = nil for _, item in ipairs(items) do local count = role.GetRoleItemNum(TargetID, item[1]) if count >= item[2] then hasItem = true itemToRemove = item break end end if not hasItem then bRet = 103 -- Notify the player that the required item is not present end return bRet, bIgnore, itemToRemove end function I6600972_GiftBag(MapID, InstanceID, TypeID, TargetID) local bRet, bIgnore, itemToRemove = I6600972_CanUseGiftBag(MapID, InstanceID, TypeID, TargetID) if bRet ~= 0 then return bRet, bIgnore end -- Remove the specific item from the player's inventory if itemToRemove then role.RemoveFromRole(MapID, InstanceID, TargetID, itemToRemove[1], itemToRemove[2], 101) end -- Add a random item from a predefined table local r = math.random(10000) local temp = 0 local index = 1 local tbl = { {6600973, 1, 5, 2000}, {6600973, 1, 5, 2000}, {6600973, 1, 5, 2000}, {6600973, 1, 5, 4000} } for i = 1, #tbl do temp = temp + tbl[i][4] if temp >= r then index = i break end end role.AddRoleItem(MapID, InstanceID, TargetID, tbl[index][1], tbl[index][2], tbl[index][3], 8, 35) end aux.RegisterItemEvent(6600972, 1, "I6600972_GiftBag") aux.RegisterItemEvent(6600972, 0, "I6600972_CanUseGiftBag") function I6600772_CanUse(MapID, InstanceID, TypeID, TargetID) local bRet, bIgnore = 0, false -- Check if there is enough free space in the bag local FreeSize = role.GetBagFreeSize(TargetID) if FreeSize < 1 then bRet = 40 -- Notify the player that the bag space is insufficient return bRet, bIgnore end -- Check if the player has at least one of the specific soul stones local soulStones = { {3020022, 5}, {3020023, 6}, {3020024, 7}, {3020025, 8}, {3020026, 9}, {3020027, 10}, {3020028, 14}, {3020029, 18}, {3020030, 20}, {3020031, 25}, {3020032, 30}, {3020033, 35}, {3020034, 40}, {3020035, 45}, {3020036, 50}, {3020037, 55}, {3020038, 70}, {3020039, 90}, {3020040, 120}, {3020041, 150}, {3020042, 200} } local hasSoulStone = false local soulStoneToRemove = nil for _, stone in ipairs(soulStones) do local count = role.GetRoleItemNum(TargetID, stone[1]) if count >= 1 then hasSoulStone = true soulStoneToRemove = stone break end end if not hasSoulStone then bRet = 103 -- Notify the player that the required soul stone is not present end return bRet, bIgnore, soulStoneToRemove end function I6600772_Use(MapID, InstanceID, TypeID, TargetID) local bRet, bIgnore, soulStoneToRemove = I6600772_CanUse(MapID, InstanceID, TypeID, TargetID) if bRet ~= 0 then return bRet, bIgnore end -- Remove the specific soul stone from the player's inventory if soulStoneToRemove then role.RemoveFromRole(MapID, InstanceID, TargetID, soulStoneToRemove[1], 1, 101) end -- Add the Soul Dust to the player's inventory based on the level of the soul stone local soulDustAmount = soulStoneToRemove[2] -- Add the Soul Dust to the player's inventory role.AddRoleItem(MapID, InstanceID, TargetID, 6600771, soulDustAmount, 1, 8, 35) -- Assuming 6600771 is the ID for Soul Dust end aux.RegisterItemEvent(6600772, 1, "I6600772_Use") aux.RegisterItemEvent(6600772, 0, "I6600772_CanUse")