• 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 Gift box

sick

Member
Joined
Feb 5, 2009
Messages
258
Reaction score
6
Location
Lithuania, Vilnius
Hello,

So i've came across an issue:

Idea is to click on a gift box and receive items on random basis, get not just one item but any of listed ones. Currently it rewards you with only 1 item. Please help out with this one:

Lua:
local items = {
     [0] = {id = 10129, count = 1, chance = 2},
     [1] = {id = 10128, count = 1, chance = 5},
     [2] = {id = 2328, count = 1, chance = 10},
     [3] = {id = 2195, count = 1, chance = 15},
     [4] = {id = 2160, count = 10, chance = 30},
     [5] = {id = 6569, count = 10, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
     for i = 0, #items do
         if (items[i].chance > math.random(1, 100)) then
             doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
             doPlayerAddItem(cid, items[i].id, items[i].count)  
             doRemoveItem(item.uid, 1)
             return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
         end
     end
     doRemoveItem(item.uid, 1)
     return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end

REP+ for assistance! :)
 
change
Lua:
return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
to
Lua:
doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
 
Back
Top