gref
New Member
- Reaction score
- 33
Attack Detection 1.10
No current versions are stable. Please wait to use this in your map until a stable version has been released.
System Description:
An Attack Detection system is system that triggers, for all units, when they take damage, depending on whether that damage was caused via a spell or an attack, a predefined action. The purpose of the system is to make it as simple as possible to detect and respond to damage events, as it is for all generic events.
Most recent update: January 10th 2008.
GUI: 1.10b: Removed the need for 3 global variables.
Jass: 1.10c: ExecuteFunc use changed to trigger action use. Syntax errors will occur on compile now rather than in game.
Changelog
Screenshots:
System Code:
No current versions are stable. Please wait to use this in your map until a stable version has been released.
System Description:
An Attack Detection system is system that triggers, for all units, when they take damage, depending on whether that damage was caused via a spell or an attack, a predefined action. The purpose of the system is to make it as simple as possible to detect and respond to damage events, as it is for all generic events.
Most recent update: January 10th 2008.
GUI: 1.10b: Removed the need for 3 global variables.
Jass: 1.10c: ExecuteFunc use changed to trigger action use. Syntax errors will occur on compile now rather than in game.
Changelog
Version 1.00:
-Changed to PUI from CSCache- More user friendliness/safety as a result
-Added more demo items
-Added shop to get items from in game
-File size is halved
Version 1.01:
-Added support for excluding dummy units from system. Slight performance increase, has no effect on system behaviour as dummy units do not take damage.
Version 1.10
-Removed everyones hands from my library
-Added support for GUI
-Added ExecuteFunc for Jass
Version 1.10b Jass
-Added an important level of data abstraction for Jass users
Version 1.10b GUI
-Removed the need for 3 Global variables, making initialization simpler.
Version 1.10c Jass
-Change ExecuteFunc use to TriggerExecute, allowing syntaxing, and removing multiple-thread abuse.
-Changed to PUI from CSCache- More user friendliness/safety as a result
-Added more demo items
-Added shop to get items from in game
-File size is halved
Version 1.01:
-Added support for excluding dummy units from system. Slight performance increase, has no effect on system behaviour as dummy units do not take damage.
Version 1.10
-Removed everyones hands from my library
-Added support for GUI
-Added ExecuteFunc for Jass
Version 1.10b Jass
-Added an important level of data abstraction for Jass users
Version 1.10b GUI
-Removed the need for 3 Global variables, making initialization simpler.
Version 1.10c Jass
-Change ExecuteFunc use to TriggerExecute, allowing syntaxing, and removing multiple-thread abuse.
Screenshots:
System Code:
Jass 1.10c
GUI 1.10b
JASS:
//====================>
// AD by gref.
//====================>
// To add functions scroll down to where it says Add Functions.
library AttackDetection initializer Init_AttackDetection requires PUI
//====================>
// Constants
//====================>
// AbilCode = the integer id of AD Ability
// BuffCode = the interger id of AD Buff
globals
private constant integer BuffCode = 039;B000039;
private constant integer AbilCode = 039;A000039;
private trigger array SpellTriggers
private trigger array AttackTriggers
private integer SpellNumber = 0
private integer AttackNumber = 0
unit AD_Attacker
unit AD_Defender
real AD_Damage
private integer array Dummys
private integer DummyNumber = 0
endglobals
//====================>
// Data types
//====================>
struct AD
trigger t
triggeraction ta
unit u
private static AD array THIS
static method Get takes unit whichUnit returns AD
local integer pui = GetUnitIndex(whichUnit)
if .THIS[pui]==null then
set .THIS[pui] = AD.allocate()
endif
return .THIS[pui]
endmethod
endstruct
//====================>
// User Editted Functions
//====================>
function AD_AddDummy takes integer id returns nothing
set Dummys[DummyNumber] = id
set DummyNumber = DummyNumber + 1
endfunction
function AD_AddFunction takes code userFunc, boolean attack returns nothing
if(attack == true) then
set AttackTriggers[AttackNumber] = CreateTrigger()
call TriggerAddAction(AttackTriggers[AttackNumber], userFunc)
set AttackNumber = AttackNumber + 1
else
set SpellTriggers[SpellNumber] = CreateTrigger()
call TriggerAddAction(SpellTriggers[SpellNumber], userFunc)
set SpellNumber = SpellNumber + 1
endif
endfunction
private function IsUnitDummy takes integer id returns boolean
local integer i = 0
loop
exitwhen i == DummyNumber
if (id == Dummys<i>) then
return true
endif
set i = i + 1
endloop
return false
endfunction
//Add Functions in the demonstrated spaces below.
private function UnitDamaged takes nothing returns nothing
local integer i = 0
set AD_Damage = GetEventDamage()
set AD_Attacker = GetEventDamageSource()
set AD_Defender = GetTriggerUnit()
if(GetUnitAbilityLevel(GetTriggerUnit(), BuffCode) > 0) then
call UnitRemoveAbility(GetTriggerUnit(), BuffCode)
loop
exitwhen i == AttackNumber
call TriggerExecute(AttackTriggers<i>)
set i = i+1
endloop
else
loop
exitwhen i == SpellNumber
call TriggerExecute(SpellTriggers<i>)
set i = i+1
endloop
endif
endfunction
//====================>
// Initialization
//====================>
private function UnitEntersWorld takes nothing returns nothing
local unit u = GetEnteringUnit()
local AD a = AD.Get(u)
if(IsUnitDummy(GetUnitTypeId(u)) != true) then
//Clear the previous units triggers
if(a.u != null) then
call TriggerRemoveAction(a.t, a.ta)
call DestroyTrigger(a.t)
endif
//Add the new ones.
set a.u = u
set a.t = CreateTrigger()
call TriggerRegisterUnitEvent(a.t, u, EVENT_UNIT_DAMAGED)
call UnitAddAbility(u, AbilCode)
set a.ta = TriggerAddAction(a.t, function UnitDamaged)
endif
set u = null
endfunction
private function Init_AttackDetection takes nothing returns nothing
// Adds all units on the map at initilization to damage detection triggers.
local unit u
local group g = CreateGroup()
local AD a
local trigger t = CreateTrigger() //Add a trigger to make all units entering the map added.
call GroupEnumUnitsInRect(g, GetWorldBounds(), null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
set a = AD.Get(u)
//Clear the previous units triggers
if(a.u != null) then
call TriggerRemoveAction(a.t, a.ta)
call DestroyTrigger(a.t)
endif
//Add the new ones.
set a.u = u
set a.t = CreateTrigger()
call TriggerRegisterUnitEvent(a.t, u, EVENT_UNIT_DAMAGED)
call UnitAddAbility(u, AbilCode)
set a.ta = TriggerAddAction(a.t, function UnitDamaged)
call GroupRemoveUnit(g, u)
endloop
//Add units entering world trigger.
call TriggerRegisterEnterRectSimple(t, GetWorldBounds())
call TriggerAddAction(t, function UnitEntersWorld)
set u = null
set g = null
set t = null
endfunction
endlibrary</i></i></i>
GUI 1.10b
JASS:
//====================>
// AD by gref.
//====================>
// To add functions scroll down to where it says Add Functions.
library AttackDetection initializer Init_AttackDetection requires PUI
//====================>
// Constants
//====================>
// AbilCode = the integer id of AD Ability
// BuffCode = the interger id of AD Buff
globals
private constant integer BuffCode = 039;B000039;
private constant integer AbilCode = 039;A000039;
endglobals
//====================>
// Data types
//====================>
struct AD
trigger t
triggeraction ta
unit u
private static AD array THIS
static method Get takes unit whichUnit returns AD
local integer pui = GetUnitIndex(whichUnit)
if .THIS[pui]==null then
set .THIS[pui] = AD.allocate()
endif
return .THIS[pui]
endmethod
endstruct
//====================>
// User Editted Functions
//====================>
private function IsUnitDummy takes integer id returns boolean
local integer i = 0
loop
exitwhen udg_AD_Dummys<i> == null
if (id == udg_AD_Dummys<i>) then
return true
endif
set i = i + 1
endloop
return false
endfunction
//Add Functions in the demonstrated spaces below.
private function UnitDamaged takes nothing returns nothing
local integer i = 0
set udg_AD_Damage = GetEventDamage()
set udg_AD_Attacker = GetEventDamageSource()
set udg_AD_Defender = GetTriggerUnit()
if(GetUnitAbilityLevel(GetTriggerUnit(), BuffCode) > 0) then
call UnitRemoveAbility(GetTriggerUnit(), BuffCode)
loop
exitwhen udg_AD_AttackTriggers<i> == null
if(TriggerEvaluate(udg_AD_AttackTriggers<i>)) then
call TriggerExecute(udg_AD_AttackTriggers<i>)
endif
set i = i+1
endloop
else
loop
exitwhen udg_AD_SpellTriggers<i> == null
if(TriggerEvaluate(udg_AD_SpellTriggers<i>)) then
call TriggerExecute(udg_AD_SpellTriggers<i>)
endif
set i = i+1
endloop
endif
if(i == 0) then
call BJDebugMsg("Error: No AD triggers defined. Start at 0 array index.")
endif
endfunction
//====================>
// Initialization
//====================>
private function UnitEntersWorld takes nothing returns nothing
local unit u = GetEnteringUnit()
local AD a = AD.Get(u)
if(IsUnitDummy(GetUnitTypeId(u)) != true) then
//Clear the previous units triggers
if(a.u != null) then
call TriggerRemoveAction(a.t, a.ta)
call DestroyTrigger(a.t)
endif
//Add the new ones.
set a.u = u
set a.t = CreateTrigger()
call TriggerRegisterUnitEvent(a.t, u, EVENT_UNIT_DAMAGED)
call UnitAddAbility(u, AbilCode)
set a.ta = TriggerAddAction(a.t, function UnitDamaged)
endif
set u = null
endfunction
private function Init_AttackDetection takes nothing returns nothing
// Adds all units on the map at initilization to damage detection triggers.
local unit u
local group g = CreateGroup()
local AD a
local trigger t = CreateTrigger() //Add a trigger to make all units entering the map added.
call GroupEnumUnitsInRect(g, GetWorldBounds(), null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
set a = AD.Get(u)
//Clear the previous units triggers
if(a.u != null) then
call TriggerRemoveAction(a.t, a.ta)
call DestroyTrigger(a.t)
endif
//Add the new ones.
set a.u = u
set a.t = CreateTrigger()
call TriggerRegisterUnitEvent(a.t, u, EVENT_UNIT_DAMAGED)
call UnitAddAbility(u, AbilCode)
set a.ta = TriggerAddAction(a.t, function UnitDamaged)
call GroupRemoveUnit(g, u)
endloop
//Add units entering world trigger.
call TriggerRegisterEnterRectSimple(t, GetWorldBounds())
call TriggerAddAction(t, function UnitEntersWorld)
set u = null
set g = null
set t = null
endfunction
endlibrary</i></i></i></i></i></i></i></i>