1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  4. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  5. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  6. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  7. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  8. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  9. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  10. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

IsUnitEngageable

Discussion in 'JASS Resources' started by mckill2009, Aug 2, 2012.

  1. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    This s a simple one function that undetects un-engageable(non-attackable) units...
    It's main purpose is for AI making...e.g. if an AI searches an enemy target, it will filter out non-attackable units,
    thus not wasting time to lock to the unit that cannot be attacked...

    Used by my AI systems:
    EngageSystem
    StrikeForce

    Code (vJASS):

    library IsUnitEngageable /* v1.2
    ************************************************************************************
    *   by mckill2009
    ************************************************************************************
    *
    *   Installation:
    *       - Copy this script to your trigger editor via custom text
    *       - Copy the custom abilty from the object editor named 'IsUnitEngageable' to your map
    *       - Make sure you change also the rawID below (SPELL_ID) if you change the rawID of your imported ability
    *
    ************************************************************************************
    *
    *   function IsUnitEngageable takes unit u returns boolean
    *        Undetects units that is:
    *          - Invulnerable
    *          - Burrowed
    *          - Invisible
    *          - Ethereal
    *          - Have locust
    *
    ************************************************************************************/


    globals
    /************************************************************************************
    *
    *   Change the SPELL_ID according to the ability object named 'IsUnitEngageable'
    *
    *************************************************************************************/

        private constant integer SPELL_ID = 'A000' //based on chain lightning
    /************************************************************************************
    *
    *   Never touch anything below this block
    *
    *************************************************************************************/

        private constant integer DUMMY_ID = 'hmpr'
        private unit DUMMY
    endglobals

    struct onInit
        static method onInit takes nothing returns nothing
            set DUMMY = CreateUnit(Player(15), DUMMY_ID, 0,0,0)
            call UnitAddAbility(DUMMY, SPELL_ID)
            call UnitAddAbility(DUMMY, 'Aloc')  
            call ShowUnit(DUMMY, false)
        endmethod
    endstruct

    function IsUnitEngageable takes unit u returns boolean
        call SetUnitPosition(DUMMY, GetUnitX(u), GetUnitY(u))
        return IssueTargetOrderById(DUMMY, 852119, u) and not IsUnitType(u,UNIT_TYPE_ETHEREAL)
    endfunction

    endlibrary
     


    Demo

    Code (vJASS):

    scope DEMO initializer init

    globals
        group grp = CreateGroup()
    endglobals

    function fil takes nothing returns boolean
        call GroupAddUnit(grp,GetFilterUnit())
        return false
    endfunction

    function grploop takes nothing returns nothing
        local unit u = GetEnumUnit()
        local texttag tag
        if IsUnitEngageable(u) then
            set tag = CreateTextTag()
            call SetTextTagPosUnit(tag, u, 0)
            call SetTextTagText(tag, GetUnitName(u), 0.025)
            call SetTextTagPermanent(tag, false)
            call SetTextTagVelocity(tag, 0.03, 0.03)
            call SetTextTagLifespan(tag, 3)
            call SetTextTagFadepoint(tag, 0.01)
        endif
    endfunction

    function grplooper takes nothing returns nothing
        call ForGroup(grp,function grploop)
    endfunction

    function init takes nothing returns nothing
        call GroupEnumUnitsInRect(grp,bj_mapInitialPlayableArea,Filter(function fil))
        call TimerStart(CreateTimer(),1.0,true,function grplooper)
    endfunction

    endscope
     



    Changelogs

    v1.2
    - Object ability Unholy Frenzy is replaced by Chain Lightning due to unwanted sound

    v1.1
    - I've decided to remove the LUA object since it's difficult for me to make a good instruction on how to import it
     

    Attached Files:

    Last edited: Aug 14, 2013
  2. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    You should issue a stop order to the dummy.

    You can do this efficiently by returning this:

    return IssueTargetOrderById(DUMMY, 852209, u) and IssueImmediateOrderById(DUMMY, 851972) and not IsUnitType(u,UNIT_TYPE_ETHEREAL)


    Also, you don't really need to modify the Unholy Frenzy ability.
    Actually, if you keep the modification to it and change the cast range to 92083, you won't have to move the dummy unit to the target unit at all.

    This way, your function would be inline friendly.

    edit
    How can't Unholy Frenzy work on Invulnerable units? o_O
    Wouldn't a simple attack order be better?
     
  3. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    This isn't really acceptable

    Code (vJASS):

    //! externalblock extension=lua ObjectMerger $FILENAME$
        //! i setobjecttype("abilities")
        //! i createobject("ACuf","eng0")
        //! i makechange(current,"anam","IsUnitEngageable")
        //! i makechange(current,"ansf","")
        //! i makechange(current,"Uhf1","1","0")
        //! i makechange(current,"Uhf2","1","0")
        //! i makechange(current,"abuf","1","")
        //! i makechange(current,"acdn","1","0")
        //! i makechange(current,"ahdu","1","0.01")
        //! i makechange(current,"adur","1","0.01")
        //! i makechange(current,"amcs","1","0")
        //! i makechange(current,"atar","1","")
    //! endexternalblock
     


    Either do cnp of the object from a map to ensure a unique id or use LUA_OBJECT_ID or both.
     
  4. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    @Mags
    Unholy frenzy can't target structures that's why I modified it to target ALL units...also, I already tried attack
    order before and it doesnt work coz it will still return true if the first unit it encounters returns true...
    You're right about the XY but the stop order is just a waste/slow since it will automatically stop if unit is NOT engageable...

    @Nes
    I just know the basics of this LUA, so I dont need to complicate things, this for me is very much readable...
     
  5. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,791
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Just one hint: the "smart" order returns false if the unit can not be reached by the dummy (for example when the dummy is stunned, entangled, etc.) - the attack order doesn't return false in this case - so I am pretty sure you can also use "smart" to detect orders on your "untargetable" units.
    No ability required in this case.
     
  6. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    then use a map

    edit

    which you are now, gj ; )
     
  7. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    @Zwiebelchen
    the dummy cannot be stunned, entangled, etc...coz its invisible and has an Aloc ability, in ANY case, the dummy will and can
    reach enemies/allies, besides I just tested 'smart' right now and it still returns true when unit is invulnetable...
     
  8. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    That's why the stop order is required.
    You order the unit to attack, and if he does, you stop him.

    return Something and SomethingElse
    will first look at "Something". If "Something" is false, it will just return false and avoid SomethingElse.
    If "Something" returns true, it will continue.
    That's how the line I gave you is functional ;)
     
  9. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    I tried and tested...It doesnt work, well maybe for enemies, not for neutrals and allies...
     
  10. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    An ally should be marked as engageable because he is.

    Any unit that is not invulnerable, burrowed, invisible or ethereal should be engageable. (Units without locust too)
     
  11. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    Yes Mags, it does that...
     
  12. edo494

    edo494

    Joined:
    Apr 16, 2012
    Messages:
    3,855
    Resources:
    5
    Spells:
    1
    JASS:
    4
    Resources:
    5
    invisible, burrowed
    isnt it a little bit problematic?
    If I have the owl from priestress of the moon then I see either burrowed and invisible units, also roflcopter can see them with true sight upgrade
     
  13. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Yes, because technically, they are engageable.
     
  14. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    you have a good point there edo494, unfortunately this system is from Player15's point of view, not the engaging player or the player that has the true sight and I made this for AI's coz in the system I made (EngageSystem), if not for this, AI unit still locks the target even if it's 'really' invisible to them, therefore they cant attack another potential target...
     
  15. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    ~Approved.