Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <mod name="Daily Rewards" version="0.4.0" author="Oskar" contact="oskar1121@gmail.com" enabled="yes">
- <config name="dailyRewards_conf"><![CDATA[
- ONE_DAY = 24 * 60 * 60
- CODE_LENGTH = 10
- DAILY_CONFIG = {
- exhaustedStorage = 5000,
- checkingStorage = 5001,
- idStorage = 5002,
- codeStorage = 5003,
- --[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},
- }
- ]]></config>
- <action actionid="2026" event="script"><![CDATA[
- domodlib("dailyRewards_conf")
- local letters = {{48, 57}, {65, 76}, {78, 90}, {161, 186}}
- local function generateCode()
- local code = ''
- for i = 1, CODE_LENGTH do
- local id = letters[math.random(#letters)]
- code = code .. math.random(id[1], id[2])
- end
- return code
- end
- local function addReward(cid, id)
- local var = DAILY_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, DAILY_CONFIG.idStorage, id)
- doCreatureSetStorage(cid, DAILY_CONFIG.checkingStorage, os.time() + (ONE_DAY * 2))
- doCreatureSetStorage(cid, DAILY_CONFIG.exhaustedStorage, os.time() + ONE_DAY)
- end
- function onUse(cid, item, frompos, itemEx, toPos)
- local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
- if codeStorageValue ~= -1 then
- return false
- end
- local idStorageValue = getCreatureStorage(cid, DAILY_CONFIG.idStorage) + 1
- if idStorageValue ~= 0 then
- local exhaustedStorageValue = getCreatureStorage(cid, DAILY_CONFIG.exhaustedStorage)
- if exhaustedStorageValue > os.time() then
- -- daily reward was taken
- return false
- end
- local checkingStorageValue = getCreatureStorage(cid, DAILY_CONFIG.checkingStorage)
- if checkingStorageValue < os.time() or idStorageValue > #DAILY_CONFIG then
- -- did't taked daily reward, start counting again
- doCreatureSetStorage(cid, DAILY_CONFIG.idStorage, 0)
- end
- end
- local code = generateCode()
- doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, code)
- doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Your code is: "' .. code .. '".')
- addEvent(function()
- local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
- if codeStorageValue == -1 then
- return false
- end
- doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, -1)
- doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You didnt enter the code.')
- end, 30 * 1000)
- end
- ]]></action>
- <talkaction words='!reward' event='script'><![CDATA[
- domodlib('dailyRewards_conf')
- function onSay(cid, words, param, channel)
- local codeStorageValue = getCreatureStorage(cid, DAILY_CONFIG.codeStorage)
- if codeStorageValue == -1 then
- return true
- end
- if param ~= codeStorageValue then
- doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Wrong code.')
- return false
- end
- local idStorageValue = getCreatureStorage(cid, DAILY_CONFIG.idStorage) + 1
- if idStorageValue == 0 then
- addReward(cid, 1)
- else
- addReward(cid, idStorageValue)
- end
- return true
- end
- ]]></talkaction>
- </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement