HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Duplicate attack button functionality

10-06-2007, 05:27 PM#1
aaero
I want the ability "Attack" in one of my Spellbooks. Adding the standard "attack" ability to a SpellBook doesn't give an icon or any attack functionality, so I figured I'd just trigger one.

I'm using "Shockwave" as a base - it allows you to target the ground or to target a unit. The issue is, I can't tell the difference between them. If they target a unit, I want them to attack that unit. If they target the ground, I want them to attack-move there.

Currently, I've triggered attack move to work perfectly - attacking a single unit does not work at all (it just attack-moves). This might be a very simple question, but does anyone have an idea on how to do this?

Thanks for any help!
10-06-2007, 07:45 PM#2
TaintedReality
If GetSpellTargetUnit() != null, then it's targeting a unit. At least that's how I've always done it.
10-06-2007, 07:55 PM#3
aaero
Yep,

Collapse JASS:
   local unit target = GetSpellTargetUnit()
    local location loc = GetSpellTargetLoc()

    if target == null then
       call IssuePointOrderLoc( GetTriggerUnit(), "attack", loc )
    else
        call IssueTargetOrder( GetTriggerUnit(), "attack", target )
    endif
    
    set target = null
    set loc = null

works perfectly. Thanks very much!

If anyone wants to verify that the code above is leak free, I'd appreciate it. I'm not sure if locations always leak.
10-06-2007, 08:08 PM#4
TaintedReality
Yeah, that's leaking a location, just RemoveLocation() before you set it to null. Locations always leak =\.