Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local config = {
- exhaustedStorage = 5000,
- checkingStorage = 5001,
- idStorage = 5002,
- --[reward id] = {itemId1, amount1, itemId2, amount2, ... , itemIdX, amountX},
- [1] = {2148, 1},
- [2] = {2152, 1},
- [3] = {2152, 25},
- [4] = {2160, 1},
- [5] = {2128, 1, 2152, 50},
- }
- local day = 24 * 60 * 60
- local function addReward(cid, id)
- local var = config[id]
- if not var then
- -- reward isn't exist
- return false
- end
- for i = 1, #var / 2 do
- doPlayerAddItem(cid, var[i * 2 - 1], var[i * 2])
- end
- doCreatureSetStorage(cid, config.idStorage, id)
- doCreatureSetStorage(cid, config.checkingStorage, os.time() + (day * 2))
- doCreatureSetStorage(cid, config.exhaustedStorage, os.time() + day)
- end
- function onUse(cid, item, fromPosition, itemEx, toPosition)
- local idStorageValue = getCreatureStorage(cid, config.idStorage) + 1
- if idStorageValue == 0 then
- addReward(cid, 1)
- else
- local exhaustedStorageValue = getCreatureStorage(cid, config.exhaustedStorage)
- if exhaustedStorageValue > os.time() then
- -- daily reward was taken
- return false
- end
- local checkingStorageValue = getCreatureStorage(cid, config.checkingStorage)
- if checkingStorageValue < os.time() or idStorageValue > #config then
- -- did't taked daily reward
- idStorageValue = 1
- end
- addReward(cid, idStorageValue)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment