AGS, realtime, and computer clock

Started by KingMick, Tue 09/08/2005 21:26:06

Previous topic - Next topic

KingMick

I am wondering if there is a way to have AGS "know" how long it's been since the player last played the game, perhaps via the computer's clock?  It would be an intriguing feature of a game, I think, if the gameworld progressed in time at the same rate as the real world, so that when you come back to it, the same amount of time has passed there as the amount of time that has passed in the real world.  Is there anyway to have AGS do this?

And my second question is, if there IS a way to do this, is there any way around the obvious cheating method of simply moving your clock backward or forward so as to skirt around the game's timekeeping system?

If anyone has any ideas, let me know.

--Mick

DoorKnobHandle

This is straight out of the manual. Please read it next time before posting here.

Code: ags

DateTime *dt = DateTime.Now;
Display("The date is: %02d/%02d/%04d", dt.DayOfMonth, dt.Month, dt.Year);
Display("The time is: %02d:%02d:%02d", dt.Hour, dt.Minute, dt.Second);


Oh, and if you have three questions in a row, then rather post them all in one thread than creating three ones at the same time.
Thanks.

KingMick

Heh, ok sorry, I thought it would be preferred for me to post this way rather than have all three questions in the same topic.  My mistake.  Guess I missed that in the manual--I looked for this but couldn't find it there.

Thanks for all your help.  You don't happen to know if there's any way to avoid the cheating method I mentioned above, do you?

DoorKnobHandle

Quote from: KingMick on Tue 09/08/2005 21:30:15
Thanks for all your help.  You don't happen to know if there's any way to avoid the cheating method I mentioned above, do you?

I'm afraid not, since even Windows can be "cheated" that way, I don't think AGS has a different way of getting the time.

Ishmael

...unless you script a little background progress in some other language, that counts time, but then there is the problem of how to run it... So don't even dream about it.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

monkey0506

#5
Don't ever listen when someone tells you it can't be done in AGS*:

Code: ags
// main global script

void GetTimeSincePlayed() {
  File* in = File.Open("gametime.dat", eFileRead);
  if (in == null) return;
  int prevrawtime = in.ReadInt();
  in.Close();
  DateTime* now = DateTime.Now;
  int rawtime = now.RawTime;
  int rawdiff = rawtime - prevrawtime;
  int years = rawdiff / (60 * 60 * 24 * 365);
  int days = (rawdiff - (years * 60 * 60 * 24 * 365)) / (60 * 60 * 24);
  int hours = ((rawdiff - (years * 60 * 60 * 24 * 365)) - (days * 60 * 60 * 24)) / (60 * 60);
  int minutes = (((rawdiff - (years * 60 * 60 * 24 * 365)) - (days * 60 * 60 * 24)) - (hours * 60 * 60)) / 60;
  int seconds = (((rawdiff - (years * 60 * 60 * 24 * 365)) - (days * 60 * 60 * 24)) - (hours * 60 * 60)) - (minutes * 60);
  Display("It has been %d years, %d days, %d hours, %d minutes, %d seconds since you last played!", years, days, hours, minutes, seconds);
  }

// in game_start
GetTimeSincePlayed(); /* display time since game last played*/

// in on_key_press
  if (keycode == 27) { /* ESC */
    File* out = File.Open("gametime.dat", eFileWrite);
    DateTime* now = DateTime.Now;
    out.WriteInt(now.RawTime);
    out.Close();
    QuitGame(0);
    }


This bit of code will display the time since you last played the game (if you have played it previously and exited it by pressing Esc) when the game starts.  However there is the problem of saving the time that the user exited.  So, in your Exit Game script just put that last bit (replace keycode == 27 with the appropriate keycode or move the code to the GUI button click function or w/e).  I hope this helps!


Edit:  Note that this does not save the game time if an error is encountered or the game is exited without using the Esc key (this key can be changed or moved to a GUI button click function as previously mentioned though).


Edit:
*Unless of course that someone is Chris (Pumaman).  Seeing as he made AGS he probably tends to know when something can't be done. :D

DoorKnobHandle

:) No hard feelings here, but I have to say, that I did think of that way, and I must say it would propbably be even easier and quicker to hack this .dat file than to change your computer clock.

The only really safe way would be a correct working AGS function, and that does not exists.

But anyways, who really cares about "cheaters"... 8)

Kweepa

