Snippet Event

tooltiperror

Super Moderator
Reaction score
231
No idea, I don't see a readme or anything in the JassHelper folder, other than the LICENSE file.

Edit: Figured it out, updating now.
 

dudeim

New Member
Reaction score
22
Hey I have a little problem with attaching a struct to an event using EventReg
here is what I do:

JASS:

set t.i = 5 //just a simple integer var in the struct that I set to 5 for testing purpose
call SetEventRegData(t.er,t) //t.er is the EventReg in the struct and t is the structs var
call OnEvent.fire()

Now this is what I use to obtain the struct in the trigger that goes when the event fires
JASS:

scope test initializer tes

private function go takes nothing returns nothing
local TestStruct t = GetEventRegData(GetTriggeringEventReg()) //I think this line is wrong cus even when I do "integer i = 57" in the struct var list and leave the t.i=5 line out it says 0
    call BJDebugMsg("The integer is [" + I2S(t.i) + "]" //this displays: The Integer is [0]
endfunction

private function tes takes nothing returns nothing
local trigger t = CreateTrigger()
    call TestStruct.registerEvent(t) //teststruct is the struct I used for testing how this all works, registerEvent(t) simply registers the event to this trigger
    call TriggerAddAction(t,function go)
endfunction
endscope


What am I doing wrong?
 

dudeim

New Member
Reaction score
22
Well this was a quick example I made, but I'll give you the full code (it's a damage and crit detection system trying to expand my skills):
(There are a few structs like Unit and Playor, Unit refers to a unit's struct and Playor refers to a players struct)
system
JASS:
library DDamage requires AIDS, ZTS, Event, UnitData

globals
    Event OnDamage
    Event OnCrit
    
    boolean damageEventEnabled = true
    boolean critEventEnabled = true
    
    integer LastEventDamageIndex
//    DDamage LastDamageEvent
    
    constant integer NORMAL_DAMAGE = 0
    constant integer SPELL_DAMAGE = 1
    constant integer PURE_DAMAGE = 2
    constant integer NORMAL_DAMAGE_JASS = 3
    constant integer INPUTNAMEHERE_DAMAGE = 4
endglobals

//enable and disable the events
function enableDamage takes nothing returns nothing
        set damageEventEnabled = true
endfunction

function disableDamage takes nothing returns nothing
        set damageEventEnabled = false
endfunction

function enableCrit takes nothing returns nothing
        set critEventEnabled = true
endfunction

function disableCrit takes nothing returns nothing
        set critEventEnabled = false
endfunction

struct DDamage
/*    private boolean damageEnabled = true
    private boolean critEnabled = true */
    unit target
    real damage
    boolean crit
    unit source
    real realdamage
    real threat
    real dmgmultiplier = 1.0
    integer dtype = NORMAL_DAMAGE
    EventReg er
    integer i = 67
    
    
    //global methods like the unit used in the event
    
    method getTargetUnit takes nothing returns unit
        return .target
    endmethod
    
    method getSourceUnit takes nothing returns unit
        return .source
    endmethod
    
    method getTarget takes nothing returns Unit
        return Unit(GetUnitId(.target))
    endmethod
    
    method getSource takes nothing returns Unit
        return Unit(GetUnitId(.target))
    endmethod
    
    method getTargetOwner takes nothing returns Playor
        return Playor(GetPlayerId(GetOwningPlayer(.target)))
    endmethod
    
    method getSourceOwner takes nothing returns Playor
        return Playor(GetPlayerId(GetOwningPlayer(.target)))
    endmethod
    
    //the Damage and Crit Methods (You can use all these methods for both)
    
    //dunno if everything resets it's a just incase
    private method onDestroy takes nothing returns nothing
        set .dtype = NORMAL_DAMAGE
        set .target = null
        set .damage = 0
        set .crit = false
        set .threat = 0
        set .dmgmultiplier = 1.0
        set .er = 0
        set .source = null
    endmethod
    //creating the events
    private static method onInit takes nothing returns nothing
        set OnDamage = Event.create()
        set OnCrit = Event.create()
    endmethod
    //you can check using this if the damageevent is enabled
    method isDamageEnabled takes nothing returns boolean
        return damageEventEnabled
    endmethod
    //register the event damage using this                           
    static method registerDamage takes trigger whichtrigger returns nothing
        call OnDamage.register(whichtrigger)
    endmethod    
    //unregister the event damage using this
    static method unregisterDamage takes trigger whichtrigger returns nothing
        call OnDamage.unregister(whichtrigger)
    endmethod
    //enable the damage event for a specific instance
    //check if the crit event is enabled
    method isCritEnabled takes nothing returns boolean
        return critEventEnabled
    endmethod
    //register the crit event
    static method registerCrit takes trigger whichtrigger returns nothing
        call OnCrit.register(whichtrigger)
    endmethod    
    //unregister the crit event
    static method unregisterCrit takes trigger whichtrigger returns nothing
        call OnCrit.unregister(whichtrigger)
    endmethod
    //enables the crit event for a specific instance
    //
    method getDamageMultiplier takes nothing returns real
        return .dmgmultiplier
    endmethod
    
    method setDamageMultiplier takes real multiplier returns nothing
        set .dmgmultiplier = multiplier
    endmethod
    
    method getDamage takes nothing returns real
        return .damage
    endmethod
    
    method isCrit takes nothing returns boolean
        return .crit
    endmethod
    
    method getRealDamage takes nothing returns real
        return .realdamage
    endmethod
    
    method getThreat takes nothing returns real
        return .threat
    endmethod
    
    method getType takes nothing returns integer
        return .dtype
    endmethod
    
    method isNormal takes nothing returns boolean
        if .dtype == NORMAL_DAMAGE then
            return true
        endif
        return false
    endmethod
    
    method isJass takes nothing returns boolean
        if .dtype == NORMAL_DAMAGE_JASS then
            return true
        endif
        return false
    endmethod
    
    method isNormalJass takes nothing returns boolean
        return .isJass()
    endmethod
    
    method isSpell takes nothing returns boolean
        if .dtype == SPELL_DAMAGE then
            return true
        endif
        return false
    endmethod
    
    method isPure takes nothing returns boolean
        if .dtype == PURE_DAMAGE then
            return true
        endif
        return false
    endmethod
    
 /*   method isINPUTNAMEHERE takes nothing returns boolean
        if .dtype == INPUTNAMEHERE_DAMAGE then
            return true
        endif
        return false
    endmethod */
    
    method doDamage takes unit source, unit target, real damage, boolean applythreat, real threatbonus, real critchance, real critmultiplier returns nothing
        set .damage = damage
        set .source = source
        set .target = target
        call .normaldamage(critchance,critmultiplier,applythreat,threatbonus)
    endmethod
    
    method doSpellDamage takes unit source, unit target, real damage, boolean applythreat, real threatbonus, real critchance, real critmultiplier returns nothing
        set .damage = damage
        set .source = source
        set .target = target
        call .spelldamage(critchance,critmultiplier,applythreat,threatbonus)
    endmethod
    
        method doPureDamage takes unit source, unit target, real damage, boolean applythreat, real threatbonus, real critchance, real critmultiplier returns nothing
        set .damage = damage
        set .source = source
        set .target = target
        call .puredamage(critchance,critmultiplier,applythreat,threatbonus)
    endmethod
    
    method normaldamage takes real critchance, real critmultiplier, boolean applythreat, real threatbonus returns nothing
        local real rand = GetRandomReal(0,100)
        local Unit u = Unit(GetUnitId(.source))
            set .dtype = NORMAL_DAMAGE_JASS
            if critchance > rand then
                if critEventEnabled == true then
                    call OnCrit.fire()
                    set .crit = true
                endif
                set .damage = .damage * critmultiplier
            endif
             call UnitDamageTarget(.source,.target,.damage,false,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
            if applythreat == true then
                set .threat = .threat * u.getThreatMultiplier() + threatbonus
                call ZTS_ModifyThreat(.source, .target, .threat, true)
            endif    
        call .destroy()
    endmethod
    
    method spelldamage takes real critchance, real critmultiplier, boolean applythreat, real threatbonus returns nothing
        local real rand = GetRandomReal(0,100)
        local Unit u = Unit(GetUnitId(.source))
            set .dtype = SPELL_DAMAGE
            if critchance > rand then
                if critEventEnabled == true then
                    call OnCrit.fire()
                    set .crit = true
                endif
                set .damage = .damage * critmultiplier
            endif
            call UnitDamageTarget(.source,.target,.damage,false,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_UNIVERSAL,WEAPON_TYPE_WHOKNOWS)
            if applythreat == true then
                set .threat = .threat * u.getThreatMultiplier() + threatbonus
                call ZTS_ModifyThreat(.source, .target, .threat, true)
            endif 
        call .destroy()    
    endmethod
    
    method puredamage takes real critchance, real critmultiplier, boolean applythreat, real threatbonus returns nothing
        local real rand = GetRandomReal(0,100)
        local Unit u = Unit(GetUnitId(.source))
            set .dtype = PURE_DAMAGE
            if critchance > rand then
                if critEventEnabled == true then
                    call OnCrit.fire()
                    set .crit = true
                endif
                set .damage = .damage * critmultiplier
            endif
            if GetWidgetLife(.source) > .damage then
                call SetWidgetLife(.source,GetWidgetLife(.source)-damage)
                if damageEventEnabled == true then
                    call OnDamage.fire()
                endif
            else    
                call SetWidgetLife(.source,GetWidgetLife(.source)-damage+1)
                call UnitDamageTarget(.source,.target,.damage,false,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_UNIVERSAL,WEAPON_TYPE_WHOKNOWS)
            endif
            if applythreat == true then
                set .threat = .threat * u.getThreatMultiplier() + threatbonus
                call ZTS_ModifyThreat(.source, .target, .threat, true)
            endif    
        call .destroy()    
    endmethod
    
     static method onDamage takes nothing returns boolean
        local DDamage d = DDamage.create()
        local unit un = GetEventDamageSource()
        local Unit u = Unit.create(un)
        local real dmg = GetEventDamage()
     //       set d.i = 5  */
        if damageEventEnabled == true and dmg != 0 then
            set d.damage = dmg
            set d.target = GetTriggerUnit()
            set d.source = un
            set d.realdamage = dmg
            
            set d.threat = d.damage * (u.getThreatMultiplier())
            call SetEventRegData(d.er,d)
            call SetWidgetLife(d.target,GetWidgetLife(d.target)+dmg)
            call OnDamage.fire()
        endif
        set d = GetEventRegData(d.er)
      //  set LastDamageEvent = d
        
        
        return false
    endmethod
    
  /*  static method CCreate takes integer index returns DDamage
        local DDamage d = DDamage(index)
        return d
    endmethod */

endstruct


//I copied this from your DD system
private struct Detect extends array
        //! runtextmacro AIDS()
        
        private static conditionfunc COND
        private trigger t
        
        private method AIDS_onCreate takes nothing returns nothing
            set .t=CreateTrigger()
            call TriggerAddCondition(.t,.COND)
            call TriggerRegisterUnitEvent(.t,.unit,EVENT_UNIT_DAMAGED)
        endmethod
        
        private method AIDS_onDestroy takes nothing returns nothing
            call DestroyTrigger(.t)
        endmethod
        
        private static method AIDS_onInit takes nothing returns nothing
            set .COND=Condition(function DDamage.onDamage)
        endmethod
    endstruct

endlibrary

function to check if it works
JASS:
scope test initializer tes

private function go takes nothing returns nothing
//local Event evs = ev.GetTriggeringEventReg
local DDamage d = GetEventRegData(GetTriggeringEventReg())

    call BJDebugMsg("The integer is: " + I2S(d.i)) //this displays The integer is: 0


endfunction

private function crit takes nothing returns nothing
    call BJDebugMsg("A crit occured")
endfunction

private function tes takes nothing returns nothing
local trigger t = CreateTrigger()
    call DDamage.registerDamage(t)
    call TriggerAddAction(t,function go)
    set t = CreateTrigger()
    call DDamage.registerCrit(t)
    call TriggerAddAction(t,function crit)
    
endfunction

endscope

The code is probably really messy I first wanted to get the main things done before cleaning up:p
 

dudeim

New Member
Reaction score
22
In the onDamage method I use this to set the data

call SetEventRegData(d.er,d)

Shouldn't that work?

Also what do you mean by the last line? Could you give me a little example of it:p
 

dudeim

New Member
Reaction score
22
Hmmmm maybe I got it all wrong from the start, but what I'm trying to do is bind a struct's instance to a specific instance of the event so I can retrieve the values from the specific struct's instance when the event fires. (so I can get the damage dealt and all other values at the time the event fires)
Ex:
JASS:
//I got some random struct set up and an event etc..
function bla ....
//some instance of the struct is created here lets say number 276 and when this reruns there is a new instance 277
//some values I set in the structs instance
endfunction

//here this function runs when the event I set up before fires
function run ...
//here I want to retrieve the values of the structs instance number 276, when the event fires first, not 277, I want the values from 277 when it fires for instance 277
//I hope this makes it a little bit clearer
//I left most things about but imagine I made them (the event,struct,the function to trigger this trigger, which is linked to the event created etc..)
endfunction
 

dudeim

New Member
Reaction score
22
Yep like that only can I still set values to the struct stored in the EventReg?
Like when I check if I need to fire the event or not?

JASS:
function fireevent takes.....
local mystruct m = //dunno what goes here then don't think MyStruct.create works here in this case as it's already created?
if /* something for ex. dmg != 0 */ then
//and here I still want to do stuff with the struct
set m.i = GetRandomInt(1,100) //some random integer that's on the struct as example so in the later trigger actions I can retrieve the correct random value chosen here
call event.fire()
endif
 

Nestharus

o-o
Reaction score
84
Yea, I just thought you should know that I think this is done pretty badly for trigger events-
JASS:

method registerTrigger takes trigger t returns nothing
        call TriggerRegisterVariableEvent(t,SCOPE_PRIVATE+"q",EQUAL,this)
endmethod


Turning the firing method into this-
JASS:

method fire takes nothing returns nothing
        set q=0
        set q=this
        call TriggerEvaluate(e[this])
endmethod



And ofc, the variable event firing is much, much, much, much faster than what you are doing right now.


You managed to turn like a 24 line script into a 100 line script
 

tooltiperror

Super Moderator
Reaction score
231
Hey guys, let's break maps using the optimizer!
 

Magthridon96

Member
Reaction score
2
Sorry for the bump, but Frotty is on the verge of creating a new optimizer (The Froptimizer)
Nestharus' Event is perfect. I don't think it should be deprecated only because Vexorian's
Failtimizer breaks NATIVE warcraft III features.
Plus, TriggerRegisterVariableEvent only breaks with concatenation.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • 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 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