Warcraft III resources & community, 2003–2006 · archived

IsUnit Behind/InFrontOf Unit

not rated
Submitted by paskovichPhysics0 downloads
As i saw many people asking "how to make a backstab"-like ability, i thought of making a simple script. Many people don't know how to work with the facing angles. The order in which you add the two units doesn't matter.
*Changed the code as PurplePoot advised.
**Optimized the code again, but i haven't tested it yet...

Source

function IsUnitBehindUnit takes unit A, unit B returns boolean
    local real a = GetUnitFacing(A)
    local real b = GetUnitFacing(B)
    return -45<(a-b) and (a-b)<45
endfunction

function IsUnitInFrontOfUnit takes unit A, unit B returns boolean
    local real a = GetUnitFacing(A)
    local real b = GetUnitFacing(B)
    if a > b then
    	return (a-b-135)<90
    endif
    return (b-a-135)<90
endfunction

Comments

6
every 20 bytes is 20 bytes saved :D

however, thats more like 176 bytes lol
Yeah, my map is 20Bytes smaller! :lol:
The size optimization was negligible, I think, but the rest is good. Nice script by the way, might prove useful. :)
there isnt really much point not optimizing, cuz not only will it run faster, but its easier to read and takes up less map space :D
I changed my mind (:D) and optimized the code as you said...
Also fixed a minor bug:
When checking for a unit i.f.o.u., i changed the interval from [170,200] to [160,200].
oh, and im sure alot of noobs will be happy

(if they can find the Custom Script tag, that is )

YES! perhaps....
And sry i won't change the script, it isn't used too many times (1 or 2 times per trigger), it won't cause lagg.
uuh, you might want to change

function GetFacingDifferenceOfUnits takes unit A, unit B returns real
    local real a = GetUnitFacing(A)
    local real b = GetUnitFacing(B)
    if a > b then
        return a - b
    endif
    return b - a
endfunction
 
function IsUnitBehindUnit takes unit A, unit B returns boolean
    return GetFacingDifferenceOfUnits(A,B)<45
endfunction


to

function IsUnitBehindUnit takes unit A, unit B returns boolean
        local real a = GetUnitFacing(A)
    local real b = GetUnitFacing(B)
    if a > b then
        return (a - b)<45
    endif
    return (b - a)<45
endfunction


oh, and im sure alot of noobs will be happy :D

(if they can find the Custom Script tag, that is :lol:)