Mirage Engine
Real-Time System - Printable Version

+- Mirage Engine (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49)
+---- Thread: Real-Time System (/showthread.php?tid=808)



Real-Time System - Matt2 - 09-03-2007

Dificulty: 1/5(just C & P, do a little reading and understanding)

Yes, this is an actual time system, not using the player's system clocks to take time, but making the server have an independent timer for itself. To give it a personal timing system.

Everyone knows MS comes with a cheap Day/Night system(no gfx for it, 60 second days) And I'm sure some people have added Day/Night(Still no actual time system, just a timer that triggers day and night)

Well here, this just goes in the GameAI sub server-side.

Code:
' time sequencing
    If TimeSeconds >= 60 Then
        TimeMinutes = TimeMinutes + 1
        TimeSeconds = 0
        Call PutVar(FileName, "Time", "Minute", Trim$(TimeMinutes))
    End If
    
    If TimeMinutes >= 60 Then
        TimeHours = TimeHours + 1
        TimeMinutes = 0
        Call PutVar(FileName, "Time", "Minute", Trim$(TimeMinutes))
        Call PutVar(FileName, "Time", "Hour", Trim$(TimeHours))
    End If
    
    If TimeHours = 6 And GameTime = TIME_DAY And AMPM = "PM" Then
        GameTime = TIME_NIGHT
        PutVar FileName, "Time", "Hour", Trim$(TimeHours)
        PutVar FileName, "Time", "ToD", Trim$(GameTime)
        For i = 1 To MAX_PLAYERS
            If IsPlaying(i) = True Then
                PlayerMsg i, "It is now night.", Blue
            End If
        Next i
    End If
    
    If TimeHours = 4 And GameTime = TIME_NIGHT And AMPM = "AM" Then
        GameTime = TIME_DAY
        For i = 1 To MAX_PLAYERS
            If IsPlaying(i) = True Then
                PlayerMsg i, "It is now day.", Yellow
            End If
        Next i
        PutVar FileName, "Time", "Day", Trim$(TimeDay)
        PutVar FileName, "Time", "Hour", Trim$(TimeHours)
        PutVar FileName, "Time", "ToD", Trim$(GameTime)
    End If
    
    If TimeHours >= 12 And AMPM = "AM" And GameTime = TIME_DAY Then
        AMPM = "PM"
        PutVar FileName, "Time", "Hour", Trim$(TimeHours)
        PutVar FileName, "Time", "Day", Trim$(TimeDay)
        PutVar FileName, "Time", "Hour", Trim$(TimeHours)
        PutVar FileName, "Time", "AM/PM", Trim$(AMPM)
        If GameTime  TIME_DAY Then
            GameTime = TIME_DAY
        End If
    End If
    
    If TimeHours >= 12 And AMPM = "PM" And GameTime = TIME_NIGHT Then
        TimeDay = TimeDay + 1
        AMPM = "AM"
        PutVar FileName, "Time", "Day", Trim$(TimeDay)
        PutVar FileName, "Time", "ToD", Trim$(GameTime)
        PutVar FileName, "Time", "Hour", Trim$(TimeHours)
        PutVar FileName, "Time", "AM/PM", Trim$(AMPM)
        If GameTime  TIME_NIGHT Then
            GameTime = TIME_NIGHT
        End If
    End If
    
    If TimeHours >= 13 Then TimeHours = 1
    
    If TimeDay >= 8 Then TimeDay = 1
Don't forget to add in all the noted Variables! TimeHours, TimeDay and TimeMinute. A Byte is good enough for each of them. Publicly declare them somewhere. AMPM, declare it as a String, Publicly as you did the others.

All it does is keep track of time, change day/night when appropriate(according to Pokemon) and change the day when it's appropriate. That doesn't actually display it, though I'm sure it isn't that hard...

What is does is keep time on a 24 hr clock, and also changes day systems too. I don't care how you handle the day system, or if you take it out completely. It's just, for Pokemon, time is important, expecially time of day, and day of the week(GSC, anyone? Lapris on Fridays? FTW!) Anyways, there's one more peice of code you might want.

