• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Make unit unattackable by ground

Status
Not open for further replies.
Level 6
Joined
Sep 13, 2008
Messages
261
I have a regular ground unit and I want to make him temporarily unattackable by ground units. If there is any way to do this with 1-2 triggers max lmk.
 
  • Ground
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacking unit) is A ground unit) Equal to True
    • Actions
      • Unit - Add Evasion (neutral Hostile 100%) to (Triggering unit)
  • Flying
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacking unit) is A flying unit) Equal to True
    • Actions
      • Unit - Remove Evasion (neutral Hostile 100%) from (Triggering unit)
When the spell ends, remove the Evasion again.

It's not very accurate if many units are attacking it, but maybe from this idea you can figure out better how to do it...
 
Level 6
Joined
Sep 13, 2008
Messages
261
Thx but no cigar doesn't fit my current situation. Unit must be unattackable by ground units. I guess there isn't a way. Thx again +Rep
 
Level 4
Joined
Mar 14, 2009
Messages
98
The answer to your question depends on what you mean by "unattackable". Would that mean that units trying to attack it have to stop? What about splash damage from ground units? What about spells?

The solution to the first one is the same thing HappyCockroach posted. The second requires some knowledge of JASS, at least if you want it to be MUI. The 3rd is impossible without making it spell immune as well, at least if we're talking about immunity to the buffs/debuffs. Damage prevention can be done with JASS.

Edit: I don't think it's feasible to prevent damage in GUI, unless you want to put an insane amount of work into it. It's much better to learn JASS than even attempt it, I suppose.
 
Last edited:
Level 4
Joined
Mar 14, 2009
Messages
98
I'll show you an example of a damage prevention function, but it's in JASS. I'm not entirely sure it will work on AoE attacks either, but you can use arrays and Vexorian's TimerUtils to be sure it does.

JASS:
globals
    unit PreventDamageTarget
    real PreventDamageAmount
endglobals

function PreventDamage2 takes nothing returns nothing
    call SetUnitState(PreventDamageTarget, UNIT_STATE_LIFE, GetUnitState(PreventDamageTarget, UNIT_STATE_LIFE)+PreventDamageAmount)
    call DestroyTimer(GetExpiredTimer())
endfunction

function PreventDamage takes unit whichUnit, real amountDamage returns nothing
    local real CurrentLife = GetUnitState(whichUnit, UNIT_STATE_LIFE)
    local real MaxLife = GetUnitState(whichUnit, UNIT_STATE_MAX_LIFE)
    if CurrentLife > 0.405 then
        if amountDamage > MaxLife-CurrentLife then
            if amountDamage > CurrentLife then
                call SetUnitState(whichUnit, UNIT_STATE_LIFE, MaxLife)
                set PreventDamageAmount = amountDamage+CurrentLife-MaxLife
            else
                set PreventDamageAmount = amountDamage
            endif
            set PreventDamageTarget = whichUnit
            call TimerStart(CreateTimer(), 0.00, false, function PreventDamage2)
        else
            call SetUnitState(whichUnit, UNIT_STATE_LIFE, CurrentLife+amountDamage)
        endif
    endif
endfunction
This will only work if the damage is less than the unit's max hp. You need the 0.00 timer so that the heal would happen right after the damage takes place. EVENT_UNIT_DAMAGED happens right before the unit is damaged, which is why you can prevent damage with it.
 
Level 6
Joined
Sep 13, 2008
Messages
261
Again none of this helped. I want the unit unattackable by ground. I don't want an attack to initiate and then it get stopped by a trigger. I want it to stop before it starts.

Kevv2. How do you make a unit flying temporarily. I gave unit crow form set flight height to 500 the unit flys but ground units still attack it so its pseudo flying?

My definition of unattackable in this case is- I want ground units to never be able to target the unit ai units or players.

A hint don't post an a unit is attacked function.
  • Unit - A unit Is attacked
=attacked
 
Level 4
Joined
Mar 14, 2009
Messages
98
Two options:
First is make two triggers.
One with unit is attacked, action should be order the attacking unit to stop.
The second with unit is issued an order targeting a unit. Condition should be issued order is "attack" or "smart". Action should be issue order to ordered unit to stop.

The drawback with this is that if you attack-move a unit and it comes across the unattackable unit, the moving unit will just stand there. Good thing about this is that you get to keep the classifications for other stuff.

Second option is to go with the unit classifications, though I would suggest make it suicidal instead of flying. Make every ground unit able to attack only non-suicidal. There's a Unit - Add Classification action somewhere in the GUI menu, use that to add the proper classification. Then change the error that comes out if you want. It's under Advanced->Game Interface.

