Oskar1121

Untitled

Oct 10th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 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. doShowTextDialog(cid, 2333, code)
  80. -- doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Your code is: "' .. code .. '".')
  81. addEvent(function()
  82. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  83. if codeStorageValue == -1 then
  84. return false
  85. end
  86.  
  87. doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, -1)
  88. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You didnt enter the code.')
  89. end, 30 * 1000)
  90. end
  91. ]]></action>
  92.  
  93. <talkaction words='!reward' event='script'><![CDATA[
  94. domodlib('dailyRewards_conf')
  95.  
  96. function onSay(cid, words, param, channel)
  97. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  98. if codeStorageValue == -1 then
  99. return true
  100. end
  101.  
  102. if param ~= codeStorageValue then
  103. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Wrong code.')
  104. return false
  105. end
  106.  
  107. local idStorageValue = getCreatureStorage(cid, DAILY_CONFIG.idStorage) + 1
  108. if idStorageValue == 0 then
  109. addReward(cid, 1)
  110. else
  111. addReward(cid, idStorageValue)
  112. end
  113.  
  114. return true
  115. end
  116.  
  117. ]]></talkaction>
  118. </mod>
Advertisement
Add Comment
Please, Sign In to add comment