• 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.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

Making a ground unit targeted as flying

Status
Not open for further replies.
Level 8
Joined
Aug 4, 2006
Messages
357
Hey guys,

I'm currently working on a Jump system. Once the unit is in the air, I want it to be targeted as a flying unit, so that ground units can't hit it while it's 50 feet in the air. Once the unit comes back down, it should be treated as a ground unit.

Now my question is: Is there a way to change how a unit is targeted in-game, without replacing it with another unit? I tried doing:
JASS:
call UnitRemoveType(u, UNIT_TYPE_GROUND)
call UnitAddType(u, UNIT_TYPE_FLYING)
and that didn't seem to work.

Edit: I did some debugging using IsUnitType, and neither of the above function calls do anything. Even if I could manage to change the unittype, I don't know if this would affect how the unit is targeted.
 
Level 9
Joined
Aug 21, 2008
Messages
533
the type of a unit and how its targeted are 2 different things. Just look it up in object editor you can seperatly choose if it is a flying unit and if it is targeted as one. You cant change that exactly like you cant change unit names.

But maybe you can use crow form and order it to cast it instaed of just adding and removing it. this may work.You just have to hide the abilty(or add when the jump is cast and remove it when jump is finished)
 
Level 17
Joined
Sep 8, 2007
Messages
994
It is easy. To be able to change a ground units fly height use this...

JASS:
function UnitAllowFly takes unit u returns nothing
   call UnitAddAbility(u, 'Arav')
   call UnitRemoveAbility(u, 'Arav')
endfunction

'Arav' is the ability "Ravenform" or something from Wizard of Taloon. By adding and deleting this ability the unit's fly height can be changed. The unit is still a ground unit.
 
Level 8
Joined
Aug 4, 2006
Messages
357
That's not what he's asking, he wants to know how to make the unit TARGETED as flying while it's jumping.

So that way for example headhunters can still hit a jumping unit but grunts cannot.
Right. Anyway, I came up with a solution. I use a trigger that fires when a unit is attacked (A.K.A. when the attacker just starts his attack animation). If the attacked unit is jumping, and the attacker is not able to attack flying, the attacker is ordered to stop. The only "problem" is that the attackers still run up to the jumper's shadow. Here's some of the code:
JASS:
private function StopGroundAttackers takes nothing returns nothing
    local JumpData dat = JumpData[GetTriggerUnit()]
    if(dat != 0 and dat.isInAir == true and /*
    */not IsUnitType(GetAttacker(), UNIT_TYPE_ATTACKS_FLYING))then
        call IssueImmediateOrder(GetAttacker(), "stop")
    endif
endfunction
//==================================================================================

private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( trig, function StopGroundAttackers ) 
endfunction

Edit: I don't know how I'm going to deal with spells that target ground units.
 
Status
Not open for further replies.
Top