The drawbacks with this method are: You have to be sure that every ground unit cannot attack suicidal. You have to have no suicidal units in game. You could always go with non-ancients if you have sappers in your game or whatever. Finally, you can't use the unit classification suicidal for other purposes you might want.
 
Level 6
Joined
Sep 13, 2008
Messages
261
Two options:
The second with unit is issued an order targeting a unit. Condition should be issued order is "attack" or "smart". Action should be issue order to ordered unit to stop.

My definition of unattackable in this case is- I want ground units to never be able to target the unit ai units or players.

read you clearly have the word target used in there
 
Level 6
Joined
Sep 13, 2008
Messages
261
That was referring to the second trigger you had to create if you chose the first option. Sheesh.

Edit: Wait...untargettable as in locust-like or more like trying to attack a bat rider with a footman untargettable?

Untargetable as in both. You can't target it if your a ground unit. Locust won't work thought because it works on air units too.

I really don't believe there is a solution here, I'm just asking because I could be wrong and it couldn't hurt to ask.
 
Level 4
Joined
Mar 14, 2009
Messages
98
There is no way to make a unit have locust on ground units and lose it for air units.

What you want implies that if a player is selects ground units, he isn't allowed to click on the unattackable unit. Yet, when he's selects air units, he's allowed to.
 
Level 4
Joined
Mar 14, 2009
Messages
98
Here's a solution if you want.
1. Create a dummy unit that looks exactly like the triggering unit. Add locust to it, and add a bunch of dummy abilities for visual effect. Set it's damage to 1. Range should be the same as the original unit. Add a "Claws of Attack"-like ability that adds -1 damage. Have it's acquisition range be 0.
2. Remove the original unit.
3. Create another unit with no model that has the original unit's life. Everything should be the same.
4. Create a bunch of triggers that would make the dummy visual unit copy everything that the no-model unit does, except changing the abilities to the visual-dummy abilities.
5. Make the no-model unit unattackable by all ground units. That means make all ground units unable to attack suicidal, and add the suicidal classification to the no-model unit.
6. Wait the duration out.
7. Remove the locust unit and the no-model unit. In their place, put the a copy of the original unit with the current HP of the no-model unit.

This makes the unit unselectable and untargettable by all players, unless it's a hero. It's invulnerable to attacks by ground units. Air units can attack it by going close enough to acquire it. It cannot be focus fired by players as it's not possible to manually target it.

I did not post an irrelevant comment. I was clarifying what you wanted.
 
Level 6
Joined
Sep 13, 2008
Messages
261
I have a regular ground unit and I want to make him temporarily unattackable by ground units. If there is any way to do this with 1-2 triggers max lmk.


Your solution removes the unit. Making it permanently unattackable. Again irrelevant post reported for spam.
 
Level 4
Joined
Mar 14, 2009
Messages
98
Fine, good luck with your whatever. I'm just trying to help and you're here being all holier-than-thou.

Edit: Nevermind, all this time I thought he was seriously asking a question. I feel dumb; I've been feeding a troll.
 
Again none of this helped. I want the unit unattackable by ground. I don't want an attack to initiate and then it get stopped by a trigger. I want it to stop before it starts.

Kevv2. How do you make a unit flying temporarily. I gave unit crow form set flight height to 500 the unit flys but ground units still attack it so its pseudo flying?

My definition of unattackable in this case is- I want ground units to never be able to target the unit ai units or players.

A hint don't post an a unit is attacked function.
  • Unit - A unit Is attacked
=attacked

Did you even try my solution? It works.
The "A unit is attacked event" checks before the attack happen. So the unit won't be attackable by ground units.
It may not sound a great solution, but it works perfectly.

You won't get anywhere mistreating people that are trying to help you.
 
Level 6
Joined
Sep 13, 2008
Messages
261
Did you even try my solution? It works.
The "A unit is attacked event" checks before the attack happen. So the unit won't be attackable by ground units.
It may not sound a great solution, but it works perfectly.

You won't get anywhere mistreating people that are trying to help you.

in your first solution the unit was being attacked he was just being missed.
I said unattackable.

your second solution didn't work for me and I stated why
Howl2000 said:
My definition of unattackable in this case is- I want ground units to never be able to target the unit ai units or players.

I don't think I mistreated him he doubled the size of my thread and didn't help at all.
 
Last edited:
Level 4
Joined
Mar 14, 2009
Messages
98
HappyCockroach, there's really no point in trying to help him. What he wants is... actually I have no idea what he wants exactly. Something about a unit having locust against a player when the player selects a ground unit, and losing locust when the player selects an air unit. We all know that locust can't be removed... right? Right.
 
in your first solution the unit was being attacked he was just being missed.
I said unattackable.

your second solution didn't work for me and I stated why


I don't think I mistreated him he doubled the size of my thread and didn't help at all.
Using my suggestion the unit WILL be unnattackable, as you said, by any ground unit, since whenever it starts an attack it is ordered to stop the attack.
But if you want the unit to be INVULNERABLE to any ground unit, you should base yourself of Divine Armor and add to every flying unit on the map a default active autocasting skill that can target Invulnerable units. (this is quite risky, since it will attack invulnerable things as well)
 
Level 6
Joined
Sep 13, 2008
Messages
261
Using my suggestion the unit WILL be unnattackable, as you said, by any ground unit, since whenever it starts an attack it is ordered to stop the attack.
But if you want the unit to be INVULNERABLE to any ground unit, you should base yourself of Divine Armor and add to every flying unit on the map a default active autocasting skill that can target Invulnerable units. (this is quite risky, since it will attack invulnerable things as well)

This overly complicated and makes invulnerable unusable by other units. Thanks for the idea though.
 
Level 13
Joined
May 11, 2008
Messages
1,198
i guess you could give the unit the invulnerable ability and then make all air units able to attack invulnerable.... alternatively it seems like if you can change the targeted as datafield for the unit with a function that would be the simplest and easiest way. you just make it so whatever field that is, be it ward or ancient or tauren or whatever....that air can attack it and ground can't. i can check the function list for something like that but i think it doesn't exist...yeah i'm not seeing anything like that. maybe you have to do some kind of morphing and make the morphed unit have that targeted as field which ground units won't be able to attack.

i use this method but i haven't tried doing the morphing thing yet...it's not something that's practical for a tag map like what i made but in my new map i might make some hero be able to morph...i'm not sure yet.

i know it's not a perfect solution because you have to take something that you wouldn't use much anyway and make it also be for that single unit.

for example...in my map you can't target critters with your heroes... so my message will pop up if you try to target them you cannot target critters or air. that's because the critters are targetted as air units. i guess you could do the same thing but take it a step further by having your unit morph into an unit which is a replica of your unmorphed unit only difference is one is targeted as ground and another is targeted as air.

i'm not sure what triggers the unit's invulnerable to ground that you are asking for, but if i had to guess, it's a simple ability right? so make the ability like storm crow form or bear form or metamorphosis or something like that and i think it should work. like i said i haven't played around with morphing so i'm not sure how it will go, but you should be able to figure it out by looking at some tutorials about morphing or something like that.

i think there will be a few different ways you can handle the morphing...you could make it auto temporary by making it have a duration, or take the duration out and it's permanent, if you need to make it temporary you can trigger the unit to use the ability which will make it morph again. although if you do that you'd want the spell to cost nothing to cast... that's all i can think of at the moment to help you figure it out.

cant you change, the unit that you want unattackable by ground, 'targeted as' type to air?

yeah i don't think there's actually a function for that, that's my suggestion too. i think the best way to work around it is to morph the unit into an alternate version like i mentioned above...

anyway it sounds like he doesn't even want archers to be able to attack the unit, if that's the case he would most likely want to select something else for this special unit's targeted as field other than air, that or make all the air units targeted by something else and change the archers' targets allowed fields, but that seems like too much work.

there should be plenty of fields to choose from, i would recommend finding one that you would rarely or better still, never use for the field...like if you have no wards in your map you can use the wards field. and again, you could make the wards that you would have in your map be targeted as something else. i'm not saying i'm recommending those, it's just an example.

this thread talks a bit about this sort of thing:
www.hiveworkshop.com/forums/triggers-and-scripts-269/trigger-item-ability-help-126229/
 
Last edited:
Level 5
Joined
Oct 10, 2008
Messages
68
  • Ground
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacked unit)) Equal to Knight
      • ((Attacking unit) is A ground unit) Equal to True
    • Actions
      • Unit - Make (Attacked unit) Invulnerable
      • Wait 0.01 seconds
      • Unit - Make (Attacked unit) Vulnerable
Maybe this? But one shot will be fired. However the unit will be unharmed..?

----Edited----
NAh that isn't going to work. I tested it and the air unit can't attack the land unit at the same time.
 
Last edited:
Status
Not open for further replies.
Top