Code:
' Init atmosphere
    GameTime = GetVar(FileName, "Time", "ToD")
    TimeSeconds = 0
    TimeMinutes = STR(GetVar(FileName, "Time", "Minute"))
    TimeHours = STR(GetVar(FileName, "Time", "Hour"))
    TimeDay = STR(GetVar(FileName, "Time", "Day"))
    AMPM = GetVar(FileName, "Time", "AM/PM")

Server crashes? No problem. It restores time from the last known minute value, hour value, day value, and time of day value. This isn't necesary if you want your server to start up with 0 default value for all those values.

This goes in Sub InitServer.

This is what I did for my day system. Instead of storing them as text, I stored them as numbers(faster handling) and had a function match each number to a day. Here it is(not the actual one I use)

Code:
Public Function TimeDay(Byval Day As Byte) As String
Select Case Day
    Case 1
        TimeDay = "Sunday"
    Case 2
        TimeDay = "Monday"
    Case 3
       TimeDay = "Tuesday"
    Case 4
        TimeDay = "Wenesday"
    Case 5
        TimeDay = "Thursday"
    Case 6
       TimeDay = "Friday"
    Case 7
        TimeDay = "Saturday"
End Select

Not too hard, is it? Now go on, implement this for yourselves!


- William - 09-03-2007

ms doesn't come with a weather system. It just has constants for DAY and NIGHT. So it's not really needed.


- Matt2 - 09-03-2007

William Wrote:ms doesn't come with a weather system. It just has constants for DAY and NIGHT. So it's not really needed.

MS comes with a cheap weather system, as well as a cheap day/night.

Just uncomment WeatherSeconds and TimeSeconds and there you go. It does it's cheap magic.

Of course, one could evolve on them. I'm working with my weather system right now, and well.. That's the time system I use. I'm sure it can help noobs understand a little bit more about Visual Basic.


- William - 09-03-2007

As I said, MS doesn NOT come with a weather system. Just a few ifs and such. No actual effect what so ever. So improving some ifs isn't any idea UNLESS you add a weather system.


- Rian - 09-03-2007

Really nice AI improvement bro. I will definitely use this when I start working on day/night in my game.

Dunno how weather got dragged into this thread though. Weahter shouldn't be based on time at all imo


- Matt2 - 09-03-2007

It isn't. Lol...

But whatever floats his boat. This is a time system, not weather. xD


- Tosuxo - 21-03-2007

why keep saving the time and date to a file when it could easily be stored into memory... all you have to do is keep it in memory? :S

from what I see here you're writing to an ini file every minute which is just waste of CPU when it could store as 3 bytes in memory (hour min second)...

...just use a timer and make it update every 1000ms... (Interval = 1000), and make it get the server system clock data.... and if it's a certain number in hours or w.e. then it's day, else it's night

that's how MT's day/night system works, and it works flawlessly....


- Matt - 21-03-2007

That's not a bad idea. But he didn't write the tut for perfection. He simply wrote it as an alternative to the current system.


- Matt2 - 21-03-2007

Store it to memory. What if the server crashes?

Then, where will time start? From the begining?

I don't like that. Which is why I wrote it to an ini to start.

I could easily write to memory if I want. I say, waste the CPU, it'll make the server more professional.


- Spodi - 22-03-2007

Well how often does the time roll over vs the server crash? Saving every minute, though, is going to hardly be noticeable on performance.


- Tony - 22-03-2007

Matt Wrote:Store it to memory. What if the server crashes?

Then, where will time start? From the begining?

I don't like that. Which is why I wrote it to an ini to start.

I could easily write to memory if I want. I say, waste the CPU, it'll make the server more professional.

Then work on things that prevent the server from crashing.


- Matt2 - 22-03-2007

Kuja Wrote:
Matt Wrote:Store it to memory. What if the server crashes?

