HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS Question

02-27-2004, 03:17 AM#1
Transcendence
Ive never really used JASS before... but earlier someone posted JASS for me to use... This is my question. I want to make my trigger, but as a part of it i want to put the JASS script into it.
02-27-2004, 05:33 AM#2
Narwanza
Is that me you are talking about? In order to do this what you have to do is put this (i updated it since I posted it earlier so use this version) text into the box that appears when you are in the trigger editor and you have the map name selected by where you select triggers. In the comment box it should tell you that you can add custom script stuff there. Put it in the bottom box and then go to the trigger you want to call it from. Now if it was my JASS script that you are refering to you have to create first off 3 variables. Two of a unit, and one of a unit group. Then set the unit group = units within whatever range that you want to have the closest unit selected from. Set the second unit to the unit that you want to pick the closest unit to. Name the first variable ClosestUnit, the second, TempGroup, and the third, OriginUnit After you do all of that put this custom script line (GUI trigger action) into your map.
Code:
set udg_ClosestUnit = GetClosestUnit(udg_OriginUnit, udg_TempGroup)
That will set the first unit variable = the closest unit to the third variable. Keep in mind that this funciton will only work properly if give 3+ seconds to cool down. I am currently optomizing it to take less time to run, but right now it needs time. Here is the code that you need to paste into your custom script thing at the beginning.
Code:
function GetClosestUnit takes unit who, group pool returns unit
    local location temploc = GetUnitLoc(who)
    local integer x = 0
    local real distance = 9999999.0
    local location temploc01 = null
    local unit u = null
    local unit actualunit = null
    local real distance01 = 0
    call GroupRemoveUnitSimple(who, pool)
    loop
        set u = FirstOfGroup(pool)
        exitwhen u == null
        set temploc01 = GetUnitLoc(u)
        call GroupRemoveUnitSimple(u, pool)
        set x = DistanceBetweenPoints(temploc01,temploc)
        set distance01 = x
        if (distance01 < distance) then
            set distance = x
            set actualunit = u
        endif
        call RemoveLocation(temploc01)
        set temploc01 = null
        set u = null
    endloop
    call DestroyGroup(pool)
    call RemoveLocation(temploc)
    set temploc = null
    set distance = 9999999.0
    set pool = null
    return actualunit
endfunction