Check Trigger

Weyrling

New Member
Reaction score
25
I'm making a series of useful JASS scripts for me to call to save time, I wrote these after staying awake for many hours, so I'd appreciate somebody looking over them.
1) Determines how many enemies there are within X range
JASS:

function CountGroup takes nothing returns nothing
    set udg_Integer = udg_Integer+1
endfunction
function IsEnemyOf takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == true)
endfunction
function CheckforEnemies takes unit u, real dist returns integer
    local location l = GetUnitLoc(u)
    local group g = GetUnitsInRangeOfLocMatching(dist,l,Condition(function IsEnemyOf))
    call ForGroup(g,function CountGroup)
    return udg_Integer
endfunction

2) Sets inputted unit's flying height to match an actual Z.
JASS:

function SetUnitZ takes unit u, real z returns nothing
    local location l = GetUnitLoc(u)
    local real lz = GetLocationZ(l)
    call SetUnitFlyHeight(u,z-lz,99999)
    call RemoveLocation(l)
endfunction
 

Vassilev

New Member
Reaction score
39
Urmm...

Code #1:

No remove location ??

Code # 2:

its better to
set l = null
also

im not to sure about the rest tho :p
 

darkbeer

Beer is Good!
Reaction score
84
hm, i dont think your first code will work, since theres not triggering unit .... use a global to pass the unit to the function, well, i suggest sth like this:

JASS:
function CountGroup takes nothing returns nothing
    set udg_Integer = udg_Integer+1
endfunction

function IsEnemyOf takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(bj_ghoul[23]))
endfunction

function CheckforEnemies takes unit u, real dist returns integer
    local location l = GetUnitLoc(u)
    local group g = CreateGroup()

    set udg_Integer = 0 // if you wont set this to 0, it will become veeeeeeeeery huge^^
    set bj_ghoul[23] = u
    local group g = GroupEnumUnitsInRangeOfLoc(g, l, dist, Condition(function IsEnemyOf)
    call ForGroup(g,function CountGroup)

    call DestroyGroup(g)
    call RemoveLocation(l)
    set l = null
    set g = null

    return udg_Integer
endfunction


also hope i cleaned all leaks

2nd code:
JASS:
function SetUnitZ takes unit u, real z returns nothing
    local location l = GetUnitLoc(u)
    local real lz = GetLocationZ(l)
    call SetUnitFlyHeight(u,z-lz,0)

    call RemoveLocation(l)
    set l = null
endfunction


you have to null locals after using them, else the leak.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top