Olá @Carlinhous1996, boa noite!
Você não explicou exatamente quais storages gostaria de adicionar o tempo.
Ao meu ver, seria para receber a recompensa?
Fiz as modificações para só receber as recompensas caso a Storage tenha resetado, após 6 dias.
Também fiz uma pequena organização ao código.
-- Created by pc98
-- Edited by xMonkey
local config = {
castle_one_name = "Castle", -- Nome do castelo 1
storages = {154154,54321,123123, 123124}, -- Storages ( se vc eh iniciante, deixe como está...)
-- REWARDS I N D I V I D U A I S ---------
premio_por_vezes = 1, -- Premio por vezes de conquista de castelo. (1) = Ativo (0) = Desativa.
premio_vezes = 3, -- Caso ativo, a quantidade de conquista que o player tem, para ganhar PREMIO.
premio = 10522, -- ID do Premio
premio_cont = 1, -- Quantidade do Premio
premio_reset = 1, -- Resetar o contador do premio depois que atingir a meta?? (1) = SIM (0) = NAO
resetReward = {6, "day"} -- Tempo para resetar a storage e receber novamente a recompensa
}
-- Para deixar mais organizado, jogar essas funções em LIB (se jogar em LIB, remover o local na frente de function)
-- Custom Functions (inicio)
local function mathtime(table) -- by dwarfer
local unit = {"sec", "min", "hour", "day"}
for i, v in pairs(unit) do
if v == table[2] then
return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1)
end
end
return error("Bad declaration in mathtime function.")
end
local function getTimeString(self)
local format = {
{'dia', self / 60 / 60 / 24},
{'hora', self / 60 / 60 % 24},
{'minuto', self / 60 % 60},
{'segundo', self % 60}
}
local out = {}
for k, t in ipairs(format) do
local v = math.floor(t[2])
if(v > 0) then
table.insert(out, (k < #format and (#out > 0 and ', ' or '') or ' e ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
end
end
local ret = table.concat(out)
if ret:len() < 16 and ret:find('segundo') then
local a, b = ret:find(' e ')
ret = ret:sub(b+1)
end
return ret
end
-- Custom Functions (fim)
function onUse(cid, item, frompos, item2, topos)
local sto_ativ, position = getGlobalStorageValue(config.storages[2]), getCreaturePosition(cid)
if (isPlayerGuild(cid) == true) then
if (sto_ativ == 1 or sto_ativ == -1) then
guildname = getPlayerGuildName(cid)
guild = getPlayerGuildId(cid)
guild_sto = getGlobalStorageValue(config.storages[3])
if (guild ~= guild_sto) then
setPlayerStorageValue(cid, guild_sto, guild)
if (getPlayerStorageValue(cid, config.storages[1]) == -1) then
setPlayerStorageValue(cid, config.storages[1], 0)
end
setGlobalStorageValue(config.storages[3], getPlayerGuildId(cid))
setPlayerStorageValue(cid,config.storages[1], getPlayerStorageValue(cid, config.storages[1]) + 1)
sto_vezes_total = getPlayerStorageValue(cid, config.storages[1])
doBroadcastMessage("O(a) "..getCreatureName(cid).." acabou de conquistar o ".. config.castle_one_name .." para a guild \"".. guildname .."\" pela ".. sto_vezes_total .."ª vez(s).", 22)
doSendMagicEffect(position, 39)
doRemoveItem(item.uid, 1)
if (config.premio_por_vezes == 1) then
if (getPlayerStorageValue(cid, config.storages[4]) - os.time() > 0) then
doPlayerSendTextMessage(cid, 18, "Voce deve aguardar ".. getTimeString(getPlayerStorageValue(cid, config.storages[4]) - os.time()) .." para receber a recompensa novamente.")
return true
end
if (getPlayerStorageValue(cid, config.storages[1]) == config.premio_vezes) then
if (getItemWeightById(config.premio, 1) <= getPlayerFreeCap(cid)) then
doBroadcastMessage("O ".. getCreatureName(cid) .." ganhou uma(o) ".. getItemNameById(config.premio) .." como recompensa das suas ".. config.premio_vezes .." conquistas!", 21)
doPlayerAddItem(cid, config.premio, config.premio_cont)
doPlayerSendTextMessage(cid, 18, "Voce recebeu o(a) ".. getItemNameById(config.premio) .." como recompensa das suas ".. config.premio_vezes .." conquistas!")
if config.premio_reset == 1 then
setPlayerStorageValue(cid,config.storages[1], 0)
end
setPlayerStorageValue(cid, config.storages[4], os.time() + mathtime(config.resetReward))
else
doPlayerSendTextMessage(cid, 18, "Voce nao tem capacidade para ganhar o item. Vamos verificar novamente em 10 segundos!")
addEvent(additem, 10000, cid, config.premio, config.premio_cont, config.premio_reset)
end
end
end
else
doBroadcastMessage("O(a) ".. getCreatureName(cid) .." acabou de conquistar o ".. config.castle_one_name .." para a guild \"".. guildname .."\" pela ".. sto_vezes_total .."ª vez(s).", 22)
doSendMagicEffect(position, 39)
end
else
doPlayerSendCancel(cid, "O sistema está desativado")
end
else
doPlayerSendCancel(cid, "É nescessario ter guild para dominar o castelo!")
doSendMagicEffect(position, 2)
end
end
function additem(cid, config.premio, config.premio_cont, config.premio_reset)
if (not isPlayer(cid)) then
stopEvent(additem)
return true
end
if (getItemWeightById(config.premio, 1) <= getPlayerFreeCap(cid)) then
doPlayerAddItem(cid, config.premio, config.premio_cont)
doPlayerSendTextMessage(cid, 18, "Voce recebeu o(a) ".. getItemNameById(config.premio) .." como recompensa das suas ".. config.premio_vezes .." conquistas!")
if (config.premio_reset == 1) then
setPlayerStorageValue(cid, config.storages[1], 0)
end
setPlayerStorageValue(cid, config.storages[4], os.time() + mathtime(config.resetReward))
stopEvent(additem)
else
doPlayerSendTextMessage(cid, 18, "Voce nao tem capacidade para receber o item. Verificando novamente em 10 segundos!")
addEvent(additem, 10000, cid)
end
end
function isPlayerGuild(cid)
if (getPlayerGuildName(cid) ~= "") then
return true
else
return false
end
end