Then, where will time start? From the begining?

I don't like that. Which is why I wrote it to an ini to start.

I could easily write to memory if I want. I say, waste the CPU, it'll make the server more professional.

Then work on things that prevent the server from crashing.

And if you don't like it; rewrite it. Lol, I'm not holding anyone's hand. This is what I use, and is only very basic.


- Tosuxo - 23-03-2007

Matt Wrote:Store it to memory. What if the server crashes?

Then, where will time start? From the begining?

I don't like that. Which is why I wrote it to an ini to start.

I could easily write to memory if I want. I say, waste the CPU, it'll make the server more professional.

if you're talking about a whole date system working from the time system in game just make it save every 1 hour instead of 1 minute, it's not like people are gonna be complaining about a time being slightly wrong since they probably lost a load of time they were playing due to it crashing

my game server hasn't crashed once since 1.0's release (excepting a few minor tweaks first of all, naturally), so if your server's crashing all the time you got some serious issues you need to address

however, if you're doing like MT is... i.e. the game time is the time at the server (or can be set via a .ini to offset it for timezone you want), all you need to do is have a timer run ever 1000ms, which gets the time from the system clock.... then every 1 hour it checks for any changes in light and weather etc

if you want it to show the time client side, when the player logs in make it send the HH MM SS to the client and let the gameloop update a clock on the client Tongue


- Matt - 23-03-2007

I think the system he has is good for a basic start. If you want to add onto it, then do so, otherwise, stop complaining. That's how I see it.

Btw, I just downloaded and tried MT out. You still use copyrighted gfx for parts of your GUI, from what I understand, you are to remove any original gfx before releasing your game. Oh, that and it sucks. Mapping is horrible, there is nothing explaining what to do, and when I tried to get a monster, I couldn't.

Matt, keep up the good work. You seem to be the only one who's provided new tutorials in awhile.


- Matt2 - 23-03-2007

Tos, quit trying to doubt me...

PDoA has not crashed since I released in Early Feburary. Yeah, nearly two months. And you know what else? I've had about 20+ players on at a time, running other applications. It hardly lags for me or anyone else, and it takes up only 1/50th of my memory.

Go, work on MT, I want to see something come out of it. If you spend ALL your time trying to find problems with PDoA, nothing good will come out of it.

And yeah, saving every minute is overexaggerating, but I didn't want to save it to memory, because when the player requests for time, it pulls it from the ini, not from memory. So, yeah, that's another thing about the system. Like I said, very basic. If you wanna make it something better, be my guest...


- Tosuxo - 23-04-2007

Matt Wrote:Tos, quit trying to doubt me...

PDoA has not crashed since I released in Early Feburary. Yeah, nearly two months. And you know what else? I've had about 20+ players on at a time, running other applications. It hardly lags for me or anyone else, and it takes up only 1/50th of my memory.

Go, work on MT, I want to see something come out of it. If you spend ALL your time trying to find problems with PDoA, nothing good will come out of it.

And yeah, saving every minute is overexaggerating, but I didn't want to save it to memory, because when the player requests for time, it pulls it from the ini, not from memory. So, yeah, that's another thing about the system. Like I said, very basic. If you wanna make it something better, be my guest...

he's just cranky... he ain't been laid for awhile Wink

and 2.0 is about a week away, battle animations and all, and a full list of tutorials on the website, fully integrated website to game will come shortly after... with many little bonuses...

what have you got going up to now? being able to capture a pokémon? omg, mt had that like over a YEAR ago, everything in MT is 100% bug free, no lag, no problems.


And RE Advocate:
I'm busy working with all the backend stuff rather than graphical wise... You say about © graphics? Matt's whole GAME is stole.. every single in-game graphic! So don't use that against me...

I've recently hired a couple of mappers, who'll be completely changing the layout of the game up to now... They are waiting for the 2.0 client to begin work as there are many changes to the maps in 2.0 which would mean having to do alot of the stuff again.

THANK YOU.