Dantez
Moim sekretem jest ciasto
- Joined
- May 22, 2008
- Messages
- 1,206
- Reaction score
- 202

Author: Dantez
Version: 1.1
Platform: The Forgotten Server 0.3.6pl1
Version: 1.1
Platform: The Forgotten Server 0.3.6pl1
Dzia?anie:
Przydziela nagrody za codzienne logowanie na serwer. Logowanie musi nast?powa? w ka?dy dzie? tygodnia, niekoniecznie co 24 godziny. Nagrody wybierane s? z puli nagr?d w tablicy. Po otrzymaniu ca?ej 'tablicy' wracamy na pocz?tek kolejki i otrzymujemy przedmioty od nowa.
Konfiguracja:
Mamy do dyspozycji 3 typy nagr?d: przedmioty, do?wiadczenie, storage. Dodajemy je nast?puj?co:
{"item", ITEMID, COUNT}
{"exp", EXP_VALUE}
{"storage", STORAGE_ID, STORAGE_VALUE}
Tablica z nagrodami ma nast?puj?c? struktur?:
rewards {
{pierwszy dzie?},
{drugi dzie?},
{itd.},
}
Skrypt:
creaturescripts/scripts/rewards.lua
[LUA]local config = {
dateStorage = 25563,
rowStorage = 25564,
rewards = {
{{"item", 2160, 5}},
{{"item", 2160, 1}, {"item", 2160, 3}, {"experience", 22000}},
{{"exp", 50000}, {"storage", 80444, 5}, {"item", 2160, 10}}
}
}
local today = os.date("*t")
local tomorrow = os.date("*t", os.time() + 86400)
function onLogin(cid)
if(getPlayerAccountManager(cid) ~= MANAGER_NONE) then return true end
local nextReward, rowCount = getPlayerStorageValue(cid, config.dateStorage), getPlayerStorageValue(cid, config.rowStorage)
local nextRewardDate = os.date("*t", (nextReward ~= -1 and nextReward) or nil)
if(nextRewardDate.day == tomorrow.day and nextRewardDate.month == tomorrow.month) then
return true
else
rowCount = (rowCount > 0 and nextRewardDate.day == today.day and nextRewardDate.month == today.month
and rowCount < #config.rewards) and rowCount + 1 or 1
local configRef = config.rewards[rowCount][math.random(#config.rewards[rowCount])]
if(configRef ~= nil) then
doPlayerSetStorageValue(cid, config.dateStorage, os.time(tomorrow))
doPlayerSetStorageValue(cid, config.rowStorage, rowCount)
doPlayerSendTextMessage(cid, 24, "You have received daily login reward. Keep logging in every day to obtain better rewards!")
if(configRef[1] == "item") then
if(not doPlayerAddItem(cid, configRef[2], configRef[3], false)) then
local parcel = doCreateItemEx(ITEM_PARCEL)
doAddContainerItem(parcel, configRef[2], configRef[3])
doPlayerSendMailByName(getCreatureName(cid), parcel, getPlayerTown(cid))
doPlayerSendTextMessage(cid, 19, "Reward was sent to the depot.")
end
elseif(configRef[1] == "storage") then
doPlayerSetStorageValue(cid, configRef[2], getPlayerStorageValue(cid, configRef[2]) + configRef[3])
elseif(configRef[1] == "experience" or configRef[1] == "exp") then
doPlayerAddExp(cid, configRef[2])
else
print("[Daily reward system]: Unknown reward type.")
end
else
print("[Daily reward system]: Reference to array's element that doesn't exist.")
end
end
return true
end
[/LUA]
creaturescripts/creaturescripts.xml
[XML]<event type="login" name="Rewards" event="script" value="rewards.lua"/>[/XML]