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

[LUA] Help with a Region

Status
Not open for further replies.
Level 8
Joined
Jun 16, 2008
Messages
333
So I have this code I am trying to run but I get an error that says TriggerRegisterEnterRegionSimple expected a region but I am not to sure why my region wont work... plz help me

Lua:
function groundTrigger()
    local regionTrigger = {}
    for i = 25, 30, 1 do
        regionTrigger[i] = "gg_rct_Region_8" .. i
        TriggerRegisterEnterRegionSimple(triggerGround, regionTrigger[i])
        TriggerAddAction(triggerGround, function() groundChange(regionTrigger[i]) end)
        local triggerGround = CreateTrigger()
    end
    local triggerGround = CreateTrigger()

end

function groundChange(a)
    TerrainDeformationRippleBJ(4, false, a, 600, 600, 128, 2, 256)
    SetTerrainTypeBJ(a, FourCC("Jrtl"), -1, 1, 1)
end
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
Try this:
Lua:
function groundTrigger()
    local regionTrigger = {}
    for i = 25, 30, 1 do
        regionTrigger[i] = "gg_rct_Region_8"..i
        local triggerGround = CreateTrigger()
        TriggerRegisterEnterRegionSimple(triggerGround, regionTrigger[i])
        TriggerAddAction(triggerGround, function() groundChange(regionTrigger[i]) end)
    end

end

function groundChange(a)
    TerrainDeformationRippleBJ(4, false, GetRectCenter(a), 600, 600, 128, 2, 256)
    SetTerrainTypeBJ(GetRectCenter(a), FourCC("Jrtl"), -1, 1, 1)
end

You're creating triggerGround AFTER you register the Event to it, at least on the first time through the loop. And I'm pretty sure you need to use GetRectCenter(Region) in your groundChange function.

The string/region thing might not work either, it's going to treat regionTrigger as a string.
 
Last edited:
Level 8
Joined
Jun 16, 2008
Messages
333
Try this:
Lua:
function groundTrigger()
    local regionTrigger = {}
    for i = 25, 30, 1 do
        regionTrigger[i] = "gg_rct_Region_8"..i
        local triggerGround = CreateTrigger()
        TriggerRegisterEnterRegionSimple(triggerGround, regionTrigger[i])
        TriggerAddAction(triggerGround, function() groundChange(regionTrigger[i]) end)
    end

end

function groundChange(a)
    TerrainDeformationRippleBJ(4, false, GetRectCenter(a), 600, 600, 128, 2, 256)
    SetTerrainTypeBJ(GetRectCenter(a), FourCC("Jrtl"), -1, 1, 1)
end

You're creating triggerGround AFTER you register the Event to it, at least on the first time through the loop. And I'm pretty sure you need to use GetRectCenter(Region) in your groundChange function.

The string/region thing might not work either, it's going to treat regionTrigger as a string.

still getting expected region at TriggerRegisterEnterRegionSimple(triggerGround, regionTrigger)

but with the createtigger my dumb self should of realized that but would i have to have a different trigger name like at ' .. i ' after so its unique or that shouldn't matter?
triggerGround25
triggerGround26
triggerGround27
triggerGround28
ect.... ??


What I am trying to accomplish is to have an group of regions that once a unit enters it, the terrain will change under that region
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
I tested this setup and it works
Lua:
function groundTrigger()
    Regions = {}
    Regions[1] = gg_rct_Region_1
    Regions[2] = gg_rct_Region_2
    Regions[3] = gg_rct_Region_3
    Regions[4] = gg_rct_Region_4
    Regions[5] = gg_rct_Region_5
 
    local regionTrigger = {}
    local minx
    local miny
    local maxx
    local maxy
    for i = 1, 5 do
        minx = GetRectMinX(Regions[i])
        miny = GetRectMinY(Regions[i])
        maxx = GetRectMaxX(Regions[i])
        maxy = GetRectMaxY(Regions[i])

        regionTrigger[i] = Rect(minx, miny, maxx, maxy)

        local triggerGround = CreateTrigger()
        TriggerRegisterEnterRectSimple(triggerGround, regionTrigger[i])
        TriggerAddAction(triggerGround, function() groundChange(regionTrigger[i]) end)
    end

end

function groundChange(a)
    TerrainDeformationRippleBJ(4, false, GetRectCenter(a), 600, 600, 128, 2, 256)
    SetTerrainTypeBJ(GetRectCenter(a), FourCC("Jrtl"), -1, 1, 1)
end
 
Last edited:
Level 8
Joined
Jun 16, 2008
Messages
333
I tested this setup and it works
Lua:
function groundTrigger()
    Regions = {}
    Regions[1] = gg_rct_Region_1
    Regions[2] = gg_rct_Region_2
    Regions[3] = gg_rct_Region_3
    Regions[4] = gg_rct_Region_4
    Regions[5] = gg_rct_Region_5
 
    local regionTrigger = {}
    local minx
    local miny
    local maxx
    local maxy
    for i = 1, 5 do
        minx = GetRectMinX(Regions[i])
        miny = GetRectMinY(Regions[i])
        maxx = GetRectMaxX(Regions[i])
        maxy = GetRectMaxX(Regions[i])

        regionTrigger[i] = Rect(minx, miny, maxx, maxy)

        local triggerGround = CreateTrigger()
        TriggerRegisterEnterRectSimple(triggerGround, regionTrigger[i])
        TriggerAddAction(triggerGround, function() groundChange(regionTrigger[i]) end)
    end

end

function groundChange(a)
    TerrainDeformationRippleBJ(4, false, GetRectCenter(a), 600, 600, 128, 2, 256)
    SetTerrainTypeBJ(GetRectCenter(a), FourCC("Jrtl"), -1, 1, 1)
end
when you tested it, did it do the Terrain change? I added a print and it prints but it doesn't do the terrain change...
 
Level 8
Joined
Jun 16, 2008
Messages
333
It looked like it changed but the ripple was pretty disruptive so I'm not 100% sure. Try adjusting the radius of the terrain change to find out for sure. Unless of course you're sure, then I don't know...
It works but it is making the region bigger then it actually is.
WC3ScrnShot_051720_105931_001.png
in the image, my regions are the blue ones and the white one I created to show you what happens in game.

My updated code
Lua:
function groundTrigger()
    Regions = {}
    for i = 25, 30, 1 do
        Regions[i] = _G[string.format("gg_rct_Region_8" .. i)]
    end

    local regionTrigger = {}
    local minx
    local miny
    local maxx
    local maxy
    for i = 25, 30, 1 do
        minx = GetRectMinX(Regions[i])
        miny = GetRectMinY(Regions[i])
        maxx = GetRectMaxX(Regions[i])
        maxy = GetRectMaxX(Regions[i])

        regionTrigger[i] = Rect(minx, miny, maxx, maxy)

        local triggerGround = CreateTrigger()
        TriggerRegisterEnterRectSimple(triggerGround, regionTrigger[i])
        TriggerAddAction(triggerGround, function() groundChange(regionTrigger[i]) end)
    end

end

function groundChange(a)
    if GetOwningPlayer(GetEnteringUnit()) ~= Player(15) then
        if GetTerrainTypeBJ(GetRectCenter(a)) ~= FourCC("Jrt1") then
            print("omgWTF")
            TerrainDeformationRippleBJ(4, false, GetRectCenter(a), 600, 600, 128, 2, 256)
            SetTerrainTypeBJ(GetRectCenter(a), FourCC("Jrtl"), -1, 1, 0)
        end
    end
end
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
You're setting maxy = GetRectMaxX(Regions), you need to get the Y of that Rect. My mistake for messing that up in my code (fixed it).

Also, you can use an AND in your If Then Else:
Lua:
function groundChange(a)
    if GetOwningPlayer(GetEnteringUnit()) ~= Player(15) and GetTerrainTypeBJ(GetRectCenter(a)) ~= FourCC("Jrt1") then
        print("omgWTF")
        TerrainDeformationRippleBJ(4, false, GetRectCenter(a), 600, 600, 128, 2, 256)
        SetTerrainTypeBJ(GetRectCenter(a), FourCC("Jrtl"), -1, 1, 0)
    end
end
 
Last edited:
Level 8
Joined
Jun 16, 2008
Messages
333
You're setting maxy = GetRectMaxX(Regions), you need to get the Y of that Rect. My mistake for messing that up in my code (fixed it).

Also, you can use an AND in your If Then Else:
Lua:
function groundChange(a)
    if GetOwningPlayer(GetEnteringUnit()) ~= Player(15) and GetTerrainTypeBJ(GetRectCenter(a)) ~= FourCC("Jrt1") then
        print("omgWTF")
        TerrainDeformationRippleBJ(4, false, GetRectCenter(a), 600, 600, 128, 2, 256)
        SetTerrainTypeBJ(GetRectCenter(a), FourCC("Jrtl"), -1, 1, 0)
    end
end
something so simple...

now the Terrain doesn't match, even tho im changing it to what i am checking for

I print the terrain type and I get 1249014892 but if I print FourCC it is 1249014833

I got it to work by just checking if TerrainType ~= 1249014892
 
Last edited:
Status
Not open for further replies.
Top