• 🏆 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!

Changing Terrain with Triggers

Status
Not open for further replies.

Vunjo

Hosted Project: SC
Level 14
Joined
Jul 1, 2010
Messages
1,340
Is it possible to swap terrain with triggers? For example:
When it rains, to switch grass terrain with dirt, so it could be "mud". But, to keep other textures (mramor, leaves....) the same.

+REP
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Yes, it is:

  • Untitled Trigger 002
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Terrain type at (Center of (Playable map area))) Equal to Lordaeron Summer - Grassy Dirt
        • Then - Actions
          • Environment - Change terrain type at (Center of (Playable map area)) to Lordaeron Summer - Dirt using variation -1 in an area of size 1 and shape Circle
        • Else - Actions
Loop through all tiles and check the terrain type, and change if needed.

When looping, create an intelligent method of points to check. One tile is 128x128, so each center of a square is 128 distance units away from the next one...

Save the original terrain type and variation into hashtable for example.
 

Vunjo

Hosted Project: SC
Level 14
Joined
Jul 1, 2010
Messages
1,340
Could I just put grass in variable and just change it in that trigger?
Could you be mode specific please about this 128x128 thing ^^

And, that trigger didn't work for me =(
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Here's a test map I slapped together in a hurry. It's not a polished system, but it works.

Hit ESC to change grass to grassy dirt and grassy dirt to dirt. Hit ESC again to load original tiles.



  • Init Terrain Change
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Terrain_Hash = (Last created hashtable)
      • Set Spacing = 128.00
      • Set Reals[0] = (Min X of (Playable map area))
      • Set Reals[1] = (Min Y of (Playable map area))
      • Set Reals[2] = (Max X of (Playable map area))
      • Set Reals[3] = (Max Y of (Playable map area))
      • Set Rows = (Integer(((Reals[3] + (Abs(Reals[1]))) / Spacing)))
      • Set Columns = (Integer(((Reals[2] + (Abs(Reals[0]))) / Spacing)))
      • Set p1 = (Point(Reals[0], Reals[3]))
      • Set TerrainTypesFrom[1] = Lordaeron Summer - Grassy Dirt
      • Set TerrainTypesFrom[2] = Lordaeron Summer - Grass
      • Set TerrainTypesTo[1] = Lordaeron Summer - Dirt
      • Set TerrainTypesTo[2] = Lordaeron Summer - Grassy Dirt
      • Set TerrainTypesAmount = 2
  • Change Terrain 1
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Trigger - Turn off (This trigger)
      • Set index = 0
      • For each (Integer loopA) from 1 to Columns, do (Actions)
        • Loop - Actions
          • Set p2 = (p1 offset by (Spacing x (Real(loopA))) towards 0.00 degrees)
          • For each (Integer loopB) from 1 to Rows, do (Actions)
            • Loop - Actions
              • Set p3 = (p2 offset by (Spacing x (Real(loopB))) towards 270.00 degrees)
              • For each (Integer loopC) from 1 to TerrainTypesAmount, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Terrain type at p3) Equal to TerrainTypesFrom[loopC]
                    • Then - Actions
                      • Set i1 = (Terrain variance at p3)
                      • Unit - Create 1 Footman for Player 1 (Red) at p3 facing Default building facing degrees
                      • Custom script: call SaveInteger( udg_Terrain_Hash , GetHandleId(GetLastCreatedUnit()) , StringHash("type") , udg_loopC )
                      • Custom script: call SaveInteger( udg_Terrain_Hash , GetHandleId(GetLastCreatedUnit()) , StringHash("var") , udg_i1 )
                      • Environment - Change terrain type at p3 to TerrainTypesTo[loopC] using variation -1 in an area of size 1 and shape Circle
                      • Unit Group - Add (Last created unit) to TerrainGroup
                    • Else - Actions
              • Custom script: call RemoveLocation(udg_p3)
          • Custom script: call RemoveLocation(udg_p2)
      • Wait 0.00 seconds
      • Trigger - Turn on Change Terrain 2 <gen>
  • Change Terrain 2
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Trigger - Turn off (This trigger)
      • Unit Group - Pick every unit in TerrainGroup and do (Actions)
        • Loop - Actions
          • Custom script: set udg_i1 = LoadInteger( udg_Terrain_Hash , GetHandleId(GetEnumUnit() ) , StringHash("type") )
          • Custom script: set udg_i2 = LoadInteger( udg_Terrain_Hash , GetHandleId(GetEnumUnit() ) , StringHash("var") )
          • Set p2 = (Position of (Picked unit))
          • Environment - Change terrain type at p2 to TerrainTypesFrom[i1] using variation i2 in an area of size 1 and shape Circle
          • Unit Group - Remove (Picked unit) from TerrainGroup
          • Unit - Remove (Picked unit) from the game
          • Custom script: call RemoveLocation(udg_p2)
      • Wait 0.00 seconds
      • Trigger - Turn on Change Terrain 1 <gen>
 

Attachments

  • Terrain_Change.w3x
    15.2 KB · Views: 40
