Snippet AutoFly

Azlier

Old World Ghost
This simple, efficient script makes it so that [lJASS]SetUnitFlyHeight[/lJASS] automatically works on the units in your map. It should be more efficient than adding and removing Crow Form each time a spell is cast. ;)

JASS:
// AutoFly - by Azlier
//  Requires a vJass preprocessor

// How to import:
//  1. Create a new trigger called AutoFly.
//  2. Convert the trigger to custom script, and replace all the code inside with this.

library_once AutoFly

private function Actions takes nothing returns boolean
    return UnitAddAbility(GetFilterUnit(), 'Amrf') and UnitRemoveAbility(GetFilterUnit(), 'Amrf')
endfunction

private struct Hack extends array

    static method onInit takes nothing returns nothing
        local region r = CreateRegion()
        local rect re = GetWorldBounds()
        local group g = CreateGroup()
        local integer i = 15
        call RegionAddRect(r, re)
        call TriggerRegisterEnterRegion(CreateTrigger(), r, Filter(function Actions))
        call RemoveRect(re)
        set re = null
        
        loop
            call GroupEnumUnitsOfPlayer(g, Player(i), Filter(function Actions))
            exitwhen i == 0
            set i = i - 1
        endloop
        call DestroyGroup(g)
        set g = null

    endmethod

endstruct

endlibrary


AIDS version. Credit goes to kenny!.
JASS:
// AutoFly - by Azlier, AIDS version by Jesus4Lyf
//  Requires a vJass preprocessor, AIDS

// How to import:
//  1. Create a new trigger called AutoFly.
//  2. Convert the trigger to custom script, and replace all the code inside with this.
//  3. Import AIDS if it is not in your map already.

library AutoFly requires AIDS
    private struct Hack extends array
        private static method AIDS_filter takes unit u returns boolean
            return UnitAddAbility(u, 'Amrf') and UnitRemoveAbility(u, 'Amrf')
        endmethod
        //! runtextmacro AIDS()
    endstruct
endlibrary

Non-vJass version.
JASS:
// AutoFly - by Azlier

// How to import:
//  1. Create a new trigger called AutoFly.
//  2. Convert the trigger to custom script, and replace all the code inside with this.

function AutoFly__Actions takes nothing returns boolean
    return UnitAddAbility(GetFilterUnit(), 'Amrf') and UnitRemoveAbility(GetFilterUnit(), 'Amrf')
endfunction

function InitTrig_AutoFly takes nothing returns nothing
    local region r = CreateRegion()
    local rect re = GetWorldBounds()
    local group g = CreateGroup()
    local integer i = 15
    call RegionAddRect(r, re)
    call TriggerRegisterEnterRegion(CreateTrigger(), r, Filter(function AutoFly__Actions))
    call RemoveRect(re)
    set re = null
        
    loop
        call GroupEnumUnitsOfPlayer(g, Player(i), Filter(function AutoFly__Actions))
        exitwhen i == 0
        set i = i - 1
    endloop
    call DestroyGroup(g)
    set g = null

endfunction
 

Romek

Super Moderator
Staff member
Why do you need a custom ability for something like this?

Also, this won't work on units created in struct initializers, so I suggest you initialize this in struct too. :p

JASS:
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local region r = CreateRegion()
    call RegionAddRect(r, GetWorldBounds())
    call TriggerRegisterEnterRegion(t, r, Filter(function Actions))
endfunction

Could be:
JASS:
private function Init takes nothing returns nothing
    local region r = CreateRegion()
    call RegionAddRect(r, GetWorldBounds())
    call TriggerRegisterEnterRegion(CreateTrigger(), r, Filter(function Actions))
endfunction
 

Troll-Brain

You can change this now in User CP.
It does not work on units created outside of the map area
True.

But, you can't create units outside the map area, even the playable map area :D
Only SetUnitX/Y can do that.
So your function MakeUnitFlyable is useless.

This trigger can so fire several times for the same unit, but anyway i think i'm the only one crazy dude witch do that :p
 

Azlier

Old World Ghost
>But, you can't create units outside the map area, even the playable map area

Yay! I'll remove it right away.

>Why do you need a custom ability for something like this?

It avoids strange bugs.

Making changes...
 

Azlier

Old World Ghost
Indeed it is. But that requires more brain power to get pretty much the same result.
 

Troll-Brain

You can change this now in User CP.
Yes. If only humans were less ... humans.

I guess this is fine like it, to preserve users from themselves.
 

Romek

Super Moderator
Staff member
> It avoids strange bugs.
Such as? :p
 

Azlier

Old World Ghost
Adding and removing Storm Crow form will break Druids of the Talon.

You need a check to prevent that, and this beats that in efficiency.
 

Romek

Super Moderator
Staff member
And [ljass]if UnitAddAbility(...)[/ljass] wouldn't work?
It probably takes more time loading that ability at map init than the time you save between using a new ability in the actual map.
 

Troll-Brain

You can change this now in User CP.
Personally i would define/hook the function CreateUnit.
It would be irrelevant compare to the time required of the unit creation by itself.
In this way i'm sure it won't have unneeded enter region events fired.

If you wonder why the hell i put some units outside the whole map, check this link :
http://www.wc3c.net/showpost.php?p=1106773&postcount=70

Anyway i don't really care about it, since i already use it like that, i just wanted to give my opinion.

Hmm, i haven't played with the "chaos" abilities because of the issues, i simply leave the unit specific event leak and don't recycle units, except dummies ones , but does this still work with such units ?
 

Azlier

Old World Ghost
Alright. Make two maps with two versions of this, one with Storm Crow, the other with the dummy ability. Give them the same name, and put them in the Maps folder at random. Can you tell which is which from inside Warcraft?

>but does this still work with such units ?

Excellent question. I'll test that.
 

Troll-Brain

You can change this now in User CP.
Uhh ...

Just forget what i've said about the hook/define, usually, units are not only created with the native function CreateUnit :banghead:
They can be trained, bought, summoned, built ...
 

Azlier

Old World Ghost
It works on Chaosed units. Yay.

A unit morphing via Chaos doesn't fire the event again, as expected.
 

Troll-Brain

You can change this now in User CP.
A unit morphing via Chaos doesn't fire the event again, as expected.
I didn't wanted to mean that.
I mean, you can still change the flying height of a not flying unit after the unit have gotten a chaos ability?
In other words, the flying bug is still valid, or you have to add/remove the ability one more time ?
 

Azlier

Old World Ghost
Just a useless bit of info. I placed a footman, gave it Siege Engine chaos, ordered it, and set flying height.

Wait a minute. I forgot to wait until the footman fully changed form. Hold on.

EDIT: Works flawlessly.
 

Romek

Super Moderator
Staff member
> Can you tell which is which from inside Warcraft?
No. Which is exactly why you should just do what I said instead of using object merger to create an ability (which can then be a nuisance), increase the map size (both insignificantly and unnecessarily), and make the user have to delete the line.
Yes, you may be thinking "Oh noes, big deal". Though notice that all of that is completely unnecessary.

As for making Azlier change this snippet just because you move the occasional unit outside the map area, I think that's pointless.
The event firing again does no harm. And I can assure you that the vast majority of users will not be moving units so far outside the map.
 

Azlier

Old World Ghost
FYI, it's already been changed to use Crow Form.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    The old shoutbox wasn't supported anymore. We updated xenForo, so it had to be replaced.
  • jonas jonas:
    let's see if everyone finds it... the nice thing about the shoutbox was I could check on it even while logged out, but the existence of this one is hidden when you're not logged in
  • Ghan Ghan:
    We can fix that.
  • Ghan Ghan:
    Chat should show on the sidebar when not logged in now.
  • Ghan Ghan:
    (You'll still need to log in to post messages)
  • Ghan Ghan:
    Test!
  • tom_mai78101 tom_mai78101:
    I must be in a test server.
  • tom_mai78101 tom_mai78101:
    Nice, Twitter tweets embedding now works
  • Wizard Wizard:
    Yup.
  • Ghan Ghan:
    Excellent.
  • Ghan Ghan:
    @tom_mai78101 Hello there.
  • Ghan Ghan:
    Tagging works in the chat too.
  • tom_mai78101 tom_mai78101:
    @Ghan Missed it.
  • Wizard Wizard:
    Still fixing things here and there. Added widgets to the portal, will make it match the ones here on the forum index tomorrow.
  • Ghan Ghan:
    The venerable World Editor Tutorials site has been converted to HTTPS at last.
  • jonas jonas:
    cool
  • jonas jonas:
    and I can even edit my messages, nice
  • seph ir oth seph ir oth:
    GENERAL CHIT CHAT, YOU ARE A BOLD ONE
  • Ghan Ghan:
    Hello there
  • The Helper The Helper:
    this new chatbox is great and the forum software update is great too
    +1
  • The Helper The Helper:
    upgrade has fixed forum registration spam problem
  • tom_mai78101 tom_mai78101:
    Something tells me we might be able to customize the chatbox a bit, considering that there's a gap under every message.
  • Wizard Wizard:
    Going to deploy a fix soon, just had to take some time for myself this weekend.
  • Varine Varine:
    Unbelievable. Time for yourself? How dare you!

    Members online

    No members online now.

    Affiliates

    Hive Workshop
    Top