Skip to main content

Ingame Server Clock

SERVER CLOCK UNDER THE MINIMAP - BUILD IT FROM SCRATCH
Ether Saga Odyssey client
=====================================================================

What you get: a small bar under the minimap (top-right) that shows
"Server time 12:34:56" and counts every second.

No elementclient.exe changes. You only add two files to
interfaces.pck and one line to ingame.dcf.


WHAT YOU NEED
-------------
- A .pck tool that already opens and repacks YOUR client's
  interfaces.pck (packs can use server-specific keys)
- Notepad++ or Windows Notepad

Back up interfaces.pck first.


STEP 1 - Create the layout file  ServerClock.xml
------------------------------------------------
Make a new text file with exactly this content:

<DIALOG Name="Win_ServerClock" Width="160" Height="28">
<Resource>
<FrameImage FileName="frame\frame2.tga"/>
</Resource>
<LABEL Name="Txt_Time" y="6" Width="160" Height="18" Align="1">
<Text String="Clock: no script" FontName="方正隶二简体" FontSize="11" Shadow="150" Bold="true" Color="255,228,168,255" OutlineColor="0,0,0,0" TextUpperColor="0,0,0,0" TextLowerColor="0,0,0,0"/>
</LABEL>
</DIALOG>

Notes:
- Keep the Chinese font name exactly as written; it is the game's
  own font.
- Save the file as "UTF-16 LE BOM"
  (Notepad++: Encoding > UTF-16 LE BOM;
   Notepad: Save As > Encoding "UTF-16 LE" or "Unicode").
- frame\frame2.tga is the brown frame the game already uses for its
  "please wait" bar, so no new picture is needed.

Put it in interfaces.pck at:
   interfaces\ServerClock.xml
(same folder as MiniMap.xml)


STEP 2 - Create the script  serverclock.lua
-------------------------------------------
Make a new text file with exactly this content
(save as plain ANSI, or UTF-8 without BOM):

-------------------- copy from here --------------------
local DlgTemplate = DlgTemplate
local DlgApi  = DlgApi
local string = string
local os = os
local math = math
local pcall = pcall
local tostring = tostring

---------------- settings ----------------
local UTC_OFFSET   = -5      -- server time zone, hours from UTC
local USE_US_DST   = true    -- US/Canada daylight saving (false elsewhere)
local SHOW_SECONDS = true
local LABEL        = "Server time "
-------------------------------------------

local datamember = { this = "Win_ServerClock", lastsec = -1 };
Win_ServerClock = DlgTemplate:new(datamember)

local function weekday(y, m, d)
local t = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }
if m < 3 then y = y - 1 end
return (y + math.floor(y / 4) - math.floor(y / 100) + math.floor(y / 400) + t[m] + d) % 7
end

local function nth_sunday(y, m, n)
local first = weekday(y, m, 1)
return 1 + (7 - first) % 7 + (n - 1) * 7
end

local function in_us_dst(t)
local m, d, h = t.month, t.day, t.hour
if m < 3 or m > 11 then return false end
if m > 3 and m < 11 then return true end
if m == 3 then
local s = nth_sunday(t.year, 3, 2)
return d > s or (d == s and h >= 2)
end
local s = nth_sunday(t.year, 11, 1)
return d < s or (d == s and h < 1)
end

function Win_ServerClock:Init()
self.lastsec = -1
DlgApi.SetItemText(self.this, "Txt_Time", "Clock loaded")
end

local function update_clock(self)
local now = os.time()
if now == self.lastsec then return end
self.lastsec = now
local secs = now + UTC_OFFSET * 3600
if USE_US_DST and in_us_dst(os.date("!*t", secs)) then
secs = secs + 3600
end
local t = os.date("!*t", secs)
local text
if SHOW_SECONDS then
text = string.format("%s%02d:%02d:%02d", LABEL, t.hour, t.min, t.sec)
else
text = string.format("%s%02d:%02d", LABEL, t.hour, t.min)
end
DlgApi.SetItemText(self.this, "Txt_Time", text)
end

function Win_ServerClock:Tick(dwDeltaTime)
local ok, err = pcall(update_clock, self)
if not ok then
DlgApi.SetItemText(self.this, "Txt_Time", "ERR " .. tostring(err))
end
end
-------------------- copy to here --------------------

Put it in interfaces.pck at:
   interfaces\script\interfaces\serverclock.lua
(same folder as minigame.lua)

The name must match the layout name (ServerClock.xml ->
serverclock.lua), or the game won't load the script.


STEP 3 - Tell the game to show it (ingame.dcf)
----------------------------------------------
Take  interfaces\ingame.dcf  out of interfaces.pck and open it.
Find this line:

MiniMapClose.xml -2 0 0

Add this line directly under it:

ServerClock.xml -2 186 1

The gaps are TAB characters, not spaces.
   -2   = against the right edge of the screen
   186  = just below the minimap (the minimap is 185 pixels tall)
   1    = shown when you log in

Save it in the same encoding it already had, then put it back.
Only add the line; don't replace the whole file with someone
else's copy, because every client's ingame.dcf can be different.


STEP 4 - Repack and test
------------------------
Repack interfaces.pck, put it in the client folder and restart the
client fully. The bar should appear under the minimap with the time
counting every second.


TIME SETUP (settings at the top of serverclock.lua)
---------------------------------------------------
UTC_OFFSET   your server's time zone, hours from UTC:
               Eastern  -5      UK               0
               Central  -6      Central Europe   1
               Mountain -7      China / Taiwan   8
               Pacific  -8
             Use the standard (winter) offset; daylight saving is
             added by the next setting.

USE_US_DST   true  = add 1 hour during US daylight saving
                     (2nd Sunday of March to 1st Sunday of November)
             false = never add the hour (use this outside the
                     US/Canada, or if your server's zone has no
                     daylight saving)

SHOW_SECONDS false = show only hours:minutes

LABEL        the text in front of the time, e.g. "Server time "

How the time is worked out: the clock takes each player's own PC
clock and converts it to your server's time zone. So it shows the
right server time for every player, wherever they live, as long as
their PC clock is correct (Windows normally keeps it synced). It does
not read the server machine's clock, so also make sure your server's
own clock is set correctly, because events run on that clock.


MOVING THE BAR
--------------
In the ingame.dcf line:
   change 186 to move it up or down
   change -2 to move it left (e.g. -40)


USING YOUR OWN BAR PICTURE (optional)
-------------------------------------
Make a 160 x 28 picture, save it as a 32-bit .tga with transparency,
and put it in surfaces.pck, e.g. at:
   surfaces\Window\ServerClock.tga
Then in ServerClock.xml change
   frame\frame2.tga   to   Window\ServerClock.tga
If your picture is dark, change the text Color to "255,255,255,255"
(white) so it stays readable.


IF IT DOESN'T WORK
------------------
Look at what the bar shows:

   Nothing at all       the ingame.dcf line is missing or wrong (check
                        the TABs), or ServerClock.xml isn't in
                        interfaces\
   "Clock: no script"   serverclock.lua is in the wrong folder or has
                        a different name
   "Clock loaded" only  the script loaded but the time isn't updating
   "ERR ..."            a script error; the text says what went wrong
   Wrong hour           check UTC_OFFSET and USE_US_DST