WiseRock Posted March 23, 2013 Author Share Posted March 23, 2013 Ok after this tutorial you will have a working day and night system for DX8.. Basically we are making a game time that starts and stops when you turn on/off your server. In the map editor there is a new layer being drawn that is the darkness effect. You have the option to choose where and if this new layer is drawn so you can make lights, campfires and other things that will cause the light to not appear.. Its not the best looking thing in the world but heck its pretty cool to have this if your using DX8 still.. This was ripped from an older engine made by Stein so all credits are to him for creating this and little credit to me for converting it. Thanks to Justn for ripping it ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) >! ![](http://i46.tinypic.com/6s43z8.jpg)>! >! Lets start with the Server>! >! modConstants']>! add this>! ```>! ' Game Time>! Public Const GAME_MINUTES_PER_SECOND = 1>! ``` >! >! **modDatabase'**]>! Find this>! ```>! PutVar App.Path & "\data\options.ini", "OPTIONS", "Website", Options.Website>! ```>! Now go to Load Options and and this to the bottom>! ```>! Options.DayNight = Val(GetVar(App.Path & "\data\options.ini", "OPTIONS", "DayNight"))>! ```>! >! **modGeneral**']>! find:>! ```>! ' Initialize the random-number generator>! Randomize ', seed>! ```>! add this below>! ```>! ' Set the game time to the middle of the day.>! GameMinutes = 0>! GameHours = 12>! DayTime = True>! ```>! Find:```>! ' load options, set if they dont exist>! ```>! replace all of it with>! ```>! ' load options, set if they dont exist>! If Not FileExist(App.Path & "\data\options.ini", True) Then>! Options.Game_Name = "Eclipse Origins">! Options.Port = 7001>! Options.MOTD = "Eclipse Origins.">! Options.Website = "http://www.touchofdeathforums.com/smf/">! Options.DayNight = 1 'New part>! SaveOptions>! Else>! LoadOptions>! End If>! If Options.DayNight = 0 Then 'New>! frmServer.Label8.Visible = False 'New>! frmServer.lblGameTime.Visible = False 'New>! End If>! ```>! >! **modGlobals**']>! add this to bottom>! ```>! ' Game Time>! Public GameMinutes As Byte>! Public GameHours As Byte>! Public DayTime As Boolean>! ``` >! >! **modTypes'**]>! add to bottom of Options rec>! ```>! DayNight As Byte>! ```>! >! **modServerLoop'**]>! Find:>! ```>! If Tick > tmr1000 Then>! If isShuttingDown Then>! Call HandleShutdown>! End If>! tmr1000 = GetTickCount + 1000>! End If>! ```>! Replace with:>! ```>! If Tick > tmr1000 Then>! If isShuttingDown Then>! Call HandleShutdown>! End If>! ' Change the game time.>! If Options.DayNight = 1 Then>! GameMinutes = GameMinutes + GAME_MINUTES_PER_SECOND>! If GameMinutes > 59 Then>! GameMinutes = 0>! GameHours = GameHours + 1>! If GameHours > 23 Then>! GameHours = 0>! End If>! End If>! >! ' See if we need to switch to day or night.>! If DayTime = True And GameHours > 19 Then>! DayTime = False>! SendGameTime>! GlobalMsg "Darkness has fallen upon these Lands!", Yellow>! ElseIf DayTime = False And GameHours > 7 And GameHours < 19 Then>! DayTime = True>! SendGameTime>! GlobalMsg "The Sun has risen across the Kingdom!", Yellow>! End If>! ' Update the label>! If DayTime = True Then>! frmServer.lblGameTime.Caption = "(Day) " & Trim(STR(GameHours)) & ":" & Trim(STR(GameMinutes))>! Else>! frmServer.lblGameTime.Caption = "(Night) " & Trim(STR(GameHours)) & ":" & Trim(STR(GameMinutes))>! End If>! End If>! tmr1000 = GetTickCount + 1000>! End If>! ```>! >! **modSeverTCP**']>! ```>! Sub SendGameTime()>! Dim Buffer As clsBuffer>! Set Buffer = New clsBuffer>! Buffer.WriteLong SSendTime>! If DayTime = True Then>! Buffer.WriteLong 1>! Else>! Buffer.WriteLong 0>! End If>! SendDataToAll Buffer.ToArray()>! Set Buffer = Nothing>! End Sub>! ``` >! >! **modPlayer**']>! Find **' Send some more little goodies, no need to explain these**>! add this to the end of the calls>! ```>! Call SendGameTime>! ``` >! >! add```>! SSendTime>! ```before the SMSG>! find Public Enum MapLayer>! add>! ```>! Night>! ``` >! >! >! ```>! Public DayTime As Boolean>! ``` >! >! add this in Render_Graphics:>! ```>! ' Render Night>! If DayTime = False Or frmEditor_Map.optLayer(6).Value = True Then>! For X = 0 To Map.maxX>! For Y = 0 To Map.maxY>! DrawNightTile X, Y>! Next>! Next>! End If>! ```>! add this at the bottom of the module>! ```>! Public Sub DrawNightTile(ByVal x As Long, ByVal y As Long)>! Dim rec As RECT, i As Long>! With Map.Tile(x, y)>! i = MapLayer.Night>! >! ' skip tile if tileset isn't set>! If (.layer(i).Tileset > 0 And .layer(i).Tileset <= NumTileSets) And (.layer(i).x > 0 Or .layer(i).y > 0) Then>! ' sort out rec>! rec.Top = .layer(i).y * PIC_Y>! rec.Bottom = rec.Top + PIC_Y>! rec.Left = .layer(i).x * PIC_X>! rec.Right = rec.Left + PIC_X>! ' render>! RenderTexture Tex_Tileset(.layer(i).Tileset), ConvertMapX(x * PIC_X), ConvertMapY(y * PIC_Y), .layer(i).x * 32, .layer(i).y * 32, 32, 32, 32, 32, -1>! End If>! >! End With>! End Sub>! ``` >! >! add this at the bottom of InitMessages>! ```>! HandleDataSub(SSendTime) = GetAddress(AddressOf HandleSendTime)>! ```>! at the bottom add>! ```>! Private Sub HandleSendTime(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)>! Dim Buffer As clsBuffer>! Dim Temp As Byte>! Set Buffer = New clsBuffer>! Buffer.WriteBytes Data()>! Temp = Buffer.ReadLong>! If Temp = 1 Then DayTime = True>! If Temp = 0 Then DayTime = False>! Set Buffer = Nothing>! End Sub>! ``` >! >! modEnumerations']>! Add this before the SMSG>! ```>! SSendTime>! ```>! and add this in Public Enum MapLayer>! ```>! Night>! ```>! >! modTypes']>! add this before the end type in OptionsRec>! ```>! NightTile As Byte>! ```>! >! modDatabase']>! add this in SaveOptions above the Error Handler>! ```>! Call PutVar(Filename, "Graphics", "Night", str(Options.NightTile))>! ```>! then add this in LoadOptions below the Options.Debug = 0>! ```>! Options.NightTile = ##>! ```Now find this: **Options.Debug = GetVar(Filename, "Options", "Debug")**>! add>! ```>! Options.NightTile = GetVar(Filename, "Graphics", "Night")>! ```>! >! Ok for the **Form Work**>! **Client Side->! FrmEditor_Map:**>! Find the map layers radio buttons… Copy and paste one of them. Make sure you paste it inside of the frame: fraLayers.. After you have pasted it **make sure the index is set to 6**.>! Now Add this to the bottom of frmEditor_map:>! ```>! Private Sub optLayer_Click(Index As Integer)>! If Index = Night Then>! scrlTileSet.Value = Options.NightTile>! scrlTileSet_Change>! scrlTileSet.Enabled = False>! Else>! scrlTileSet.Enabled = True>! End If>! End Sub>! ```>! **Server Form Work-**>! **frmServer**>! 1.Anywhere on the server panel make a label named: **label 8**>! set the caption to : **Game Time:**>! 2\. Beside it make a label named: **lblGameTime**>! Set the caption to : **xx:xx**>! **OK in your Server/Data Folder open options.ini and add this to the bottom: daynight=1**>! **In your client/datafiles/ folder open the config.ini and add this to the bottom:**>! **```>! [Graphics]>! Night= 113>! [b][/b]>! You have finshed the tutorial!>! Download the attachment and put it in Tilesets and put as number 113 Do not edit the picture in any way!!>! [spoiler][img]http://i48.tinypic.com/2mr8zfc.jpg[/img][/spoiler]>! Now you should have a nice Day and Night system```** Link to comment Share on other sites More sharing options...
Yuko Posted March 23, 2013 Share Posted March 23, 2013 Awesome,If I were to modify the darkness, and I edited the spot light picture, would it work to modify its radius? Link to comment Share on other sites More sharing options...
WiseRock Posted March 23, 2013 Author Share Posted March 23, 2013 Here is a cool addon that will allow you to set whether an npc spawns during the day, night, or both.First find this in sub UpdateMapLogic:```[size]' //////////////////////////////////////[/size] ' // This is used for spawning an NPC // ' //////////////////////////////////////Change that whole part down to End Sub to this:' ////////////////////////////////////// ' // This is used for spawning an NPC // ' ////////////////////////////////////// ' Check if we are supposed to spawn an npc or not If MapNpc(mapnum).NPC(x).Num = 0 And Map(mapnum).NPC(x) > 0 Then If TickCount > MapNpc(mapnum).NPC(x).SpawnWait + (NPC(Map(mapnum).NPC(x)).SpawnSecs * 1000) Then ' See if we are using the day/night system. If we are act accordinly, otherwise just spawn the mob If Options.DayNight = 1 Then ' Check for gametime, this is an addition in 1.4.2\. We're only ' spawning NPCs that are allowed to spawn in the current time ' of the day. If DayTime = True And NPC(Map(mapnum).NPC(x)).SpawnAtDay = 1 Then Call SpawnNpc(x, mapnum) ElseIf DayTime = False And NPC(Map(mapnum).NPC(x)).SpawnAtNight = 1 Then Call SpawnNpc(x, mapnum) End If Else ' Not using Day/Night, so just spawn it regardless. Call SpawnNpc(x, mapnum) End If End If End If ' Despawn mobs if the day/night system is active. If Options.DayNight = 1 Then ' Righto, let's see if we need to despawn an NPC until the time of the day changes. ' Ignore this if the NPC has a target. If MapNpc(mapnum).NPC(x).target = 0 And Map(mapnum).NPC(x) > 0 And Map(mapnum).NPC(x) <= MAX_NPCS Then If DayTime = True And NPC(Map(mapnum).NPC(x)).SpawnAtDay = 0 Then DespawnNPC mapnum, x ElseIf DayTime = False And NPC(Map(mapnum).NPC(x)).SpawnAtNight = 0 Then DespawnNPC mapnum, x End If End If End If Next End If DoEvents Next ' Make sure we reset the timer for npc hp regeneration If GetTickCount > GiveNPCHPTimer + 10000 Then GiveNPCHPTimer = GetTickCount End If ' Make sure we reset the timer for door closing If GetTickCount > KeyTimer + 15000 Then KeyTimer = GetTickCount End IfEnd Sub```Add this at the bottom of MapNPCRec```SpawnWait As Long ' dot/hot DoT(1 To MAX_DOTS) As DoTRec HoT(1 To MAX_DOTS) As DoTRec```Add this at the bottom of modGlobals```Public KeyTimer as Long```Next Find this sub : Sub SpawnMapNpcsChange the whole sub to this :```Sub SpawnMapNpcs(ByVal mapnum As Long) Dim i As Long For i = 1 To MAX_MAP_NPCS If Map(mapnum).NPC(i) > 0 And Map(mapnum).NPC(i) <= MAX_NPCS Then If Options.DayNight = 1 Then If DayTime = True And NPC(Map(mapnum).NPC(i)).SpawnAtDay = 1 Then Call SpawnNpc(i, mapnum) ElseIf DayTime = False And NPC(Map(mapnum).NPC(i)).SpawnAtNight = 1 Then Call SpawnNpc(i, mapnum) End If Else Call SpawnNpc(i, mapnum) End If End If NextEnd Sub```In modTypes under npcrec add:```SpawnAtDay As ByteSpawnAtNight As Byte```Add this to the bottom of modGameLogic:```Sub DespawnNPC(ByVal mapnum As Long, ByVal NPCNum As Long)Dim i As Long, Buffer As clsBuffer ' Set the NPC data to blank so it despawns. MapNpc(mapnum).NPC(NPCNum).Num = 0 MapNpc(mapnum).NPC(NPCNum).SpawnWait = 0 MapNpc(mapnum).NPC(NPCNum).Vital(Vitals.HP) = 0 ' clear DoTs and HoTs For i = 1 To MAX_DOTS With MapNpc(mapnum).NPC(NPCNum).DoT(i) .Spell = 0 .Timer = 0 .Caster = 0 .StartTime = 0 .Used = False End With With MapNpc(mapnum).NPC(NPCNum).HoT(i) .Spell = 0 .Timer = 0 .Caster = 0 .StartTime = 0 .Used = False End With Next ' send death to the map Set Buffer = New clsBuffer Buffer.WriteLong SNpcDead Buffer.WriteLong NPCNum SendDataToMap mapnum, Buffer.ToArray() Set Buffer = Nothing 'Loop through entire map and purge NPC from targets For i = 1 To Player_HighIndex If IsPlaying(i) And IsConnected(i) Then If Player(i).Map = mapnum Then If TempPlayer(i).targetType = TARGET_TYPE_NPC Then If TempPlayer(i).target = NPCNum Then TempPlayer(i).target = 0 TempPlayer(i).targetType = TARGET_TYPE_NONE SendTarget i End If End If End If End If NextEnd Sub```OK now for the client side:FormWork: frmEditor_NPC1\. Somewhere make a Check box and name it : chkSdaySet the caption to: Spawn during day2.Near it make another checkbox and name it : chkSnightSet the caption to : Spawn at nightAdd this code to the bottom of frmEditor_NPC:```' day nightPrivate Sub chkSDay_Click() NPC(EditorIndex).SpawnAtDay = chkSDay.ValueEnd SubPrivate Sub chkSNight_Click() NPC(EditorIndex).SpawnAtNight = chkSNight.ValueEnd Sub```In modGameEditors find this in NpcEditorInit: .scrlAnimation.Value = NPC(EditorIndex).AnimationUnder it add this:```.chkSDay.Value = NPC(EditorIndex).SpawnAtDay .chkSNight.Value = NPC(EditorIndex).SpawnAtNightIn modTypes under npcrec add this:SpawnAtDay As Byte SpawnAtNight As Byte``` Link to comment Share on other sites More sharing options...
WiseRock Posted March 23, 2013 Author Share Posted March 23, 2013 > Awesome,> > If I were to modify the darkness, and I edited the spot light picture, would it work to modify its radius?You edit it in the Map editor Link to comment Share on other sites More sharing options...
Yuko Posted March 23, 2013 Share Posted March 23, 2013 Ok, thanks. I think I'll use it in a project my brother is making, but I honestly don't have any use for anything since it's not necessarily my game. Link to comment Share on other sites More sharing options...
WiseRock Posted March 23, 2013 Author Share Posted March 23, 2013 okay thanks its a pretty cool feature Link to comment Share on other sites More sharing options...
Yuko Posted March 23, 2013 Share Posted March 23, 2013 Well Kudos to you for sharing it ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Link to comment Share on other sites More sharing options...
willunited Posted March 23, 2013 Share Posted March 23, 2013 If you are using EA,you can use the map overlay,its better in mine oppinion. Link to comment Share on other sites More sharing options...
davidsaid Posted March 23, 2013 Share Posted March 23, 2013 I must delete my maps to get this source working? Link to comment Share on other sites More sharing options...
WiseRock Posted March 24, 2013 Author Share Posted March 24, 2013 No you do not Link to comment Share on other sites More sharing options...
Link Posted March 24, 2013 Share Posted March 24, 2013 I'm glad that you were able to convert it, but I must say this is not a good way to go about making a Day/Night system, it's inefficient..it will cause lag and other problems and so on and so forth. Not to mention you need tiles? I can see it being used for Dx7, but in Dx8 why not just use more advanced rendering methods.In any case, good job upon releasing for those who need it anyway.Regards,DeathTheKid Link to comment Share on other sites More sharing options...
WiseRock Posted March 24, 2013 Author Share Posted March 24, 2013 > I'm glad that you were able to convert it, but I must say this is not a good way to go about making a Day/Night system, it's inefficient..it will cause lag and other problems and so on and so forth. Not to mention you need tiles? I can see it being used for Dx7, but in Dx8 why not just use more advanced rendering methods.> > In any case, good job upon releasing for those who need it anyway.> > Regards,> > DeathTheKidThanks and I dont know how to do advanced rendering. Link to comment Share on other sites More sharing options...
cjsrch Posted April 5, 2013 Share Posted April 5, 2013 ResourceCache(mapnum).ResourceData(Resource_Count).cur_health = Resource(Map(mapnum).Tile(x, y).Data1).healthspitting error when i try to run it using preexisting maps.. i take it i do infact have to remove old maps? Link to comment Share on other sites More sharing options...
WiseRock Posted April 7, 2013 Author Share Posted April 7, 2013 I just commented that part out it still works fine Link to comment Share on other sites More sharing options...
cjsrch Posted April 7, 2013 Share Posted April 7, 2013 > Thanks and I dont know how to do advanced rendering.I find this ironic Link to comment Share on other sites More sharing options...
egemert35 Posted April 20, 2013 Share Posted April 20, 2013 I added Game Time: (Label8) and xx:xx (lblGameTime) to server.But labels are invisible.How can i fix that?Note: Label8 and lblGameTime Properties,Visible: TrueNote2: I'm using Dragon Eclipse.Edit: Sorry, my bad.I fixed. Link to comment Share on other sites More sharing options...
damian666 Posted April 20, 2013 Share Posted April 20, 2013 so let me get this straight, instead of using the build in tint function, which gives a nice night effect, you decide to put a layer ontop, like in old dx7 versions?right… Link to comment Share on other sites More sharing options...
BlueBean Posted April 21, 2013 Share Posted April 21, 2013 > so let me get this straight, instead of using the build in tint function, which gives a nice night effect, you decide to put a layer ontop, like in old dx7 versions?> > right…A night and day system with screen tinting would be amazing. Link to comment Share on other sites More sharing options...
boyesjs03 Posted April 21, 2013 Share Posted April 21, 2013 > A night and day system with screen tinting would be amazing.It is built in. Link to comment Share on other sites More sharing options...
damian666 Posted April 21, 2013 Share Posted April 21, 2013 > It is built in.yep, thats my point ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)you just force all maps to have a tint when its night. ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Link to comment Share on other sites More sharing options...
jordy205 Posted May 9, 2013 Share Posted May 9, 2013 Hi, i have a error, i am using Eclipse The Final Frontier and when i finished all tutorial i have these error: [http://gyazo.com/6447524894129300dd8c66281f0eb2bb](http://gyazo.com/6447524894129300dd8c66281f0eb2bb) in the client.I supused that it is a error of loading the options:```Public Sub LoadOptions()Dim filename As String ' If debug mode, handle error then exit out If Options.Debug = 1 Then On Error GoTo ErrorHandler filename = App.Path & "\Data Files\config.ini" If Not FileExist(filename, True) Then Options.Game_Name = "Eclipse Origins" Options.Password = vbNullString Options.savePass = 0 Options.Username = vbNullString Options.IP = "127.0.0.1" Options.Port = 7001 Options.MenuMusic = vbNullString Options.Music = 1 Options.sound = 1 Options.Debug = 0 Options.Lvls = 0 Options.NightTile = 1 SaveOptions Else Options.Game_Name = GetVar(filename, "Options", "Game_Name") Options.Username = GetVar(filename, "Options", "Username") Options.Password = GetVar(filename, "Options", "Password") Options.savePass = Val(GetVar(filename, "Options", "SavePass")) Options.IP = GetVar(filename, "Options", "IP") Options.Port = Val(GetVar(filename, "Options", "Port")) Options.MenuMusic = GetVar(filename, "Options", "MenuMusic") Options.Music = GetVar(filename, "Options", "Music") Options.sound = GetVar(filename, "Options", "Sound") Options.Debug = GetVar(filename, "Options", "Debug") Options.Lvls = GetVar(filename, "Options", "Levels") Options.NightTile = GetVar(filename, "Graphics", "Night") End If ' Error handler Exit SubErrorHandler: HandleError "LoadOptions", "modDatabase", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit SubEnd Sub```Sorry for my english ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png) Thanks Link to comment Share on other sites More sharing options...
jordy205 Posted May 12, 2013 Share Posted May 12, 2013 help? Link to comment Share on other sites More sharing options...
Zeno Posted May 12, 2013 Share Posted May 12, 2013 jordy205,A simultaneous strength and weakness of the Eclipse community is the number of engines. This isn't quite readily compatible with EFF, but can be easily tweaked to be.The error would come between when the server message reads load options and the next load in line. It could be this part in modGeneral:```If Options.DayNight = 0 Then 'New frmServer.Label8.Visible = False 'New frmServer.lblGameTime.Visible = False 'NewEnd If```In EFF frmServer.lblGameTime doesn't exist. This could be causing your error. Code involving this form is also in GameLoop. You should create the label in frmServer.Also, in EFF frmServer.Label8 is "Second Place: " in the status tab of the topkill event. This isn't an error, but it is silly to have two separate scripts updating the same label. Fix the labels in your frmServer.Edit: Just saw that the forms are included in the tutorial. Woops. Make sure that Label8 is not an array, such as Label8(0) and Label8(1). Check also that DayNight=1 is in the options.ini of your server. Other than that, no idea. Link to comment Share on other sites More sharing options...
abhi2011 Posted May 12, 2013 Share Posted May 12, 2013 Type Mismatch means that an invalid type is being passed to a function or a sub or a different type value was set to a variable. (e.g passed a string instead of a long, set a double instead of a string etc)Also we are not magicians to find the line of code that errors. Even though it is possible it will be a waste of time for us. Run the client in VB6 and then when the error box appears press debug. It will show the line of code that errors. Paste the line of code here.Also Press Ctrl+F5 to run in the IDE. Link to comment Share on other sites More sharing options...
jordy205 Posted May 12, 2013 Share Posted May 12, 2013 > jordy205,> > A simultaneous strength and weakness of the Eclipse community is the number of engines. This isn't quite readily compatible with EFF, but can be easily tweaked to be.> > The error would come between when the server message reads load options and the next load in line. It could be this part in modGeneral:> > ```> > If Options.DayNight = 0 Then 'New> > frmServer.Label8.Visible = False 'New> > frmServer.lblGameTime.Visible = False 'New> > End If> > ```> In EFF frmServer.lblGameTime doesn't exist. This could be causing your error. Code involving this form is also in GameLoop. You should create the label in frmServer.> > Also, in EFF frmServer.Label8 is "Second Place: " in the status tab of the topkill event. This isn't an error, but it is silly to have two separate scripts updating the same label. Fix the labels in your frmServer.> > Edit: Just saw that the forms are included in the tutorial. Woops. Make sure that Label8 is not an array, such as Label8(0) and Label8(1). Check also that DayNight=1 is in the options.ini of your server. Other than that, no idea.But the error is in the client xD in the server is perfect i change the label 8 thanks for your help ![;)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/wink.png) But it is the client when i open the client. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now