Oskar1121

Untitled

Oct 10th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <mod name="Daily Rewards" version="0.4.0" author="Oskar" contact="[email protected]" enabled="yes">
  3. <config name="dailyRewards_conf"><![CDATA[
  4. ONE_DAY = 24 * 60 * 60
  5. CODE_LENGTH = 10
  6.  
  7. DAILY_CONFIG = {
  8. exhaustedStorage = 2000,
  9. checkingStorage = 2001,
  10. idStorage = 2002,
  11. codeStorage = 2003,
  12. --[reward id] = {itemId1, amount1, itemId2, amount2, ... , itemIdX, amountX},
  13. [1] = {2148, 1},
  14. [2] = {2152, 1},
  15. [3] = {2152, 25},
  16. [4] = {2160, 1},
  17. [5] = {2128, 1, 2152, 50},
  18.  
  19.  
  20. }
  21.  
  22. function addReward(cid, id)
  23. local var = DAILY_CONFIG[id]
  24. if not var then
  25. -- reward isn't exist
  26. return false
  27. end
  28.  
  29. for i = 1, #var / 2 do
  30. doPlayerAddItem(cid, var[i * 2 - 1], var[i * 2])
  31. end
  32.  
  33. doCreatureSetStorage(cid, DAILY_CONFIG.idStorage, id)
  34. doCreatureSetStorage(cid, DAILY_CONFIG.checkingStorage, os.time() + (ONE_DAY * 2))
  35. doCreatureSetStorage(cid, DAILY_CONFIG.exhaustedStorage, os.time() + ONE_DAY)
  36. doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, -1)
  37. end
  38.  
  39. ]]></config>
  40.  
  41. <action actionid="2026" event="script"><![CDATA[
  42. domodlib("dailyRewards_conf")
  43.  
  44. local letters = {{48, 57}, {65, 90}, {97, 122}}
  45.  
  46. local function generateCode()
  47. local code = ''
  48. for i = 1, CODE_LENGTH do
  49. local id = letters[math.random(#letters)]
  50. code = code .. string.char(math.random(id[1], id[2]))
  51. end
  52.  
  53. return code
  54. end
  55.  
  56. function onUse(cid, item, frompos, itemEx, toPos)
  57. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  58. if codeStorageValue ~= -1 then
  59. return false
  60. end
  61.  
  62. local idStorageValue = getCreatureStorage(cid, DAILY_CONFIG.idStorage) + 1
  63. if idStorageValue ~= 0 then
  64. local exhaustedStorageValue = getCreatureStorage(cid, DAILY_CONFIG.exhaustedStorage)
  65. if exhaustedStorageValue > os.time() then
  66. -- daily reward was taken
  67. return false
  68. end
  69.  
  70. local checkingStorageValue = getCreatureStorage(cid, DAILY_CONFIG.checkingStorage)
  71. if checkingStorageValue < os.time() or idStorageValue > #DAILY_CONFIG then
  72. -- did't taked daily reward, start counting again
  73. doCreatureSetStorage(cid, DAILY_CONFIG.idStorage, 0)
  74. end
  75. end
  76.  
  77. local code = generateCode()
  78. doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, code)
  79. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Your code is: "' .. code .. '".')
  80. addEvent(function()
  81. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  82. if codeStorageValue == -1 then
  83. return false
  84. end
  85.  
  86. doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, -1)
  87. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You didnt enter the code.')
  88. end, 30 * 1000)
  89. end
  90. ]]></action>
  91.  
  92. <talkaction words='!reward' event='script'><![CDATA[
  93. domodlib('dailyRewards_conf')
  94.  
  95. function onSay(cid, words, param, channel)
  96. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  97. if codeStorageValue == -1 then
  98. return true
  99. end
  100.  
  101. if param ~= codeStorageValue then
  102. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Wrong code.')
  103. return false
  104. end
  105.  
  106. local idStorageValue = getCreatureStorage(cid, DAILY_CONFIG.idStorage) + 1
  107. if idStorageValue == 0 then
  108. addReward(cid, 1)
  109. else
  110. addReward(cid, idStorageValue)
  111. end
  112.  
  113. return true
  114. end
  115.  
  116. ]]></talkaction>
  117. </mod>
Advertisement
Add Comment
Please, Sign In to add comment