• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Too much trigger!

Status
Not open for further replies.
Level 5
Joined
Sep 19, 2006
Messages
152
This trigger seems needlessly complex. Are there any ways to simple it but keep the functionality?


JASS:
function HubExit_Filter01 takes nothing returns boolean
    local unit U             = GetFilterUnit ()
    local boolean B
//
    if GetUnitTypeId (U) == 'hpea' then
        set B = false
    elseif IsUnitType (U, UNIT_TYPE_STRUCTURE) == true then
        set B = false
    else
        set B = GetUnitState (U, UNIT_STATE_LIFE) > 0.00
    endif
    set U = null
    return B
endfunction

function HubExit_Action01 takes nothing returns nothing
    local unit u             = GetLeavingUnit ()
    local integer q          = GetPlayerId (GetOwningPlayer (u))
    local real uX            = GetUnitX (u)
    local real uY            = GetUnitY (u)
    local rect r             = gg_rct_NeutralRegion          
    local boolean b          = true
    local group G
    local group g
    local unit f
//
    if GetOwningPlayer (u) == Player (15) then
        set b = false
    elseif GetUnitTypeId (u) == 'hphx' then
        set b = false
    elseif GetRectMinX (r) < uX and GetRectMaxX (r) > uX and GetRectMinY (r) < uY and GetRectMaxY (r) > uY then
        set b = false
    endif
    if b == true then
        call SetUnitInvulnerable (u, false)
    endif
    if IsUnitType (u, UNIT_TYPE_HERO) == true then
        set G = CreateGroup ()
        set g = CreateGroup ()
        call GroupEnumUnitsOfPlayer (G, Player (q), Filter (function HubExit_Filter01))
        loop
            set f = FirstOfGroup (G)
            exitwhen f == null
            call GroupRemoveUnit (G, f)
            call GroupAddUnit (g, f)
            call SetUnitPosition (f, uX, uY)
        endloop
        call DestroyGroup (G)
        set G = null
        call TriggerSleepAction (1.00)
        loop
            set f = FirstOfGroup (g)
            exitwhen f == null
            call GroupRemoveUnit (g, f)
            call IssueTargetOrder (f, "smart", u)
        endloop
        call DestroyGroup (g)
        set g = null
        set f = null
    endif
    set u = null
endfunction

function InitTrig_HubExit takes nothing returns nothing
    set gg_trg_HubExit = CreateTrigger ()
    call TriggerRegisterLeaveRectSimple (gg_trg_HubExit, gg_rct_Hub)
    call TriggerAddAction (gg_trg_HubExit, function HubExit_Action01)
endfunction
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Didn't get why are you using 2 groups ? :huh:

JASS:
function HubExit_Filter01 takes nothing returns boolean
    local unit U             = GetFilterUnit ()
    local boolean B
//
    if GetUnitTypeId (U) != 'hpea' and IsUnitType (U, UNIT_TYPE_STRUCTURE) != true then
              set B = GetUnitState (U, UNIT_STATE_LIFE) > 0.00
    endif
    set U = null
    return B
endfunction
function HubExit_Action01 takes nothing returns nothing
    local unit u             = GetLeavingUnit ()
    local integer q          = GetPlayerId (GetOwningPlayer (u))
    local real uX            = GetUnitX (u)
    local real uY            = GetUnitY (u)
    local rect r             = gg_rct_NeutralRegion
    local group G
    local group g
    local unit f
//
    if GetOwningPlayer (u) != Player (15) and elseif GetUnitTypeId (u) != 'hphx' and not(GetRectMinX (r) < uX and GetRectMaxX (r) > uX and GetRectMinY (r) < uY and GetRectMaxY (r) > uY) then
           call SetUnitInvulnerable (u, false)
    endif
    if IsUnitType (u, UNIT_TYPE_HERO) == true then
        set G = CreateGroup ()
        set g = CreateGroup ()
        call GroupEnumUnitsOfPlayer (G, Player (q), Filter (function HubExit_Filter01))
        loop
            set f = FirstOfGroup (G)
            exitwhen f == null
            call GroupRemoveUnit (G, f)
            call GroupAddUnit (g, f)
            call SetUnitPosition (f, uX, uY)
        endloop
        call DestroyGroup (G)
        set G = null
        call TriggerSleepAction (1.00)
        loop
            set f = FirstOfGroup (g)
            exitwhen f == null
            call GroupRemoveUnit (g, f)
            call IssueTargetOrder (f, "smart", u)
        endloop
        call DestroyGroup (g)
        set g = null
        set f = null
    endif
    set u = null