Level 37
Joined
Mar 6, 2006
Messages
9,240
I improved my system. It bothered me because it was not good enough.

  • You can set the region you want to apply changes to
  • Uses coordinates, not locations
  • Uses one unit, instead of separate unit for each point


  • Init Terrain Change
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set th = 0
      • Set x1 = 0.00
      • Set x2 = 0.00
      • Set y1 = 0.00
      • Set y2 = 0.00
      • Set i1 = 0
      • Set i2 = 0
      • Hashtable - Create a hashtable
      • Set Terrain_Hash = (Last created hashtable)
      • Set Spacing = 128.00
      • Set TerrainUnit = Blood Mage 0000 <gen>
      • Custom script: set udg_th = GetHandleId(udg_TerrainUnit)
  • Run Terrain Change
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- ------------------------------------------------------------ --------
      • -------- The region you want to change tiles in --------
      • -------- ------------------------------------------------------------ --------
      • Set Region = (Playable map area)
      • -------- ------------------------------------------------------------ --------
      • -------- The tiles to be changed, the tiles used for replacing --------
      • -------- ------------------------------------------------------------ --------
      • Set TerrainTypesFrom[1] = Lordaeron Summer - Grassy Dirt
      • Set TerrainTypesFrom[2] = Lordaeron Summer - Grass
      • Set TerrainTypesTo[1] = Lordaeron Summer - Dirt
      • Set TerrainTypesTo[2] = Lordaeron Summer - Grassy Dirt
      • -------- ------------------------------------------------------------ --------
      • -------- How many terrain types to check --------
      • -------- ------------------------------------------------------------ --------
      • Set TerrainTypesAmount = 2
      • -------- ------------------------------------------------------------ --------
      • -------- Don't Change these --------
      • -------- ------------------------------------------------------------ --------
      • Set Reals[0] = (Min X of Region)
      • Set Reals[1] = (Min Y of Region)
      • Set Reals[2] = (Max X of Region)
      • Set Reals[3] = (Max Y of Region)
      • Set Rows = (Integer(((Reals[3] + (Abs(Reals[1]))) / Spacing)))
      • Set Columns = (Integer(((Reals[2] + (Abs(Reals[0]))) / Spacing)))
      • Set TilesChanged = 0
      • -------- ------------------------------------------------------------ --------
      • -------- Run the change --------
      • -------- ------------------------------------------------------------ --------
      • Trigger - Turn off (This trigger)
      • Trigger - Run Change Terrain 1 <gen> (checking conditions)
      • Wait 3.00 seconds
      • Trigger - Run Change Terrain 2 <gen> (checking conditions)
      • Wait 1.00 seconds
      • Trigger - Turn on (This trigger)
  • Change Terrain 1
    • Events
    • Conditions
    • Actions
      • For each (Integer loopA) from 0 to Columns, do (Actions)
        • Loop - Actions
          • Custom script: set udg_x1 = udg_Reals[0] + udg_Spacing * udg_loopA * Cos(0)
          • Custom script: set udg_y1 = udg_Reals[3] + udg_Spacing * udg_loopA * Sin(0)
          • For each (Integer loopB) from 0 to Rows, do (Actions)
            • Loop - Actions
              • Custom script: set udg_x2 = udg_x1 + udg_Spacing * udg_loopB * Cos( 3 * bj_PI / 2 )
              • Custom script: set udg_y2 = udg_y1 + udg_Spacing * udg_loopB * Sin( 3 * bj_PI / 2 )
              • For each (Integer loopC) from 1 to TerrainTypesAmount, do (Actions)
                • Loop - Actions
                  • Custom script: if GetTerrainType( udg_x2 , udg_y2 ) == udg_TerrainTypesFrom[udg_loopC] then
                  • Custom script: set udg_i1 = GetTerrainVariance( udg_x2 , udg_y2 )
                  • Custom script: call SaveInteger( udg_Terrain_Hash , udg_th , StringHash("type" + I2S(udg_TilesChanged ) ) , udg_loopC )
                  • Custom script: call SaveInteger( udg_Terrain_Hash , udg_th , StringHash("var" + I2S(udg_TilesChanged ) ) , udg_i1 )
                  • Custom script: call SaveReal( udg_Terrain_Hash , udg_th , StringHash("x" + I2S(udg_TilesChanged ) ) , udg_x2 )
                  • Custom script: call SaveReal( udg_Terrain_Hash , udg_th , StringHash("y" + I2S(udg_TilesChanged ) ) , udg_y2 )
                  • Custom script: call SetTerrainType( udg_x2 , udg_y2 , udg_TerrainTypesTo[udg_loopC] , -1 , 1 , 0 )
                  • Set TilesChanged = (TilesChanged + 1)
                  • Custom script: endif
      • Custom script: call SaveInteger( udg_Terrain_Hash , udg_th , StringHash("amount") , udg_TilesChanged -1 )
  • Change Terrain 2
    • Events
    • Conditions
    • Actions
      • Custom script: set udg_TilesChanged = LoadInteger( udg_Terrain_Hash , udg_th , StringHash("amount") )
      • For each (Integer loopA) from 0 to TilesChanged, do (Actions)
        • Loop - Actions
          • Custom script: set udg_i1 = LoadInteger( udg_Terrain_Hash , udg_th , StringHash("type" + I2S(udg_loopA ) ) )
          • Custom script: set udg_i2 = LoadInteger( udg_Terrain_Hash , udg_th , StringHash("var" + I2S(udg_loopA ) ) )
          • Custom script: set udg_x1 = LoadReal( udg_Terrain_Hash , udg_th , StringHash("x" + I2S(udg_loopA) ) )
          • Custom script: set udg_x2 = LoadReal( udg_Terrain_Hash , udg_th , StringHash("y" + I2S(udg_loopA) ) )
          • Custom script: call SetTerrainType( udg_x1 , udg_x2 , udg_TerrainTypesFrom[udg_i1] , udg_i2 , 1 , 0 )
 

Attachments

  • Terrain_Change_2.w3x
    15.2 KB · Views: 54
Status
Not open for further replies.
Top