• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Terrain Change by Region {changing ground textures/tiles}

Status
Not open for further replies.
Level 5
Joined
Dec 18, 2007
Messages
205
Basically it should be done in JASS.

You must use the GetRect min and max funcitons for x and y coordinates in that rect. then make a double loop and increase x and y by 128 each time and check whether the coordinates are still in the rect.
then check terrain type via the raw code of the searched terrain and replacing it.
it's not that easy and without any jass knowledge not triggerable.
 
Level 5
Joined
Dec 18, 2007
Messages
205
I've once made a terrain change in one of my maps.
I rewrote it so it fits your terrain change.

Copy/Paste this script into the map header:
JASS:
function TerrainChangeInRect takes nothing returns nothing
    local real minx = GetRectMinX(gg_rct_YOURRECT) // Replace YOURRECT with the name of your rect. Blanks must be replaced with _
    local real miny = GetRectMinY(gg_rct_YOURRECT) // e.g. gg_rct_Rect_Change
    local real maxx = GetRectMaxX(gg_rct_YOURRECT)
    local real maxy = GetRectMaxY(gg_rct_YOURRECT)
    local real x=minx
    local real y=maxy
    local integer TType
    loop
        exitwhen y<miny
        loop
            exitwhen x>maxx
            set TType = GetTerrainType(x, y)
            if TType == 'Ldrt' then // 'Ldrt' is the TerrainType-Id that should be found
                call SetTerrainType(x, y, 'Nice', -1, 1, 0)
                // 'Nice' ist the TerrainType-Id that will replace 'Ldrt
            elseif TType == 'Lgrd' then
                // use more elseif's to add more terrain types that can be found in the rect and replace them with other ones
                call SetTerrainType(x, y, 'Bdsr', -1, 1, 0)
            endif
            set x=x+128
        endloop
        set x=minx
        set y=y-128.0
        call TriggerSleepAction(0.01) // The wait could be needed to prevent a small lag and to make the terrain completely change if the rect is too big
    endloop
endfunction

To find out what the id of a terrain is create a "Terrain Type"-variable, make a trigger like this:

  • Actions
    • Set TerrainType = Lordaeron Summer - Earth
    • Set TerrainType = Lordaeron Summer - Rock
and convert the trigger to suctom script (Edit -> Conver to custom script)
the you would see:

JASS:
function Trig_Unbezeichneter_Ausl__ser_006_Actions takes nothing returns nothing
    set udg_TerrainType = 'Ldrt' // 'Ldrt' and 'Lrok' are the integers you searched for
    set udg_TerrainType = 'Lrok'
endfunction

To call the terrainchange use the following:

  • Custom script: call TerrainChangeInRect()
greetings
 
Level 4
Joined
Jan 29, 2009
Messages
79
JASS:
function Trig__map_header_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig__map_header takes nothing returns nothing
    set gg_trg__map_header = CreateTrigger(  )
    call TriggerAddAction( gg_trg__map_header, function Trig__map_header_Actions )
endfunction
function TerrainChangeInRect takes nothing returns nothing
    local real minx = GetRectMinX(gg_rct_TERRAIN_1) // Replace YOURRECT with the name of your rect. Blanks must be replaced with _
    local real miny = GetRectMinY(gg_rct_TERRAIN_1) // e.g. gg_rct_Rect_Change
    local real maxx = GetRectMaxX(gg_rct_TERRAIN_1)
    local real maxy = GetRectMaxY(gg_rct_TERRAIN_1)
    local real x=minx
    local real y=maxy
    local integer TType
    loop
        exitwhen y<miny
        loop
            exitwhen x>maxx
            set TType = GetTerrainType(x, y)
            if TType == 'Lgrs' then // 'Ldrt' is the TerrainType-Id that should be found
                call SetTerrainType(x, y, 'Dgrs', -1, 1, 0)
                // 'Nice' ist the TerrainType-Id that will replace 'Ldrt
            elseif TType == 'Lgrd' then
                // use more elseif's to add more terrain types that can be found in the rect and replace them with other ones
                call SetTerrainType(x, y, 'Bdsr', -1, 1, 0)
            endif
            set x=x+128
