• 🏆 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!

[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:
 
Level 12
Joined
Jul 27, 2008
Messages
1,181
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).
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
or if you dont want to use BJs

set tempgroup = units of type "Survivors"

set tempgroup2 = random unit of "tempgroup"

pick all units in tempgroup2 and do actions
Loop
unit - order last created to attack picked unit

call DestroyGroup(udg_tempgroup)
call DestroyGroup(udg_tempgroup2)
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
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:
Level 16
Joined
Oct 12, 2008
Messages
1,570
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.
 
Level 12
Joined
Jul 27, 2008
Messages
1,181
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.
Top