Snippet Event

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.
 
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?
 
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
 
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
 
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
 
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
 
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
 
Hey guys, let's break maps using the optimizer!
 
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.
  • Varine Varine:
    A probate is usually done with a will, yes? If so I am sorry for your loss
    +1
  • The Helper The Helper:
    Yeah Tom, me too sorry for your loss buddy my mom told me she finds out her olds friend died from Google searching them. She had not talked to one of her old friends in a year and found out she died from Google. Also another one in the same session. RIP all of them my sincere condolences Tom
    +1
  • Varine Varine:
    We have some elderly guests that regularly come hang out at the bar at the end of the night, and every once in a while we don't see someone for a few weeks and then someone shows up with their obituary.
  • Varine Varine:
    We usually let them do their memorials there in the morning if they want to and I'll make them some snacks and drinks. There was one guy named Tom that came in like every night and would sit by himself and get a bunch of soup and a glass of wine. idk why but he LOVED our fucking soup, like he would order a fucking quart of it at a time and would always get so sad when we stop doing it for the summer.
    +1
  • Varine Varine:
    But he also loved our calamari, which is another thing I hate but it sells super well so I can't change it. There was one day he came in and was asking me how to make it, because he tried to at home once in the off season when we stop running it and he really wanted it lol
  • Varine Varine:
    I think he's one of the only people I've made recipes for for free because he really wanted a broccoli cheddar, and it was like dude I don't have a recipe, it's just whatever I have, but here, this is how you do it
  • Varine Varine:
    I don't think he ever figured out how to do the calamari in a pan though, like idk how to do that either. He was afraid of the at home deep fryers though and it's like yeah, that's fair, I am too
  • Varine Varine:
    He was just such a sweet old man, we had two servers pregnant and they held a baby shower together, he was soooooo fucking excited to get to see a baby. Unfortunately he died a month or so before they were born
  • The Helper The Helper:
    So I decided to Google some people that I had not seen or heard from in a while and sure enough one of my old best friends, we had a falling out years ago but whatever, find out he died of Pancreatic Cancer in January. I have also lost a few of my closer acquaintances from growing up the last year. Getting old - people die - I kinda thought it was going to be this way a few years ago....
    +2
  • The Helper The Helper:
    Forum running super slow again
  • Ghan Ghan:
    Not really clear from the stats as to what is causing the slowness.
  • Ghan Ghan:
    We get a lot of guest traffic so it may just be the load is getting too high and not from any particular source.
  • Ghan Ghan:
    Looks like the server is maxed out on CPU.
  • Ghan Ghan:
    Oh it looks like a lot of the traffic is Silkroad Forums. That domain isn't protected by Cloudflare.
  • Ghan Ghan:
    But the old Silkroad site is still on its own server. I just had a test site set up on this server for it.
  • Ghan Ghan:
    I just disabled that test site. Let's see if that helps the load.
  • Ghan Ghan:
    Looks much better already.
  • The Helper The Helper:
    I had actually forgot about the Silkroad site. I had asked
  • The Helper The Helper:
    SD Ryoko about it and he said the couple of people left on there really like it, that was a few years ago, maybe I should check back
  • jonas jonas:
    I guess when you're getting old, and the last day of soup season draws near, you start wondering
  • jonas jonas:
    will I make it to the start of the next season? or was this the last time I'll ever have my favorite dish?
  • The Helper The Helper:
    I am doing my first Vibe Coding project. In installed the environment and tools according to instructions but it is all chat doing this for me at my direction. It is fun really and holy shit I might finish in 2 hours what it would have taken a day to in my Access and this would be an electron app complete new
  • Ghan Ghan:
    Good stuff.
  • Ghan Ghan:
    Just make sure it is secure. :)
  • The Helper The Helper:
    It will only be on internal network

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials
      Top