Advertisement
Guest User

Untitled

a guest
May 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. local TYPE_LOWER = 1
  2. local TYPE_HIGHER = 2
  3.  
  4. local config = {
  5. itemid = 2160,
  6. maximum = 16
  7. }
  8. local lever = {
  9. [3008] = {'y', -1, TYPE_LOWER},
  10. [3009] = {'x', 1, TYPE_HIGHER},
  11. [3010] = {'y', 1, TYPE_HIGHER},
  12. [3011] = {'x', -1, TYPE_LOWER}
  13. }
  14.  
  15. function onUse(cid, item, fromPosition, itemEx, toPosition)
  16. local var = lever[item.actionid]
  17. if not var then
  18. return false
  19. end
  20.  
  21. local pos = getThingPos(item.uid)
  22. local toPos = {x = pos.x, y = pos.y, z = pos.z}
  23. if var[1] == 'x' then
  24. pos.x = pos.x + var[2]
  25. toPos.x = toPos.x + var[2]
  26. toPos.y = toPos.y - 1
  27. elseif var[1] == 'y' then
  28. pos.y = pos.y + var[2]
  29. toPos.y = toPos.y + var[2]
  30. toPos.x = toPos.x - 1
  31. end
  32.  
  33. local coin = getTileItemById(pos, config.itemid)
  34. if coin.uid == 0 then
  35. return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You do not have the required amount of items.')
  36. end
  37.  
  38. local amount = math.min(config.maximum, coin.type) * 6
  39. doSendMagicEffect(pos, CONST_ME_HOLYAREA)
  40. doRemoveItem(coin.uid, amount)
  41.  
  42. local dice = nil
  43. for i = 0, 5 do
  44. dice = getTileItemById(toPos, 5792 + i)
  45. if dice.uid > 0 then
  46. break
  47. end
  48. end
  49.  
  50. local value = math.random(0, 5)
  51. if not dice then
  52. doCreateItem(5792 + value, 1, toPos)
  53. else
  54. doTransformItem(item.uid, 5792 + value)
  55. end
  56.  
  57. doCreatureSay(cid, 'Rolled ' .. (value + 1), TALKTYPE_MONSTER, false, 0, toPos)
  58. if (var[3] == TYPE_HIGHER and value > 2) or (var[3] == TYPE_LOWER and value < 3) then
  59. local fromPos = getThingPos(cid)
  60. fromPos.x = fromPos.x + 1
  61. doCreateItem(config.itemid, amount, fromPos)
  62. doSendMagicEffect(pos, CONST_ME_FIREAREA)
  63. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You won ' .. amount .. ' ' .. getItemInfo(config.itemid).name .. '.')
  64. else
  65. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You lose.')
  66. end
  67.  
  68. return false
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement