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

[Solved] Event Response - Unit destroying destructable?

Status
Not open for further replies.
Level 5
Joined
Jun 25, 2005
Messages
92
I have a bridge controlled by a lever. When something kills the lever, the units on the bridge are killed, but I want the one who kills the lever to get the bounty of the units killed.

If the lever was a unit, I could just make the killing unit damage the units on the bridge, but there is no "(killing unit)" for destructables in GUI, is there? Is there in (v)Jass?
 
Level 11
Joined
Nov 23, 2013
Messages
665
Does your lever have to be a destructible? What if it's a unit (passive or hostile neutral)?
 
Level 5
Joined
Jun 25, 2005
Messages
92
It can't be a unit, because I'm using every single player slot, including neutral passive, neutral hostile, neutral extra and neutral victim.

How'd I go about getting the closest unit? Kinda like this?

  • Set TempPoint = (Position of (Dying destructible))
  • Set TempReal = 600.00
  • Set TempRect = (Region centered at TempPoint with size (TempReal, TempReal))
  • Set TempUnitGroup = (Units in TempRect)
  • Set TempUnit = (Random unit from TempUnitGroup)
  • For each (Integer A) from 1 to (Number of units in TempUnitGroup), do (Actions)
    • Loop - Actions
      • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between (Position of (Picked unit)) and TempPoint) Less than (Distance between (Position of TempUnit) and TempPoint)
            • Then - Actions
              • Set TempUnit = (Picked unit)
            • Else - Actions
  • Custom script: call DestroyGroup(udg_TempUnitGroup)
  • Custom script: call RemoveLocation(udg_TempPoint)
  • Custom script: call RemoveRect(udg_TempRect)
 
Last edited:
Level 11
Joined
Nov 23, 2013
Messages
665
The closest unit might not be the best solution. Potentially, there could be a unit other than the killing unit closer to the lever, especially if the killing unit has a ranged attack.
 
Level 13
Joined
May 10, 2009
Messages
868
Something like this:
  • Set Minimum = 5000.00
  • Set ClosestUnit = No unit
  • Set pointA = (Position of (Dying destructible))
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units within 1200.00 of pointA) and do (Actions)
    • Loop - Actions
      • Set pointB = (Position of (Picked unit))
      • Set CurrentDistance = (Distance between pointA and pointB)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentDistance Less than Minimum
        • Then - Actions
          • Set Minimum = CurrentDistance
          • Set ClosestUnit = (Picked unit)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_pointB)
  • Custom script: call RemoveLocation(udg_pointA)
 
Level 11
Joined
Nov 23, 2013
Messages
665
Maybe it's possible to detect the last unit that was issued an order targeting the lever.
I don't know if this would work:
  • Unit Detection
    • Events
      • Unit - A unit is issued an Order
    • Conditions
      • (Issued order) Equals (Order(attack))
      • (Target destructible of issued order) Equals Lever
    • Actions
      • Set Killing_Unit = (Ordered unit)
And then:
  • Lever Dies
    • Events
      • Destructible - Lever dies
    • Conditions
    • Actions
      • Unit - Cause Killing_Unit to damage circular area after 0.00 seconds of radius 500.00 at (Position of Bridge), dealing 2000.00 damage of attack type Chaos and damage type Divine
Edit: nevermind that, it can't work if left like this. The wrong unit can be picked if several units attack the lever, if the last to do it receives another order before killing the lever.
 
Last edited:
Level 13
Joined
May 10, 2009
Messages
868
No, It works with a location (point). Then, it returns a unit group, which is destroyed by set bj_wantDestroyGroup = true
JASS:
function GetUnitsInRangeOfLocMatching takes real radius, location whichLocation, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRangeOfLoc(g, whichLocation, radius, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction
JASS:
function ForGroupBJ takes group whichGroup, code callback returns nothing
    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

The only problem with it is the local group g which is never set to null.
 
Last edited:
Level 5
Joined
Jun 25, 2005
Messages
92
Interesting, didn't know that.
I actually rewrote all my triggers, replacing "unit/destructable/etc. in range Y of point Z" with functions making temporary rects with width/height Y, originating from point Z, and picking unit/destructable/etc. groups from that, because I thought that rects are created from everything that has "in range".
 
Status
Not open for further replies.
Top