• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Failed "detect nearest unit" trigger, need halp

Status
Not open for further replies.
Level 2
Joined
Apr 5, 2009
Messages
18
So this is what its supposed to do:
The targeted hero is tied up to the nearest object within 250 range, whether its a tree, a unit, or a building.
If there are no units, trees, or buildings the targeted hero will be ensnared.

Currently the effects are all over the place. From my tests, the code in the destructible and "no units, tree or building" part is sound a.k.a the beginning and end are fine. Just the massive bulk in the middle is riddled with bugs that i cannot seem to see.

I think the bug(s) have/has got to do with detecting whether or not the system has picked up a "nearest unit" and how it stores this info. Anyway, please and thank you.

Warning: Following is a massive wall of code
  • Tie em up
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Tie em up!
    • Actions
      • Unit - Kill TieemupDummy
      • Unit - Kill TieemupDummy2
      • Set TieemupUnitCaster = (Casting unit)
      • Set TieemupTarget = (Target unit of ability being cast)
      • Set TieemupPositionZ = (Position of TieemupTarget)
      • Destructible - Pick every destructible within 250.00 of (Position of TieemupTarget) and do (Actions)
        • Loop - Actions
          • Set TieemupNearestDoodad = (Picked destructible)
          • Set TieemupPositionX = (Position of TieemupNearestDoodad)
      • Destructible - Pick every destructible within 250.00 of (Position of TieemupTarget) and do (Actions)
        • Loop - Actions
          • Set TieemupPositionY = (Position of (Picked destructible))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between TieemupPositionZ and TieemupPositionY) Less than (Distance between TieemupPositionZ and TieemupPositionX)
            • Then - Actions
              • Set TieemupNearestDoodad = (Picked destructible)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_TieemupPositionY)
      • Unit - Create 1 Tie em up! Dummy for (Owner of TieemupUnitCaster) at (Position of TieemupNearestDoodad) facing Default building facing degrees
      • Set TieemupDummy = (Last created unit)
      • Unit - Order TieemupDummy to Human Dragonhawk Rider - Aerial Shackles TieemupTarget
      • Custom script: call RemoveLocation(udg_TieemupPositionX)
      • Custom script: call RemoveLocation(udg_TieemupPositionZ)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TieemupNearestDoodad Equal to No destructible
        • Then - Actions
          • Set TieemupNearestUnit = (Random unit from (Units within 250.00 of (Position of TieemupTarget) matching (((Matching unit) Not equal to TieemupTarget) and (((Matching unit) belongs to an enemy of (Owner of TieemupUnitCaster)) Equal to True))))
          • Set TieemupPositionX = (Position of TieemupNearestUnit)
          • Unit Group - Pick every unit in (Units within 250.00 of (Position of TieemupTarget)) and do (Actions)
            • Loop - Actions
              • Set TieemupPositionY = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between TieemupPositionZ and TieemupPositionY) Less than (Distance between TieemupPositionZ and TieemupPositionX)
                • Then - Actions
                  • Set TieemupNearestUnit = (Picked unit)
                • Else - Actions
              • Custom script: call RemoveLocation(udg_TieemupPositionY)
          • Unit - Create 1 Tie em up! Dummy for (Owner of TieemupUnitCaster) at (Position of TieemupNearestUnit) facing Default building facing degrees
          • Set TieemupDummy = (Last created unit)
          • Unit - Order TieemupDummy to Human Dragonhawk Rider - Aerial Shackles TieemupTarget
          • Unit - Create 1 Tie em up! Dummy for (Owner of TieemupUnitCaster) at (Position of TieemupTarget) facing Default building facing degrees
          • Set TieemupDummy2 = (Last created unit)
          • Unit - Order TieemupDummy2 to Human Dragonhawk Rider - Aerial Shackles TieemupNearestUnit
          • Custom script: call RemoveLocation(udg_TieemupPositionX)
          • Custom script: call RemoveLocation(udg_TieemupPositionZ)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TieemupNearestUnit Equal to No unit
            • Then - Actions
              • Unit - Create 1 Tie em up! Dummy for (Owner of TieemupUnitCaster) at (Position of TieemupTarget) facing Default building facing degrees
              • Unit - Order TieemupDummy to Orc Raider - Ensnare TieemupTarget
              • Set TieemupDummy = (Last created unit)
            • Else - Actions
              • Do nothing
      • Set TieemupNearestDoodad = No destructible
      • Set TieemupNearestUnit = No unit
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Here's the bit about picking the nearest destructible/unit:

  • Tie Emp Up
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Tie Em Up
    • Actions
      • Set Temp_Unit_1 = (Target unit of ability being cast)
      • Set Temp_Loc_1 = (Position of (Target unit of ability being cast))
      • -------- -------------------- --------
      • Set Temp_Unit_2 = No unit
      • Set Temp_Destructible = No destructible
      • -------- -------------------- --------
      • -------- Check if there's a unit closer to the target of the spell than 250 --------
      • -------- Checked unit must not be the targeted unit or the caster --------
      • -------- You could add the possible dummy unit here too --------
      • -------- -------------------- --------
      • Set Temp_Real_1 = 251.00
      • Set Temp_Group = (Units within 250.00 of Temp_Loc_1 matching (1 Equal to 1))
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Loc_2 = (Position of (Picked unit))
          • Set Temp_Real_2 = (Distance between Temp_Loc_1 and Temp_Loc_2)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Real_2 Less than Temp_Real_1
              • Temp_Unit_1 Not equal to (Picked unit)
              • (Picked unit) Not equal to (Triggering unit)
            • Then - Actions
              • Set Temp_Unit_2 = (Picked unit)
              • Set Temp_Real_1 = Temp_Real_2
            • Else - Actions
          • Custom script: call RemoveLocation(udg_Temp_Loc_2)
      • -------- -------------------- --------
      • -------- The position of the closest unit is stored to Temp_Loc_3 --------
      • -------- -------------------- --------
      • Set Temp_Loc_3 = (Position of Temp_Unit_2)
      • -------- -------------------- --------
      • Custom script: call DestroyGroup(udg_Temp_Group)
      • -------- -------------------- --------
      • -------- Checks if there's destcuctibles within 250 range of the targeted unit --------
      • -------- -------------------- --------
      • Set Temp_Real_1 = 251.00
      • Destructible - Pick every destructible within 250.00 of Temp_Loc_1 and do (Actions)
        • Loop - Actions
          • Set Temp_Loc_2 = (Position of (Picked destructible))
          • Set Temp_Real_2 = (Distance between Temp_Loc_1 and Temp_Loc_2)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Real_2 Less than Temp_Real_1
            • Then - Actions
              • Set Temp_Destructible = (Picked destructible)
              • Set Temp_Real_1 = Temp_Real_2
            • Else - Actions
      • -------- -------------------- --------
      • -------- The position of nearest destructible is saved to Temp_Loc_4 --------
      • -------- -------------------- --------
      • Set Temp_Loc_4 = (Position of Temp_Destructible)
      • -------- -------------------- --------
      • -------- Checks if there was a unit or destructible inside the range --------
      • -------- If there was, then check which one was closer, the closest destructible or the closest unit --------
      • -------- -------------------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Unit_2 Equal to No unit
          • Temp_Destructible Equal to No destructible
        • Then - Actions
          • Special Effect - Create a special effect attached to the chest of Temp_Unit_1 using Abilities\Spells\Undead\Web\WebTarget.mdl
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Temp_Loc_1 and Temp_Loc_3) Less than (Distance between Temp_Loc_1 and Temp_Loc_4)
            • Then - Actions
              • Set Temp_Loc_2 = Temp_Loc_3
            • Else - Actions
              • Set Temp_Loc_2 = Temp_Loc_4
      • Floating Text - Create floating text that reads moi at Temp_Loc_2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
      • Custom script: call RemoveLocation(udg_Temp_Loc_3)
      • Custom script: call RemoveLocation(udg_Temp_Loc_4)
      • -------- -------------------- --------
      • Custom script: call RemoveLocation(udg_Temp_Loc_1)
      • Custom script: call RemoveLocation(udg_Temp_Loc_2)
The floating text is there so you can see that it works.

Perhaps you can work on from there.
 
Status
Not open for further replies.
Top