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

[JASS] Mass Sending Units Trigger

Status
Not open for further replies.
Level 6
Joined
Jun 30, 2006
Messages
230
Edit: Doesn't freaking fire!
JASS:
globals
    rect gg_rct_HeartOfTheAlliance = Rect( -4064.0, -448.0, -3616.0, 0.0 )
    rect gg_rct_HeartOfTheHorde = Rect( 3616.0, -512.0, 4064.0, -64.0 )
    region array udg_Region
endglobals
function Regions takes nothing returns nothing
    local integer i = 0
    local rect array udg_Rect
    set udg_Rect[0] = Rect( -7328.0, 2080.0, -7136.0, 2272.0 )
    set udg_Rect[1] = Rect( -7328.0, 800.0, -7136.0, 992.0 )
    set udg_Rect[2] = Rect( -7328.0, -480.0, -7136.0, -288.0 )
    set udg_Rect[3] = Rect( -7328.0, -1760.0, -7136.0, -1568.0 )
    set udg_Rect[4] = Rect( -7328.0, -3040.0, -7136.0, -2848.0 )
    set udg_Rect[5] = Rect( 7136.0, 2208.0, 7328.0, 2400.0 )
    set udg_Rect[6] = Rect( 7136.0, 928.0, 7328.0, 1120.0 )
    set udg_Rect[7] = Rect( 7136.0, -352.0, 7328.0, -160.0 )
    set udg_Rect[8] = Rect( 7136.0, -1632.0, 7328.0, -1440.0 )
    set udg_Rect[9] = Rect( 7136.0, -2912.0, 7328.0, -2720.0 )
    loop
        exitwhen i>9
        call RegionAddRect( udg_Region[i], udg_Rect[i] )
        set i = i + 1
    endloop
endfunction
function MassAttack takes nothing returns nothing
    local unit u = GetEnumUnit()
    local player p = GetOwningPlayer(u)
    local integer i = GetPlayerId(p)
    local rect r
    local location l
    if i < 10 then
        if i < 5 then
             set r = gg_rct_HeartOfTheHorde
        else
             set r = gg_rct_HeartOfTheAlliance
        endif
        set l = GetRectCenter(r)
        call IssuePointOrderLoc( u, "attack", l )
    endif
    call RemoveLocation(l)
    set l = null
    call RemoveRect(r)
    set r = null
    set p = null
    set u = null
endfunction
function MassSendActions takes nothing returns nothing
    local integer i = 0
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local region Region = GetTriggeringRegion()
    local rect r = GetWorldBounds()
    local group g
    loop
        exitwhen i>9
        if ( Region == udg_Region[i] ) then
            if ( p == Player(i) ) then
                set g = GetUnitsInRectOfPlayer( r, Player(i) )
                call ForGroup( g, function MassAttack )
            endif
        endif
        set i = i + 1
    endloop
    call DestroyGroup(g)
    set g = null
    set Region = null
    call RemoveRect(r)
    set r = null
    set p = null
    set u = null
endfunction

//===========================================================================
function InitTrig_MassSend takes nothing returns nothing
    local integer i = 0
    set gg_trg_MassSend = CreateTrigger()
    loop
        exitwhen i>9
        call TriggerRegisterEnterRegion( gg_trg_MassSend, udg_Region[i], null )
        set i = i + 1
    endloop
    call TriggerAddAction( gg_trg_MassSend, function MassSendActions )
endfunction
 
Last edited:
Level 11
Joined
Jun 13, 2007
Messages
570
setting the variable to null doesnt remove it from memory since locations are just pointer variables, your setting the pointer to null but leaking the actual location which consists of an X and Y coord.

call RemoveLocation(l)

same with rects, they contain 4 locations per variable, the rect variable is just another pointer. However, since you do NOT want to remove the triggering rect, its fine as is

but I am pretty sure that 'local rect l = GetEntireMapRect()' will leak 4 locations or 8 variables of X and Y every time its called as it creates a rect instead of just returning the end of map points
 
Why use GetEntireMapRect()? it just returns GetWorldBounds().

Get rect center = creates a new location, must be removed.

Rects have to be removed with RemoveRect() unless you don't want them away.

'local rect l = GetEntireMapRect()' will leak 4 locations or 8 variables of X and Y every time its called as it creates a rect instead of just returning the end of map points
How can something leak cordinates when they are reals?
 
Level 6
Joined
Jun 30, 2006
Messages
230
Points taken. I didn't look at what GetEntireMapRect returns, thanks for the tip.

My function doesn't work though :/ It never fires. Also, if I create a region based on the rectangles, do I need to keep the rectangles intact, or can I get rid of them? This should be the only function using them if I can get it to work, so they don't need to be globals.

Reposted some of the changes. I'm not sure on how to properly remove locations because I've never used them before. Could someone give a more detailed example?
 
Level 6
Joined
Jun 30, 2006
Messages
230
Never used them, what's the advantage? If you can't tell, I've never messed around with locations/points/etc before. And how to use them?

Also, if I create a region based on the rectangles, do I need to keep the rectangles intact, or can I get rid of them?
 
Ermm... You do know that when you create variables using "globals" and "endglobals", you don't need any prefixes. Ie:
JASS:
globals
    rect udg_x
    rect udg_y
    rect gg_rct_xy 
    rect gg_rct_yx
endglobals

function JASS takes nothing returns nothing
    set udg_x = udg_y
    set udg_y = udg_x
    set gg_rct_xy = gg_rct_yx
    set gg_rct_yx = gg_rct_xy
endfunction

Can simply be:
JASS:
globals 
    rect x
    rect y
    rect xy
    rect yx
endglobals

function JASS takes nothing returns nothing
    set x = y
    set y = x
    set xy = yx
    set yx = xy
endfunction

It looks much more neat. :thumbs_up:
 
Level 6
Joined
Jun 30, 2006
Messages
230
Yes, I knew. But udg_ helps me keep track of them in my head. udg_ auto tells me it's a global vs local (sometimes I use the same base name, so it's necessary), but every man to his own, eh?

I still haven't been answered this: if I create a region based on the rectangles, do I need to keep the rectangles intact, or can I get rid of them? Nor, why use GetRectCenterX and GetRectCenterY vs GetRectCenter?
 
Level 6
Joined
Jun 30, 2006
Messages
230
Those are just details, especially because the trigger isn't firing, but thanks anyway. I can't figure out why it's not firing... I'll repost if I ever get it too...
 
Last edited:
Level 6
Joined
Jun 30, 2006
Messages
230
Does my trigger still leak, meaning the one posted at the top?

Also, it doesn't fire, anyone know why? I've made a lot of changes hoping it would fix it, but it STILL doesn't fire. Perhaps I am misunderstanding Regions?

Edit: I just had a thought. Wouldn't destroying GetWorldBounds be the same type of thing as destroying All Players?
 
Last edited:
Status
Not open for further replies.
Top