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

Adding Random Tile Placement [EOv2]


Carim123
 Share

Recommended Posts

Hello there, and welcome to a new tutorial from me; **Adding Random Tile Placement**, complete with frequency options, and even functional with just about any autotile system you use. About 15 mins. ago, I looked at the old EOv2 official thread, and found that under TODO, there was "- Random tile placement.". This is a must for any map editor system, so I set about making it. It's a lot more simple then I thought it'd be, and extremely helpful when making fluid and distinctive maps.

This may work with CSDE, but I haven't tested it, nor do I want to test it.

At the moment, I haven't made it work with multi-tile selection, but it's an easy edit. I'll post it here when I remember to do so once I'm done.

Here's a picture of what the result is…just a hastily made map, using only random tiles.
![](http://dl.dropbox.com/u/35436625/randomtileplacement.png)

* * *

First off, go to frmEditor_Map.

Inside fra_Layers, add a scrollbar, a label, and a button.
Name the scrollbar "scrlFrequency", the label "lblFrequency", and the button "cmdRandomTile". Give the lblFrequency a caption of "Freq.: 75", and set the scrlFrequency's Min to 1, Max to 100, and the current Value to 75.

Now, to actually play with some code…

Inside scrlFrequency_Change, add...

```
lblFrequency.Caption = "Freq.: " & scrlFrequency.value
```
Simple, huh? Even though it's simple, the basis of this is that it changes the label to match the scrlFrequency's value. Pretty helpful when you want to determine how much you want your tile placed.

Now, inside cmdRandomTile, add…

```
Dim x As Long
Dim y As Long
Dim chance As Long
Dim rate As Long

    For x = 0 To Map.MaxX
        For y = 0 To Map.MaxY
            chance = Rand(1, scrlFrequency.value)
            rate = Rand(1, 100)

            If chance >= rate Then
                Call RandomTilePlacement(x, y)
            End If

            DoEvents
        Next
    Next
```What this does is it runs a ForNext statement, and within it, runs against your entire map. If the chance is higher than the rate, it places, hence the frequency needs. It's not difficult to modify it to work from a section.

Now, after "Public Sub MapEditorMouseDown", add this sub.
```
Public Sub RandomTilePlacement(ByVal x As Long, ByVal y As Long)
Dim i As Long
Dim CurLayer As Long

' If debug mode, handle error then exit out
If Opt.Debug = 1 Then On Error GoTo errorhandler

' find which layer we're on
For i = 1 To MapLayer.Layer_Count - 1
If frmEditor_Map.optLayer(i).value Then
CurLayer = i
Exit For
End If
Next

If Not isInBounds Then Exit Sub

    If frmEditor_Map.optLayers.value Then
        If EditorTileWidth = 1 And EditorTileHeight = 1 Then 'single tile
            MapEditorSetTile x, y, CurLayer
        Else ' multi tile!
            MapEditorSetTile x, y, CurLayer, True
        End If
    End If

CacheResources

' Error handler
Exit Sub
errorhandler:
HandleError "MapEditorMouseDown", "modGameEditors", Err.Number, Err.Description, Err.Source, Err.HelpContext
Err.Clear
Exit Sub
End Sub
```
Now, if you'll look at it carefully, you'll see this is an edit of MapEditorMouseDown. MapEditorMouseDown uses CurX and CurY, so I've substituted this to run from the x and y values given in the ForNext loop.

Also, if you ripped the autotile function from the WN source, swap:
```
        If EditorTileWidth = 1 And EditorTileHeight = 1 Then
```For
```
        If EditorTileWidth = 1 And EditorTileHeight = 1 Or CurLayer = MapLayer.Autotile Then
```
And that's honestly it!
I beleive this is everything, so if you have this, you have even less excuse to make linear RMXP maps. >:D

I'll get an example up quickly.
I may have missed something, so just post if something doesn't work.
Link to comment
Share on other sites

Sorry, little error on my part, if you've already added this, chance cmdRandomTile to:
```
Dim x As Long
Dim y As Long
Dim chance As Long
Dim rate As Long

    For x = 0 To Map.MaxX
        For y = 0 To Map.MaxY
            chance = Rand(1, scrlFrequency.value)
            rate = Rand(1, 100)

            If chance >= rate Then
                Call RandomTilePlacement(x, y)
            End If

            DoEvents
        Next
    Next
```
Added on the OP.
Link to comment
Share on other sites

Tested on CS:DE. Require modification for auto-tile but it work great.

Here's what I changed to fit what I want:
Instead of the whole map, it only do select region. Pretty simple. Just change the For x = 0 to Map.MaxX to For x = txtMinX.text to txtMaxX.text or something the like.
For autotile, just check whether the scrlAutoTile = 0\. If it's 0, do the regular code. Else just add a , , frmMap_Editor.scrlAutoTile.value to the end of the SetTile Method.

Sincerely,
Rithy
Link to comment
Share on other sites

@Rithy58:

> Tested on CS:DE. Require modification for auto-tile but it work great.
>
> Here's what I changed to fit what I want:
> Instead of the whole map, it only do select region. Pretty simple. Just change the For x = 0 to Map.MaxX to For x = txtMinX.text to txtMaxX.text or something the like.
> For autotile, just check whether the scrlAutoTile = 0\. If it's 0, do the regular code. Else just add a , , frmMap_Editor.scrlAutoTile.value to the end of the SetTile Method.
>
> Sincerely,
> Rithy

Yep, that's exactly the modification I had in mind, and it's great to see it works in CSDE. Thanks for trying it out. =D
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...