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

[Solved] Check If Unit Is In Combat / Use Both Attacks

Status
Not open for further replies.
Level 2
Joined
May 20, 2015
Messages
7
I'm trying to recreate the functionality of the sentry from TF2, and upgrading is fine and dandy, but getting the level 3 to use its bullets and rockets is apparently impossible without some trigger/scripting. Someone suggested creating a dummy unit that will spawn on the building and attack with rockets when the sentry is in combat, and restrict the sentry to just its bullets. I've followed some basic tutorials with triggers, but I'm not completely used to it yet, so please forgive me for any naivety I have on the subject.

So if I was going to break down what I needed
- Check if building is in combat
- Spawn dummy unit to act as secondary attack, which I think I can do with
Code:
Unit - Create 1 Sentry (Level 3) |cffffff00[Dummy]|r for (Matching player) at (Position of (Triggering unit)) facing Default building facing degrees
- Despawn dummy unit when outside of combat

Thanks for any help anyone can provide.

Edit: Solved by Uncle
 
Last edited:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Why would you need a combat check?

I mean, assuming the upgrade is permanent why would you need to spawn/despawn the unit depending on combat state?
Wouldn't you just attach it and let it do its thing by default, assuming the attack range is set correctly.

So to me, the request should be:
  • When turret (level 3) enters the map, spawn an invisible unit on top of the turret which will do a secondary attack which operates independently from the standard attack
  • despawn the invisible unit when the turret dies
The downside is that the two units can attack separate targets which might look weight if the turret is pointing to the right but the invisible is shooting something in the opposite direction.

So optionally, the two units should also target the same enemy.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
I created what Chaosy suggested using a Unit Indexer and a few triggers:
  • Sentry Is Created
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Sentry Lvl 3
    • Actions
      • Set VariableSet Sentry_Point = (Position of (Triggering unit))
      • Unit - Create 1 Sentry (Dummy) for (Owner of (Triggering unit)) at Sentry_Point facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_Sentry_Point)
      • Set VariableSet CV = (Custom value of (Triggering unit))
      • Set VariableSet Sentry_Dummy[CV] = (Last created unit)
^If you literally upgrade your Sentries then you would want to change the Event to this:
  • Unit - A unit Finishes an upgrade
  • Sentry Is Destroyed
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Sentry Lvl 3
    • Actions
      • Set VariableSet CV = (Custom value of (Triggering unit))
      • Unit - Remove Sentry_Dummy[CV] from the game
      • Set VariableSet Sentry_Target[CV] = No unit
      • Set VariableSet Sentry_Dummy[CV] = No unit
  • Sentry Attacks
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Attacking unit)) Equal to Sentry Lvl 3
        • Then - Actions
          • Set VariableSet CV = (Custom value of (Attacking unit))
          • Unit - Order Sentry_Dummy[CV] to Attack (Attacked unit)
          • Set VariableSet CV = (Custom value of Sentry_Dummy[CV])
          • Set VariableSet Sentry_Target[CV] = (Attacked unit)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Attacking unit)) Equal to Sentry (Dummy)
            • Then - Actions
              • Set VariableSet CV = (Custom value of (Attacking unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Attacked unit) Not equal to Sentry_Target[CV]
                • Then - Actions
                  • Unit - Order (Attacking unit) to Attack Sentry_Target[CV]
                • Else - Actions
            • Else - Actions
The Unit Indexer is a single trigger. All you need to do is copy and paste it into your map and it'll automatically do it's thing.

A quick summary on how a Unit Indexing systems work:
The system assigns each unit a unique Custom Value upon creation, which is just an Integer value that essentially numbers the unit. So in my example map, all of those Peasants have their own Custom Values and the Sentry + Sentry (Dummy) have their own Custom Values. No two units will ever share the same Custom Value.

You can then use this Custom Value as the Index in your variable Arrays ( inside the brackets --> [] ) to store information directly to any unit. This is useful for making MUI effects (Multi-Unit-Instance able), which means the effects will work for more than 1 unit at a time. In other words, you can have as many Sentries as you want on the map and they will all work properly.

You'll see I use the Variable CV as a shortcut to keep track of a unit's custom value temporarily. This is NOT needed, it just makes your life easier and is slightly more efficient in some cases. It's rather annoying having to do "Sentry_Target[custom value of some unit]" over and over again instead of "Sentry_Target[CV]".
 

Attachments

  • Sentry.w3m
    23.6 KB · Views: 21
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Oh my goodness! Thank you so much for that! It works exactly like I need it too! I'll study unit indexing and see what else I can do with it.
No problem, think of Unit Indexing as a more limited version of a Hashtable, but with a lot more convenience.

It's useful for creating things like custom stats, mimicking the behavior of things like Strength, Agility, Intelligence, etc...

Say for example you wanted a 4th attribute for your Heroes, let's go with Charisma. All you'd have to do is create a Real variable with an Array and name it Charisma. Then do something like this:

  • Events:
  • A unit gains a level
  • Actions:
  • Set Variable Charisma[custom value of triggering unit] = Charisma[custom value of triggering unit] + 2.50
Your Heroes now gain 2.50 Charisma per level. You can then reference this value for any Hero, all you have to do is plug the unit's custom value into the Index [].

Then you could define a hero's Charisma starting value like so:
  • Events:
  • A unit enters map
  • Conditions:
  • Unit-type of triggering unit Equal to Paladin
  • Actions:
  • Set Variable Charisma[custom value of triggering unit] = 15.00
 
Status
Not open for further replies.
Top