endfunction
function InitTrig_HubExit takes nothing returns nothing
    set gg_trg_HubExit = CreateTrigger ()
    call TriggerRegisterLeaveRectSimple (gg_trg_HubExit, gg_rct_Hub)
    call TriggerAddAction (gg_trg_HubExit, function HubExit_Action01)
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
GhostWolf, your syntax is horribly wrong in one spot. I don't think you understand elseif.

[jass=Try this]function HubExit_Filter01 takes nothing returns boolean
return not(GetUnitTypeId(GetFilterUnit())=='hpea' or IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE)) and GetWidgetLife(GetFilterUnit()) > 0
endfunction

function HubExit_Child takes nothing returns nothing
local unit f = bj_ghoul[100]
local unit u = bj_ghoul[101]
call SetUnitPosition(f,GetUnitX(u),GetUnitY(u))
call PolledWait(1)
call IssueTargetOrder(f,"smart",u)
set f = null
set u = null
endfunction

function HubExit_Action01 takes nothing returns nothing
local unit u = GetLeavingUnit()
local real uX = GetUnitX(u)
local real uY = GetUnitY(u)
local group g
local unit f
//
if not(GetOwningPlayer(u)==Player(15) or GetUnitTypeId(u)=='hphx' or(GetRectMinX(gg_rct_NeutralRegion) < uX and GetRectMaxX(gg_rct_NeutralRegion) > uX and GetRectMinY(gg_rct_NeutralRegion) < uY and GetRectMaxY(gg_rct_NeutralRegion) > uY)) then
call SetUnitInvulnerable(u,false)
endif
if IsUnitType(u,UNIT_TYPE_HERO) then
set g = CreateGroup()
call GroupEnumUnitsOfPlayer(g,GetOwningPlayer(u),Filter(function HubExit_Filter01))
set bj_ghoul[101] = u
loop
set f = FirstOfGroup(g)
exitwhen f == null
call GroupRemoveUnit(g,f)
set bj_ghoul[100] = f
call ExecuteFunc("HubExit_Child")
endloop
call DestroyGroup(g)
set g = null
endif
set u = null
endfunction

function InitTrig_HubExit takes nothing returns nothing
set gg_trg_HubExit = CreateTrigger()
call TriggerRegisterLeaveRectSimple(gg_trg_HubExit,gg_rct_Hub)
call TriggerAddAction(gg_trg_HubExit,function HubExit_Action01)
endfunction[/code]
 
Last edited:
Level 5
Joined
Sep 19, 2006
Messages
152
I have a few questions:

set f = FirstOfGroup(g)
if group g is empty, does this command provide f the same nullifying effect as set f = null?

I'm a little unclear about the purpose of the call PolledWait(1) command in the HubExit_Action01 function. Related to that, isn't TriggerSleepAction the prefered method of delay?

The bj_ghoul[101] value, I'm guessing, is used to store values across different functions of the same trigger. Shouldn't there then be a similar use for the GetUnitX and GetUnitY commands (like bj_realvalueX, for example), so these two values won't be calculated multiple times, once for each unit in group g?

Also related to the bj_ghoul[100] and bj_ghoul[101] values, what purpose is there of making these 2 values an array, and not single units like bj_ghoula and bj_ghoulb?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
  1. Yes, or the loop wouldn't work anyways! :p
  2. PolledWait is better; it accounts for game speed, pauses, and is more accurate.
  3. bj_ghoul is just a unit array used by AI scripts that is handy for passing units globally. There are plenty of bj globals of type real. Just pop open JassCraft, check to search BJ globals, search bj_, and look around.
  4. An array can store up to 8192 things at once, and access them dynamically (via variable indexes) in scripts.
 
Level 11
Joined
Feb 18, 2004
Messages
394
I have a few questions:

set f = FirstOfGroup(g)
if group g is empty, does this command provide f the same nullifying effect as set f = null?

