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
 

NeuroToxin

New Member
Reaction score
46
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.
 

Tyrulan

Ultra Cool Member
Reaction score
37
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. :/
 

tooltiperror

Super Moderator
Reaction score
231
>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].
 

Sevion

The DIY Ninja
Reaction score
413
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.

      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