darkmu
Well-Known Member
I'm trying to make a system that he will be signaling the time for the next opening of the castle, could someone help me with this solution?
TFS 1.X
TFS 1.X
Code:
local warCastle = {
['Sunday'] = { timeOpen = '22:00' },
['Tuesday'] = { timeOpen = '22:00' },
['Friday'] = { timeOpen = '22:00' },
}
function onThink(interval)
local currentTime = os.time()
local targetTime = os.time()
local targetDate = os.date('*t', targetTime)
local targetDay = warCastle[os.date('%A', os.time(targetDate))]
if targetDay then
for timeStr, openTime in pairs(targetDay) do
local split = timeStr:split(':')
targetDate.hour, targetDate.min = split[1], split[2]
local timeLeft = os.time(targetDate) - currentTime
if timeLeft > 0 then
local spectators = Game.getSpectators(settings.position, false, true, 7, 7, 5, 5)
if #spectators > 0 then
if settings.text then
for i = 1, #spectators do
spectators[i]:say(string.format("Next War Castle Open %s.", showTimeLeft(timeLeft, true)), TALKTYPE_MONSTER_SAY, false, spectators[i], Position(81, 315, 6))
end
end
end
break
end
end
end
return true
end