Need help with units of type in range

Shadow

TH.net Regular
Reaction score
23
So what I want is like if you ever played some of those maps such as gauntlet where you step on the items it gives your hero the effects of the item.

So I Think my event would be



then add my stuff like add 100 health to GetTriggerUnit

but these items are gonna be randomly dropped by slain enenmies so how do i make it so if a unit is in range of "TypeUnit" (My item is really a unit with no pathing/ collision size)

Thanks in advance to any help
 
I'd use two groups to accomplish that. Every second, check the units in X range of the unit, if its more than 0, do whatever to that unit.
 
I can see two ways of going about this. All depending on your perspective.

First, you can create a trigger with an event as you've mentioned "Unit in Range." This could work but if you wanted more than say.. 5 items with proximity affects then the code will become disorganized and difficult to read.

Secondly, (and my preferred method) is a little more CPU intensive. This way works from the perspective of items on the ground checking to see if units are near them. I would create an "ItemWithProximityAffect" base class and unit with numerous properties to contain its ID and affects. Further you could create a hashtable of items on the ground (visible by players or not, your choice) which checks on a time based trigger for nearby units.

Also, to the above comment: "Something wrong with runes?" Yes. There is.. runes only give consumable affects. :/
 
>Specific Unit Enter Range vs Generic Unit Acquires An Item
This is not the JASS stone age, we have AIDS.

JASS:
//! zinc

library UnitEntersRange {
    constant boolean TRIGGERCONDS = false;

    struct Data {
       trigger t;
       static if TRIGGERCONDS { triggercondition tc; }

        static method onEvent() -> boolean {
            // do your stuff
            static if TRIGGERCONDS { TriggerRemoveCondition(this.t,this.tc); }
            DestroyTrigger(this.t);
            return false;
        }

        method AIDS_onDestroy() {
            DestroyTrigger(this.t);
        }

        method AIDS_onCreate() {
            this.t=CreateTrigger();
            TriggerRegisterUnitInRange(this.t,this.unit,200,null);
            TriggerAddCondition(thistype.t,Condition(function thistype.onEvent))
        }

        //! runtextmacro AIDSZinc();
    }
}

//! endzinc


I did the optional TRIGGERCONDS because I forget if it's dangerous to leak those guys, don't even know if it works, are dynamic triggers bad or something? I'd like something like [LJASS]local TriggerPool pool=TriggerPool[1000][/LJASS] and maybe [LJASS]trigger t=pool.get()[/LJASS].
 
I made this for him a few days ago:

JASS:
library UnitInRangeOfType requires AIDS, Event, Alloc
    globals
        private key EVENT_KEY
        private key TRIGGER_KEY
        private key RANGE_KEY
        private key TYPE_KEY
        private key UNIT_KEY
    endglobals
    
    private struct idlist extends array
        public static integer count = 0        
        implement Alloc
        
        public integer id
        
        public static method create takes integer id returns thistype
            local thistype this = thistype.allocate()
            
            set this.id = id
            set thistype.count = thistype.count + 1
            
            return this            
        endmethod
    endstruct
    
    private struct data extends array
        public static hashtable hash
        public static unit lastcenter
        public Event e
        
        //! runtextmacro AIDS()
        
        private static method AIDS_filter takes unit u returns boolean
            local integer i = idlist.count
            local boolean b = false
            local integer id = GetUnitTypeId(u)
            
            loop
                exitwhen i == 0
                set b = b or ( id == idlist<i>.id )
                set i = i - 1
            endloop
            
            set b = b or ( IsUnitType(u, UNIT_TYPE_HERO) )
            
            return b
        endmethod
        
        private static method OnEvent takes nothing returns boolean
            call FireEvent(Event(LoadInteger(data.hash, LoadInteger(thistype.hash, GetHandleId(GetTriggeringTrigger()), TYPE_KEY), EVENT_KEY)))
            set thistype.lastcenter = LoadUnitHandle(thistype.hash, GetHandleId(GetTriggeringTrigger()), UNIT_KEY)
            return false
        endmethod
        
        private method AIDS_onCreate takes nothing returns nothing
            local trigger t = CreateTrigger()
            local integer i = GetUnitTypeId(this.unit)
            set this.e = Event.create()
            
            call TriggerRegisterUnitInRange(t, this.unit, LoadReal(thistype.hash, i, RANGE_KEY), null)
            call TriggerAddCondition(t, Condition(function thistype.OnEvent))
            call SaveInteger(thistype.hash, GetHandleId(t), TYPE_KEY, i)
            call SaveUnitHandle(thistype.hash, GetHandleId(t), UNIT_KEY, this.unit)
        endmethod
        
        private static method AIDS_onInit takes nothing returns nothing
            set hash = InitHashtable()
        endmethod
    endstruct

    function GetCenterUnit takes nothing returns unit
         return data.lastcenter
    endfunction
    
    function TriggerRegisterUnitInRangeOfType takes trigger whichTrigger, integer whichType, real range returns Event
        local Event e
        
        if ( HaveSavedInteger(data.hash, whichType, EVENT_KEY) ) then
            set e = LoadInteger(data.hash, whichType, EVENT_KEY)
        else
            set e = Event.create()
            call SaveInteger(data.hash, whichType, EVENT_KEY, e)
            call TriggerRegisterEvent(whichTrigger, e)
        endif
        
        call idlist.create(whichType)
        call SaveTriggerHandle(data.hash, whichType, TRIGGER_KEY, whichTrigger)
        call SaveReal(data.hash, whichType, RANGE_KEY, range)
        
        return e
    endfunction
endlibrary

struct asdf extends array
    private static method a takes nothing returns nothing
        call BJDebugMsg(&quot;Test&quot;)
    endmethod
    
    private static method onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call CreateUnit(Player(0), &#039;hfoo&#039;, 0, 0, 0)
        call CreateUnit(Player(0), &#039;hfoo&#039;, 0, 550, 0)
        call CreateUnit(Player(0), &#039;hfoo&#039;, 0, -550, 0)
        call CreateUnit(Player(0), &#039;hkni&#039;, 550, 0, 0)
        call CreateUnit(Player(0), &#039;hkni&#039;, -550, 0, 0)
        call TriggerRegisterUnitInRangeOfType(t, &#039;hfoo&#039;, 500)
        call TriggerAddAction(t, function thistype.a)
    endmethod
endstruct
</i>
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top