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

[CS:DE] Making the Fogs Work


jcsnider
 Share

Recommended Posts

I do not make source tutorials very often but here are a few quick edits to enable fogs in Cs:DE.

As long as you are able to read and follow directions step by step you will be fine, otherwise you may find this difficult.

**CLIENT SIDE.**
In modTypes find Private Type Map Rec and Before the End Type add
```
    Fog As Byte
    FogOpacity As Byte
    FogBlendMode As Byte
```
Next, in Sub SendMap find
```
    With Map
        For x = 1 To MAX_MAP_NPCS
            Buffer.WriteLong .Npc(x)
        Next
    End With
```
UNDER it add
```
    Buffer.WriteByte Map.Fog
    Buffer.WriteByte Map.FogOpacity
    Buffer.WriteByte Map.FogBlendMode
```
Next, in sub HandleMapData find
```
    For x = 1 To MAX_MAP_NPCS
        Map.Npc(x) = Buffer.ReadLong
    Next
```
UNDER it add
```
    Map.Fog = Buffer.ReadByte
    Map.FogOpacity = Buffer.ReadByte
    Map.FogBlendMode = Buffer.ReadByte

```
Next, in Sub MapEditorProperties find,
```
        .scrlBoss = Map.BossNpc
```
UNDER it add…
```
        .scrlFog.value = Map.Fog
        .scrlFogOpacity.value = Map.FogOpacity
        .scrlFogBlending.value = Map.FogBlendMode
```
Find and Replace Sub DrawFog() with this one…
```
Public Sub DrawFog()
Dim fogNum As Long, colour As Long, x As Long, y As Long, renderState As Long

    fogNum = Map.Fog
    If fogNum <= 0 Or fogNum > Count_Fog Then Exit Sub
    renderState = Map.FogBlendMode + 1
    colour = D3DColorARGB(Map.FogOpacity, 255, 255, 255)

    ' render state
    Select Case renderState
        Case 1 ' Additive
            D3DDevice8.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_MODULATE
            D3DDevice8.SetRenderState D3DRS_DESTBLEND, D3DBLEND_ONE
        Case 2 ' Subtractive
            D3DDevice8.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_SUBTRACT
            D3DDevice8.SetRenderState D3DRS_SRCBLEND, D3DBLEND_ZERO
            D3DDevice8.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR
    End Select

    For x = 0 To 4
        For y = 0 To 3
            'RenderTexture Tex_Fog(fogNum), (x * 256) + fogOffsetX, (y * 256) + fogOffsetY, 0, 0, 256, 256, 256, 256, colour
            RenderTexture Tex_Fog(fogNum), (x * 256), (y * 256), 0, 0, 256, 256, 256, 256, colour
        Next
    Next

    ' reset render state
    If renderState > 0 Then
        D3DDevice8.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
        D3DDevice8.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
        D3DDevice8.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_MODULATE
    End If
End Sub
```Note: There are two lines of code, 1 commented out, that draw the fog, the top one is the scrolling fog while the bottom places it on the screen but does not give the moving effect. It is your choice which type you would like.

In sub SaveMap find,
```
    Put #f, , Map.BossNpc
```
under it add
```
    Put #f, , Map.Fog
    Put #f, , Map.FogOpacity
    Put #f, , Map.FogBlendMode
```
In Sub LoadMap find,
```
        Get #f, , Map.BossNpc
```
Under it add,
```
        Get #f, , Map.Fog
        Get #f, , Map.FogOpacity
        Get #f, , Map.FogBlendMode
```
Finally, replace your frmEditor_MapProperties with the one I have attached to this post.
(If, for whatever reason you do not want to replace yours, add mine to an empty project and copy over the changes I have made to the bars/labels and the code that goes with them.)

**SERVER SIDE**

Find Private Type MapRec and before the End Type add
```
    Fog As Byte
    FogOpacity As Byte
    FogBlendMode As Byte
```
Next, in Sub HandleMapData find
```
    For x = 1 To MAX_MAP_NPCS
        Map(mapNum).Npc(x) = Buffer.ReadLong
        Call ClearMapNpc(x, mapNum)
    Next
```
Under it add
```
    Map(mapNum).Fog = Buffer.ReadByte
    Map(mapNum).FogOpacity = Buffer.ReadByte
    Map(mapnum).FogBlendMode = Buffer.ReadByte
```
Finally, in sub MapCache_Create find,
```
    For x = 1 To MAX_MAP_NPCS
        Buffer.WriteLong Map(mapNum).Npc(x)
    Next
```
and under it add,
```
    Buffer.WriteByte Map(mapNum).Fog
    Buffer.WriteByte Map(mapNum).FogOpacity
    Buffer.WriteByte Map(mapNum).FogBlendMode
```

