• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts random suprise bag

delikerem

Member
Joined
Jan 9, 2020
Messages
91
Solutions
1
Reaction score
13
hello,

i have been looking around for a random suprise bag/box w/e but all i find is chest or only items, i have seen in other ots that they are using something called mystery box that gives items, mounts, addons etc.

i have been trying to modify red suprise bag to give mounts and outfits aswell but with no luck so i am wondering if someone could help me with this one.

i am using 1.4.2 10.98 if that would make it easier also if its possible to get it as a rev script.
 
Solution
hey thx for the code i will try it out but i am wondering if its possible to do

Something like that:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Define the reward pool with chances, types, and specific details
    local rewardPool = {
        {chance = 10, type = "item", id = 2160, count = 10}, -- 10x Crystal Coins
        {chance = 5, type = "mount", id = MOUNT_ID}, -- Replace MOUNT_ID with the actual mount ID
        {chance = 5, type = "addon", outfitMale = MALE_OUTFIT_ID, outfitFemale = FEMALE_OUTFIT_ID, addon = 1} -- Replace MALE_OUTFIT_ID and FEMALE_OUTFIT_ID with actual outfit IDs
        -- Add more rewards as needed
    }

    -- Calculate the total chance
    local totalChance =...
try:

xml:
XML:
<action itemid="YOUR_MYSTERY_BOX_ITEM_ID" script="mystery_box.lua"/>

lua:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Define the reward pool with chances and item details
    local rewardPool = {
        {chance = 10, id = 2160, count = 10}, -- 10x Crystal Coins
        {chance = 5, id = ITEM_ID_2, count = 1}, -- Replace ITEM_ID_2 with the item ID
        {chance = 3, id = ITEM_ID_3, count = 1}  -- Replace ITEM_ID_3 with the item ID
        -- Add more items as needed
    }

    -- Calculate the total chance
    local totalChance = 0
    for i = 1, #rewardPool do
        totalChance = totalChance + rewardPool[i].chance
    end

    -- Generate a random chance and select an item based on that
    local randomChance = math.random(totalChance)
    local currentChance = 0

    for i = 1, #rewardPool do
        currentChance = currentChance + rewardPool[i].chance
        if randomChance <= currentChance then
            local reward = rewardPool[i]
            -- Give the item to the player
            player:addItem(reward.id, reward.count or 1)
            break
        end
    end

    -- Remove the Mystery Box after use
    item:remove(1)
    return true
end
 
try:

xml:
XML:
<action itemid="YOUR_MYSTERY_BOX_ITEM_ID" script="mystery_box.lua"/>

lua:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Define the reward pool with chances and item details
    local rewardPool = {
        {chance = 10, id = 2160, count = 10}, -- 10x Crystal Coins
        {chance = 5, id = ITEM_ID_2, count = 1}, -- Replace ITEM_ID_2 with the item ID
        {chance = 3, id = ITEM_ID_3, count = 1}  -- Replace ITEM_ID_3 with the item ID
        -- Add more items as needed
    }

    -- Calculate the total chance
    local totalChance = 0
    for i = 1, #rewardPool do
        totalChance = totalChance + rewardPool[i].chance
    end

    -- Generate a random chance and select an item based on that
    local randomChance = math.random(totalChance)
    local currentChance = 0

    for i = 1, #rewardPool do
        currentChance = currentChance + rewardPool[i].chance
        if randomChance <= currentChance then
            local reward = rewardPool[i]
            -- Give the item to the player
            player:addItem(reward.id, reward.count or 1)
            break
        end
    end

    -- Remove the Mystery Box after use
    item:remove(1)
    return true
end
hey thx for the code i will try it out but i am wondering if its possible to do

{chance = 3, mountid = ITEM_ID_3, count = 1} -- Replace ITEM_ID_3 with the item ID
{chance = 3, outfitid = ITEM_ID_3, count = 1} -- Replace ITEM_ID_3 with the item ID
 
