- Joined
- Oct 9, 2015
- Messages
- 721
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.
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.
Code:
//TESH.scrollpos=6
//TESH.alwaysfold=0
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)
loop
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)
else
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)
endif
elseif r < 0 then
if IsUnitInRangeXY(u, Ax, Ay, distance) then // same as B, but at A instead
call GroupAddUnit(whichgroup, u)
endif
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)
endif
endif
call GroupRemoveUnit(g, u)
endloop
call DestroyGroup(g)
set g = null
endfunction
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)
endfunction
//===========================================================================
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 )
endfunction
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.