I present to you my...
On Attack Template 1.30:
a simple system that allows you do to some great things
What does this do?
In the absence of a better method for damage detection using GUI;
This allows you leverage the event "a unit is attacked", and both efficiently and accurately, detect when the target takes damage, and deal effects to said unit.
Sounds like fun no..??
Ok then hurry up and try it out!!
Version History:
enjoy!
On Attack Template 1.30:
a simple system that allows you do to some great things
What does this do?
In the absence of a better method for damage detection using GUI;
This allows you leverage the event "a unit is attacked", and both efficiently and accurately, detect when the target takes damage, and deal effects to said unit.
Sounds like fun no..??
Ok then hurry up and try it out!!
Version History:
- 1.30 - Updated for 1.24 compatibility, removed dated CSData and CSSafety requirements, re-arranged and shorten code a bit, optimized trigger execution function, added theoretical destroytrigger() bug aversion configurable
- 1.20b - Updated to CSData and CSSafety 15.0, added in a new demo ability to showcase usage of the On_Attack_Template_Function call, Demo 3 updated slightly, few minor readme/documentation errors updated
- 1.2 - Ported to vJASS, slightly updated readme, removed demo 4 ability from test map
- 1.1 - Added greater functionality
- 1.0 - Initial Release
JASS:
library OnAttackTemplate initializer Init
//=====On Attack Template 1.30=====\\
//==Configurables==\\
globals
private constant boolean AVOID = true // Experimental method for trying to avoid destroy trigger related handle stack corruption
private constant integer CASTER = 'n000' // Rawcode of your dummy caster unit (Ctrl+d in object editor)
private hashtable HT = null // If you have a global hashtable, set it here
private constant real TIME = 2. // Duration after the attack to disregard effects
endglobals
//==NO TOUCHING PAST THIS POINT!!!==\\
//==========================================================================================
// Needed globals
globals
private boolexpr B
endglobals
// Needed struct
private struct data
unit atkr
timer t
trigger trig
string type
integer abilid
integer lvl
string order
real dam
boolean show
string func
// Maybe it works!?!?!
static method destroytrigger takes trigger trig returns nothing
call TriggerSleepAction(300.)
call DestroyTrigger(trig)
endmethod
// Clean up
method destroy takes nothing returns nothing
call DisableTrigger(.trig)
call FlushChildHashtable(HT,GetHandleId(.trig))
static if AVOID then
call data.destroytrigger.execute(trig)
else
call DestroyTrigger(.trig)
endif
endmethod
// Core of the system
static method effects takes nothing returns boolean
local data this
local unit targ
local unit dum
local texttag t
if GetTriggerEventId()!=EVENT_UNIT_DAMAGED then // Timer expired
call .destroy()
elseif GetEventDamage()>.01 then // Negligable damage
set this=LoadInteger(HT,GetHandleId(GetTriggeringTrigger()),0)
if GetEventDamageSource()!=.atkr then // Wrong damage do-er
return false
endif
set targ=GetTriggerUnit()
call DisableTrigger(.trig)
if .type=="spell" then // Spell cast
set dum = CreateUnit(GetOwningPlayer(.atkr),CASTER,GetUnitX(.atkr),GetUnitY(.atkr),0.)
call UnitAddAbility(dum,.abilid)
call UnitApplyTimedLife(dum,'BTLF',2.)
call SetUnitAbilityLevel(dum,.abilid,.lvl)
call IssueTargetOrder(dum,.order,targ)
set dum = null
elseif .type=="damage" then // Damage deal
call UnitDamageTarget(.atkr,targ,.dam,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null)
if .show then
set t = CreateTextTag()
call SetTextTagText(t, "+"+I2S(R2I(.dam))+"!", 0.025)
call SetTextTagPosUnit(t, targ,15)
call SetTextTagColor(t, 255, 0, 0, 255)
call SetTextTagVelocity(t, 0, .03)
call SetTextTagVisibility(t, true)
call SetTextTagFadepoint(t, 2.)
call SetTextTagLifespan(t, 2.)
call SetTextTagPermanent(t, false)
set t = null
endif
else // Call function
call ExecuteFunc(.func)
endif
set targ = null
endif
return false
endmethod
// Create struct
static method create takes unit target returns data
local data this=data.allocate()
set .trig=CreateTrigger()
call TriggerRegisterUnitEvent(.trig,target,EVENT_UNIT_DAMAGED)
call TriggerRegisterTimerEvent(.trig,TIME,false)
call TriggerAddCondition(.trig,B)
call SaveInteger(HT,GetHandleId(.trig),0,this)
return this
endmethod
endstruct
//==User Functions==\\
function On_Attack_Template_Function takes unit attacker, unit target, string func returns nothing
local data d = data.create(target)
set d.atkr = attacker
set d.func = func
set d.type = "function"
endfunction
function On_Attack_Template_Damage takes unit attacker, unit target, real damage, boolean show returns nothing
local data d = data.create(target)
set d.atkr = attacker
set d.dam = damage
set d.show = show
set d.type = "damage"
endfunction
function On_Attack_Template_Spell takes unit attacker, unit target, integer abil, integer lvl, string order returns nothing
local data d = data.create(target)
set d.atkr = attacker
set d.abilid = abil
set d.lvl = lvl
set d.order = order
set d.type = "spell"
endfunction
//==Initialization==\\
private function Init takes nothing returns nothing
set B=Condition(function data.effects)
if HT==null then
set HT=InitHashtable()
endif
endfunction
endlibrary
enjoy!
Attachments
-
178.7 KB Views: 1,706
-
110 KB Views: 541