Snippet Event

Jesus4Lyf

Good Idea™
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
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™
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
Staff member
It needed a documentation, which it now has.
Approved. :)
 

Troll-Brain

You can change this now in User CP.
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
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
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
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
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
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
?

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
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
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™
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.
  • tom_mai78101 tom_mai78101:
    I have a GIF though
  • tom_mai78101 tom_mai78101:
    In the GIF, I've configured it so the lower the "Main Value" is, the better. I had to compress it pretty far down though.
  • tom_mai78101 tom_mai78101:
    And this is the thread with the video that shows the wall clip. https://tasvideos.org/Forum/Topics/23453
    +2
  • tom_mai78101 tom_mai78101:
    Hmm, about the Headline News, I noticed threads are being moved into the subforum (Health News, Environmental News, etc.). When that happens, the TH Forum Home page loses the articles, and instead would show old articles posted 1 or 2 weeks ago.
  • tom_mai78101 tom_mai78101:
    What do we do with the Home page?
  • Ghan Ghan:
    I added those forums to the filter for that widget.
  • tom_mai78101 tom_mai78101:
    Oh nice. They're back. Thanks.
  • tom_mai78101 tom_mai78101:
    Now I think it makes more sense for me to put news in their own subforums, without worry.
  • The Helper The Helper:
    Awesome Ghan thanks! I was purposely not moving the first 15 news articles in Headline news to the different subforums but I guess I don't have to do that now?
  • tom_mai78101 tom_mai78101:
    Question: Is there a way to remove thread redirects? It creates a copy of the moved thread and takes up space, and I am leaning towards wanting to remove them in the Headline News. But if they have an expiration date, I guess I'm fine with it.
  • The Helper The Helper:
    If you move a thread please leave a permanent redirect. You can delete any redirects after 6 months. The redirects are left to help Search Engines find the moved content.
  • tom_mai78101 tom_mai78101:
    What if you move the permanent redirect, not the thread?
  • The Helper The Helper:
    I think that works but I have not messed with it. You can delete redirects though if you have to that will not delete the original thread
  • The Helper The Helper:
    if a redirect ends up in the same forum as the post it goes to though I think the redirect drops or fails or something but they are not bugged out and when you are working on an indirect the original post is safe.
  • The Helper The Helper:
    Happy Early Friday :)
    +1
  • V-SNES V-SNES:
    Happy Friday :)
  • tom_mai78101 tom_mai78101:
    Fun Friday for me
  • tom_mai78101 tom_mai78101:
    Happy Fun Friday to all.
    +2
  • The Helper The Helper:
    Happy Sunday everyone!!!
  • V-SNES V-SNES:
    Happy Sunday!!!
    +1
  • jonas jonas:
    Happy monday :p
  • jonas jonas:
    Everyone hates mondays?
    +1
  • The Helper The Helper:
    Happy Tuesday!
  • jonas jonas:
    Happy belated tuesday

    Staff online

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top