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 = 5
- IP_LIST = {}
- DAILY_CONFIG = {
- exhaustedStorage = 31232,
- checkingStorage = 31234,
- idStorage = 31236,
- codeStorage = 31238,
- level = 1000,
- --[reward id] = {itemId1, amount1, itemId2, amount2, ... , itemIdX, amountX},
- --[5] = {2128, 1, 2152, 50},
- [1] = {2160, 50},
- [2] = {2319, 1},
- [3] = {11363, 1}, -- pet parts box
- [4] = {8939, 1}, -- clothes box
- [5] = {2355, 1}, -- exp box
- [6] = {11363, 1},
- [7] = {8938, 1}, -- leaf box
- [8] = {2355, 1},
- [9] = {11363, 1},
- [10] = {2355, 1},
- [11] = {8939, 1},
- [12] = {7863, 1}, -- casino coin
- [13] = {2355, 1},
- [14] = {8939, 1},
- [15] = {7863, 1},
- [16] = {2209, 1},
- [17] = {7863, 1},
- [18] = {2355, 1},
- [19] = {11363, 1},
- [20] = {8300, 1},
- [21] = {8939, 1},
- [22] = {7863, 1},
- [23] = {11331, 1},
- [24] = {2355, 1},
- [25] = {8938, 1},
- [26] = {8939, 1},
- [27] = {8300, 1},
- [28] = {2355, 1},
- [29] = {11331, 1},
- [30] = {8927, 1}, -- active backpack
- }
- function addReward(cid, id)
- local var = DAILY_CONFIG[id]
- if not var then
- doSendMagicEffect(getPlayerPosition(cid), 2)
- -- reward isn't exist
- return false
- end
- for i = 1, #var / 2 do
- doSendMagicEffect(getPlayerPosition(cid), 13)
- doPlayerSendTextMessage(cid, 19, "Congratulations, you have received your reward!")
- 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)
- doCreatureSetStorage(cid, DAILY_CONFIG.codeStorage, -1)
- end
- ]]></config>
- <action uniqueid="35227" event="script"><![CDATA[
- domodlib("dailyRewards_conf")
- local letters = {{48, 57}, {65, 90}, {97, 122}}
- local function generateCode()
- local code = ''
- for i = 1, CODE_LENGTH do
- local id = letters[math.random(#letters)]
- code = code .. string.char(math.random(id[1], id[2]))
- end
- return code
- 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 getPlayerLevel(cid) > 999 then
- if idStorageValue ~= 0 then
- local exhaustedStorageValue = getCreatureStorage(cid, DAILY_CONFIG.exhaustedStorage)
- local checkingStorageValue = getCreatureStorage(cid, DAILY_CONFIG.checkingStorage)
- local seconds, minutes, hours = exhaustedStorageValue - os.time(), 0, 0
- while seconds >= 60 do
- seconds = seconds - 60
- minutes = minutes + 1
- end
- while minutes >= 60 do
- minutes = minutes - 60
- hours = hours + 1
- end
- local message = 'U can again take reward in '
- if hours > 0 then
- message = message .. hours .. ' hour' .. (hours > 1 and 's' or '')
- end
- if minutes > 0 then
- message = message .. (hours > 0 and (seconds > 0 and ', ' or ' and ') or '') .. minutes .. ' minute' .. (minutes > 1 and 's' or '')
- end
- if seconds > 0 then
- message = message .. ((hours > 0 or minutes > 0) and ' and ' or '') .. seconds .. ' second' .. (seconds > 1 and 's' or '')
- end
- if exhaustedStorageValue > os.time() then
- doPlayerSendTextMessage(cid, 19, message .. '.')
- doSendMagicEffect(getPlayerPosition(cid), 2)
- -- daily reward was taken
- return false
- end
- 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)
- -- doShowTextDialog(cid, 2333, code)
- doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Your code is: "' .. code .. '". Type "!reward code" to claim reward.')
- 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
- 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