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:
    Turns out it wasn't me and it wasn't E Coli, which I was sure it wasn't. But still very stressful. Do not recommend fucking with the CDC.
  • Varine Varine:
    I think the worst was the IRS. We got audited once and they show up with like guns and shit, because I guess the IRS is technically a police force?
  • Varine Varine:
    They had a gun and it was very unnerving.
  • Varine Varine:
    I looked up why and it does make sense though. I forget they are the ones that deal with like mafias and shit, and not everyone is going to be very considerate about being told they need to explain and prove where their money comes from. We'
  • Varine Varine:
    We are pretty good about it I think. Not my job, but the people that do it are pretty one top of it.
  • The Helper The Helper:
    yeah I dont like the government. I am a total libertarian and what you are describing is what I am totally against when it comes to governing
  • Varine Varine:
    I mean I don't really like the government. But I would also prefer to have one than... not have any government. Like we need to have police forces and national welfare systems, but I don't think the cop that is pulling you over for speeding is the same cop that should also be responding to active terror events.
  • The Helper The Helper:
    I am talking about federal.
  • The Helper The Helper:
    State and local elections I believe in when it comes to governing. Of course the military
  • The Helper The Helper:
    Federal should do military
  • The Helper The Helper:
    The federal government should do the military not the police. I hope Trump gets rid of the income tax
  • The Helper The Helper:
    I hold no hope of Trump getting rid of income tax though.
  • jonas jonas:
    Trump is a wildcard, but in the end, it's the republican party that makes the laws, Trump can only do exec orders
  • jonas jonas:
    I don't think the Republicans will get rid of income tax, at most lower it a little, mostly for people with 6 figures+. But that's just my opinion
  • The Helper The Helper:
    one can dream
  • Ghan Ghan:
    FairTax would be nice.
  • Ghan Ghan:
    But the electorate would have to demand it and vote people in to do it.
  • Ghan Ghan:
    Government spending, foreign policy, and the southern border are all bigger issues than the income tax right now I'd say.
  • The Helper The Helper:
    For you those are the bigger issues. Cannabis legalization and get rid of Income tax are mine.
  • Ghan Ghan:
    We have so much cannabis up here in Oklahoma. Can't go a block without running into 3 dispensaries. xD
  • The Helper The Helper:
    if the demand is there
  • jonas jonas:
    I think the biggest issue in USA is how divided the country has become
  • Ghan Ghan:
    There's a big split happening in fundamental values that is very worrisome.
  • jonas jonas:
    I think there's always been a split in values. But now there's a split in what reality is. No matter whom you ask, they think a third of the country is insane and wants to destroy the country
  • The Helper The Helper:
    pretty big split

      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