Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Simple Dx7 Weather System (First of many tuts I am sharing today!)


Justn
 Share

Recommended Posts

Hello this tutorial will show you how to add a simple Snow/Rain setting for your maps.. I will also show you how to make a button on your server panel to toggle the weather on and off… I know there is already another weather system posted but this one seems to have alot less code but use whatever one you want. This system was created by Captian Wabbit and I had paid him for this about a year ago. All Credits are to Wabbit and also Scott for fixing an issue.

[![](http://www.freemmorpgmaker.com/files/imagehost/pics/fc32cefdaecbf071cfc5dde6126abb47.PNG)](http://www.freemmorpgmaker.com/files/imagehost/#fc32cefdaecbf071cfc5dde6126abb47.PNG)

**-Client-**

First off open your **client.vbp**.

Next add the **rain.bmp** and **snow.bmp** files to your **Client/DataFiles/Graphics/** folder… Please note that these graphics arent mine and you **DO NOT** have premission to use them and are only included for testing…

**In modtypes-**

Find near the top: **Public Party As PartyRec**

under it add:

```

Public RainDrop(0 To 200) As RainDropRec

```

Find : **maprec** and at the bottom before **End Type** add:

```

Weather As Long ' 0 = None 1 = Rain 2 = Snow

```

Then add this at the bottom of **modTypes:**

```

Public Type RainDropRec

X As Long

Y As Long

InMotion As Long

End Type

```

**In modGameLogic-**

In the **GameLoop** at the top find: **Dim tmr100 As Long** under it add:

```

Dim tmr10000 As Long, RainTick As Long, RainUpdateTick As Long

```

In the **GameLoop** towards the top look for:

```

' *** Start GameLoop ***

Do While InGame

Tick = GetTickCount ' Set the inital tick

ElapsedTime = Tick - FrameTime ' Set the time difference for time-based movement

FrameTime = Tick

```

Under it add:

```

' update rain

If RainTick < Tick And Map.Weather > 0 Then

GenerateRainWave

If Map.Weather = 1 Then

RainTick = Tick + 100 ' reset time

ElseIf Map.Weather = 2 Then

RainTick = Tick + 1000

End If

End If

If RainUpdateTick < Tick And Map.Weather > 0 Then

UpdateRainDrops ' update

If Map.Weather = 1 Then

RainUpdateTick = Tick + 10

ElseIf Map.Weather = 2 Then

RainUpdateTick = Tick + 50

End If

End If

```

At the bottom of **ModGameLogic** add:

```

Public Sub GenerateRainDrop(ByVal RainIndex As Long)

' generate raindrop

RainDrop(RainIndex).X = Rand(1, frmMain.picScreen.Width)

RainDrop(RainIndex).Y = 0

RainDrop(RainIndex).InMotion = 1

End Sub

Public Sub GenerateRainWave()

Dim i As Long

' generate a wave

For i = 1 To Rand(1, 3)

GenerateRainDrop FindRainSlot

If Map.Weather = 2 Then Exit Sub

Next

End Sub

Public Function FindRainSlot()

Dim i As Long, RainMax As Long

If Map.Weather = 1 Then RainMax = 25 Else RainMax = 15

' check if in motion

For i = 1 To RainMax

If RainDrop(i).InMotion = 0 Then

Exit For

End If

Next

' replace rain

FindRainSlot = i

End Function

Public Sub UpdateRainDrops()

Dim i As Long, RainMax As Long

If Map.Weather = 1 Then RainMax = 25 Else RainMax = 15

' loop through all raindrops

For i = 1 To RainMax

If Not RainDrop(i).InMotion = 0 Then

RainDrop(i).Y = RainDrop(i).Y + 5

' if it's past the screen, reset.

If RainDrop(i).Y > frmmain.picscreen.height Then

RainDrop(i).InMotion = 0

End If

End If

Next

End Sub

```

**modClientTCP-**

In Sub **SendMap** find: **Buffer.WriteByte .Moral** under it add:

```

Buffer.WriteLong .Weather

```

**frmEditor_MapProperties-**

Find this line of Code: Private Sub cmdOk_Click()… Now Under: .BootY = Val(txtBootY.text) add:

```

.Weather = cmbWeather.ListIndex

```

**modDatabase-**

In Sub **SaveMap** above this line: **Close #f** add:

```

Put #f, , Map.Weather

```

in Sub **LoadMap** above this line: **Close #f** add:

```

Get #f, , Map.Weather

```

**modGameEditors-**

Find this in **MapEditorProperties:**

```

' rest of it

.txtUp.text = CStr(Map.Up)

.txtDown.text = CStr(Map.Down)

.txtLeft.text = CStr(Map.Left)

.txtRight.text = CStr(Map.Right)

.cmbMoral.ListIndex = Map.Moral

.txtBootMap.text = CStr(Map.BootMap)

.txtBootX.text = CStr(Map.BootX)

.txtBootY.text = CStr(Map.BootY)

```

Under it Add;

```

.cmbWeather.ListIndex = Map.Weather

```

**modDirectDraw7**

Ok at the bottom of the **' gfx buffers** declerations add:

```

Public DDS_Rain As DirectDrawSurface7

Public DDS_Snow As DirectDrawSurface7

```

Then right under those at the bottom of the **'descriptions** declerations add:

```

Public DDSD_Rain As DDSURFACEDESC2

Public DDSD_Snow As DDSURFACEDESC2

```

Now in **InitSurfaces** find: **' load persistent surfaces**

At the bottom of those add:

```

If FileExist(App.Path & "\data files\graphics\rain.bmp", True) Then Call InitDDSurf("rain", DDSD_Rain, DDS_Rain)

If FileExist(App.Path & "\data files\graphics\snow.bmp", True) Then Call InitDDSurf("snow", DDSD_Snow, DDS_Snow)

```

Next Find this whole chunk of code:

```

' blt the hover icon

For i = 1 To Player_HighIndex

If IsPlaying(i) Then

If Player(i).Map = Player(MyIndex).Map Then

If CurX = Player(i).X And CurY = Player(i).Y Then

If myTargetType = TARGET_TYPE_PLAYER And myTarget = i Then

' dont render lol

Else

BltHover TARGET_TYPE_PLAYER, i, (Player(i).X * 32) + Player(i).xOffset, (Player(i).Y * 32) + Player(i).yOffset

End If

End If

End If

End If

Next

For i = 1 To Npc_HighIndex

If MapNpc(i).Num > 0 Then

If CurX = MapNpc(i).X And CurY = MapNpc(i).Y Then

If myTargetType = TARGET_TYPE_NPC And myTarget = i Then

' dont render lol

Else

BltHover TARGET_TYPE_NPC, i, (MapNpc(i).X * 32) + MapNpc(i).xOffset, (MapNpc(i).Y * 32) + MapNpc(i).yOffset

End If

End If

End If

Next

```

Under it add this:

```

' if map has rain

If Map.Weather > 0 And InMapEditor = False Then

' rain drops

Dim G As Long, RainRect As DxVBLib.RECT, RainMax As Long

' check if we've loaded the raindrop

If DDS_Rain Is Nothing Then

Call InitDDSurf("rain.bmp", DDSD_Rain, DDS_Rain)

ElseIf DDS_Snow Is Nothing Then

Call InitDDSurf("snow.bmp", DDSD_Snow, DDS_Snow)

End If

' setup raindrop rec

With rec

.Top = 0

.Bottom = 2

.Left = 0

.Right = 14

End With

' less drops for snow

If Map.Weather = 1 Then RainMax = 25 Else RainMax = 15

' loop through all raindrops

For G = 1 To RainMax

If RainDrop(G).InMotion = 1 Then

' render the rain

If Map.Weather = 1 Then ' rain

Call Engine_BltFast(Camera.Left + RainDrop(G).X, Camera.Top + RainDrop(G).Y, DDS_Rain, RainRect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)

Else ' snow

Call Engine_BltFast(Camera.Left + RainDrop(G).X, Camera.Top + RainDrop(G).Y, DDS_Snow, RainRect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)

End If

End If

Next

End If

```

**modHandleData-**

Ok in **Sub HandleMapDat**a above this: **ClearTempTile** add:

```

Map.Weather = Buffer.ReadLong

```

**Form Work: frmEditor_MapProperties:**

Add a **combo box** and name it **CmbWeather**. Now in the **list** add These three things: **None, Rain, Snow**

Should be it for the Client Side. Now for the easy Server Side:

**Server-**

Open your Server.vbp

**modDataBase-**

In Sub **SaveMap** above **Close #F** add:

```

Put #F, , Map(mapnum).Weather

```

In Sub **LoadMaps** above **Close #F** add:

```

Get #F, , Map(i).Weather

```

**modHandleData-**

In Sub **HandleMapData** under: **Map(mapnum).Moral = Buffer.ReadByte** Add:

```

Map(mapnum).Weather = Buffer.ReadLong

```

**modServerTCP-**

In Sub **mapcache_create** above:**MapCache(mapnum).Data = Buffer.ToArray()** Add:

```

Buffer.WriteLong Map(mapnum).Weather

```

**In modtypes-**

Find : **maprec** and at the bottom before **End Type** add:

```

Weather As Long ' 0 = None 1 = Rain 2 = Snow

```

**Optional-**

Now that is done you will have a working weather system… but always having to edit a maps weather everytime you want to turn it off and on is kinda lame.. I know there are better ways to have random or map by map toggle but here is a simple button i made to turn it off and on via the server...

**Server AND CLIENT**

modEnumerations-

Add the following to both the client.vbp and server.vbp modenurmerations list:

```

SSendWeather

```

modGlobals-

Add this to both the Server and Client modGlobals at the bottom:

```

Public Rainon As Boolean

```

**Server-**

modServerTCP

add this to the bottom:

```

Sub SendWeather()

Dim Buffer As clsBuffer

Set Buffer = New clsBuffer

Buffer.WriteLong SSendWeather

If Rainon = True Then

Buffer.WriteLong 1

Else

Buffer.WriteLong 0

End If

SendDataToAll Buffer.ToArray()

Set Buffer = Nothing

End Sub

```

ModGeneral-

In InitServer above:' Check if the directory is there, if its not make it add:

```

Rainon = False

```

modPlayer-

IN sub JoinGame find: ' Send some more little goodies, no need to explain these

Below the other Calls add:

```

Call SendWeather

```

Form Work frmServer:

Make a command button somewhere on the server control panel. Double Click the new button and add this:

```

If Rainon = True Then

Rainon = False

Call SendWeather

Else

Rainon = True

Call SendWeather

End If

```

**Client-**

modHandleData-

Add this near the top under the other ones:

```

HandleDataSub(SSendWeather) = GetAddress(AddressOf HandleSendWeather)

```

Add this to the bottom of modHandleData:

```

Private Sub HandleSendWeather(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 Rainon = True

If Temp = 0 Then Rainon = False

Set Buffer = Nothing

End Sub

```

modDirectDraw7

Find this line:

```

' if map has rain

If Map.Weather > 0 And InMapEditor = False Then

```

And change it too this:

```

' if map has rain

If Map.Weather > 0 And InMapEditor = False And Rainon = True Then

```

That should be it… If you have a bigger picscreen size and want more rain drops find all the maxrain numbers and make them higher =)
Link to comment
Share on other sites

its a good thing brandon. At the moment 2.3 is the official version and until a few bugs get sorted out i am sure plenty of users will be using 2.0/2.3 especially he people who began projects before 2.3 even existed ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png)
Link to comment
Share on other sites

> its a good thing brandon. At the moment 2.3 is the official version and until a few bugs get sorted out i am sure plenty of users will be using 2.0/2.3 especially he people who began projects before 2.3 even existed ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png)

2.3 have still major bugs with event system. And Event system is slow. I reccomedding using Steins Eclopti or mine Eclipse Advanced
Link to comment
Share on other sites

> 2.3 have still major bugs with event system. And Event system is slow. I reccomedding using Steins Eclopti or mine Eclipse Advanced

Yeah no, both still have the same fundamental flaws minus a few bugfixes. Don't go recommend bum candy you know has issues please. 2.3 is more stable and functional than 3.0 in many ways, it's just the Event System that shares issues all over.
Link to comment
Share on other sites

Screenshots look kinda stupid really needs a video to show how it looks =p

[![](http://www.freemmorpgmaker.com/files/imagehost/pics/fc32cefdaecbf071cfc5dde6126abb47.PNG)](http://www.freemmorpgmaker.com/files/imagehost/#fc32cefdaecbf071cfc5dde6126abb47.PNG)

[![](http://www.freemmorpgmaker.com/files/imagehost/pics/aeaeac19967a713e6dcc429c8c77a617.PNG)](http://www.freemmorpgmaker.com/files/imagehost/#aeaeac19967a713e6dcc429c8c77a617.PNG)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...