3. Create the script
data/actions/scripts/lucky_box.lua
local rewards = {
{id = 2148, count = {10, 40}}, -- gold coins
{id = 2152, count = {1, 3}}, -- platinum coins
{id = 7618, count = {1, 2}}, -- mana potion
{id = 7620, count = {1, 2}}, -- health potion
{id = 2145, count = {1, 2}}, -- small diamond
{id = 2146, count = {1, 2}}, -- small sapphire
{id = 2149, count = {1, 2}}, -- small emerald
{id = 2150, count = {1, 2}}, -- small ruby
}
-- 0.5% rare reward
local rareRewards = {
{id = 2160, count = 1}, -- crystal coin
{id = 2392, count = 1}, -- fire sword
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
item:remove()
-- Rare roll (0.5%)
if math.random(1000) <= 5 then
local reward = rareRewards[math.random(#rareRewards)]
player:addItem(reward.id, reward.count)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Lucky! You found a rare item!")
return true
end
-- Normal reward
local reward = rewards[math.random(#rewards)]
local count = math.random(reward.count[1], reward.count[2])
player:addItem(reward.id, count)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You found something useful!")
return true
end
4. Add the drop to monsters
Inside any monster XML:
<item id="9000" chance="500" /> <!-- 5% -->
___________________________________________________________
You can adjust the value (e.g., 250 = 2.5%, 1000 = 10%).
____________________________________________________________
Configuration Tips
- Change the item id if 9000 is used in your server.
- Feel free to add/remove rewards from both tables.
- To adjust rare drop chance, edit:
if math.random(1000) <= 5 then
(5 = 0.5% → change to 10 for 1%, etc.)
______________________________________________________________
Credit: Bluster