hey thx for the code i will try it out but i am wondering if its possible to do

Something like that:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Define the reward pool with chances, types, and specific details
    local rewardPool = {
        {chance = 10, type = "item", id = 2160, count = 10}, -- 10x Crystal Coins
        {chance = 5, type = "mount", id = MOUNT_ID}, -- Replace MOUNT_ID with the actual mount ID
        {chance = 5, type = "addon", outfitMale = MALE_OUTFIT_ID, outfitFemale = FEMALE_OUTFIT_ID, addon = 1} -- Replace MALE_OUTFIT_ID and FEMALE_OUTFIT_ID with actual outfit IDs
        -- Add more rewards as needed
    }

    -- Calculate the total chance
    local totalChance = 0
    for i = 1, #rewardPool do
        totalChance = totalChance + rewardPool[i].chance
    end

    -- Generate a random chance and select a reward based on that
    local randomChance = math.random(totalChance)
    local currentChance = 0

    for i = 1, #rewardPool do
        currentChance = currentChance + rewardPool[i].chance
        if randomChance <= currentChance then
            local reward = rewardPool[i]
            -- Give the reward based on its type
            if reward.type == "item" then
                player:addItem(reward.id, reward.count or 1)
            elseif reward.type == "mount" then
                player:addMount(reward.id)
            elseif reward.type == "addon" then
                -- Check the player's gender and give the appropriate outfit addon
                local gender = player:getSex()
                local outfitId = (gender == PLAYERSEX_FEMALE) and reward.outfitFemale or reward.outfitMale
                player:addOutfitAddon(outfitId, reward.addon)
            end
            break
        end
    end

    -- Remove the Mystery Box after use
    item:remove(1)
    return true
end
 
Solution
Something like that:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Define the reward pool with chances, types, and specific details
    local rewardPool = {
        {chance = 10, type = "item", id = 2160, count = 10}, -- 10x Crystal Coins
        {chance = 5, type = "mount", id = MOUNT_ID}, -- Replace MOUNT_ID with the actual mount ID
        {chance = 5, type = "addon", outfitMale = MALE_OUTFIT_ID, outfitFemale = FEMALE_OUTFIT_ID, addon = 1} -- Replace MALE_OUTFIT_ID and FEMALE_OUTFIT_ID with actual outfit IDs
        -- Add more rewards as needed
    }

    -- Calculate the total chance
    local totalChance = 0
    for i = 1, #rewardPool do
        totalChance = totalChance + rewardPool[i].chance
    end

    -- Generate a random chance and select a reward based on that
    local randomChance = math.random(totalChance)
    local currentChance = 0

    for i = 1, #rewardPool do
        currentChance = currentChance + rewardPool[i].chance
        if randomChance <= currentChance then
            local reward = rewardPool[i]
            -- Give the reward based on its type
            if reward.type == "item" then
                player:addItem(reward.id, reward.count or 1)
            elseif reward.type == "mount" then
                player:addMount(reward.id)
            elseif reward.type == "addon" then
                -- Check the player's gender and give the appropriate outfit addon
                local gender = player:getSex()
                local outfitId = (gender == PLAYERSEX_FEMALE) and reward.outfitFemale or reward.outfitMale
                player:addOutfitAddon(outfitId, reward.addon)
            end
            break
        end
    end

    -- Remove the Mystery Box after use
    item:remove(1)
    return true
end
it worked, thx for the help.

just a question sometimes i dont get anything so in order to get something i have to make so the "chance" is in total 100 right?

for example if i add 10 items all could be 10% witch is 100% or make 9 of them 1% and the last one 91%
 
it worked, thx for the help.

just a question sometimes i dont get anything so in order to get something i have to make so the "chance" is in total 100 right?

for example if i add 10 items all could be 10% witch is 100% or make 9 of them 1% and the last one 91%

Yes. To ensure that an item is always chosen, the sum of the chances of the items should be greater than the maximum number that can be randomly generated in the script.
 
Back
Top