Allan's Coding Tid-bits

A refuge for those migrating from the fallen DXEditing.com and a place for general discussion relating to Deus Ex editing (coding, mapping, etc).
Post Reply
Allan
NSF
Posts: 52
Joined: Thu Apr 16, 2009 4:54 pm

Allan's Coding Tid-bits

Post by Allan »

Feel free to use any code in this section for your own mods, provided you leave me credit in the class detail comments in the classes it's used in, or something.

In-Game Clock.

Make a string, that grabs your system clock data, and turns it into a DX usable string in "dd/MMMM/yyyy - hh:mm:ss" format.

Global Variables:

Code: Select all

var() localized string HumanMonths[12];
var() localized string HumanDaySuffix[10];
Actual Code:

Code: Select all

function string CalculateDateTime()
{
	local String timeString, hourStr, minStr, secStr, daySuffix;
	local DeusExSaveInfo saveInfo;
	local GameDirectory saveDir;
	local int XXV;

	// Create our Map Directory class
	saveDir = player.CreateGameDirectoryObject();

	saveInfo = saveDir.GetTempSaveInfo();
	saveInfo.UpdateTimeStamp();

	if(saveInfo.Minute<10)
		minStr="0"$saveInfo.Minute;
	else
		minStr=""$saveInfo.Minute;

	if(saveInfo.Second<10)
		secStr="0"$saveInfo.Second;
	else
		secStr=""$saveInfo.Second;
		
	if(saveInfo.Hour %12 < 10)
		hourStr="0"$int(saveInfo.Hour % 12);
	else
		hourStr=""$int(saveInfo.Hour % 12);

	if(saveInfo.Hour==0)
		hourStr = "12";

	XXV=saveInfo.Day % 10;
	daySuffix = humanDaySuffix[XXV];
	if(saveInfo.Hour<12)
		timeString = saveInfo.Day $daySuffix $" " $HumanMonths[saveInfo.Month-1] $" " $saveInfo.Year $" - " $hourStr $":" $minStr $":" $secStr $" AM";
	else
		timeString = saveInfo.Day $daySuffix $" " $HumanMonths[saveInfo.Month-1] $" " $saveInfo.Year $" - " $hourStr $":" $minStr $":" $secStr $" PM";
	return timeString;
}
Default Properties:

Code: Select all

defaultproperties
{
     HumanMonths(0)="January"
     HumanMonths(1)="February"
     HumanMonths(2)="March"
     HumanMonths(3)="April"
     HumanMonths(4)="May"
     HumanMonths(5)="June"
     HumanMonths(6)="July"
     HumanMonths(7)="August"
     HumanMonths(8)="September"
     HumanMonths(9)="October"
     HumanMonths(10)="November"
     HumanMonths(11)="December"
     HumanDaySuffix(0)="th"
     HumanDaySuffix(1)="st"
     HumanDaySuffix(2)="nd"
     HumanDaySuffix(3)="rd"
     HumanDaySuffix(4)="th"
     HumanDaySuffix(5)="th"
     HumanDaySuffix(6)="th"
     HumanDaySuffix(7)="th"
     HumanDaySuffix(8)="th"
     HumanDaySuffix(9)="th"
}
( Yes, there are probably infinitely more efficient ways to handle the human-readable data parts, but at least I know that this works. :) )

<MORE RANDOM CODE SNIPPINGS COMING SOON..?>
Last edited by Allan on Tue Dec 07, 2010 5:55 pm, edited 1 time in total.
Image
Click, and watch with false amazement as this dragon grows up.
Darma
UNATCO
Posts: 151
Joined: Wed Apr 15, 2009 2:20 pm

Re: Allan's Coding Tid-bits

Post by Darma »

OH DEAR GOD!
There are months that I try to make a mutator which would clientmessage the local-computer-time because sometimes you don't have a clock under you hand.
Didn't made it yet...
Darma
UNATCO
Posts: 151
Joined: Wed Apr 15, 2009 2:20 pm

Re: Allan's Coding Tid-bits

Post by Darma »

GAH that's awesome, it also allow me to make a datacube with a tick to get the time in direct :D

I WANT MORE!
Allan
NSF
Posts: 52
Joined: Thu Apr 16, 2009 4:54 pm

Re: Allan's Coding Tid-bits

Post by Allan »

Slight code error I noticed going through my Accessed None readouts:

Code: Select all

   if(saveInfo.Hour<12)
      timeString = saveInfo.Day $daySuffix $" " $HumanMonths[saveInfo.Month+1] $" " $saveInfo.Year $" - " $hourStr $":" $minStr $":" $secStr $" AM";
   else
      timeString = saveInfo.Day $daySuffix $" " $HumanMonths[saveInfo.Month+1] $" " $saveInfo.Year $" - " $hourStr $":" $minStr $":" $secStr $" PM";
should be

Code: Select all

   if(saveInfo.Hour<12)
      timeString = saveInfo.Day $daySuffix $" " $HumanMonths[saveInfo.Month-1] $" " $saveInfo.Year $" - " $hourStr $":" $minStr $":" $secStr $" AM";
   else
      timeString = saveInfo.Day $daySuffix $" " $HumanMonths[saveInfo.Month-1] $" " $saveInfo.Year $" - " $hourStr $":" $minStr $":" $secStr $" PM";
I'll amend that to the top post.
Image
Click, and watch with false amazement as this dragon grows up.
Post Reply