• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Replace Terrain Tiles

Status
Not open for further replies.
Level 4
Joined
Aug 16, 2013
Messages
75
There is no such resource for this type of trigger as I have looked. It seems to be a bit advanced for a lot of people.

Here's what it needs to do:

Iterate from tile to tile, if the tile is equal to a grass tile, replace the grass tile with a snow tile. Once it reaches the end of the map, it needs to move down by point(0, -100) and start from the beginning again. By doing this, all grass tiles will be changed to a snow tile. Eventually, once all grass tiles are replaced, the trigger needs to turn off.

My map is set to 256x256.

I only use GUI. I don't mind Jass as long as you can explain it so I can alter it.



  • Change to Snow
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Set tmp_point = (Point(((X of tmp_point) + 100.00), ((Y of tmp_point) + 0.01)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Terrain type at tmp_point) Equal to Lordaeron Summer - Grass
        • Then - Actions
          • Environment - Change terrain type at tmp_point to Lordaeron Winter - Snow using variation -1 in an area of size 1 and shape Circle
        • Else - Actions

If you take a look yourself on a solution for this on the hive or internet, you will see that there is none. Can anyone help with it?
 
Level 6
Joined
Oct 31, 2014
Messages
170
Well maybe instead of replacing the tiles you could just build invisibles buildings with a snowy base, or invisibles doodads with a snowy base. and just remove all the possible interactions with those buildings/doodads like colliders and selections ect..

Just an idea, I don't think you can actualy replace a texture ingame can you?
Or if you do maybe you should have the snow tiles already in your custom tiles in the map options ..
Maybe use the "corrupted soil ability" of the undeads and replace the corrupted soil by snow ..?
 
Level 4
Joined
Aug 16, 2013
Messages
75
My game has 4 seasons that you can choose from at the beginning of the game: Spring, Summer, Fall, and Winter. Depending on the season chosen, the grass tiles will be replaced by the said tile.

It would look awful if I had to replace every single tile on the map with the snow tile. I need it to target one specific tile and replace it.

The tiles need to change in-game and not in the terrain editor.
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
Iterate from tile to tile, if the tile is equal to a grass tile, replace the grass tile with a snow tile. Once it reaches the end of the map, it needs to move down by point(0, -100) and start from the beginning again. By doing this, all grass tiles will be changed to a snow tile. Eventually, once all grass tiles are replaced, the trigger needs to turn off.
It's too simple that's why no one is making it. If you know how it works, why don't you code it by yourself?

You can use [Snippet] TileDefinition to help the iteration accuracy. But it's vJass :p It's not approved yet but I guarantee it works flawlessly, it's just because moderators are slow.
 
Level 4
Joined
Aug 16, 2013
Messages
75
It's too simple that's why no one is making it. If you know how it works, why don't you code it by yourself?

I can only explain it and code some of it, I don't know how to check whether the tile is hitting the edge of the map and if it is, -1 down and start moving the other way.

For example,

> = tile moving right

< = tile moving left

| = y-point value -100 which makes it go down once

] [ = map edges


Map
Start[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]drop y-value -100
drop[<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<] |
| [>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]drop etc



I just don't know how to check whether it is hitting the edge of the map. Also, I have no idea where the terrain tile starts( it keeps starting near the bottom.. and I am not giving it any y-values.) or even the start location of the very top left of the map, to start iterating it.
 
Level 4
Joined
Aug 16, 2013
Messages
75
It would only happen at the start of the game and when the seasons change. (Each season has 30 days and each day lasts about 2-5 minutes. After the 30th day of the season, the terrain tiles will change.)

I would love the system just as long as it doesn't kill the game with lag/freezing. Some lag is fine in order to replace the tiles, but if it is a lot of lag, then it isn't worth it.

It depends, from hearing how my game works, are you able to implement it without major lag / freezing?

You could have the snow terrain replace the grass at a slower pace, all the snow terrain doesn't have to iterate through the whole thing at once (if you can accomplish something like this.)


EDIT: Oh and also, the terrain tiles won't iterate through the whole map. It will iterate through a region that covers about 1/3rd of the map. Sorry, forgot to mention.
 
Level 4
Joined
Aug 16, 2013
Messages
75
More like Rune Factory.


I can't run the map, script error.. lol
 

Attachments

  • error.png
    error.png
    1.4 MB · Views: 106
Level 4
Joined
Aug 16, 2013
Messages
75
It worked on your test map, but I got another error when importing it into my map. ( I didn't touch a thing other than changing the region.)


Also, it seems that the snow tiles get replaced with a rock tile. All rock tiles don't get replaced.
 

Attachments

  • error2.png
    error2.png
    171.1 KB · Views: 91
  • Pic1.png
    Pic1.png
    1.3 MB · Views: 113
  • Pic2.png
    Pic2.png
    1.5 MB · Views: 111
Level 4
Joined
Aug 16, 2013
Messages
75
I switched on "automatically create unknown variables while pasting trigger data" in file > preferences.

Nothing in the trigger is marked red.
 
Level 4
Joined
Aug 16, 2013
Messages
75
I'm sorry. I don't know jass. I thought you would have added the variables in already or explained how to do that. I have a general idea how but I have never used jass / custom scripts.

I tried to make a variable that the custom script uses, but it still won't run past it.

  • ChangeTile
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Set CT_Timer = 10.00
      • Set CT__Accuracy = 128.00
      • Custom script: call ExecuteFunc("CT__Initialization")
      • Custom script: endfunction
      • Custom script:
      • Custom script: function CT__IterateTiles takes nothing returns nothing
      • Set CT__CurrentX = (CT__CurrentX + CT__Accuracy)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CT__CurrentX Greater than or equal to CT__EndX
        • Then - Actions
          • Set CT__CurrentX = CT__StartX
          • Set CT__StartY = (CT__StartY + CT__Accuracy)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CT__StartY Greater than or equal to CT__EndY
            • Then - Actions
              • Custom script: call PauseTimer(udg_CT__Timer)
              • Custom script: return
            • Else - Actions
        • Else - Actions
      • Custom script: call MoveLocation(udg_CT__TempLoc, udg_CT__CurrentX, udg_CT__StartY)
      • Set CT__TempType = (Terrain type at CT__TempLoc)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CT__TempType Equal to CT__OriginalTile
        • Then - Actions
          • Environment - Change terrain type at CT__TempLoc to CT__TargetTile using variation CT__TargetTileVariation in an area of size 1 and shape Square
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CT__Switch Equal to True
          • CT__TempType Equal to CT__TargetTile
        • Then - Actions
          • Environment - Change terrain type at CT__TempLoc to CT__OriginalTile using variation CT__TargetTileVariation in an area of size 1 and shape Square
        • Else - Actions
      • Custom script: endfunction
      • Custom script:
      • Custom script: function ChangeTiles takes nothing returns nothing
      • Custom script: set udg_CT__StartX = GetTileCenterCooridnate(GetRectMinX(udg_CT__Rect))
      • Custom script: set udg_CT__StartY = GetTileCenterCooridnate(GetRectMinY(udg_CT__Rect))
      • Custom script: set udg_CT__EndX = GetTileCenterCooridnate(GetRectMaxX(udg_CT__Rect))
      • Custom script: set udg_CT__EndY = GetTileCenterCooridnate(GetRectMaxY(udg_CT__Rect))
      • Set CT__CurrentX = CT__StartX
      • Custom script: call TimerStart(udg_CT__Timer, udg_CT__IterationDelay, true, function CT__IterateTiles)
      • Custom script: endfunction
      • Custom script:
      • Custom script: function CT__Initialization takes nothing returns nothing
      • Custom script: set udg_CT__Timer = CreateTimer()
      • Set CT__TempLoc = (Point(0.00, 0.00))
 
Level 4
Joined
Aug 16, 2013
Messages
75
There.

Next time try to read our instructions carefully. :) Not everybody always have times to help.

I didn't know there could be code in the map header, never knew about it until now.

Did you declare the required global variables? All the names prefixed with "udg_" are GUI global variables.

I got it to work, but I can't get it to work how I want it to.

  • Tilevariables
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Set CT__OriginalTile = Lordaeron Summer - Grass
      • Set CT__TargetTileVariation = -1
      • Set CT__Rect = Random Spawn Point <gen>
      • Set CT__IterationDelay = 0.03
      • Set CT__Switch = False
      • Custom script: call ExecuteFunc("ChangeTiles")
  • ChangeTile
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Set CT__Accuracy = 128.00
      • Custom script: call ExecuteFunc("CT__Initialization")
      • Custom script: endfunction
      • Custom script:
      • Custom script: function CT__IterateTiles takes nothing returns nothing
      • Set CT__CurrentX = (CT__CurrentX + CT__Accuracy)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CT__CurrentX Greater than or equal to CT__EndX
        • Then - Actions
          • Set CT__CurrentX = CT__StartX
          • Set CT__StartY = (CT__StartY + CT__Accuracy)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CT__StartY Greater than or equal to CT__EndY
            • Then - Actions
              • Custom script: call PauseTimer(udg_CT__Timer)
              • Custom script: return
            • Else - Actions
        • Else - Actions
      • Custom script: call MoveLocation(udg_CT__TempLoc, udg_CT__CurrentX, udg_CT__StartY)
      • Set CT__TempType = (Terrain type at CT__TempLoc)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CT__TempType Equal to CT__OriginalTile
        • Then - Actions
          • Environment - Change terrain type at CT__TempLoc to CT__TargetTile using variation CT__TargetTileVariation in an area of size 1 and shape Square
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CT__Switch Equal to True
          • CT__TempType Equal to CT__TargetTile
        • Then - Actions
          • Environment - Change terrain type at CT__TempLoc to CT__OriginalTile using variation CT__TargetTileVariation in an area of size 1 and shape Square
        • Else - Actions
      • Custom script: endfunction
      • Custom script:
      • Custom script: function ChangeTiles takes nothing returns nothing
      • Custom script: set udg_CT__StartX = GetTileCenterCooridnate(GetRectMinX(udg_CT__Rect))
      • Custom script: set udg_CT__StartY = GetTileCenterCooridnate(GetRectMinY(udg_CT__Rect))
      • Custom script: set udg_CT__EndX = GetTileCenterCooridnate(GetRectMaxX(udg_CT__Rect))
      • Custom script: set udg_CT__EndY = GetTileCenterCooridnate(GetRectMaxY(udg_CT__Rect))
      • Set CT__CurrentX = CT__StartX
      • Custom script: call TimerStart(udg_CT__Timer, udg_CT__IterationDelay, true, function CT__IterateTiles)
      • Custom script: endfunction
      • Custom script:
      • Custom script: function CT__Initialization takes nothing returns nothing
      • Custom script: set udg_CT__Timer = CreateTimer()
      • Set CT__TempLoc = (Point(0.00, 0.00))
I am trying to make both triggers callable, having ChangeTile and Tilevariables turned off initially and then when a season is selected at start by the players, turn on both triggers.

  • Month Chosen
    • Events
      • Time - Elapsed game time is 22.00 seconds
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Month_Chosen_Fall Greater than Month_Chosen_Spring
          • Month_Chosen_Fall Greater than Month_Chosen_Summer
          • Month_Chosen_Fall Greater than Month_Chosen_Winter
        • Then - Actions
          • Set CT__TargetTile = Barrens - Grassy Dirt
          • Trigger - Turn on Tilevariables <gen>
          • Trigger - Turn on ChangeTile <gen>
        • Else - Actions
It seems Tilevariables and ChangeTile work best as initialization, but I need them to be callable so I can change the tile for each season (during the game). Also, the iteration location needs to reset and I am not sure if it does that. Depending on the season chosen, the variable "CT__TargetTile" needs to hold a different tile.
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
So you are totally new with triggering huh? You just need to do the same exact thing on season change.

You don't need to enable/disable the ChangeTile trigger because it won't run unless you call it using:
  • Custom script: call ExecuteFunc("ChangeTiles")
You need to spend more time to learn the trigger more. Don't ask every single thing. :)

Btw, your condition checking seems weird here:
  • Month_Chosen_Fall Greater than Month_Chosen_Spring
  • Month_Chosen_Fall Greater than Month_Chosen_Summer
  • Month_Chosen_Fall Greater than Month_Chosen_Winter
Are you sure it's okay?

I will give you an example, on winter you want to replace grass to snow. So on season change event:
Code:
Event - Season Changed
Condition - NextSeason is Winter
Action - 
   Set CT__OriginalTile = Lordaeron Summer - Grass
   Set CT__TargetTile = Lordaeron Winter - Snow
   Set CT__TargetTileVariation = -1
   Set CT__Rect = Random Spawn Point <gen>
   Set CT__IterationDelay = 0.03
   Set CT__Switch = False
   Custom script: call ExecuteFunc("ChangeTiles")
Read carefully and try to understand. :) Good luck with your map.
 
Level 4
Joined
Aug 16, 2013
Messages
75
Ohhh.

I totally get it now.

I have never really used custom scripts. I know now how to operate the system. You are awesome Dalv. Thanks a lot for the walk through, I will remember to give credits. Amazing system.
 
Status
Not open for further replies.
Top