• 🏆 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!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Help with rect script (JASS and GUI)

Not open for further replies.
Level 11
Oct 9, 2015
So I use this rect script in my project, it picks units whithin a rect (Loc1 and Loc2) then do damage to them, but recently I noticed that if I do the actions within about 5 seconds game time, then the action is not run, and will not be run if the action is done again. What I wanted is to ask someone to take a look to see if there's anything wrong with the script.

function LSE_GroupEnumUnitsInRangeOfSegment takes group whichgroup, real Ax, real Ay, real Bx, real By, real distance returns nothing
    local real dx = Bx-Ax
    local real dy = By-Ay
    local real L = ((dx)*(dx) + (dy)*(dy)) // Get quasi length
    local real r = SquareRoot(dx*dx+dy*dy)/2+distance + udg_LSE_MaxUnitCollision // replace 400.0 with the max collision size in your map
    local unit u
    local group g = CreateGroup()
    call GroupClear(whichgroup)
    call GroupEnumUnitsInRange(g, Ax+(dx/2), Ay+(dy/2), r, null)
        set u = FirstOfGroup(g)
        exitwhen u == null
        if L == 0 and IsUnitInRangeXY(u, Ax, Ay, distance) then // seg is actually a point so lets return the point
            call GroupAddUnit(whichgroup, u)
            set r = ((GetUnitX(u)-Ax)*(dx) + (GetUnitY(u)-Ay)*(dy))/(L) // get the ratio
            if r > 1 then // split if/thens so that it exists properly
                if IsUnitInRangeXY(u, Bx, By, distance) then // closests point is past seg, so return end point B
                    call GroupAddUnit(whichgroup, u)
            elseif r < 0 then
                if IsUnitInRangeXY(u, Ax, Ay, distance) then // same as B, but at A instead
                    call GroupAddUnit(whichgroup, u)
            elseif IsUnitInRangeXY(u, Ax+r*(dx), Ay+r*(dy), distance) then // In the middle of A and B so use the ratio to find the point
                call GroupAddUnit(whichgroup, u)
        call GroupRemoveUnit(g, u)
    call DestroyGroup(g)
    set g = null

function Trig_LSE_Run_Units_Actions takes nothing returns nothing
    call LSE_GroupEnumUnitsInRangeOfSegment(udg_LSE_Group, GetLocationX(udg_LSE_Loc_1), GetLocationY(udg_LSE_Loc_1), GetLocationX(udg_LSE_Loc_2), GetLocationY(udg_LSE_Loc_2), udg_LSE_Width)

function InitTrig_LSE_Get_Units takes nothing returns nothing
    set gg_trg_LSE_Get_Units = CreateTrigger(  )
    call TriggerAddAction( gg_trg_LSE_Get_Units, function Trig_LSE_Run_Units_Actions )

When I try to do actions to units in LSE_Group (I run the trigger LSE_Units) they will only work if about five seconds of game have passed, otherwise it will glitch the action and it is not possible to do them again.
Level 15
Mar 25, 2016
The trigger seems fine to me. I did not look at the math behind it, but I found nothing that would cause the problem you have.
Maybe the variables you are using this function with are not initialized when calling this function.
If you are using an array of unit groups you must first create a unit group, before you can units to it.
If you are using for example UnitGroupA[2] as a variable in the variable editor, only UnitGroupA[0] and UnitGroupA[1] are initialized.
Not open for further replies.