Oskar1121

Untitled

Oct 9th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. local config = {
  2. exhaustedStorage = 5000,
  3. checkingStorage = 5001,
  4. idStorage = 5002,
  5. --[reward id] = {itemId1, amount1, itemId2, amount2, ... , itemIdX, amountX},
  6. [1] = {2148, 1},
  7. [2] = {2152, 1},
  8. [3] = {2152, 25},
  9. [4] = {2160, 1},
  10. [5] = {2128, 1, 2152, 50},
  11.  
  12.  
  13. }
  14.  
  15. local day = 24 * 60 * 60
  16.  
  17. local function addReward(cid, id)
  18. local var = config[id]
  19. if not var then
  20. -- reward isn't exist
  21. return false
  22. end
  23.  
  24. for i = 1, #var / 2 do
  25. doPlayerAddItem(cid, var[i * 2 - 1], var[i * 2])
  26. end
  27.  
  28. doCreatureSetStorage(cid, config.idStorage, id)
  29. doCreatureSetStorage(cid, config.checkingStorage, os.time() + (day * 2))
  30. doCreatureSetStorage(cid, config.exhaustedStorage, os.time() + day)
  31. end
  32.  
  33. function onUse(cid, item, fromPosition, itemEx, toPosition)
  34. local idStorageValue = getCreatureStorage(cid, config.idStorage) + 1
  35. if idStorageValue == 0 then
  36. addReward(cid, 1)
  37. else
  38. local exhaustedStorageValue = getCreatureStorage(cid, config.exhaustedStorage)
  39. if exhaustedStorageValue > os.time() then
  40. -- daily reward was taken
  41. return false
  42. end
  43.  
  44. local checkingStorageValue = getCreatureStorage(cid, config.checkingStorage)
  45. if checkingStorageValue < os.time() or idStorageValue > #config then
  46. -- did't taked daily reward
  47. idStorageValue = 1
  48. end
  49.  
  50. addReward(cid, idStorageValue)
  51. end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment