Advertisement
Oskar1121

Untitled

Oct 10th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 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 = 10
  6.  
  7. DAILY_CONFIG = {
  8. exhaustedStorage = 5000,
  9. checkingStorage = 5001,
  10. idStorage = 5002,
  11. codeStorage = 5003,
  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. ]]></config>
  23.  
  24. <action actionid="2026" event="script"><![CDATA[
  25. domodlib("dailyRewards_conf")
  26.  
  27. local letters = {{48, 57}, {65, 76}, {78, 90}, {161, 186}}
  28.  
  29. local function generateCode()
  30. local code = ''
  31. for i = 1, CODE_LENGTH do
  32. local id = letters[math.random(#letters)]
  33. code = code .. math.random(id[1], id[2])
  34. end
  35.  
  36. return code
  37. end
  38.  
  39. local function addReward(cid, id)
  40. local var = DAILY_CONFIG[id]
  41. if not var then
  42. -- reward isn't exist
  43. return false
  44. end
  45.  
  46. for i = 1, #var / 2 do
  47. doPlayerAddItem(cid, var[i * 2 - 1], var[i * 2])
  48. end
  49.  
  50. doCreatureSetStorage(cid, DAILY_CONFIG.idStorage, id)
  51. doCreatureSetStorage(cid, DAILY_CONFIG.checkingStorage, os.time() + (ONE_DAY * 2))
  52. doCreatureSetStorage(cid, DAILY_CONFIG.exhaustedStorage, os.time() + ONE_DAY)
  53. end
  54.  
  55. function onUse(cid, item, frompos, itemEx, toPos)
  56. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  57. if codeStorageValue ~= -1 then
  58. return false
  59. end
  60.  
  61. local idStorageValue = getCreatureStorage(cid, DAILY_CONFIG.idStorage) + 1
  62. if idStorageValue ~= 0 then
  63. local exhaustedStorageValue = getCreatureStorage(cid, DAILY_CONFIG.exhaustedStorage)
  64. if exhaustedStorageValue > os.time() then
  65. -- daily reward was taken
  66. return false
  67. end
  68.  
  69. local checkingStorageValue = getCreatureStorage(cid, DAILY_CONFIG.checkingStorage)
  70. if checkingStorageValue < os.time() or idStorageValue > #DAILY_CONFIG then
  71. -- did't taked daily reward, start counting again
  72. doCreatureSetStorage(cid, DAILY_CONFIG.idStorage, 0)
  73. end
  74. end
  75.  
  76. local code = generateCode()
  77. doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, code)
  78. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Your code is: "' .. code .. '".')
  79. addEvent(function()
  80. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  81. if codeStorageValue == -1 then
  82. return false
  83. end
  84.  
  85. doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, -1)
  86. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You didnt enter the code.')
  87. end, 30 * 1000)
  88. end
  89. ]]></action>
  90.  
  91. <talkaction words='!reward' event='script'><![CDATA[
  92. domodlib('dailyRewards_conf')
  93.  
  94. function onSay(cid, words, param, channel)
  95. local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
  96. if codeStorageValue == -1 then
  97. return true
  98. end
  99.  
  100. if param ~= codeStorageValue then
  101. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Wrong code.')
  102. return false
  103. end
  104.  
  105. local idStorageValue = getCreatureStorage(cid, DAILY_CONFIG.idStorage) + 1
  106. if idStorageValue == 0 then
  107. addReward(cid, 1)
  108. else
  109. addReward(cid, idStorageValue)
  110. end
  111.  
  112. return true
  113. end
  114.  
  115. ]]></talkaction>
  116. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement