- Joined
- Sep 9, 2007
- Messages
- 6,759
Update: Version 1.01 is out!
Fixed:
Notes to fixes:
Dummyfilter
Dummys will not longer trigger the system. Useful and removes cache.
RemoveUnitX
Know you can remove a unit and trigger the system first.
If you do NOT use this function
to remove the units you leak a trigger.
Hero Register Death = off
Heroes will now stay in system even after death.
KNOWN BUGS IN 1.01 (Which I fix today
while dealing damage with critical strike it can also deal again
damage with critical strike (loop).
I fix this later.
I'll attach the example map as soon as I can.
Fixed:
- Dummyfilter
- Added RemoveUnitX function
- Heroes do not longer unregister after death
Notes to fixes:
Dummyfilter
Dummys will not longer trigger the system. Useful and removes cache.
RemoveUnitX
Know you can remove a unit and trigger the system first.
If you do NOT use this function
to remove the units you leak a trigger.
Hero Register Death = off
Heroes will now stay in system even after death.
KNOWN BUGS IN 1.01 (Which I fix today
while dealing damage with critical strike it can also deal again
damage with critical strike (loop).
I fix this later.
JASS:
//######################################################################################################
//#
//#
//# § Damage Detection System §
//# by dhk_undead_lord aka Anachron
//#
//# Introduction
//#
//# -> What is system thought for?
//# - Well this system is thought to register when an unit is damaged.
//# -> What can I do with this system?
//# - You can easily modify the way the unit take damage, deal damage, etc.
//#
//#
//# How does it work?
//# - At mapstart, the function RegisterAllStartUnits will be called, and runs
//# the register function for each unit on map.
//#
//# The function RegisterUnit will create a new temporary trigger, which
//# detects when the unit takes damage. Additionally I've added the units death.
//# I'll now explain why.
//#
//# The function UnregisterUnit will remove all triggers from the unit in the
//# system at once.
//#
//#
//#
//# Function TakeDmg
//# This function includes all actions for each unit in the system.
//# When one of the registered units are attacked, those actions will be
//# runned instantly while getting damaged. Each time.
//# The Variables:
//#
//# local unit source = GetEventDamageSource()
//# This will store the source of the damage.
//#
//# local unit target = GetTriggerUnit()
//# This will store the damaged unit
//#
//# local real damage = GetEventDamage()
//# This will store the damage being dealt
//#
//# local real life = GetUnitState(target,UNIT_STATE_LIFE)
//# This will store the current life of the target
//#
//# local real rem_life = life - damage
//# This will store the life after taking damage
//#
//# local trigger t
//# This will story the current trigger in a variable, I'll explain soon why
//#
//# local boolean destroy = false
//# This will store a boolean if we need to destroy this trigger.
//#
//#
//# if source == target and damage == 0.00 then
//# set destroy = true
//# endif
//# This firstly checks if we have used the Unregister function, by dealing 0
//# damage to the unit itself.
//#
//# if damage >= 0.00 then
//# call float(GetUnitX(target),GetUnitY(target),I2S(R2I(damage)))
//# if 0.405 > rem_life then
//# set destroy = true
//# endif
//# else
//# if life <= 0.405 then
//# set destroy = true
//# endif
//# endif
//#
//# This checks if the damage is higher or equal to 0. If so, the unit took damage.
//# (Why not bigger then? Because an illusion does 0 damage, not less, not more)
//#
//# If the damage is higher or equal to 0 we know that the event MUST be that the
//# target unit is damaged (remember, we have 2 events, one : Unit is damaged, second
//# = Unit dies). But if damage is not equal to 0, we know that the unit is not dead
//# yet.
//#
//# With calling the float function we will create the damage text.
//#
//# After that, we check if the lifes of the unit are less then 0,405. If so, we can destroy
//# The current trigger, because the unit is dead after getting the damage. Remember that
//# You can save the boolean if you want to kill the trigger or not.
//#
//# Else, if the damage is less then 0, the unit might got healed. But it can also be that
//# the unit died, through the event unit dies. So we check again the current life of the unit
//#
//# if destroy == true then
//# //call DisplayTextToForce(GetPlayersAll(),"A " + GetUnitName(target) + " died, trigger
//# has been destroyed")
//# set t = GetTriggeringTrigger()
//# call DestroyTrigger(t)
//# endif
//#
//# This function will be only runned if the target unit is death after all the actions.
//# It will get the triggering trigger (because every unit has its own trigger) and destroy it
//# instantly.
//#
//# Hints, using of the DD_Damage function
//#
//# I've also added a small Damage function, which is named DD_Damage.
//# You call it with using call DD_Damage(caster,target,real,heal?).
//# If you chosen heal = true, the value will be inverted. Please do NOT modify it yet,
//# because I will advance my system with that soon.
//#
//# To register a unit, simply use RegisterUnit(unit)
//#
//# To remove an unit from game, please use the RemoveUnitX(unit)
//# function. That function will kill each trigger which has been created for damage detection
//# to the target unit.
//#
//# The CRITICAL STRIKE ability
//# Well, I've decided to intigrate the triggered critical strike, its basic but ok.
//# It'll first check if the unit does an attack, if yes, we'll check the attack spells
//#
//# if anim == "attack" or anim == "smart" then
//# call AttackFunctions(target,source,damage)
//# endif
//#
//# I think the AttackFunctions are self explaining.
//#
//#
//#
//#
//#
//# Please give credits to dhk_undead_lord (Anachron)
//# Thanks for reading
//#
//#
//#
//######################################################################################################
library DDSystemFuns
function DD_Damage takes unit caster, widget target, real amount, boolean heal returns nothing
if heal == true then
set amount = 0 - amount
endif
call UnitDamageTarget(caster,target,amount,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endfunction
endlibrary
scope DDSystem initializer Init
globals
integer dummy = '0000'
endglobals
private function Conditions takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) != dummy
endfunction
private function float takes real x, real y, string s returns nothing
local texttag t = CreateTextTag()
local real speed = 45.00
local real angle = 90.00
local real vel = TextTagSpeed2Velocity(speed)
local real xvel = vel * Cos(angle * bj_DEGTORAD)
local real yvel = vel * Sin(angle * bj_DEGTORAD)
call SetTextTagPermanent(t,false)
call SetTextTagAge(t,0.00)
call SetTextTagColor(t,95,255,50,100)
call SetTextTagFadepoint(t,0.00)
call SetTextTagLifespan(t,2.00)
call SetTextTagText(t,s,10.0 * 0.023 / 10)
call SetTextTagPos(t,x,y,90.00)
call SetTextTagVelocity(t, xvel, yvel)
set t = null
endfunction
private function AttackFunctions takes unit u, unit s, real dmg returns nothing
local integer spells_critical_chance = 0
local real spells_critical_dmg = 0.00
if u != s then
if GetUnitAbilityLevel(s,'A000') != 0 then
set spells_critical_chance = GetRandomInt(1,100)
if spells_critical_chance <= 15 then
set spells_critical_dmg = GetUnitAbilityLevel(s,'A000') * dmg
call SetUnitAnimation(s,"Attack slam")
call UnitDamageTarget(s,u,spells_critical_dmg,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endif
endif
endif
endfunction
private function TakeDmg takes nothing returns nothing
local unit source = GetEventDamageSource()
local unit target = GetTriggerUnit()
local real damage = GetEventDamage()
local real life = GetUnitState(target,UNIT_STATE_LIFE)
local real rem_life = life - damage
local trigger t
local string anim = OrderId2String(GetUnitCurrentOrder(source))
local boolean destroy = false
// Check for unit doing spells
if anim == "attack" or anim == "smart" then
call AttackFunctions(target,source,damage)
endif
if damage > 0 then
call float(GetUnitX(target),GetUnitY(target),I2S(R2I(damage)))
if 1 > rem_life then
set destroy = true
endif
else
if life <= 0.405 then
set destroy = true
endif
endif
// Now lets check if the unregister action has been used
if source == target and damage == 0.00 then
set destroy = true
endif
if destroy == true then
//call DisplayTextToForce(GetPlayersAll(),"A " + GetUnitName(target) + " has been unregistered")
set t = GetTriggeringTrigger()
call DestroyTrigger(t)
endif
set anim = null
set t = null
set source = null
set target = null
endfunction
function RegisterUnit takes unit u returns nothing
local trigger t = CreateTrigger()
//call DisplayTextToForce(GetPlayersAll(),"A Trigger has been created for the "+ GetUnitName(u))
call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DAMAGED )
if IsUnitType(u,UNIT_TYPE_HERO) == false then
call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
endif
call TriggerAddAction(t, function TakeDmg )
set u = null
set t = null
endfunction
function UnregisterUnit takes unit u returns nothing
call UnitDamageTarget(u,u,0.00,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endfunction
function RemoveUnitX takes unit u returns nothing
call UnregisterUnit(u)
call RemoveUnit(u)
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
call RegisterUnit(u)
set u = null
endfunction
private function GroupRegistration takes nothing returns nothing
local unit u = GetEnumUnit()
call RegisterUnit(u)
set u = null
endfunction
private function RegisterAllStartUnits takes nothing returns nothing
local group g= GetUnitsInRectAll(GetPlayableMapRect())
call ForGroupBJ(g, function GroupRegistration)
call DestroyGroup(g)
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger DDSystemTrg = CreateTrigger()
local trigger DDSystemStartTrg = CreateTrigger()
local region rectRegion = CreateRegion()
call RegionAddRect(rectRegion, GetWorldBounds())
call TriggerAddAction(DDSystemTrg, function Actions )
call TriggerAddCondition(DDSystemTrg,Condition(function Conditions))
call TriggerRegisterEnterRegion(DDSystemTrg, rectRegion, null)
call TriggerAddAction(DDSystemStartTrg, function RegisterAllStartUnits )
call TriggerRegisterTimerEventSingle( DDSystemStartTrg, 0.01 )
set DDSystemTrg = null
set DDSystemStartTrg = null
set rectRegion = null
endfunction
endscope
JASS:
//######################################################################################################
//#
//#
//# § Damage Detection System §
//# by dhk_undead_lord aka Anachron
//#
//# Introduction
//#
//# -> What is system thought for?
//# - Well this system is thought to register when an unit is damaged.
//# -> What can I do with this system?
//# - You can easily modify the way the unit take damage, deal damage, //# etc.
//#
//#
//# How does it work?
//# - At mapstart, the function RegisterAllStartUnits will be called, and //# runs the register function for each unit on map.
//#
//# The function RegisterUnit will create a new temporary trigger, which
//# detects when the unit takes damage. Additionally I've added the
//# units death. I'll now explain why.
//#
//# The function UnregisterUnit will remove all triggers from the unit in
//# the system at once.
//#
//#
//#
//# Function TakeDmg
//# This function includes all actions for each unit in the system.
//# When one of the registered units are attacked, those actions will be
//# runned instantly while getting damaged. Each time.
//# The Variables:
//#
//# local unit source = GetEventDamageSource()
//# This will store the source of the damage.
//#
//# local unit target = GetTriggerUnit()
//# This will store the damaged unit
//#
//# local real damage = GetEventDamage()
//# This will store the damage being dealt
//#
//# local real life = GetUnitState(target,UNIT_STATE_LIFE)
//# This will store the current life of the target
//#
//# local real rem_life = life - damage
//# This will store the life after taking damage
//#
//# local trigger t
//# This will story the current trigger in a variable, I'll explain soon why
//#
//# local boolean destroy = false
//# This will store a boolean if we need to destroy this trigger.
//#
//#
//# if source == target and damage == 0.00 then
//# set destroy = true
//# endif
//# This firstly checks if we have used the Unregister function, by
//# dealing 0 damage to the unit itself.
//#
//# if damage >= 0.00 then
//# call float(GetUnitX(target),GetUnitY(target),I2S(R2I(damage)))
//# if 0.405 > rem_life then
//# set destroy = true
//# endif
//# else
//# if life <= 0.405 then
//# set destroy = true
//# endif
//# endif
//#
//# This checks if the damage is higher or equal to 0. If so, the unit took
//# damage.(Why not bigger then? Because an illusion does 0 damage, not
//# less, not more)
//# If the damage is higher or equal to 0 we know that the event MUST
//# be that thetarget unit is damaged (remember, we have 2 events, one :
//# Unit is damaged, second = Unit dies). But if damage is not equal to 0,
//# we know that the unit is not dead
//# yet.
//#
//# With calling the float function we will create the damage text.
//#
//# After that, we check if the lifes of the unit are less then 0,405. If so,
//# we can destroy the current trigger, because the unit is dead after
//# getting the damage. Remember thatYou can save the boolean if you
//# want to kill the trigger or not.
//#
//# Else, if the damage is less then 0, the unit might got healed. But it can
//# also be that the unit died, through the event unit dies. So we check again the current life of the unit
//#
//# if destroy == true then
//# //call DisplayTextToForce(GetPlayersAll(),"A " + GetUnitName(target) + " died, trigger
//# has been destroyed")
//# set t = GetTriggeringTrigger()
//# call DestroyTrigger(t)
//# endif
//#
//# This function will be only runned if the target unit is death after all the actions.
//# It will get the triggering trigger (because every unit has its own trigger) and destroy it
//# instantly.
//#
//# Hints, using of the DD_Damage function
//#
//# I've also added a small Damage function, which is named DD_Damage.
//# You call it with using call DD_Damage(caster,target,real,heal?).
//# If you chosen heal = true, the value will be inverted. Please do NOT modify it yet,
//# because I will advance my system with that soon.
//#
//# To register a unit, simply use RegisterUnit(unit)
//#
//# To remove an unit from game, please unregister it first using the UnregisterUnit(unit)
//# function. That function will kill each trigger which has been created for damage detection
//# to the target unit.
//#
//# The CRITICAL STRIKE ability
//# Well, I've decided to intigrate the triggered critical strike, its basic but ok.
//# It'll first check if the unit does an attack, if yes, we'll check the attack spells
//#
//# if anim == "attack" or anim == "smart" then
//# call AttackFunctions(target,source,damage)
//# endif
//#
//# I think the AttackFunctions are self explaining.
//#
//#
//#
//#
//#
//# Please give credits to dhk_undead_lord (Anachron)
//# Thanks for reading
//#
//#
//#
//######################################################################################################
library DDSystemFuns
function DD_Damage takes unit caster, widget target, real amount, boolean heal returns nothing
if heal == true then
set amount = 0 - amount
endif
call UnitDamageTarget(caster,target,amount,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endfunction
endlibrary
scope DDSystem initializer Init
private function float takes real x, real y, string s returns nothing
local texttag t = CreateTextTag()
local real speed = 45.00
local real angle = 90.00
local real vel = TextTagSpeed2Velocity(speed)
local real xvel = vel * Cos(angle * bj_DEGTORAD)
local real yvel = vel * Sin(angle * bj_DEGTORAD)
call SetTextTagPermanent(t,false)
call SetTextTagAge(t,0.00)
call SetTextTagColor(t,95,255,50,100)
call SetTextTagFadepoint(t,0.00)
call SetTextTagLifespan(t,2.00)
call SetTextTagText(t,s,10.0 * 0.023 / 10)
call SetTextTagPos(t,x,y,90.00)
call SetTextTagVelocity(t, xvel, yvel)
set t = null
endfunction
private function AttackFunctions takes unit u, unit s, real dmg returns nothing
local integer spells_critical_chance = 0
local real spells_critical_dmg = 0.00
if u != s then
if GetUnitAbilityLevel(s,'A000') != 0 then
set spells_critical_chance = GetRandomInt(1,100)
if spells_critical_chance <= 15 then
set spells_critical_dmg = GetUnitAbilityLevel(s,'A000') * dmg
call SetUnitAnimation(s,"Attack slam")
call UnitDamageTarget(s,u,spells_critical_dmg,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endif
endif
endif
endfunction
private function TakeDmg takes nothing returns nothing
local unit source = GetEventDamageSource()
local unit target = GetTriggerUnit()
local real damage = GetEventDamage()
local real life = GetUnitState(target,UNIT_STATE_LIFE)
local real rem_life = life - damage
local trigger t
local string anim = OrderId2String(GetUnitCurrentOrder(source))
local boolean destroy = false
// Check for unit doing spells
if anim == "attack" or anim == "smart" then
call AttackFunctions(target,source,damage)
endif
if damage > 0 then
call float(GetUnitX(target),GetUnitY(target),I2S(R2I(damage)))
if 1 > rem_life then
set destroy = true
endif
else
if life <= 0.405 then
set destroy = true
endif
endif
// Now lets check if the unregister action has been used
if source == target and damage == 0.00 then
set destroy = true
endif
if destroy == true then
//call DisplayTextToForce(GetPlayersAll(),"A " + GetUnitName(target) + " has been unregistered")
set t = GetTriggeringTrigger()
call DestroyTrigger(t)
endif
set anim = null
set t = null
set source = null
set target = null
endfunction
function RegisterUnit takes unit u returns nothing
local trigger t = CreateTrigger()
local effect e
local real x = GetUnitX(u)
local real y = GetUnitY(u)
//call DisplayTextToForce(GetPlayersAll(),"A Trigger has been created for the "+ GetUnitName(u))
call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DAMAGED )
call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
call TriggerAddAction(t, function TakeDmg )
set e = AddSpecialEffect("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",x,y)
call DestroyEffect(e)
set e = null
set u = null
set t = null
endfunction
function UnregisterUnit takes unit u returns nothing
call UnitDamageTarget(u,u,0.00,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
call RegisterUnit(u)
set u = null
endfunction
private function GroupRegistration takes nothing returns nothing
local unit u = GetEnumUnit()
call RegisterUnit(u)
set u = null
endfunction
private function RegisterAllStartUnits takes nothing returns nothing
local group g= GetUnitsInRectAll(GetPlayableMapRect())
call ForGroupBJ(g, function GroupRegistration)
call DestroyGroup(g)
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger DDSystemTrg = CreateTrigger()
local trigger DDSystemStartTrg = CreateTrigger()
local region rectRegion = CreateRegion()
call RegionAddRect(rectRegion, GetWorldBounds())
call TriggerAddAction(DDSystemTrg, function Actions )
call TriggerRegisterEnterRegion(DDSystemTrg, rectRegion, null)
call TriggerAddAction(DDSystemStartTrg, function RegisterAllStartUnits )
call TriggerRegisterTimerEventSingle( DDSystemStartTrg, 0.01 )
set DDSystemTrg = null
set DDSystemStartTrg = null
set rectRegion = null
endfunction
endscope
Last edited: