• 🏆 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] Unit needs to be near a certain building to use spell

Status
Not open for further replies.

xplicitjohn

X

xplicitjohn

I want to make it that hero needs to be near a building inorder for the mech spell to work. Im using the druid of claw's bear form spell btw.

I tried something like this :

  • Mech
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Mech
    • Actions
      • Set MechLocation = (Position of (Casting unit))
      • Set MechGroup = (Units within 400.00 of MechLocation)
      • Unit Group - Pick every unit in MechGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Mech Upgrade Centre
            • Then - Actions
              • Do nothing
            • Else - Actions
              • Unit - Order (Casting unit) to Stop
      • Custom script: call DestroyGroup(udg_MechGroup)
      • Custom script: call RemoveLocation(udg_MechLocation)
It just dosent seem to work. Any ideas?
Also, when the trigger tells the unit to stop. The transformation appears ( The ability to return back to normal). But the hero has not transformed yet.
 
Level 12
Joined
Aug 12, 2008
Messages
349
Did you set what the hero going to transform? Check "Techtree - Dependacy Equivalents" in your Object Editor. I'm still not sure why this spell bug.

By the way, the trigger can be improve:
[1] You can use this native:
  • Custom script: set bj_wantDestroyGroup = true
instead of storing it into MechGroup then destroy it. The native helps you to automatically clean it up after using it.
[2] Remove "Do nothing". Just leave it blank. It does the same thing too.

I would suggest you to use a dummy spell to replace the spell. In the trigger, if it's true then add the transformation ability to the caster and then remove it.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
this should woprk...but you should clear leaks in group...
  • Bear
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Bear Form
    • Actions
      • Set caster = (Triggering unit)
      • Set loc1 = (Position of caster)
      • Unit Group - Pick every unit in (Units within 400.00 of loc1 matching ((Unit-type of (Matching unit)) Equal to Farm)) and do (Actions)
        • Loop - Actions
          • Set loc2 = (Position of (Picked unit))
          • Set distance = (Distance between loc1 and loc2)
          • Custom script: call RemoveLocation(udg_loc2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • distance Equal to 0.00
        • Then - Actions
          • Unit - Order caster to Stop
        • Else - Actions
          • Game - Display to (All players) the text: do spell
      • Custom script: call RemoveLocation(udg_loc1)
 
Level 11
Joined
Nov 15, 2007
Messages
781
Your trigger would not work because you do a loop for every unit in the group - if any unit in range isn't a mech center - including the caster himself - it orders the caster to stop.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Your trigger would not work because you do a loop for every unit in the group - if any unit in range isn't a mech center - including the caster himself - it orders the caster to stop.

This. Its running twice, so it will stop the caster if more than the building is in range. Use this instead (after cleaning leaks and swapping variables)

  • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Mother Rat
        • Then - Actions
          • Set Temp_Integer = 1
        • Else - Actions
          • Do nothing
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Temp_Integer Equal to 1
    • Then - Actions
      • Do nothing
    • Else - Actions
      • Unit - Order (Casting unit) to Stop
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
To mckill2009: You leaked the group itself :p By the way, why would you set the distance to 0? Isn't that giving it a range is much better to check?

To Illidans911: You should move the If/Then/Else block below "set Temp_Integer = 1". Besides, you should remove the "Do nothing".

Wha?
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
To mckill2009: You leaked the group itself :p By the way, why would you set the distance to 0? Isn't that giving it a range is much better to check?
- I already mention the group leak above...
- Take note that units within range picks every units in range, what if there are 5 units
in range?, so the desired spell will be casted also 5 times, the trigger I wrote enumerates
'outside' the picking of all units in the group, so it will work only once...

I forgot this though;
  • Else - Actions
    • Game - Display to (All players) the text: do spell
    • Set distance = 0
EDIT:
"do nothing" is really bad and MUST not be used at all times...
 

xplicitjohn

X

xplicitjohn

Ok i tried this trigger and it still dosent work. I dont understand illidans trigger too.

  • Mech
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Mech
    • Actions
      • Set MechLocation = (Position of (Casting unit))
      • Unit Group - Pick every unit in (Units within 400.00 of MechLocation matching ((Unit-type of (Matching unit)) Equal to Mech Upgrade Centre)) and do (Actions)
        • Loop - Actions
          • Set MechLocation2 = (Position of (Picked unit))
          • Set MechDistance = (Distance between MechLocation and MechLocation2)
          • Custom script: call RemoveLocation(udg_MechLocation2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MechDistance Greater than or equal to 400.00
        • Then - Actions
          • Unit - Order (Casting unit) to Stop
        • Else - Actions
          • Game - Display to (All players) the text: spell
      • Custom script: call RemoveLocation(udg_MechLocation)
 

xplicitjohn

X

xplicitjohn

[1] Why do you change the (Triggering Unit) to (Casting Unit)? Don't change it. It runs much faster if you use (Triggering Unit).
[2] Why do you change the equation? It should "MechDistance equals to 0.00"

mckill2009 is a great coder. You shouldn't simply change the trigger he gave.

Sorry. Ok, new problem :
Casting Unit would not turn into a Mech if he is near a Mech Upgrade Centre.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
I would do it like this
  • Untitled Trigger 026
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set point = (Position of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units within 400.00 of point matching ((((Matching unit) is alive) Equal to True) and ((Unit-type of (Matching unit)) Equal to Barracks)))) Equal to 0
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: stop ord
          • Unit - Pause (Triggering unit)
          • Unit - Order (Triggering unit) to Stop
          • Unit - Unpause (Triggering unit)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_point)
You can add to the filter that the building must be owned by the player/ally for example.


EDIT: Ok, it was solved.
 

xplicitjohn

X

xplicitjohn

I would do it like this
  • Untitled Trigger 026
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set point = (Position of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units within 400.00 of point matching ((((Matching unit) is alive) Equal to True) and ((Unit-type of (Matching unit)) Equal to Barracks)))) Equal to 0
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: stop ord
          • Unit - Pause (Triggering unit)
          • Unit - Order (Triggering unit) to Stop
          • Unit - Unpause (Triggering unit)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_point)
You can add to the filter that the building must be owned by the player/ally for example.


EDIT: Ok, it was solved.

None of them works yet. LOL

I tried it your way , but the Casting Unit would turn into a mech still.

I Did :

  • Mech Copy
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Mech
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set MechLocation = (Position of (Casting unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units within 400.00 of MechLocation matching ((((Matching unit) is alive) Equal to True) and ((Unit-type of (Matching unit)) Equal to Mech Upgrade Centre)))) Equal to 0
        • Then - Actions
          • Game - Display to (All players) the text: dsada
          • Unit - Pause (Triggering unit)
          • Unit - Order (Triggering unit) to Stop
          • Unit - Unpause (Triggering unit)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_MechLocation)
 
Level 12
Joined
Aug 12, 2008
Messages
349
To xplicitjohn: Weird. It shouldn't have problem now. I tried it and it works properly. You must have miss out something important. Have you set alternate form of the unit? By the way, you should add the below custom script above the unit group.
  • Custom script: set bj_wantDestroyGroup = true
To Maker: Sir, why need to add the Pause and Unpause the unit? Is ordering the unit to stop might interrupts the order? Besides, isn't that using "Unit - A unit Starts the effect of an ability" would be much better?

EDIT: Lol... It really didn't work by using Bear Form.
 

xplicitjohn

X

xplicitjohn

To xplicitjohn: Weird. It shouldn't have problem now. I tried it and it works properly. You must have miss out something important. Have you set alternate form of the unit? By the way, you should add the below custom script above the unit group.
  • Custom script: set bj_wantDestroyGroup = true
To Maker: Sir, why need to add the Pause and Unpause the unit? Is ordering the unit to stop might interrupts the order? Besides, isn't that using "Unit - A unit Starts the effect of an ability" would be much better?


Which trigger did you test? I have set alternate form too.
i prefer bear form sinse it is pernament and metamorphasis is on a timer

edit : nvm just saw ur eddited post. ill try and check everything tomorrow
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
I didn't realize it could be a metamorphosis spell. Is it? Then it should be like this:
  • Untitled Trigger 026
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Issued order) Equal to (Order(metamorphosis))
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set point = (Position of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units within 400.00 of point matching ((((Matching unit) is alive) Equal to True) and ((Unit-type of (Matching unit)) Equal to Barracks)))) Equal to 0
        • Then - Actions
          • Unit - Order (Triggering unit) to Stop
        • Else - Actions
      • Custom script: call RemoveLocation(udg_point)
To Maker: Sir, why need to add the Pause and Unpause the unit? Is ordering the unit to stop might interrupts the order? Besides, isn't that using "Unit - A unit Starts the effect of an ability" would be much better?

I pause/unpause because the unit might not stop otherwise. The stop gets ordered too quickly.

Begins casting is better here as it runs before starts the effect.
 
Level 12
Joined
Aug 12, 2008
Messages
349
Maker said:
I pause/unpause because the unit might not stop otherwise. The stop gets ordered too quickly.

Begins casting is better here as it runs before starts the effect.
Oh I see.. Thanks :)

To xpliciton: If it still don't work. I got another way. Create a dummy spell which based on an Instant ability not the Bear Form. Then, read what in here: Hero Passive Transformation You just need to play around with your trigger if you would like to use this passive transformation.
 

xplicitjohn

X

xplicitjohn

I didn't realize it could be a metamorphosis spell. Is it? Then it should be like this:
  • Untitled Trigger 026
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Issued order) Equal to (Order(metamorphosis))
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set point = (Position of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units within 400.00 of point matching ((((Matching unit) is alive) Equal to True) and ((Unit-type of (Matching unit)) Equal to Barracks)))) Equal to 0
        • Then - Actions
          • Unit - Order (Triggering unit) to Stop
        • Else - Actions
      • Custom script: call RemoveLocation(udg_point)
I pause/unpause because the unit might not stop otherwise. The stop gets ordered too quickly.

Begins casting is better here as it runs before starts the effect.
I'm uing the bear form. ill.try again tomorrow morning. going to sleep

edit : i checked everything and it still dosent work ):
 
Last edited by a moderator:
Status
Not open for further replies.
Top