Post by nebula on Dec 26, 2005 0:11:04 GMT -5
I was bored, i really have no use for this but it seems the clock thingy in ffassist is popular. feel free to use the code and pretty it up with moon phase pics or what-not, jes give credit where credit is due
oh, and btw, this is prolly buggier than hell, if times are way off, post your timezone, your clock time, and the time the script said it should be and i'll look more at it
oh a note about FixTime, its vanadiel minutes, so 15*60 would actually be 15 minutes ingame VD time, differences in clock values are prolly from this value being different for people
Clock.lua
Airship schedule (added 1/1/06)
Airship.lua
oh, and btw, this is prolly buggier than hell, if times are way off, post your timezone, your clock time, and the time the script said it should be and i'll look more at it
oh a note about FixTime, its vanadiel minutes, so 15*60 would actually be 15 minutes ingame VD time, differences in clock values are prolly from this value being different for people
Clock.lua
-- Vana'diel Clock by Nebula
-- Copyright (C) 2006 Kyle Buller
--
-- Code adapted from FFXI Time Information by Pyogenes (http://www.pyogenes.com/ffxi/timer/)
-- (and by adapted, i mean changed, mangled, and forced to work)
--
-- Note: All times are translated from YOUR SYSTEM clock, not magically pulled from the ffxi servers
-- if the times are wrong *cough*its very likely i screwed something up*cough* sync your clock
--
GMTOffset = -6 --your timezone rel to GMT
FixTime = 15*60 --number of seconds to add if your clock is off (subjective)
showSeconds = 1 --0 = off, 1 = show seconds on moon timers, 2 = show vana'diel (milli)seconds
-- Don't touch --
-- dates used to convert real time to game time
BasisDate = os.time{year=2002, month=6, day=23, hour=16+GMTOffset, min=0, sec=0}
MoonDate = os.time{year=2004, month=1, day=25, hour=2+GMTOffset, min=31, sec=12}
VanaDayList = {"Earthsday", "Watersday", "Windsday", "Iceday", "Lightningsday", "Lightsday", "Darksday","Firesday"}
PhaseNameList = {"Full Moon","Waning Gibbous","Last Quarter Moon","Waning Crescent","New Moon","Waxing Crescent","First Quarter Moon","Waxing Gibbous"}
msGameDay = (24 * 60 * 60 * 1000 / 25) --milliseconds in a game day
msRealDay = (24 * 60 * 60 * 1000) --milliseconds in a real day
--returns a string if no 'formating string', returns a table if passed "*t"
function getVanadielTime(f)
local now = os.time()
local vTime = ((898 * 360 + 30 + 32) * msRealDay + FixTime*1000) + (now * 1000 - BasisDate * 1000) * 25
local vYear = math.floor(vTime / (360 * msRealDay))
local vMon = math.floor(math.mod(vTime, 360 * msRealDay) / (30 * msRealDay)) --+ 1
local vDate = math.floor(math.mod(vTime, 30 * msRealDay) / (msRealDay)) --+ 2
local vHour = math.floor(math.mod(vTime, msRealDay) / (60 * 60 * 1000)) --+ 1
local vMin = math.floor(math.mod(vTime, 60 * 60 * 1000) / (60 * 1000))
local vSec = math.floor(math.mod(vTime, 60 * 1000) / 1000)
local vDay = math.floor(math.mod(vTime, 8 * msRealDay) / msRealDay) + 1
local VanaTimeTable = {year=vYear, month=vMon, day=vDate, hour=vHour, min=vMin, sec=vSec, wday=vDay}
local VanaTime = string.format("%02d/%02d/%d, %s, %02d:%02d",vMon,vDate,vYear,VanaDayList[vDay],vHour,vMin)
if showSeconds == 2 then
VanaTime = VanaTime .. string.format(":%02d",vSec)
end
if f == nil then
return VanaTime
elseif f == "*t" then
return VanaTimeTable
end
end
function getMoonPhase()
--new moon starts on day 38 (-10%)
--full moon starts at 80 (90%)
--Moon cycle lasts 84 game days
local now = os.time()
local moonDays = math.mod(math.floor((now * 1000 - MoonDate * 1000) / msGameDay),84)
local mnElapsedTime = math.mod(now * 1000 - MoonDate * 1000,msGameDay)
local mnPhase, optPhase, toNextPhase, toOptimalPhase
-- determine phase percentage
local moonpercent = math.floor(((moonDays - 42) / 42 * 100) + 0.5)
if (moonpercent <= -94) then
mnPhase = 1
optPhase = 5
toNextPhase = (3 - moonDays) * msGameDay - mnElapsedTime
toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime
elseif (moonpercent >= 90) then
mnPhase = 1
optPhase = 5
toNextPhase = (87 - moonDays) * msGameDay - mnElapsedTime
toOptimalPhase = (38 + 84 - moonDays) * msGameDay - mnElapsedTime
elseif (moonpercent >= -93 and moonpercent <= -62) then
mnPhase = 2
optPhase = 5
toNextPhase = (17 - moonDays) * msGameDay - mnElapsedTime
toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime
elseif (moonpercent >= -61 and moonpercent <= -41) then
mnPhase = 4
optPhase = 5
toNextPhase = (25 - moonDays) * msGameDay - mnElapsedTime
toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime
elseif (moonpercent >= -40 and moonpercent <= -11) then
mnPhase = 4
optPhase = 5
toNextPhase = (38 - moonDays) * msGameDay - mnElapsedTime
toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime
elseif (moonpercent >= -10 and moonpercent <= 6) then
mnPhase = 5
optPhase = 1
toNextPhase = (45 - moonDays) * msGameDay - mnElapsedTime
toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime
elseif (moonpercent >= 7 and moonpercent <= 36) then
mnPhase = 6
optPhase = 1
toNextPhase = (58 - moonDays) * msGameDay - mnElapsedTime
toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime
elseif (moonpercent >= 37 and moonpercent <= 56) then
mnPhase = 7
optPhase = 1
toNextPhase = (66 - moonDays) * msGameDay - mnElapsedTime
toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime
elseif (moonpercent >= 57 and moonpercent <= 89) then
mnPhase = 8
optPhase = 1
toNextPhase = (60 - moonDays) * msGameDay - mnElapsedTime
toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime
end
local currentPhase = string.format("%s (%d%%)",PhaseNameList[mnPhase],math.abs(moonpercent))
local nextPhase = string.format("Next phase (%s): %s",PhaseNameList[math.mod(mnPhase,8)+1],formatTime(toNextPhase))
local nextOptPhase = string.format("Next %s: %s",PhaseNameList[optPhase],formatTime(toOptimalPhase))
return currentPhase, nextPhase, nextOptPhase
end
function formatTime(t)
local dayLeft = t / msRealDay
local hourLeft = (dayLeft - math.floor(dayLeft)) * 24
local minLeft = (hourLeft - math.floor(hourLeft)) * 60
local secLeft = (minLeft - math.floor(minLeft)) * 60
local formattedTime = ""
dayLeft = math.floor(dayLeft)
hourLeft = math.floor(hourLeft)
minLeft = math.floor(minLeft)
if dayLeft > 0 then formattedTime = formattedTime .. string.format("%d:",dayLeft) end
if hourLeft > 0 then formattedTime = formattedTime .. string.format("%02d:",hourLeft) end
formattedTime = formattedTime .. string.format("%02d",minLeft)
if showSeconds then formattedTime = formattedTime .. string.format(":%02d",secLeft) end
return formattedTime
end
Text = Graphics.text_CreateObject()
Graphics.text_SetPosition(600,50,Text)
Graphics.text_SetColor(255,255,255,255,Text)
Graphics.text_SetFont("Arial Bold",11,Text)
Graphics.text_SetBold(true,Text)
while true do
local Output = ""
--Output = Output .. os.date("%a. %d, %Y %I:%M%p") .. "\n"
Output = Output .. string.format("%s\n",getVanadielTime())
Output = Output .. string.format("%s\n%s\n%s\n",getMoonPhase())
Graphics.text_SetText(Output,Text)
Windower.script_Sleep(900)
end
Airship schedule (added 1/1/06)
Airship.lua
-- Vana'diel Clock: Airship Schedule by Nebula
-- Copyright (C) 2006 Kyle Buller
--
-- Code adapted from FFXI Time Information by Pyogenes (http://www.pyogenes.com/ffxi/timer/)
-- (and by adapted, i mean changed, mangled, and forced to work)
--
-- Note: All times are translated from YOUR SYSTEM clock, not magically pulled from the ffxi servers
-- if the times are wrong *cough*its very likely i screwed something up*cough* sync your clock
GMTOffset = -6
FixTime = 15*60
-- Be careful --
Text = Graphics.text_CreateObject()
Graphics.text_SetPosition(400,100,Text)
Graphics.text_SetColor(255,255,255,255,Text)
Graphics.text_SetFont("Courier New",11,Text) --pick a fixed width font or it won't look pretty
Graphics.text_SetBold(true,Text)
-- Don't touch --
Graphics.text_SetText("Loading...",Text)
BasisDate = os.time{year=2002, month=6, day=23, hour=16+GMTOffset, min=0, sec=0}
MoonDate = os.time{year=2004, month=1, day=25, hour=2+GMTOffset, min=31, sec=12}
VanaDayList = {"Earthsday", "Watersday", "Windsday", "Iceday", "Lightningday", "Lightsday", "Darksday","Firesday"}
msGameDay = (24 * 60 * 60 * 1000 / 25) --milliseconds in a game day
msRealDay = (24 * 60 * 60 * 1000) --milliseconds in a real day
function getAirSchedule()
local now = os.time()
local elapsedTime = math.mod(now * 1000 - BasisDate * 1000, msGameDay) + 144000
local vTime = ((898 * 360 + 30) * msRealDay + FixTime*1000) + (now * 1000 - BasisDate * 1000) * 25
local vDay = math.floor(math.mod(vTime, 8 * msRealDay) / msRealDay) + 1
local offset1 = ((1 * 60) + 10) * 60 * 1000 / 25 -- 1:10 offset used by B->J J->S
local offset2 = ((2 * 60) + 40) * 60 * 1000 / 25 -- 2:40 offset used by J->W K-J
local offset3 = ((4 * 60) + 10) * 60 * 1000 / 25 -- 4:10 offset used by J->B S->J
local offset4 = ((5 * 60) + 35) * 60 * 1000 / 25 -- 5:35 offset used by J->K
local offset5 = ((5 * 60) + 45) * 60 * 1000 / 25 -- 5:45 offset used by W->J
local outAir = string.format("%s %s %s %s\n",
padstring("Airship Route",20),
padstring("Day",14),
padstring("Arrive",8),
padstring("Depart",8)
)
outAir = outAir .. ASHelper(elapsedTime, offset3, vDay, "Jeuno To Bastok")
outAir = outAir .. ASHelper(elapsedTime, offset4, vDay, "Jeuno To Kazham")
outAir = outAir .. ASHelper(elapsedTime, offset1, vDay, "Jeuno To San d'Oria")
outAir = outAir .. ASHelper(elapsedTime, offset2, vDay, "Jeuno To Windurst")
outAir = outAir .. "\n"
outAir = outAir .. ASHelper(elapsedTime, offset1, vDay, "Bastok To Jeuno")
outAir = outAir .. ASHelper(elapsedTime, offset2, vDay, "Kazham To Jeuno")
outAir = outAir .. ASHelper(elapsedTime, offset3, vDay, "San d'Oria To Jeuno")
outAir = outAir .. ASHelper(elapsedTime, offset5, vDay, "Windurst To Jeuno")
return outAir
end
function ASHelper(Elapsed, Offset, Day, City)
local newOffset = Offset;
local count = 0
while (newOffset < Elapsed) do
count = count + 1
newOffset = newOffset + (msGameDay / 4)
end
if (count >= 4) then
Day = math.mod(Day + 1, 8)
end
local arrivalTime = newOffset - Elapsed - 144000
if (arrivalTime < 0) then
arrivalTime = 0
end
local s = string.format("%s %s %s %s\n",
padstring(City,20),
padstring(VanaDayList[Day],14),
padstring(formatTime(arrivalTime),8),
padstring(formatTime(newOffset-Elapsed),8)
)
return s
end
function padstring(s,len)
if string.len(s) > len then return s end
s = s .. string.rep(" ",len-string.len(s))
return s
end
function formatTime(t)
local hourLeft = (t / msRealDay - math.floor(t / msRealDay)) * 24
local minLeft = (hourLeft - math.floor(hourLeft)) * 60
local secLeft = (minLeft - math.floor(minLeft)) * 60
return string.format("%02d:%02d",math.floor(minLeft),secLeft)
end
while true do
Output = string.format("\n%s\n",getAirSchedule())
Graphics.text_SetText(Output,Text)
Windower.script_Sleep(1000)
end