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. Players can drag it
anywhere, and it stays where they put it, even after they log out.
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="180" Height="28">
<Resource>
<FrameImage FileName="frame\frame2.tga"/>
</Resource>
<LABEL Name="Txt_Time" y="6" Width="180" 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.
- Keep the label at least 160 wide. The game's font is wider than it
looks; if the label is too narrow, the time drops onto a hidden
second line and you only see "Server time".
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 io = io
local math = math
local pcall = pcall
local tostring = tostring
local tonumber = tonumber
---------------- 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 SAVE_FILE = "userdata\\serverclock.txt" -- remembers the position
-------------------------------------------
local datamember = { this = "Win_ServerClock", lastsec = -1,
posx = nil, posy = nil, posdone = false, postimer = 0,
lastx = nil, lasty = nil, moved = false };
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
-- saved position: "x y" in userdata\serverclock.txt
local function load_position()
local f = io.open(SAVE_FILE, "r")
if not f then return nil, nil end
local line = f:read("*l") or ""
f:close()
local x, y = string.match(line, "(%-?%d+)%s+(%-?%d+)")
x, y = tonumber(x), tonumber(y)
if x and y and x >= 0 and y >= 0 then return x, y end
return nil, nil
end
local function save_position(x, y)
local f = io.open(SAVE_FILE, "w")
if f then f:write(tostring(x) .. " " .. tostring(y)) f:close() end
end
-- put the bar back where the player left it, then watch for moves
local function track_position(self, dt)
if not self.posdone then
self.posdone = true
if self.posx and self.posy then
DlgApi.SetDialogPosition(self.this, self.posx, self.posy)
end
local p = DlgApi.GetDialogProp(self.this)
self.lastx, self.lasty = p.x, p.y
return
end
self.postimer = self.postimer + dt
if self.postimer < 1000 then return end -- check once a second
self.postimer = 0
local p = DlgApi.GetDialogProp(self.this)
if p.x ~= self.lastx or p.y ~= self.lasty then
self.lastx, self.lasty = p.x, p.y -- still being moved
self.moved = true
elseif self.moved then
self.moved = false -- stopped: save it
save_position(p.x, p.y)
end
end
function Win_ServerClock:Init()
self.lastsec = -1
local ok, x, y = pcall(load_position)
if ok then self.posx, self.posy = x, y end
self.posdone = false
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))
return
end
pcall(track_position, self, dwDeltaTime or 0)
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
This is only the STARTING spot. Once a player drags the bar, their
own spot is used instead (see "Remembering the position" below).
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.
REMEMBERING THE POSITION
------------------------
How it works (already in the script above):
- Players drag the bar like any other window.
- Once a second the script checks where the bar is. When it has
moved and then stays still, the spot is saved to
userdata\serverclock.txt
in the player's client folder (just two numbers: x y).
- At the next login the bar is put back on that spot.
- Players who never move it keep the starting spot from ingame.dcf.
To reset a player's bar to the starting spot: delete
userdata\serverclock.txt (or log in once with it deleted).
Things to know:
- The saved spot is in screen pixels. If a player moves the bar and
then switches to a smaller screen resolution, it can end up off
screen. Deleting userdata\serverclock.txt fixes that.
- The userdata folder must exist in the client folder (it normally
does). If it doesn't, the clock still works but the position isn't
remembered.
- Want the bar locked in place instead? Remove the line
pcall(track_position, self, dwDeltaTime or 0)
and add this as the last line inside Win_ServerClock:Init():
DlgApi.SetDialogProp(self.this, { canmove = false })
MOVING THE STARTING SPOT
------------------------
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 picture (e.g. 180 x 28), 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
and make the DIALOG and LABEL widths match the picture.
If your picture is dark, change the text Color to "255,255,255,255"
(white) so it stays readable.
Tip: to match the minimap's name bar, look at surfaces\Window\Radar.tga.
Its name bar is a navy gradient at about 60% opacity (alpha 153)
with a cream border.
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
Only "Server time", the label is too narrow; make the DIALOG and
no numbers LABEL wider (see Step 1)
Wrong hour check UTC_OFFSET and USE_US_DST
Position not kept check that the userdata folder exists in the
client folder