In Sub SaveMap find,
```
    Put #F, , Map(mapNum).BossNpc
```
Under it add,
```
    Put #F, , Map(mapNum).Fog
    Put #F, , Map(mapNum).FogOpacity
    Put #F, , Map(mapNum).fogblendmode
```
Finally, in Sub LoadMaps find,
```
        Get #F, , Map(i).BossNpc
```
under it add,
```
        Get #F, , Map(i).Fog
        Get #F, , Map(i).FogOpacity
        Get #F, , Map(i).fogblendmode
```
And you are done!

>! ![](http://www.freemmorpgmaker.com/files/imagehost/pics/afcca64db43198f966447e1c6cdc9a30.png)
>! ![](http://www.freemmorpgmaker.com/files/imagehost/pics/4640ad04d0ddf2aa731433baae6821a7.png)

Notice: The overall fog system was made by Robin this is just a tutorial to make it work, most of the credit goes to him ;)

-jcsnider

Do Not forget to replace your frmEditor_MapProperties with the one I have attached below.
Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...
This sort of works for me..

When I add the fog in the map editor (properties) it appears, and it works. However, as soon as I save the map (Send) it disappears..
I have no idea why. Has anyone else had this problem, and how do I fix it?

Thanks.
Link to comment
Share on other sites

If anyone else had the "Runtime Error 380" problem, the same as Ç○D륙 and I did, then have a look here:
[http://www.touchofdeathforums.com/smf2/index.php/topic,80277.msg859285.html#new](http://www.touchofdeathforums.com/smf2/index.php/topic,80277.msg859285.html#new)

That should fix it.
Link to comment
Share on other sites

I don't understand this : Note: There are two lines of code, 1 commented out, that draw the fog, the top one is the scrolling fog while the bottom places it on the screen but does not give the moving effect. It is your choice which type you would like.

How to make the fog moving ? help me please
Link to comment
Share on other sites

Eltony, look at the link I posted:
[http://www.touchofdeathforums.com/smf2/index.php/topic,80277.msg859285.html#new](http://www.touchofdeathforums.com/smf2/index.php/topic,80277.msg859285.html#new)

There's a solution which is really quite easily to follow.
But, here's a quick summary:

@Synergy:

> For the new frmMapProperties, you have to add "None", "Safe Zone" and "Boss Chamber" manually (typing!) to the list - this then creates the correct references in the List and ItemData properties.

Finalmix16,
There are two lines of code. One has been commented out (it has a ') just delete one of the lines of code. It doesn't matter which, it's up to you.
Just remove the comment if you use the top line of code.
Link to comment
Share on other sites

So if I understand, I have to delete this one to make the fog moving ?

    ' reset render state
    If renderState > 0 Then
        D3DDevice8.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
        D3DDevice8.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
        D3DDevice8.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_MODULATE
    End If

?

(Sorry I'm a noob..)
Link to comment
Share on other sites

No.
```
For x = 0 To 4
        For y = 0 To 3
            'RenderTexture Tex_Fog(fogNum), (x * 256) + fogOffsetX, (y * 256) + fogOffsetY, 0, 0, 256, 256, 256, 256, colour
            RenderTexture Tex_Fog(fogNum), (x * 256), (y * 256), 0, 0, 256, 256, 256, 256, colour
        Next
```
The ' comments out the line.
Delete one of the lines, either:
```
' RenderTexture Tex_Fog(fogNum), (x * 256) + fogOffsetX, (y * 256) + fogOffsetY, 0, 0, 256, 256, 256, 256, colour
```OR:
```
RenderTexture Tex_Fog(fogNum), (x * 256), (y * 256), 0, 0, 256, 256, 256, 256, colour
```
If you delete the second one, you need to uncomment the first one. Just delete the ' - hope that helps.
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...