Snippet Event

Jesus4Lyf

Good Idea™
Reaction score
397
Good to see you too, Cohadar. Was starting to wonder... :p

EventReg's are the joining point of an event and a trigger. A trigger registered to an event produces an EventReg which is only used for storing data. Typecasting Events to EventRegs is a way of restricting what users can do (wouldn't want them to call chainDestroy or something).

>Just because blizzard does not have one does not...
You're right. Is there a good way to do this with O(1) complexity? Otherwise I'll just have it do the search.

I'll find time to update this once the bulk of my exams are over. I had to release this because watching Azlier trying to write it over and over again in his systems was like watching a kid cut his finger off while slicing tomatoes. =/
 

Cohadar

master of fugue
Reaction score
209
EventReg's are the joining point of an event and a trigger. A trigger registered to an event produces an EventReg which is only used for storing data. Typecasting Events to EventRegs is a way of restricting what users can do (wouldn't want them to call chainDestroy or something).
*sigh*, learn to use keyword

>Just because blizzard does not have one does not...
You're right. Is there a good way to do this with O(1) complexity? Otherwise I'll just have it do the search.
Speed is not an issue there.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Haven't added unregister trigger (yet, heh), but I've updated the documentation to make this respectable. I'm aware several resources which rely on this have already been approved, and a growing number of those submitted are using it.

If a mod would like to either approve this or let me know what needs to be done to get this approved, that would be great. :)
 

Romek

Super Moderator
Reaction score
963
It needed a documentation, which it now has.
Approved. :)
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Why do you want the Remove Event thing?

I didn't want to add it won't be O(1) but DestroyTrigger is, and can be used in its place...

Because it is the only feature which will force me to use it instead of Table.
The price is that a resource which use that can only be approved here, for me it's definitely too much if the user can't remove the custom event.

Sometimes destroy an event is useful instead of destroy and recreate the entire trigger, in case you have multiple events on a same trigger and just want to disable one.
But if you don't do it i will live with that.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Even after reading everything, I have no idea how I can create an event.

I want to create an event "Player presses a key "A") e.g...
Based off the Game - Force player to press UI key
 

Azlier

Old World Ghost
Reaction score
461
You trigger events yourself. Inside the system that operates the event, everything is done by triggers. From the outside, it looks and acts like a normal WC3 event. Except that it doesn't leak.
 

Azlier

Old World Ghost
Reaction score
461
Here's an example of a custom event. It detects when a unit enters the playable map area. Freehand, beware.

JASS:
scope EnterWorldEvent initializer Init

globals
    private Event Ev
endglobals

function TriggerRegisterEnterWorld takes trigger whichTrigger returns nothing
    call Ev.register(whichTrigger)
endfunction

private function Fire takes nothing returns nothing
    call Ev.fire()
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEnterRectSimple(t, bj_mapInitialPlayableArea) //I hate BJ's, but I'm lazy right now.
    call TriggerAddAction(t, function Fire)

    set Ev = Event.create() //Create Event
endfunction
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
TriggerRegisterEnterWorld(trig) would become the event of another trigger?

I don't understand the mechanic at all.

Ev.Register; Ev is the Event, register means that you register it to the function TriggerRegisterEnterWorld?

I also don't understand where do you set that Ev means



Could you give me an example with an action?

Like SetUnitFacing, Event: UnitFacingIsSet.. Something like that :p +rep if you do|
 

Azlier

Old World Ghost
Reaction score
461
TriggerRegisterEnterWorld will cause the trigger to fire when a unit enters the playable map area. Just like your everyday event.

An Event is just a stack of triggers that you can add to and fire. Nothing that special.

.register adds a trigger to the stack.
.fire fires every trigger in the stack.
.create creates an Event.
.destroy destroys an Event.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
?

Can you give me an example?
I really don't understand what you said. :D

How can I cause that when a unit's facing is changed by trigger, it will fire?
 

Azlier

Old World Ghost
Reaction score
461
That isn't an easy one to do. vJass' hooks aren't developed enough for that quite yet.

EDIT: Actually, they are. vJass' hooks would work fine for that.
 

Azlier

Old World Ghost
Reaction score
461
This might work. You use TriggerRegisterUnitFacingSetEvent to make a trigger fire when the native SetUnitFacing is used. Wow, thassa long function name. Oh, and this is totally untested and uncompiled. Good luck!

JASS:
library wTf initializer Init

globals
    private Event Ev
endglobals

private function Hook takes unit u, real angle returns nothing
    call Ev.fire()
endfunction

hook SetUnitFacing Hook

function TriggerRegisterUnitFacingSetEvent takes trigger t returns nothing
    call Ev.register(t)
endfunction

private function Init takes nothing returns nothing
    set Ev = Event.create()
endfunction

endlibrary
 

Jesus4Lyf

Good Idea™
Reaction score
397
You understand that "fire" fires the Event, right? This is the only time the Event will ever fire.

For example, in Warcraft let's say you have your standard unit dies event. Killing a unit fires that event! Let's say you wanted an Event to fire when a unit's mana drops below half. First, you need triggers to detect that. Then you need to fire an Event when it occurs. Notice in this example that every trigger created fires the same Event, so when a trigger is registered on that Event, it will fire when any unit's mana drops below half.
JASS:
struct ManaEvent extends array
    static Event ev // A global Event.
    private trigger t // A trigger attached to every unit through AIDS.
    
    // Runs when a unit's mana drops - the condition on every unit's trigger.
    private static method fireThings takes nothing returns boolean
        call thistype.ev.fire()
        return false
    endmethod
    
    // Runs when a unit enters the map.
    private method AIDS_onCreate takes nothing returns nothing
        set this.t=CreateTrigger()
        call TriggerRegisterUnitManaEvent(this.t,this.unit,LESS_THAN_OR_EQUAL,GetUnitState(this.unit,UNIT_STATE_MANA)/2.0)
        call TriggerAddCondition(this.t,Condition(function thistype.fireThings))
    endmethod
    
    // Runs after a unit leaves the map.
    private method AIDS_onDestroy takes nothing returns nothing
        call DestroyTrigger(this.t)
    endmethod
    
    // Runs on map initialisation.
    private static method AIDS_onInit takes nothing returns nothing
        set thistype.ev=Event.create()
    endmethod
    
    static method register takes trigger t returns nothing
        call thistype.ev.register(t)
    endmethod
    //! runtextmacro AIDS()
endstruct
// Can now call ManaEvent.register(trigger) to register drop to half mana event on a trigger.

Event/AIDS combo. :) (But this particular example won't work for units whose maximum mana changes - that can be worked around fairly easily. Hey, you could even have an Event for when its maximum mana changes, and use this to recreate the trigger. :))

Feel free to keep asking for more examples and the like.

You can make Events for all kinds of things, the condition is that you can detect when they should fire using JASS.
You also will often need to write your own event responses - but in some cases GetTriggerUnit and such will work, by picking up the unit that triggered the warcraft III event that ran the trigger that fired the Event. For example, in Damage (the native GetEventDamage() and others all work, like on a normal on damage event, because that's what the Event is fired from).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top