View Full Version : date and time script
caldas
13th June 2018, 00:54
hi
is there any way to show the system time directly inside the cod2 server?
how can i store this information in a string?
how to put in the hud i already know, i would like to know even a way to get her in the mod!
preferably without mysql ..
the options that i researched in the forum i could not make it work!
thanks
kung foo man
13th June 2018, 01:40
Im not a big fan of hacks to do something as simple as getting "date and time", so just do it properly: add the function to libcod if it doesn't exist yet
But a quick skip over vorons code shows this tho:
{"getsystemtime", gsc_utils_getsystemtime, 0},
{"getserverstarttime", gsc_utils_getserverstarttime, 0},
{"getlocaltime", gsc_utils_getlocaltime, 0},
https://github.com/voron00/libcod/blob/master/gsc.cpp#L212
And since code is documentation, just look what it does:
https://github.com/voron00/libcod/blob/master/gsc_utils.cpp#L321
caldas
13th June 2018, 02:31
the function already exists in my libcod, I compiled the source of vorons ..
how should I call it in the mod?
kung foo man
13th June 2018, 07:11
Based on the C code it should simply be: player iprintlnbold("its " + getlocaltime() + " on the server");
caldas
13th June 2018, 22:27
******* script runtime error *******
pair 'its ' and 'Wed Jun 13 22:25:49 2018' has unmatching types 'localized string' and 'string': (file 'maps/pam/precache.gsc', line 191)
game["datetimenow"] = &"its " + getlocaltime() + " on the server";
*
called from:
(file 'maps/pam/start_gametype.gsc', line 39)
maps\pam\precache::Precache();
*
called from:
(file 'maps/pam/dm.gsc', line 24)
maps\pam\start_gametype::Init();
*
called from:
(file 'maps/mp/gametypes/_callbacksetup.gsc', line 17)
[[level.callbackStartGameType]]();
*
started from:
(file 'maps/mp/gametypes/_callbacksetup.gsc', line 10)
CodeCallback_StartGameType()
*
************************************
********************
ERROR: script runtime error
(see console for details)
(file 'maps/mp/gametypes/_callbacksetup.gsc', line 10)
********************
----- Server Shutdown -----
localtime = newHudElem();
localtime.x = 70;
localtime.y = 460;
localtime.alignX = "left";
localtime.alignY = "top";
localtime.fontScale = 0.8;
localtime.color = (1, 0, 0);
localtime setText(game["datetimenow"]);
// datetime
game["datetimenow"] = &"its " + getlocaltime() + " on the server";
precacheString(game["datetimenow"]);
kung foo man
14th June 2018, 02:15
You need to learn your way around this: https://killtube.org/showthread.php?2087-Tutorial-settext()-without-precaching
caldas
14th June 2018, 02:29
see my simple script...
init()
{
thread ShowTime();
}
ShowTime()
{
self endon("disconnect");
wait level.fps_multiplier * 1;
time = newHudElem();
time.x = 70;
time.y = 460;
time.alignX = "left";
time.alignY = "top";
time.fontScale = 0.8;
time.color = (1, 0, 0);
time setText(game["showtime"]);
}
i wish the game["showtime"] were the date.
but ... when you say to inform getlocaltime() everything goes blank... hud does not appear.
buLLeT_
14th June 2018, 12:15
https://killtube.org/showthread.php?2857-COD2-Random-string-hud&highlight=makeLocalizedString
Alright, if you use libcod you can use use new makelocalizedstring function:
// Find free localized string index
index = findFreeConfigStringIndex(1310, 256);
// Set configstring
setConfigString(index, level.mapcandidate[0]["mapname"]);
// Your Hud Stuff
level.votemap0 setText(makeLocalizedString(level.mapcandidate[0]["mapname"]));
findFreeConfigStringIndex(start, end)
{
for (i = start + 1; i < start + end; i++)
{
configstring = getConfigString(i);
if (!isDefined(configstring))
return i;
}
return undefined;
}
Just tested it, works quite nicely.
edit:
This works
1533
init()
{
thread ShowTime();
}
ShowTime()
{
self endon("disconnect");
wait level.fps_multiplier * 1;
localtime = getlocaltime();
index = findFreeConfigStringIndex(1310, 256);
setConfigString(index, localtime);
time = newHudElem();
time.x = 70;
time.y = 460;
time.alignX = "left";
time.alignY = "top";
time.fontScale = 0.8;
time.color = (1, 0, 0);
time setText(makeLocalizedString(localtime));
}
findFreeConfigStringIndex(start, end)
{
for (i = start + 1; i < start + end; i++)
{
configstring = getConfigString(i);
if (!isDefined(configstring))
return i;
}
return undefined;
}
caldas
14th June 2018, 21:44
cool..
Is there a way for the hour to update? like a clock?
IzNoGoD
15th June 2018, 16:13
https://killtube.org/showthread.php?2087-Tutorial-settext()-without-precaching
Don't use the makelocalized thing for stuff that changes a lot, you'll end up with an aweful lot of configstrings.
caldas
16th June 2018, 00:08
https://killtube.org/showthread.php?2087-Tutorial-settext()-without-precaching
Don't use the makelocalized thing for stuff that changes a lot, you'll end up with an aweful lot of configstrings.
but I did not understand how it would fit into my script ...
maxdamage99
16th June 2018, 00:41
try
/*
*/
//precache this somewhere
precacheString(&"tech_date"); //tech_date very long, better "t_d" or "td"
/*
*/
PlayerConnect() //make thread after player connected or logged
{
self.time_hud = newHudElem();
self.time_hud.x = 70;
self.time_hud.y = 460;
self.time_hud.alignX = "left";
self.time_hud.alignY = "top";
self.time_hud.fontScale = 0.8;
self.time_hud.color = (1, 0, 0);
self.time_hud.label = &"tech_date";
index = G_FindConfigstringIndex("tech_date", 1310, 256);
while (1)
{
sendGameServerCommand(self getEntityNumber(), "d " + index + " " + getlocaltime());
wait 5; //rate of update date hud
}
}
buLLeT_
16th June 2018, 01:24
Change newHudElem to NewClientHudElem(self);
caldas
16th June 2018, 01:34
try
/*
*/
//precache this somewhere
precacheString(&"tech_date"); //tech_date very long, better "t_d" or "td"
/*
*/
PlayerConnect() //make thread after player connected or logged
{
self.time_hud = newHudElem();
self.time_hud.x = 70;
self.time_hud.y = 460;
self.time_hud.alignX = "left";
self.time_hud.alignY = "top";
self.time_hud.fontScale = 0.8;
self.time_hud.color = (1, 0, 0);
self.time_hud.label = &"tech_date";
index = G_FindConfigstringIndex("tech_date", 1310, 256);
while (1)
{
sendGameServerCommand(self getEntityNumber(), "d " + index + " " + getlocaltime());
wait 5; //rate of update date hud
}
}
working!! thanks! =]
IzNoGoD
16th June 2018, 06:01
Make sure you self endon("disconnect") or there will be a lot of threads running after a client disconnects.
caldas
16th June 2018, 12:50
do you think this can affect server performance?
--
i made a small change and recompile voron00 libcod
void gsc_utils_getlocaltime()
{
time_t timer;
struct tm *timeinfo;
time(&timer);
timeinfo = localtime(&timer);
char timestring[256];
strftime(timestring, sizeof(timestring), "%d/%m/%Y %H:%M", timeinfo);
char stripped_time[128];
strncpy(stripped_time, timestring, sizeof(stripped_time));
stripped_time[strlen(timestring) - 1] = '\0';
stackPushString( stripped_time );
}
IzNoGoD
16th June 2018, 13:03
Why would you copy the output over to a new stringbuffer and return that? Just return the original var...
caldas
16th June 2018, 13:06
how can i do this? i have not mastered much yet
IzNoGoD
16th June 2018, 15:50
stackPushString(timestring);
And drop the stripped_time thing.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.