• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Trigger] Zombie auto attack targets

Status
Not open for further replies.
Level 6
Joined
Dec 9, 2007
Messages
208
Hey peeps,

just a fast question.
I am making a zombie survival map, and I need help with a trigger, that makes the trigger spawned zombies follow(attack) a random Surviver.

Someone that can make me a good one? :grin:
 
Do you already have the spawn trigger? Anyway, I believe you do, add this after the zombies are spawned.

  • Trigger
    • Events
      • ......
    • Conditions
      • ......
    • Actions
      • ......
      • Custom script: set bj_wantDestroyGroup = true
      • Unit - Order last Created Unit to attack (Random Unit of (Units Matching UNIT_SURVIVER))
Change UNIT_SURVIVER to the condition (unit is a surviver).
 
baassee, Reapers way is also leakless. Look at the ForGroupBJ function (The JASS version of Pick Every Unit In ... And ...)
JASS:
function ForGroupBJ takes group whichGroup, code callback returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    call ForGroup(whichGroup, callback)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
endfunction
You can see that if bj_wantDestroyGroup is set to true before using it, destroys the group. Now Reaper doesnt use ForGroupBJ, but GroupPickRandomUnit, which is this:
JASS:
function GroupPickRandomUnit takes group whichGroup returns unit
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupRandomConsidered = 0
    set bj_groupRandomCurrentPick = null
    call ForGroup(whichGroup, function GroupPickRandomUnitEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
    return bj_groupRandomCurrentPick
endfunction
As you can see, this also uses bj_wantDestroyGroup, and destroys the group afterwards if that is true. Why create 2 global variables and do stuff with it etc. if you can destroy it with only 1 custom script line, why bother with all those variables if it also destroys the leaks?

EDIT: Ok you didnt say it wasnt leakless,, but you are using BJs always, almost Only in GUI,, So avoiding BJs in GUI is useless.
 
Last edited:
You have got a point, half. BJ-functions are slower, BJ-variables are faster than normal variables. And BJ-variables are already made, even if you dont use them.
And now you can say that ForGroupBJ is a BJ-function, but it is the Standard "Pick every unit in ... and do ..." function in GUI, the only way to avoid it is to change your GUI.
 
Yes but some stuff in GUI is avoidable as "wantdestroy group" , FG isn't

Actually it's faster this way. Your way:

1 extra global.
Save group to it.
Does the bj_wantDestroyGroup == true check anyway
Calls the function to destroy it afterwards.

My way:
No global.
Group is only temp.
It is destroyed by the function.
No need for other function afterwards.
 
Last edited:
Status
Not open for further replies.
Back
Top