• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Mystery Box ?

Teddy

SweStream.se
Joined
Oct 2, 2008
Messages
3,797
Reaction score
10
Location
Sweden 172
Can someone make a scripts when you use item you will get another random item ?

Like
OnUSE =
10 % = Item
40 % = Item
50 % = Item
 
This code's prettier <3
LUA:
local items = { --The sum of all % must be 100
  --{itemId, count, win %},
    {1111, 1, 10},
    {2222, 1, 40},
    {3333, 1, 50}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local chance = math.random(1,100)
    for i = 1, #items, 1 do
        if(chance < items[i][3]) then
            local itemInfo = getItemInfo(items[i][1])
            doPlayerAddItem(cid, items[i][1], items[i][2])
            if(items[i][2] == 1) then
                itemInfo = itemInfo.article .. " " .. itemInfo.name
            else
                itemInfo = items[i][2] .. " " .. itemInfo.plural
            end
            doPlayerSendTextMessage(cid, 25, "You have received " .. itemInfo .. ".")
            doRemoveItem(item.uid)
            return true
        else
            chance = chance - items[i][3]
        end
    end
    --This should never happen if done correctly!
    doPlayerSendTextMessage(cid, 25, "You failed to open the box.")
    return false
end
 
Last edited:
@up
[05/11/2012 01:10:27] [Error - LuaScriptInterface::loadFile] data/actions/scripts/mbox.lua:27: 'end' expected (to close 'function' at line 10) near '<eof>'
[05/11/2012 01:10:27] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/mbox.lua)
[05/11/2012 01:10:27] data/actions/scripts/mbox.lua:27: 'end' expected (to close 'function' at line 10) near '<eof>'
 
Back
Top