JASS:
set f = FirstOfGroup(g)
exitwhen f == null
If it only exits the loop when FoG() returns null.... then of course it gets nulled. Its still good practice to null all variables before a return anyway.


I'm a little unclear about the purpose of the call PolledWait(1) command in the HubExit_Action01 function. Related to that, isn't TriggerSleepAction the prefered method of delay?
Using TriggerSleepAction() as a method of delay is poor practice and bound to cause issue somewhere. TriggerSleepAction() would be more appropriately named if it where named ThreadSleep().

PolledWait() uses TriggerSleepAction() for time delay, and is thus still not a good solution. The "prefferd" method of delay is using timers.

The bj_ghoul[101] value, I'm guessing, is used to store values across different functions of the same trigger. Shouldn't there then be a similar use for the GetUnitX and GetUnitY commands (like bj_realvalueX, for example), so these two values won't be calculated multiple times, once for each unit in group g?

Also related to the bj_ghoul[100] and bj_ghoul[101] values, what purpose is there of making these 2 values an array, and not single units like bj_ghoula and bj_ghoulb?

errr....

bj_ghoul[] is an array defined in blizzard.j within its globals block. each script file may have a single globals block at the top of the script, used to define global variables. The reason to use this variable over creating your own variables is that you must use the variable editor to define variables, which can be a pain in the ass. Thus, using a pre-defined and not used variable allows code to be easily CnP'd.

However, the JASS NewGen pack (which includes the vJASS compiler JASS Helper) merges all globals blocks on save, meaning you can declare new global variables anywhere in a maps script, and in code, instead of using the variable editor. (vJASS Manual can be found here for more info: http://wc3campaigns.net/vexorian/jasshelpermanual.html) If you want to get in to JASS coding, i suggest you look more in to these tools.

Edit: Damn you poot! :p I will have vengeance!
 
Level 5
Joined
Sep 19, 2006
Messages
152
That was quick!

Wow, you guys replied quick! Like 10 minutes! Anyway, assuming each player has only one hero, and each hero is assigned udg_PlayerHero [q] (q being the player number), is this trigger any better?

JASS:
function HubExit_Filter01 takes nothing returns boolean
    local unit U             = GetFilterUnit ()
    local boolean B          = GetUnitTypeId (U) != 'hpea' and IsUnitType (U, UNIT_TYPE_STRUCTURE) == false and GetUnitState (U, UNIT_STATE_LIFE) > 0.00
    set U = null
    return B
endfunction

function HubExit_Action01 takes nothing returns nothing
    local unit u             = GetLeavingUnit ()
    local integer q          = GetPlayerId (GetOwningPlayer (u))
    local real uX            = GetUnitX (u)
    local real uY            = GetUnitY (u)
    local rect r             = gg_rct_NeutralRegion
    local group g
    local unit f
//
    if GetOwningPlayer (u) != Player (15) and GetUnitTypeId (u) != 'hphx' then
        if (GetRectMinX (r) < uX and GetRectMaxX (r) > uX and GetRectMinY (r) < uY and GetRectMaxY (r) > uY) == false then
            call SetUnitInvulnerable (u, false)
        endif
    endif
    if IsUnitType (u, UNIT_TYPE_HERO) then
        set g = CreateGroup ()
        call GroupEnumUnitsOfPlayer (g, Player (q), Filter (function HubExit_Filter01))
        loop
            set f = FirstOfGroup (g)
            exitwhen f == null
            call GroupRemoveUnit (g, f)
            call SetUnitPosition (f, uX, uY)
        endloop
        call DestroyGroup (g)
        set g = null
    else
        call PolledWait (1.00)
        call IssueTargetOrder (u, "smart", udg_PlayerHero [q])
    endif
    set u = null
endfunction

function InitTrig_HubExit takes nothing returns nothing
    set gg_trg_HubExit = CreateTrigger ()
    call TriggerRegisterLeaveRectSimple (gg_trg_HubExit, gg_rct_Hub)
    call TriggerAddAction (gg_trg_HubExit, function HubExit_Action01)
endfunction
 
Level 5
Joined
Sep 19, 2006
Messages
152
No, u is the leaving unit. If the leaving unit is not a Hero (udg_PlayerHero [q]), then the leaving unit (u) is ordered to follow the Hero (udg_PlayerHero [q]).
 
Status
Not open for further replies.
Top