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

Attack while moving (Ability)

Status
Not open for further replies.
Level 14
Joined
Nov 25, 2004
Messages
1,185
I have a dummy unit moving all the time (IssuePointOrder). I want it to attack while moving. The dummy unit is having a Poison Arrows ability. I tried using Barrage, but it doesn't work, Phoenix Fire would be great but it don't poison the enemy units.

Is there another way (in jass or gui) ?
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
Moving an unit acts just like blinking it (is you use Unit - Move Unit Instantly). No, there is no way you can move the unit and order it to attack as well. You can however create another dummy unit at the position of the unit and order than unit to cast the ability while stationary (or attack).

I personally tried to do this with life Drain, and failed. When I moved the unit, it stopped casting the ability. And yes, practically moving the unit forcefully would be the solution but unfortunately Blizzard doesn't allow that. Not yet though...

~Daelin
 
Level 14
Joined
Nov 25, 2004
Messages
1,185
You said you're going for 3 days...
As for my question i've come with 2 more :

1. Is there(ingame) a model with attachment points but invisible?

Probably not then my second question :

2. How looks making unit invisible. I tried to make invisible my unit by

SetUnitVertexColor(255, 255, 255, 100)

and it isn't working.
 
Level 3
Joined
Mar 27, 2004
Messages
70
This is in reply to your first post. Daelin is absolutely right that no unit can move and attack at the same time.
But what's stopping us from simulating an attack? :)
I put something together that might help.
Note that I havn't got WE with me here so I can't test if it works.
Try calling the CastPoisonArrow function when you want to unit to attack and it will hopefully shoot a single poison arrow towards the target.
But first replace the 'h000' in the CastPoisonArrow function with a dummy unit type with the Poison Arrow model.
Btw, you need the Handle Vars functions to use the code below.

As for your two other questions:
1. Not that I know of.. :(
2. SetUnitVertexColor(myUnit, 0, 0, 0, 0) (only the last 0 actually matters)

JASS:
// ==================================
//   Spawn Projectiles as units
function SpawnUnitProjectile_Update takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local real speed = GetHandleReal(t, "speed")
    local unit projectile = GetHandleUnit(t, "projectile")
    local widget target = GetHandleUnit(t, "target")
    local real dx = GetWidgetX(target) - GetUnitX(projectile) 
    local real dy = GetWidgetY(target) - GetUnitY(projectile)

    local real angle = Atan2(dy, dx)
    local trigger trg = GetHandleTrigger(t, "trg")
    if ( target == null ) then // Target might die before we hit it
        // This is a cheap solution though...
        call KillUnit(projectile)
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        call FlushHandleLocals(trg)
        call DestroyTrigger(trg)
        return
    endif
    if ( dx*dx+dy*dy <= speed*speed ) then // See if the target is hit
        // Projectile hit!
        call KillUnit(projectile) // Get rid of arrow/fireball/etc
        if ( trg != null ) then
            call TriggerExecute(trg) // Deal the damage and stuff
        endif
        call FlushHandleLocals(t) // Clean up
        call DestroyTimer(t) // Stop loop
        return
    endif
    call SetUnitX(projectile, GetUnitX(projectile)+Cos(angle)*speed)
    call SetUnitY(projectile, GetUnitY(projectile)+Sin(angle)*speed)
    call SetUnitFacing(projectile, angle*bj_RADTODEG)
endfunction
function SpawnUnitProjectile takes integer unitid, real x, real y, widget target, real speed returns trigger
    local real angle = Atan2(GetUnitY(target)-y, GetUnitX(target)-x)*bj_RADTODEG)
    local unit projectile = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), unitid, x, y, angle)
    local timer t = CreateTimer()
    local trigger whenHit = CreateTrigger()
    local real update = 0.05 // Update interval
    call SetHandleHandle(t, "target", target)
    call SetHandleHandle(t, "projectile", projectile)
    call SetHandleReal(t, "speed", speed*update)
    call UnitAddAbility(projectile, 'Aloc')    // Make unselectable
    call SetUnitInvulnerable(projectile, true) // Make untargetable
    call TimerStart(t, update, true, function SpawnUnitProjectile_Update)
    return whenHit
endfunction

// ==================================
//   Simulate poison arrows
function CastPoisonArrow_Update takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer duration = GetHandleInt(t, "duration") - 1
    local unit caster = GetHandleUnit(t, "caster")
    local unit target = GetHandleUnit(t, "target")
    local real dmg = GetHandleReal(t, "dmg")
    call UnitDamageTarget(caster, target, dmg, false, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_POISON, WEAPON_TYPE_WHOKNOWS)
    if ( duration <= 0 or target == null) then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        return
    endif
    call SetHandleInt(t, "duration", duration)
endfunction
function CastPoisonArrow_Start takes nothing returns nothing
    local trigger trg = GetTriggeringTrigger()
    local unit caster = GetHandleUnit(trg, "caster")
    local unit target = GetHandleUnit(trg, "target")
    local real dmgInitial = GetHandleReal(trg, "dmgInitial")
    local timer t = CreateTimer()
    local real update = 0.5
    call UnitDamageTarget(caster, target, dmgInitial, false, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_POISON, WEAPON_TYPE_WHOKNOWS)
    call SetHandleHandle(t, "caster", caster)
    call SetHandleHandle(t, "target", target)
    call SetHandleReal(t, "dmg", GetHandleReal(trg, "dmgPerSec")*update)
    call SetHandleInt(t, "duration", R2I(GetHandleReal(trg, "duration")/update))
    call TimerStart(t, update, true, CastPoisonArrow_Update)
    call FlushHandleLocals(trg)
    call DestroyTrigger(trg)
endfunction
function CastPoisonArrow takes unit caster, unit target, real dmgInitial, real dmgPerSec, real duration returns nothing
    local trigger t = SpawnUnitProjectile('h000', GetUnitX(caster), GetUnitY(caster), target, 1000)
    call TriggerAddAction(t, function CastPoisonArrow_Start)
    call SetHandleHandle(t, "caster", caster)
    call SetHandleHandle(t, "target", target)
    call SetHandleReal(t, "dmgInitial", dmgInitial)
    call SetHandleReal(t, "dmgPerSec", dmgPerSec)
    call SetHandleReal(t, "duration", duration)
endfunction
 
Status
Not open for further replies.
Top