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

[vJASS] target type function doesn't work

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
hi,
i wanted to make an air unit temporarly targetable by ground attack...
but it doesn't work.

[Jass=]
library Hawk

public function Swoop takes unit caster, unit target, integer spell returns nothing
local unit dummy
local integer targetid
local player owner
local player victim
local integer number
local integer number2
local real maxlife
local real life
local real divehawk
local real divedmg
local real x
local real y
set targetid = GetUnitTypeId(target)
if targetid == 'h02F' or targetid == 'n011' or targetid == 'n000' then
call DisplayTimedTextToPlayer( GetOwningPlayer(GetTriggerUnit()), 0, 0, 6.00, "the hawk cannot swoop this target" )
call UnitRemoveAbility( caster, spell )
call UnitAddAbility( caster, spell )
set caster = null
set target = null
else
set owner = GetOwningPlayer(caster)
set number = GetPlayerId(owner) + 1
set victim = GetOwningPlayer(target)
set number2 = GetPlayerId(victim) + 1
set maxlife = GetUnitState( target, UNIT_STATE_MAX_LIFE)
set life = GetUnitState( target, UNIT_STATE_LIFE)
set udg_Swoop[number] = true
if spell == 'A0JW' then
set divehawk = 40.00
elseif spell == 'A0K0' then
set divehawk = 60.00
elseif spell == 'A0K1' then
set divehawk = 80.00
elseif spell == 'A0KF' then
set divehawk = 100.00
endif
set divedmg = divehawk / 2.00
if targetid == 'H000' or targetid == 'H001' or targetid == 'H002' or targetid == 'H003' then
if udg_MaskOwned[number2] != 0 then
set divedmg = 0
endif
elseif targetid == 'h01Q' or targetid == 'h019' or targetid == 'h01C' or targetid == 'h02I' or targetid == 'h02X' or targetid == 'h02U' or targetid == 'h032' or targetid == 'h02V' or targetid == 'h033' then
set divedmg = 150
endif
// Hide the Hawk and order dummy to cast stun on target, the spell missile effect is the hawk model
set x = GetUnitX(caster)
set y = GetUnitY(caster)
call SelectUnit( caster, false )
call ShowUnit( caster, false )
set dummy = CreateUnit( owner, 'n01F', x, y, bj_UNIT_FACING )
call PlaySoundOnUnitBJ( gg_snd_HawkYes2, 100, dummy )
call UnitAddAbility( dummy, 'A0KH' )
call IssueTargetOrder( dummy, "creepthunderbolt", target )
call TriggerSleepAction( 0.80 )
// move the hawk to the target location and unhide it
set x = GetUnitX(target)
set y = GetUnitY(target)
call SetUnitPosition( caster, x, y )
call ShowUnit( caster, true )
call SelectUnit( caster, true )
set dummy = null
// check if target is air or ground, if ground check if target maxhp < swoop ability
if IsUnitIdType(targetid, UNIT_TYPE_FLYING) then
call UnitRemoveBuffBJ( 'BPSE', target )
call IssueTargetOrder( caster, "attack", target )
else
call UnitAddType(caster, UNIT_TYPE_GROUND)
if divedmg > life then
call KillUnit(target)
call SetUnitState( caster, UNIT_STATE_MANA, GetUnitState( caster, UNIT_STATE_MANA ) + I2R(GetUnitPointValueByType(GetUnitTypeId(target))) )
elseif maxlife > divehawk then
call UnitDamageTarget(caster, target, divedmg, false, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
call TriggerSleepAction( 2.00 )
call UnitRemoveBuffBJ( 'BPSE', target )
else
set x = GetUnitX(caster)
set y = GetUnitY(caster)
set dummy = CreateUnit( Player(bj_PLAYER_NEUTRAL_EXTRA), 'n00N', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy, 'ACsi' )
call IssuePointOrder( dummy, "silence", x, y )
set udg_Hawk[number] = true
set udg_HawkDamage[number] = divedmg
set udg_HawkPrey[number] = target
set udg_HawkPrey[( number + 12 )] = caster
set udg_HawkPreyHp[number] = life
call ShowUnit( udg_HawkPrey[number], false )
call EnableTrigger( gg_trg_Hawk_Swoop_Damage_JASS )
endif
call TriggerSleepAction( 1.50 )
call UnitRemoveType(caster, UNIT_TYPE_GROUND)
set udg_Swoop[number] = false
endif
endif
set caster = null
set target = null
set owner = null
set victim = null
set dummy = null
endfunction
endlibrary
[/code]

this doesn't work : call UnitAddType(caster, UNIT_TYPE_GROUND)
because the unit cannot be targeted by ground attack even while this should be applied...

is it a bug? or is there something wrong with the trigger?
basically the unit could be targetable as anything (multiple type)
so is adding a type ingame doesn't work, or need a delay to activate?
 
I think UNIT_TYPE_SAPPER can be added by trigger, so use this instead.

Make all your attacks target both air and ground units, but only non-sapper types and add the sapper type to flying units.
Now you can simply remove the sapper type of the air units you want attackable.
You'd need to change the error message for "can not target sapper units" in the game interface table.

EDIT:
Btw you can replace those "UnitRemoveBuffBJ" functions with "UnitRemoveAbility".
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Zwiebelchen
Btw you can replace those "UnitRemoveBuffBJ" functions with "UnitRemoveAbility".

the : "call UnitRemoveBuffBJ( 'BPSE', target )"
'BPSE' is the stun buff which stun the unit
so i don't know if i can remove a buff by removing an ability?
and wich ability should i remove since this is a buff that could be applied by different abilities?
since i didn't added any ability but just targeted the unit with a stunning spell, i don't know what else should be done except removing the buff to un-stun the unit?

about the UNIT_TYPE_SAPPER it is a good solution, but i already remade my trigger as before using chaos and a twin unit targeted as ground, so it is ok.
 
Buffs are extended abilities
Proven by common.j:
type buff extends ability
So you can do it.

If you want a proper proof,here is the wrapper for that function:
[jass=]function UnitRemoveBuffBJ takes integer buffcode, unit whichUnit returns boolean

return UnitRemoveAbility(whichUnit, buffcode)

endfunction[/code]

That should do it my friend.

You should read the common.j and blizzard.j
 
Status
Not open for further replies.
Top