Advertisement
Prawdziwynrtn

Untitled

Apr 21st, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <mod name="Daily Rewards" version="0.4.0" author="Oskar" contact="oskar1121@gmail.com" enabled="yes">
  3. <config name="dailyRewards_conf"><![CDATA[
  4. ONE_DAY = 24 * 60 * 60
  5. CODE_LENGTH = 5
  6.  
  7. IP_LIST = {}
  8. DAILY_CONFIG = {
  9. exhaustedStorage = 31232,
  10. checkingStorage = 31234,
  11. idStorage = 31236,
  12. codeStorage = 31238,
  13. level = 1000,
  14. --[reward id] = {itemId1, amount1, itemId2, amount2, ... , itemIdX, amountX},
  15. --[5] = {2128, 1, 2152, 50},
  16.  
  17. [1] = {2160, 50},
  18. [2] = {2319, 1},
  19. [3] = {11363, 1}, -- pet parts box
  20. [4] = {8939, 1}, -- clothes box
  21. [5] = {2355, 1}, -- exp box
  22. [6] = {11363, 1},
  23. [7] = {8938, 1}, -- leaf box
  24. [8] = {2355, 1},
  25. [9] = {11363, 1},
  26. [10] = {2355, 1},
  27. [11] = {8939, 1},
  28. [12] = {7863, 1}, -- casino coin
  29. [13] = {2355, 1},
  30. [14] = {8939, 1},
  31. [15] = {7863, 1},
  32. [16] = {2209, 1},
  33. [17] = {7863, 1},
  34. [18] = {2355, 1},
  35. [19] = {11363, 1},
  36. [20] = {8300, 1},
  37. [21] = {8939, 1},
  38. [22] = {7863, 1},
  39. [23] = {11331, 1},
  40. [24] = {2355, 1},
  41. [25] = {8938, 1},
  42. [26] = {8939, 1},
  43. [27] = {8300, 1},
  44. [28] = {2355, 1},
  45. [29] = {11331, 1},
  46. [30] = {8927, 1}, -- active backpack
  47. }
  48.  
  49. function addReward(cid, id)
  50. local var = DAILY_CONFIG[id]
  51. if not var then
  52. doSendMagicEffect(getPlayerPosition(cid), 2)
  53. -- reward isn't exist
  54. return false
  55. end
  56.  
  57. for i = 1, #var / 2 do
  58. doSendMagicEffect(getPlayerPosition(cid), 13)
  59. doPlayerSendTextMessage(cid, 19, "Congratulations, you have received your reward!")
  60. doPlayerAddItem(cid, var[i * 2 - 1], var[i * 2])
  61. end
  62.  
  63. doCreatureSetStorage(cid, DAILY_CONFIG.idStorage, id)
  64. doCreatureSetStorage(cid, DAILY_CONFIG.checkingStorage, os.time() + (ONE_DAY * 2))
  65. doCreatureSetStorage(cid, DAILY_CONFIG.exhaustedStorage, os.time() + ONE_DAY)
  66. doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, -1)
  67. end
  68.  
  69. ]]></config>
  70.  
  71. <action uniqueid="35227" event="script"><![CDATA[
  72. domodlib("dailyRewards_conf")
  73.  
  74. local letters = {{48, 57}, {65, 90}, {97, 122}}
  75.  
  76. local function generateCode()
  77. local code = ''
  78. for i = 1, CODE_LENGTH do
  79. local id = letters[math.random(#letters)]
  80. code = code .. string.char(math.random(id[1], id[2]))
  81. end
  82.  
  83. return code
  84. end
  85.  
  86. function onUse(cid, item, frompos, itemEx, toPos)
  87. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  88. if codeStorageValue ~= -1 then
  89. return false
  90. end
  91.  
  92. local idStorageValue = getCreatureStorage(cid, DAILY_CONFIG.idStorage) + 1
  93. if getPlayerLevel(cid) > 999 then
  94. if idStorageValue ~= 0 then
  95.  
  96. local exhaustedStorageValue = getCreatureStorage(cid, DAILY_CONFIG.exhaustedStorage)
  97. local checkingStorageValue = getCreatureStorage(cid, DAILY_CONFIG.checkingStorage)
  98.  
  99. local seconds, minutes, hours = exhaustedStorageValue - os.time(), 0, 0
  100.  
  101.  
  102. while seconds >= 60 do
  103. seconds = seconds - 60
  104. minutes = minutes + 1
  105. end
  106.  
  107. while minutes >= 60 do
  108. minutes = minutes - 60
  109. hours = hours + 1
  110. end
  111.  
  112. local message = 'U can again take reward in '
  113. if hours > 0 then
  114. message = message .. hours .. ' hour' .. (hours > 1 and 's' or '')
  115. end
  116.  
  117. if minutes > 0 then
  118. message = message .. (hours > 0 and (seconds > 0 and ', ' or ' and ') or '') .. minutes .. ' minute' .. (minutes > 1 and 's' or '')
  119. end
  120.  
  121. if seconds > 0 then
  122. message = message .. ((hours > 0 or minutes > 0) and ' and ' or '') .. seconds .. ' second' .. (seconds > 1 and 's' or '')
  123. end
  124.  
  125.  
  126. if exhaustedStorageValue > os.time() then
  127. doPlayerSendTextMessage(cid, 19, message .. '.')
  128. doSendMagicEffect(getPlayerPosition(cid), 2)
  129. -- daily reward was taken
  130. return false
  131. end
  132.  
  133.  
  134. if checkingStorageValue < os.time() or idStorageValue > #DAILY_CONFIG then
  135. -- did't taked daily reward, start counting again
  136. doCreatureSetStorage(cid, DAILY_CONFIG.idStorage, 0)
  137. end
  138. end
  139.  
  140. local code = generateCode()
  141. doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, code)
  142. -- doShowTextDialog(cid, 2333, code)
  143. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Your code is: "' .. code .. '". Type "!reward code" to claim reward.')
  144. addEvent(function()
  145. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  146. if codeStorageValue == -1 then
  147. return false
  148. end
  149.  
  150. doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, -1)
  151. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You didnt enter the code.')
  152. end, 30 * 1000)
  153. end
  154. end
  155. ]]></action>
  156.  
  157. <talkaction words='!reward' event='script'><![CDATA[
  158. domodlib('dailyRewards_conf')
  159.  
  160. function onSay(cid, words, param, channel)
  161. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  162. if codeStorageValue == -1 then
  163. return true
  164. end
  165.  
  166. if param ~= codeStorageValue then
  167. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Wrong code.')
  168. return false
  169. end
  170.  
  171. local idStorageValue = getCreatureStorage(cid, DAILY_CONFIG.idStorage) + 1
  172. if idStorageValue == 0 then
  173. addReward(cid, 1)
  174. else
  175. addReward(cid, idStorageValue)
  176. end
  177.  
  178. return true
  179. end
  180.  
  181. ]]></talkaction>
  182. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement