• 🏆 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 can't seem to differ friend from foe - help

Status
Not open for further replies.
Level 12
Joined
May 9, 2009
Messages
735
I am making autocast chain-lightning spell that should only be autocasted by the unit when there are at least 3 enemies nearby. Well 3 part works fine but the trigger also registers all of the nearby allies of the unit even though I tried putting a condition to limit it only to only enemies:

  • Sage Chain Lightning
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Sage
    • Actions
      • Set AAAPositionSageLightning = (Position of (Attacking unit))
      • Set AAAGroupSageLightning = (Units within 800.00 of AAAPositionSageLightning)
      • Unit Group - Pick every unit in AAAGroupSageLightning and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in AAAGroupSageLightning) Greater than or equal to 3
              • ((Picked unit) belongs to an enemy of (Owner of (Attacking unit))) Equal to True
            • Then - Actions
              • Unit - Order (Attacking unit) to Orc Far Seer - Chain Lightning (Attacked unit)
            • Else - Actions
              • Do nothing
      • Custom script: call RemoveLocation(udg_AAAPositionSageLightning)
      • Custom script: call DestroyGroup (udg_AAAGroupSageLightning)
Can somebody show what I did wrong or how to make it so the spell will go off only when 3 or more enemies are within range?
 
Not sure what the problem is, but your trigger doesn't really do what you think it does. Right now, you are looping through every unit in the group and repeatedly counting the number of units in it, while also ordering the attacking unit to cast chain lighting once for every unit in the group that matches the condition. You should remove the "pick every units in.." action alltogether, and just add the if-check immediately. Also, the "do nothing" action literally does nothing (it calls an empty funciton), so there is no point in using it.
 
Level 25
Joined
May 11, 2007
Messages
4,651
This one is based of what Fingolfin says.
Confirmed to work when +3 units are attacked by the far seer.

  • Chain Lighting Spam
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Far Seer
    • Actions
      • Set tempPoint1 = (Position of (Attacked unit))
      • Set tempGroup1 = (Units within 800.00 of tempPoint1 matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is A structure) Equal to False) and (((Owner of (Matching unit)) is an enemy of (Owner of (Attacking unit))) Equal to True))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in tempGroup1) Greater than or equal to 3
        • Then - Actions
          • Unit - Order (Attacking unit) to Orc Far Seer - Chain Lightning (Attacked unit)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_tempPoint1)
      • Custom script: call DestroyGroup (udg_tempGroup1)
 

Attachments

  • DzChainLighting.w3x
    18.9 KB · Views: 34
Level 12
Joined
May 9, 2009
Messages
735
I am using the Do Nothing Action just for aesthetic organisational purposes. I will test this now just wanted to ask if Matching unit is alive is necessary I mean a dead unit can't be attacked in the first place, can it? I will also remove the matching unit is a structure since my chain lightning spell is supposed to work against buildings too >.<

Edit: Tested and works good, now I see why the alive condition is needed, otherwise the nearby corpses are seen as enemies too and 1 unit can get chain lightningd when he is next to 2 dead buddies.
 
Level 11
Joined
Dec 19, 2012
Messages
411
'do nothing' doesn't slow down or having side-effect, as it just call an empty function. Removing it just make sure your map having lower length/lines of map scripts (also there is no point for putting a useless function into your trigger)
 
Status
Not open for further replies.
Top