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 The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • 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 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