endloop
        set x=minx
        set y=y-128.0
call TriggerSleepAction(0.01) // The wait could be needed to prevent a small lag and to make the terrain completely change if the rect is too big
    endloop
endfunction
Then i found IDs for Dark Grass in Loardereon (Default) and then for Grey Stones which i want to replace Dark Grass
JASS:
function Trig_Terrains_Actions takes nothing returns nothing
    set udg_TerrainType[1] = 'Lgrs'
    set udg_TerrainType[1] = 'Dgrs'
endfunction

//===========================================================================
function InitTrig_Terrains takes nothing returns nothing
    set gg_trg_Terrains = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Terrains, function Trig_Terrains_Actions )
endfunction

and finally
  • Flag Dies
  • Events
  • Unit - Humanity Flag 0013 <gen> Dies
  • Conditions
  • Actions
  • Custom script : call TerrainChangeInRect(gg_rct_TERRAIN_1)
but dont work... i dont know whats the problem...

when i test it ..it disables Flag Died trigger (with Custom script)
 
Level 11
Joined
Mar 31, 2009
Messages
732
JASS:
function TerrainChangeInRect takes nothing returns nothing
    local real minx = GetRectMinX(gg_rct_YOURRECT)
Change to:
JASS:
function TerrainChangeInRect takes rect yourRect returns nothing
    local real minx = GetRectMinX(yourRect)
Unless theres some important reason you're using a global that I overlooked?
 
Level 5
Joined
Dec 18, 2007
Messages
205
the map header is not a trigger, it is the custom script section that appears when you click on the map name in the trigger editor.
go to the trigger edtor and then click on the very first line/trigger (this is the map's name) and then paste the code i wrote you there.

then change gg_rct_YOURRECT with your rect (like you did, this is correct).

you repalced the terrain, that's also correct (you could also delete the elseif and the actions below the elseif until the endif, but if you don't understand what i mean just keep it as it is now)

so and the last action you have to do is using the line

  • Custom script : call TerrainChangeInRect()
don't put anything in the brackets.

now try it once again.
 
Level 4
Joined
Jan 29, 2009
Messages
79
it works great...thanks...but now i need to do this with 25 more regions :p

for Example
Unit - Humanity Flag 0014 <gen> Dies
Change Terrain type at gg_rct_TERRAIN_2 to The Same tileset
Unit - Humanity Flag 0015 <gen> Dies
Change Terrain type at gg_rct_TERRAIN_3 to The Same tileset
Etc.
How i can do this ? Thanks
 
Level 5
Joined
Dec 18, 2007
Messages
205
use this script instead of the old one:

JASS:
function TerrainChangeInRect takes rect r returns nothing
    local real minx = GetRectMinX(r)
    local real miny = GetRectMinY(r)
    local real maxx = GetRectMaxX(r)
    local real maxy = GetRectMaxY(r)
    local real x=minx
    local real y=maxy
    local integer TType
    loop
        exitwhen y<miny
        loop
            exitwhen x>maxx
            set TType = GetTerrainType(x, y)
            if TType == 'Ldrt' then // 'Ldrt' is the TerrainType-Id that should be found
                call SetTerrainType(x, y, 'Nice', -1, 1, 0)
                // 'Nice' ist the TerrainType-Id that will replace 'Ldrt
            elseif TType == 'Lgrd' then
                // use more elseif's to add more terrain types that can be found in the rect and replace them with other ones
                call SetTerrainType(x, y, 'Bdsr', -1, 1, 0)
            endif
            set x=x+128
        endloop
        set x=minx
        set y=y-128.0
        call TriggerSleepAction(0.01) // The wait could be needed to prevent a small lag and to make the terrain completely change if the rect is too big
    endloop
endfunction

and call it with
  • Custom script : call TerrainChangeInRect(gg_rct_YOURRECT)
instead of the empty brackets. then enter for each event the correct region.

i hope there won't occur any error now.
 
Status
Not open for further replies.
Top