• 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!

Lua Reward Bag

Dreww

Banned User
Joined
Oct 7, 2011
Messages
252
Reaction score
415
Location
México
Hello, someone could help me with a script when i click a bag give a random reward (example: 50% chance obtain "x" item, 25% another item) and i need a key to open the bag (if i open the bag both key and bag dissapear and i obtain reward to my backpack)

I'm using this script but i don't need key to open it and give me only 1 reward item:
LUA:
local prize = {
    [1] = {chance = 25, id = 5897, amount = 1,5},
    [2] = {chance = 30, id = 5896, amount = 1,5},
    [3] = {chance = 40, id = 5909, amount = 1,5},
    [4] = {chance = 55, id = 5913, amount = 1,5},
    [5] = {chance = 100, id = 5914, amount = 2,5},
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1,#prize do local number = math.random() * 100
    if prize[i].chance>100-number then
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:addItem(prize[i].id, prize[i].amount)
        item:remove()
        break
    end
    end
    return true
end

Sorry my bad english and thanks
 
try this
LUA:
local prizes = {
    [1] = {chance = 25, id = 5897, amount = {1,5}},
    [2] = {chance = 30, id = 5896, amount = {1,5}},
    [3] = {chance = 40, id = 5909, amount = {1,5}},
    [4] = {chance = 55, id = 5913, amount = {1,5}},
    [5] = {chance = 100, id = 5914, amount = {2,5}},
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1, #prizes do 
        local number = math.random(100)
        if prizes[i].chance <= number then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            player:addItem(prizes[i].id, math.random(prizes[i].amount[1], prizes[i].amount[2])
            item:remove(1)
            break
        end
    end
    return true
end
 
try this
LUA:
local prizes = {
    [1] = {chance = 25, id = 5897, amount = {1,5}},
    [2] = {chance = 30, id = 5896, amount = {1,5}},
    [3] = {chance = 40, id = 5909, amount = {1,5}},
    [4] = {chance = 55, id = 5913, amount = {1,5}},
    [5] = {chance = 100, id = 5914, amount = {2,5}},
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1, #prizes do
        local number = math.random(100)
        if prizes[i].chance <= number then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            player:addItem(prizes[i].id, math.random(prizes[i].amount[1], prizes[i].amount[2])
            item:remove(1)
            break
        end
    end
    return true
end
f0e3184f9f6ec0268b10fdf6fda157c3.png

@edit
Fixed just missed a ")" and now its working good! But what if the bag need a key to be opened?
 
Last edited:
Back
Top