System Event Broadcaster

Reaction score
333
The Event Broadcaster system allows you to easily register functions to execute when a broadcast function is called. This system requires vJass.

JASS:
//! textmacro Broadcaster takes EVENT
scope $EVENT$
    globals
        private string array A
    endglobals

    public function AddAction takes string s returns nothing
        local integer i = 0

        loop
            exitwhen i>8191

            if A<i> == null then
                set A<i> = s
                exitwhen true
            endif
            
            set i=i+1
        endloop
    endfunction

    public function RemoveAction takes string s returns nothing
        local integer i = 0
        local boolean b = false

        loop
            exitwhen i&gt;8191 or A<i> == null

            if A<i> == s then
                set b = true
            endif
            
            if b then
                set A<i> = A[i+1]
            endif
            
            set i=i+1
        endloop
    endfunction

    public function Broadcast takes nothing returns nothing
        local integer i = 0

        loop
            exitwhen i&gt;8191 or A<i> == null

            call ExecuteFunc(A<i>)
            
            set i=i+1
        endloop
    endfunction
endscope
//! endtextmacro</i></i></i></i></i></i></i>


Usage details:

You must run the text macro for each different event you want. Once you have done that, you can call the 3 functions for each event.

AddAction will take a string, which must be a function name. This string will be added to an array of functions to be called when the Broadcast function runs. RemoveAction will remove a string from the function array.

Here is an example:
//! runtextmacro Broadcaster("onMapInit")

function Test1 takes nothing returns nothing
call BJDebugMsg("Test1 has run.")
endfunction

function Test2 takes nothing returns nothing
call BJDebugMsg("Test2 has run.")
endfunction
You might then have a trigger called "Run Test":
function Run_Test_Actions takes nothing returns nothing
call onMapInit_Broadcast()
endfunction

function InitTrig_Run_Test takes nothing returns nothing
call onMapInit_AddAction("Test1")
call onMapInit_AddAction("Test2")
call ExecuteFunc("Run_Test_Actions")
endfunction
This would run the 2 test functions and display their messages on the screen at map init.

Possible Usages:

The above examples have little practical use and are only there for the purpose of demonstration. To reap the full benefits, you must use this system in conjunction with complicated events.

For example, you may have a global "unit damaged" detection system, and a generic nuke which deals damage and leaves a 0.01 buff. You could detect when a unit is damaged and then run "onUnitDamaged_Broadcast".

You may have a range of items which give bonuses to spells when carried. When such an item is acquired, you might add an action to the "onUnitDamaged" broadcaster which gives a chance to deal double the damage dealt if the buff for your generic nuke is present. This function could then call "onSpellCrit_Broadcast" which may, if the casting unit has learnt a special ability, run a function which stuns the target unit.

Rather than having to load the original "unit damaged" trigger actions with "if"s and "call"s for every special spell effect you want in your map, you can add each effect separately and decide when they are eligible for execution.

Enjoy:

But make sure you report bugs and/or typos in my code/post. I have tested this system to the best of my abilities but have not been able to find any particular flaws, but that doesn't mean they are out there! Suggestions are also very welcome.
 
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

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top