Advertisement
Oskar1121

Untitled

Sep 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. local itemList = { 7402, {1, 1}, 500, 25, -- Glove of Nunoboko
  2. 7416, {1, 1}, 250, 25, -- Deadly Katar [Quest]
  3. 7403, {1, 1}, 500, 25, -- Sword of Nunoboko
  4. 7407, {1, 1}, 250, 25, -- Shichiseiken [Quest]
  5. 2446, {1, 1}, 500, 25, -- Bashosen
  6. 7406, {1, 1}, 250, 25, -- Susanoo Bow [Quest]
  7. 8866, {1, 1}, 250, 25, -- Chakra Mode Protector
  8. 8874, {1, 1}, 250, 25, -- Rikudou Sennin Mask
  9. 8878, {1, 1}, 500, 25, -- Kaguya Mask
  10. 8879, {1, 1}, 500, 25, -- Kaguya Coat
  11. 8867, {1, 1}, 250, 25, -- Chakra Mode Coat
  12. 8875, {1, 1}, 250, 25, -- Rikudou Sennin Coat
  13. 8868, {1, 1}, 250, 25, -- Chakra Mode Legs
  14. 8876, {1, 1}, 250, 25, -- Rikudou Sennin Legs
  15. 8869, {1, 1}, 250, 25, -- Chakra Mode Boots
  16. 8877, {1, 1}, 250, 25, -- Rikudou Sennin Boots
  17. 2161, {1, 1}, 500, 25, -- Premium Ring
  18. 2511, {1, 1}, 500, 25, -- Yata no Kagami
  19. 2512, {1, 1}, 250, 25, -- Shield of Nunoboko
  20. 6099, {1, 1}, 100, 25, -- Brikus Crystal
  21. 2344, {1, 5}, 500, 25, -- Perfect Upgrade Stone
  22. 2159, {25, 35}, 500, 25, -- Casino Coins
  23. 5904, {10, 25}, 500, 25 -- MVP Chakra
  24. }
  25.  
  26. local minimumAmount = 0
  27. local maximumAmount = 0
  28. for i = 1, #itemList / 4 do
  29. maximumAmount = math.max(maximumAmount, itemList[i * 4])
  30. minimumAmount = math.min(minimumAmount, itemList[i * 4])
  31. end
  32.  
  33. local cache = {}
  34.  
  35. local CASINO_NONE = 0
  36. local CASINO_LEVER = 100
  37. local CASINO_REWARD = 101
  38. local CASINO_LAST_REWARD = 102
  39. local CASINO_COINS = 103
  40.  
  41. local POSITION_LAST_REWARD = 1
  42. local POSITION_REWARD = 2
  43. local POSITION_LAST = 3
  44. local POSITION_COINS = 4
  45.  
  46. local casinoCoin = 2159
  47.  
  48. local config = {
  49. [1000] = {
  50. rewardTile = 4,
  51. area = {
  52. {CASINO_LAST_REWARD, 0, 1, 0, 0, 0, 0, 0, 0},
  53. {0, 12, 0, 2, 0, 0, 0, 0, 0},
  54. {11, 0, 0, 0, 3, 0, 0, 0, 0},
  55. {10, 0, 0, 0, 4, 0, CASINO_REWARD, CASINO_LEVER, CASINO_COINS},
  56. {9, 0, 0, 0, 5, 0, 0, 0, 0},
  57. {0, 8, 0, 6, 0, 0, 0, 0, 0},
  58. {0, 0, 7, 0, 0, 0, 0, 0, 0}
  59. }
  60. }
  61.  
  62. }
  63.  
  64. local function getItem(amount)
  65. while true do
  66. for i = 1, #itemList / 4 do
  67. if amount >= itemList[i * 4] and math.random(100000) <= itemList[i * 4 - 1] then
  68. return itemList[i * 4 - 3], itemList[i * 4 - 2]
  69. end
  70. end
  71. end
  72.  
  73. return nil
  74. end
  75.  
  76. local function executeReward(position, positions, items, list)
  77. local item = getTileItemById(list[positions[POSITION_LAST]], items[positions[POSITION_LAST]][1])
  78. if item.uid > 0 then
  79. doTeleportThing(item.uid, positions[POSITION_REWARD])
  80. doSendMagicEffect(positions[POSITION_REWARD], 40)
  81.  
  82. doCleanTile(positions[POSITION_LAST_REWARD])
  83. doCreateItem(item.itemid, item.type, positions[POSITION_LAST_REWARD])
  84. doSendMagicEffect(positions[POSITION_LAST_REWARD], 40)
  85. end
  86.  
  87. cache[position.y][position.x] = nil
  88. for i = #list, 1, -1 do
  89. doCleanTile(list[i])
  90. end
  91. end
  92.  
  93. local function executeRoll(position, positions, items, list, n, duration)
  94. local item = getTileItemById(list[1], items[1][1])
  95. if item.uid > 0 then
  96. doRemoveItem(item.uid)
  97. end
  98.  
  99. local itemList = {}
  100. for i = #list, 1, -1 do
  101. if i > 1 then
  102. item = getTileItemById(list[i], items[i][1])
  103. if item.uid > 0 then
  104. if i < #list then
  105. doTeleportThing(item.uid, list[i + 1])
  106. else
  107. doTeleportThing(item.uid, list[1])
  108. end
  109. end
  110. end
  111.  
  112. if i < #list then
  113. itemList[i + 1] = items[i]
  114. else
  115. itemList[1] = items[i]
  116. end
  117. end
  118.  
  119. doCreateItem(items[1][1], items[1][2], list[2])
  120.  
  121. if n > 0 then
  122. local delay = 200
  123. if n > duration / 2 then
  124. delay = 50
  125. elseif n > duration / 4 then
  126. delay = 100
  127. elseif n > duration / 8 then
  128. delay = 150
  129. elseif n > duration / 16 then
  130. delay = 200
  131. elseif n > duration / 32 then
  132. delay = 250
  133. end
  134.  
  135. addEvent(executeRoll, delay, position, positions, itemList, list, n - 1, duration)
  136. else
  137. addEvent(executeReward, 2000, position, positions, itemList, list)
  138. end
  139. end
  140.  
  141. local function doCreateItems(position, positions, list, n, amount, items)
  142. if not items then
  143. items = {}
  144. end
  145.  
  146. if n > #list then
  147. local duration = math.random(100, 200)
  148. addEvent(executeRoll, 2000, position, positions, items, list, duration, duration)
  149. return true
  150. end
  151.  
  152. local id, count = getItem(amount)
  153. if type(count) == 'table' then
  154. count = math.random(count[1], count[2])
  155. end
  156.  
  157. doCleanTile(list[n])
  158. doCreateItem(id, count, list[n])
  159. doSendMagicEffect(list[n], CONST_ME_POFF)
  160. items[n] = {id, count}
  161.  
  162. addEvent(doCreateItems, 50, position, positions, list, n + 1, amount, items)
  163. end
  164.  
  165. function onUse(cid, item, fromPosition, itemEx, toPosition)
  166. local var = config[item.actionid]
  167. if not var then
  168. return false
  169. end
  170.  
  171. local x, y, position = 0, 0, getThingPos(item.uid)
  172. if not cache[position.y] then
  173. cache[position.y] = {}
  174. end
  175.  
  176. if cache[position.y][position.x] then
  177. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You can\'t roll right now.')
  178. return true
  179. end
  180.  
  181. for py = 1, #var.area do
  182. for px = 1, #var.area[py] do
  183. if var.area[py][px] == CASINO_LEVER then
  184. x = px - 1
  185. y = py - 1
  186. break
  187. end
  188. end
  189. end
  190.  
  191. local positions = {}
  192. local rollList = {}
  193. for py = 1, #var.area do
  194. for px = 1, #var.area[py] do
  195. local value, pos = var.area[py][px], {x = position.x + (px - x - 1), y = position.y + (py - y - 1), z = position.z}
  196. if value == CASINO_REWARD then
  197. positions[POSITION_REWARD] = pos
  198. elseif value == CASINO_LAST_REWARD then
  199. positions[POSITION_LAST_REWARD] = pos
  200. elseif value == CASINO_COINS then
  201. positions[POSITION_COINS] = pos
  202. elseif value ~= CASINO_NONE and value ~= CASINO_LEVER then
  203. if value == var.rewardTile then
  204. positions[POSITION_LAST] = value
  205. end
  206.  
  207. rollList[value] = pos
  208. end
  209. end
  210. end
  211.  
  212. if #rollList == 0 then
  213. return false
  214. end
  215.  
  216. local item = getTileItemById(positions[POSITION_COINS], casinoCoin)
  217. if item.uid == 0 or item.type < minimumAmount then
  218. return true
  219. end
  220.  
  221. cache[position.y][position.x] = true
  222. doCreateItems(position, positions, rollList, 1, item.type)
  223. doRemoveItem(item.uid, math.min(item.type, maximumAmount))
  224. return false
  225. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement