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 The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      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