Quote from: monkey_05_06 on Tue 09/08/2005 23:06:21
And I have passed the challenge.Ã,  (Also @Ish & [...]:Ã,  I didn't mean to make you guys out to be the bad guys...but you did both say that it couldn't be done.Ã,  And Ish even went as far as to say "don't even dream about it."Ã,  No hard feelings you guys. :=)

You do realize that the "challenge" was to prevent cheating by changing the computer clock between runs, and that you have miserably failed the "challenge"? You also seem to have forgotten to make use of the "leapdays" variable in your calculations. Perhaps more reading and concentrating, and less gloating, would help.

Still, you have supplied some code that KingMick can work with. Huzzah!
Still waiting for Purity of the Surf II

monkey0506

#8
Well I didn't mean to gloat...sorry if I sounded bigheaded.  I misunderstood what he meant when he said that (about cheating), but then there would be no way of doing it without connecting to a clock on the internet that the user couldn't tamper with which would also require implementation of the TCP/IP plugin.  The leap days are included into the days automatically in the math that is already provided.  I didn't realize that at first but I caught on later and forgot to delete the variable.

Edit:  Also, the DAT file is encrypted by AGS, so if someone really wanted to hack it they would have to hack AGS to find out the encryption method, or edit the DAT file, destroying it's contents making them unusable...Unless of course there's a method I've overlooked...

KingMick

Oh, thanks monkey!  I will definitely copy and save this code you provided, it should prove useful.  However, if  I understand correctly, even with this code as part of my program, players can still "fool" the game by adjusting their computer clock, correct?  The code seems to still make use of the computer clock to see how long its been since the game was last played, so someone would still be able to cheat...right?

I am just making sure, here--I actually still do find this code to be very valuable and if I make a game that involves realtime I will assuredly make use of this :-D

--Mick

monkey0506

Yes, the user can still screw with their clocks to change the game time.  However, you could try to work something out with connecting to a global time server on the net if you are that worried about cheating.

Vince Twelve

There's one very simple way to stop people from cheating by changing their system clock:  make it a gameplay feature.

And I have passed the challenge.  I didn't mean to make you guys out to be the bad guys...but I did just rock your socks off.

KingMick

I'm sorry, what do you mean exactly, Vince?  Are you saying, use an in-game clock that does not connect to the computer clock at all?  Because that defeats the purpose of the question--what I was asking is if there's a way for the game to "know" how much time has passed since it was last played and if there's a way to avoid cheating with this, so the timekeeping device could not be an in-game feature.

Vince Twelve

#13
No no.  It was a bit of a joke.  I was suggesting that you use the computer clock to keep the real-time thing going, but you make it a game play feature that the player has to change the computer clock to "time travel" to different points in time. (i.e. set your computer's clock to two days previous and stop a murder from having happened). 

The simple idea is that if it's a gameplay feature, it's not technically cheating, is it?

It's actually a really bad idea, because the player would have to keep quitting out of the game to change the clock.

As a real suggestion:  simply saving the date and time when the player is saving/quitting can prevent the player from changing the clock backwards, though I can't think of a way to stop the player from changing the clock forwards short of connecting to a web server.

KingMick

Ahhhh!  Now I get it!  LOL, that would actually be a rather funny and intuitive feature.  Reminds me of playing "Metal Gear Solid" for the PlayStation 1.  There was this one scene where a character you are talking to tells you, "You have to dial this certain number...I have it with me...where did I put it?  Oh, that's right.  It's on the back of the CD case."  I spent a solid twenty minutes trying to find a "CD Case" inventory item in the room I was in and surrounding area, before realizing that he meant it literally--the number is printed on the back of the real CD case that Metal Gear Solid comes in.  Oy vey.

You do make a good point though--if nothing else, backward-time-travel cheating could be prevented, just not forward-time-travel.

--Mick

Snarky

He he. MGS on the PSX had any number of such corny moments of breaking the fourth wall. If you play it with a rumble pack gamepad, one of the enemy bosses will tell you to put down your controller, which he'll then move across the floor to demonstrate his "telekinetic powers". Then, in order to defeat him, you have to plug the controller into the other port to overcome his ability to predict your every move.

I think the idea of using the PC clock as a time traveling machine is really good.  You wouldn't want to do it all the time, but once in a while it would be fun. If your game features several puzzles that involve things outside of the game itself (like clues in the manual, or having to visit a real-world website), it would fit right in.

SMF spam blocked by CleanTalk