Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TYPE_LOWER = 1
- local TYPE_HIGHER = 2
- local config = {
- itemid = 2160,
- maximum = 16
- }
- local lever = {
- [3008] = {'y', -1, TYPE_LOWER},
- [3009] = {'x', 1, TYPE_HIGHER},
- [3010] = {'y', 1, TYPE_HIGHER},
- [3011] = {'x', -1, TYPE_LOWER}
- }
- function onUse(cid, item, fromPosition, itemEx, toPosition)
- local var = lever[item.actionid]
- if not var then
- return false
- end
- local pos = getThingPos(item.uid)
- local toPos = {x = pos.x, y = pos.y, z = pos.z}
- if var[1] == 'x' then
- pos.x = pos.x + var[2]
- toPos.x = toPos.x + var[2]
- toPos.y = toPos.y - 1
- elseif var[1] == 'y' then
- pos.y = pos.y + var[2]
- toPos.y = toPos.y + var[2]
- toPos.x = toPos.x - 1
- end
- local coin = getTileItemById(pos, config.itemid)
- if coin.uid == 0 then
- return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You do not have the required amount of items.')
- end
- local amount = math.min(config.maximum, coin.type) * 6
- doSendMagicEffect(pos, CONST_ME_HOLYAREA)
- doRemoveItem(coin.uid, amount)
- local dice = nil
- for i = 0, 5 do
- dice = getTileItemById(toPos, 5792 + i)
- if dice.uid > 0 then
- break
- end
- end
- local value = math.random(0, 5)
- if not dice then
- doCreateItem(5792 + value, 1, toPos)
- else
- doTransformItem(item.uid, 5792 + value)
- end
- doCreatureSay(cid, 'Rolled ' .. (value + 1), TALKTYPE_MONSTER, false, 0, toPos)
- if (var[3] == TYPE_HIGHER and value > 2) or (var[3] == TYPE_LOWER and value < 3) then
- local fromPos = getThingPos(cid)
- fromPos.x = fromPos.x + 1
- doCreateItem(config.itemid, amount, fromPos)
- doSendMagicEffect(pos, CONST_ME_FIREAREA)
- doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You won ' .. amount .. ' ' .. getItemInfo(config.itemid).name .. '.')
- else
- doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You lose.')
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement