• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Changing Rect?

Not open for further replies.
Level 15
Nov 30, 2007
The black area is the ground pathing, in this case a 8x8 grid. The red regions are the enter of the regions adjacent to the black area. I want to search the blue areas for buildings, how do I go about that?

So, how do I confiure a rect to the size of 8x2 only knowing the center of either the black or red rect?

The purpose is to search for buildings that are right next to it.

So I would move the rect around using this i think...
 call SetRect(r, 0, 0, dimension*64,128)
 call MoveRectTo(r, x[i], y[i])

... And for searching for buildings and trees nearby hmmm..

I got this far, but when I tried to change the rect it prevented the loop from happening again. What I was trying to achieve was to random out location (check) and move it there.

All Units get created at 0,0... No idea whats wrong.
library FireSpreadSystem initializer Init

    private constant integer FIRE_LIMIT = 10
    private hashtable hash = InitHashtable()
    private rect area = null
    private group g = CreateGroup()


private function Kill takes nothing returns nothing
    call KillUnit(GetEnumUnit())

private function Main takes  nothing returns nothing
    local unit u = GetTriggerUnit()
    local boolean array vert 
    local real array x
    local real array y
    local integer i
    local integer j
    local integer k
    local integer curMax = 4
    local integer nGrid = LoadInteger(hash, GetUnitTypeId(u), 0)
    if nGrid != 0 then
        set k = (nGrid/4 + 1)*64
        set x[0] = GetUnitX(u)
        set y[0] = GetUnitY(u)
        set vert[1] = false 
        set vert[2] = false
        set vert[3] = true 
        set vert[4] = true
        set x[1] = x[0] - k
        set y[1] = y[0]
        set x[2] = x[0] + k
        set y[2] = y[0]
        set x[3] = x[0]
        set y[3] = y[0] - k
        set x[4] = x[0]
        set y[4] = y[0] + k 
            exitwhen curMax < 1
            set i = GetRandomInt(1, curMax)
            //set u = CreateUnit(Player(0), 'hpea', x[i], y[i], 0)
            if vert[i] == true then
                set area = Rect(x[i], y[i], x[i] + nGrid*64, y[i] + 64*3)
                call BJDebugMsg("Vertical")
                set area = Rect(x[i], y[i], x[i] + 64*3, y[i] + nGrid*64)
                call BJDebugMsg("Horizontal")
            call GroupEnumUnitsInRect(g, area, null) 
                set u = FirstOfGroup(g)
                exitwhen u == null
                call GroupRemoveUnit(g, u)
                call KillUnit(u)    
            call TriggerSleepAction(0.8) // debug
            set vert[i] = vert[curMax]
            set x[i] = x[curMax]
            set y[i] = y[curMax]
            set curMax = curMax - 1

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger() 
    call TriggerRegisterPlayerUnitEvent(t, Player(0), EVENT_PLAYER_UNIT_SELECTED, null)
    call TriggerAddAction(t, function Main)
    call SaveInteger(hash, 'hhou', 0, 4)    // 4x4 Pathing Size
    call SaveInteger(hash, 'halt', 0, 6)    
    call SaveInteger(hash, 'hbla', 0, 8)    
    call SaveInteger(hash, 'hlum', 0, 10)   
    call SaveInteger(hash, 'htow', 0, 12)  



  • ex.png
    333.6 KB · Views: 70
Last edited:
Level 12
Feb 22, 2010
You can't do this by just knowing the center of black rect or red rect.You need at least 2 things.(Two of four: Center of black, center of red, size of black)
Last edited:
Not open for further replies.