local items = {{1111,20},{2222,50},{3333,30}}
-- {itemid, chance}
local total = 0
for i,v in pairs(items) do
items[i][3] = total
total = total + v[2]
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local item = math.random(0,total)
for _,v in pairs(items) do
if (item >= v[3] and item < (v[2]+v[3])) then
doPlayerAddItem(cid,v[1],1)
break
end
end
doRemoveItem(item.uid)
return true
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
doSendMagicEffect(getCreaturePosition(cid), 12)
doRemoveItem(item.uid, 1)
return true
end
local items = {{1111,20},{2222,50},{3333,30}}
-- {itemid, chance}
local total = 0
for i,v in pairs(items) do
items[i][3] = total
total = total + v[2]
end
function onUse(cid, oitem, fromPosition, itemEx, toPosition)
local item = math.random(0,total)
for _,v in pairs(items) do
if (item >= v[3] and item < (v[2]+v[3])) then
doPlayerAddItem(cid,v[1],1)
break
end
end
doRemoveItem(oitem.uid)
return true
end
local items = {{1111,5,20},{2222,1,50},{3333,100,30}}
-- {itemid, count, chance}
local total = 0
for i,v in pairs(items) do
items[i][4] = total
total = total + v[3]
end
function onUse(cid, oitem, fromPosition, itemEx, toPosition)
local item = math.random(0,total)
for _,v in pairs(items) do
if (item >= v[4] and item < (v[3]+v[4])) then
doPlayerAddItem(cid,v[1],v[2])
break
end
end
doRemoveItem(oitem.uid)
return true
end
Code:local items = {{1111,5,20},{2222,1,50},{3333,100,30}} -- {itemid, count, chance} local total = 0 for i,v in pairs(items) do items[i][4] = total total = total + v[3] end function onUse(cid, oitem, fromPosition, itemEx, toPosition) local item = math.random(0,total) for _,v in pairs(items) do if (item >= v[4] and item < (v[3]+v[4])) then doPlayerAddItem(cid,v[1],v[2]) break end end doRemoveItem(oitem.uid) return true end
You should try tabbing![]()
Good luck tabbing in this forum box.
Gah, you should at least use note pad ._.
I do, for actual server scripting.
But why should I open notepad if I can do without it? To please you?