• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[vJASS] Custom Event Help

Status
Not open for further replies.
Level 5
Joined
Feb 22, 2013
Messages
161
I created a simple custom event for damage detection, but I dont know how to make it accessible from other triggers as usage of like a TriggerRegister type thing for another trigger. How can I do this?

JASS:
library DamageDetection initializer DamageDetectionInit

	globals
		trigger damageEvent = CreateTrigger()
	endglobals

	function DetectDamage takes nothing returns nothing
		local unit damageSource = GetEventDamageSource()
	
		set damageSource = null
	endfunction

	function MapInit takes nothing returns nothing
		local unit enumUnit = GetEnumUnit()
	
		call TriggerRegisterUnitEvent(damageEvent, enumUnit, EVENT_UNIT_DAMAGED)
	
		set enumUnit = null
	endfunction

	function UnitEnters takes nothing returns nothing
		local unit triggerUnit = GetTriggerUnit()
	
		call TriggerRegisterUnitEvent(damageEvent, triggerUnit, EVENT_UNIT_DAMAGED)
	
		set triggerUnit = null
	endfunction

	function DamageDetectionInit takes nothing returns nothing
		local trigger unitsEnterMap = CreateTrigger()
		local region playableMap = CreateRegion()
		local group initialUnitGroup = CreateGroup()
    
	
		call GroupEnumUnitsInRect(initialUnitGroup, bj_mapInitialPlayableArea, null)
		call ForGroup(initialUnitGroup, function MapInit)
	
		call RegionAddRect(playableMap, bj_mapInitialPlayableArea)
		call TriggerRegisterEnterRegion(unitsEnterMap, playableMap, null)
		call TriggerAddAction(unitsEnterMap, function UnitEnters)
	
		call TriggerAddAction(damageEvent, function DetectDamage)
	
		call DestroyGroup(initialUnitGroup)
		set initialUnitGroup = null
	endfunction
	
endlibrary
 
You would add their function as an action to your event:
JASS:
function RegisterDamageEvent takes code c returns nothing 
    call TriggerAddAction(damageEvent, c)
endfunction

Then whenever the damageEvent trigger fires, it will fire those actions.

However, I recommend using conditions instead. You will need to put "return false" at the end of each function that is registered but they are more efficient in the end, especially when it comes to dynamic triggers:
JASS:
function RegisterDamageEvent takes code c returns nothing
    call TriggerAddCondition(damageEvent, Condition(c))
endfunction
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
I don't know if you care or not, but this

call TriggerRegisterUnitEvent(damageEvent, triggerUnit, EVENT_UNIT_DAMAGED)

returns a handle of type event

As you continue to call it, more and more of these handles are created. When a unit is removed, these handles aren't cleaned as the trigger is still valid. When the trigger is cleaned, it is theorized (not tested, but it's very probable considering the behavior of triggerconditions) that these events are cleaned.

If you were to register 10,000 units over the lifetime of a map, that would be 10,000 event handles floating around in the handle table regardless of if they are being used or not (the unit may no longer exist).

Thus, you should rebuild the trigger every once and awhile to clean up the event handles. Some people even register 1 trigger to each unit. This will generate 1 trigger handle, 1 triggercondition handle, and 1 event handle per unit vs 1 event handle per unit (3:1 ratio of leaks).

This resource was created to handle rebuilding these triggers as efficiently as possible, but it does require Unit Indexer.

http://www.hiveworkshop.com/forums/...ems-using-single-unit-events-like-dds-231167/

edit
http://www.hiveworkshop.com/forums/spells-569/dds-damage-detection-system-231238/?prev=mmr=6 is a framework that uses the above system along with 3 plugin systems to implement various behaviors commonly used with DDS resources.

These include: damage detection, damage manipulation, and damage archetype detection (magic vs physical vs code).

The code within each module is about the simplest behavior you can get (there are a few extra things for ease of use).
 
Status
Not open for further replies.
Top