tooltiperror
Super Moderator
- Reaction score
- 232
Of course.
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()
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
To be honest I can't follow your code. There simply isn't enough of it there to clearly trace everything you are doing, so I can't help you unless you post all the relevant code to your example.What am I doing wrong?
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
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
//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
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
method registerTrigger takes trigger t returns nothing
call TriggerRegisterVariableEvent(t,SCOPE_PRIVATE+"q",EQUAL,this)
endmethod
method fire takes nothing returns nothing
set q=0
set q=this
call TriggerEvaluate(e[this])
endmethod