Trying to learn to use AIDS and Event ?!

Komaqtion

You can change this now in User CP.
Reaction score
469
Hi!

Ok, I don't really know why but I'm having a really hard time learning both of there :(

I'm now, just because I saw the thread which needed this, trying to make the events which will detect when a unit comes within X range of an item, or when an item comes within X range of unit (I have these two because you might want to use a specific unit or item...)

Ok, so I haven't gotten very far, but I'm just wondering if I've done anything correct so far... :S

JASS:
library IIROU requires Event, AIDS

    globals
        private constant real PERIOD = 0.5
    endglobals
    
    globals
        private constant integer ITEM_EVENT_ITEM_COMES_IN_RANGE = 1
        private constant integer ITEM_EVENT_UNIT_COMES_IN_RANGE = 2
    endglobals
    
    globals
        private group g = CreateGroup()
        private group enum = CreateGroup()
        private Event e
    endglobals
    
    struct ItemEvents
    
        //! runtextmacro AIDS()
        
        integer event
        unit u
        item i
        
        private static method Enum_Actions takes nothing returns nothing
            
        endmethod
    
        private static method FireEvents takes nothing returns nothing
            call ForGroup( g, function thistype.Enum_Actions )
        endmethod
        
        private static method AIDS_onInit takes nothing returns nothing
            set e = Event.create()
            
            call TimerStart( CreateTimer(), PERIOD, true, function thistype.FireEvents )
        endmethod
        
        static method TriggerRegisterUnitInItemRange takes trigger whichTrigger, integer whichEvent, item whichItem, boolexpr filter returns thistype
            local thistype this = thistype.allocate()
            
            call e.register( whichTrigger )
            set this.event = whichEvent
            
            return this
        endmethod
        
        static method TriggerRegisterItemInUnitRange takes trigger whichTrigger, integer whichEvent, unit whichUnit, boolexpr filter returns thistype
            local thistype this = thistype.allocate()
            
            call e.register( whichTrigger )
            call GroupAddUnit( g, whichUnit )
            
            set this.event = whichEvent
            
            return this
        endmethod
        
    endstruct
    
    /*function TriggerRegisterItemInUnitRange takes trigger whichTrigger, integer whichEvent, unit whichUnit, boolexpr filter returns nothing
            call e.register( whichTrigger )
            call GroupAddUnit( g, whichUnit )
            
            set ItemEvents( GetUnitId( whichUnit ) ).event = whichEvent
    endfunction*/
    
endlibrary


Ok, so right now I just have ( I hope :S) so that when you register the event you'll add the unit ( This example is for "TriggerRegisterItemInUnitRange" ) to a group which will keep track of which units are registered...
Then, the periodic timer will pick each unit in that group each PERIOD ( Isn't doing it now, but I hope to make it XD ) and check if they have an item near it ( I also need to store the range in their own struct, right... ? ) and if they have, fire their triggers :D

Is this (Basically) what I have now ? :S
 

Komaqtion

You can change this now in User CP.
Reaction score
469
I have only two, don't I ?

But, yeah :D Thanks ! ;)

(Just a question, do you understand what I want from the information I gave ? :S)
 

Jesus4Lyf

Good Idea™
Reaction score
397
>I have these two because you might want to use a specific unit or item...
Shouldn't matter.

I would make one Event, for when any item comes within X range of any unit, where X is a constant. You can then filter in the trig for what unit/item or whatever.

Events cannot have parameters, like "comes within ? range of a unit". It must be "comes within 500 range of a unit", for example.

It is possible to make this system with O(1) complexity by placing dummy units on the items and registering unit comes in range events. ;)
You must also then fire the event when the item first spawns, probably.

So the easiest way to do it is unit comes within range of item. You'd have to attach, to the dummy unit, the item, and attach to the item, the dummy unit... I was thinking about this because I was thinking I should make an AIDS for items type thing, AIDS structs for items could be sweet. :D

'Til then, hashtables or Azlier's IDEA system or something, I guess. :thup:
 

SerraAvenger

Cuz I can
Reaction score
234
So the easiest way to do it is unit comes within range of item. You'd have to attach, to the dummy unit, the item, and attach to the item, the dummy unit... I was thinking about this because I was thinking I should make an AIDS for items type thing, AIDS structs for items could be sweet. :D

I like rects better. Unit in range events need attaching to triggers, which can be quite messy when using structs (thanks to trigger executes/evaluates)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top