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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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