TriggerHappy
...
- Reaction score
- 341
PeriodicDamage
TriggerHappy187
TriggerHappy187
Information
PeriodicDamage will let you cause damage to a unit over time. All it takes is one simple function call and with the three public functions this library provides it's easy to do so. Below is a list of the public functions.
- UnitDamageTimedEx This function allows you to specify every option you would need for damaging a unit, including weapontype, damagetype and so on. Use this function if you have specific needs for how a unit should be damaged.
- UnitDamageTimed This has less parameters than the one above but it is easier to use.
- UnitDamageTimedSimple The easiest of all of the functions. This function doesn't require you to specify an attacker which is useful if you just want to damage a unit without another unit getting the experience or whatever.
- GetLasCreatedPeriodicDamage Returns the last registered damagetimed struct.
- DestroyPeriodicDamage Removes an instance of periodic damage, which means that nore more damage will be dealt to the unit.
- SetTimedDamageValue Changes the damage dealt to a unit under the effect of PeriodicDamage.
- SetTimedDamagePeriod Changes how often the unit is damaged.
- SetPeriodicDamageEffect Creates an effect on the unit each time he is damaged.
Requirements
- JassHelper (Comes with JassNewGenPack)
- TimerUtils
System Code
JASS:
//========================================================================================+
// _____ |
//| ___ \ (_) | |(_) |
//| |_/ /___ _ __ _ ___ __| | _ ___ |
//| __// _ \| '__|| | / _ \ / _` || | / __| |
//| | | __/| | | || (_) || (_| || || (__ |
//\_| \___||_| |_| \___/ \__,_||_| \___| |
// ______ |
// | _ \ By TriggerHappy187 Version 1.2 |
// | | | | __ _ _ __ ___ __ _ __ _ ___ |
// | | | |/ _` || '_ ` _ \ / _` | / _` | / _ \ |
// | |/ /| (_| || | | | | || (_| || (_| || __/ |
// |___/ \__,_||_| |_| |_| \__,_| \__, | \___| |
// __/ | |
// |___/ |
// |
//+=======================================================================================+
// |
// |
// What is PeriodicDamage? |
// ^^^^^^^^^^^^^^^^^^^^^^^ |
// PeriodicDamage will let you cause damage to a unit over time. |
// All it takes is one simple function call. These function calls |
// will be explained below. |
// |
// |
// Public Functions |
// ^^^^^^^^^^^^^^^^^^^^^^^ |
// UnitDamageTimedEx |
// This function allows you to specify every option you would need |
// for damaging a unit, including weapontype, damagetype and so on. |
// Use this function if you have specific needs for how a unit should be damaged.|
// Parameters: |____________________+
// call UnitDamageTimedEx(attacker, unit, dmg, attacktype, damagetype, weapontype, timeout, times)|
// |
// UnitDamageTimed |
// This has less parameters than the one above but it is easier to use. |
// Parameters: |
// call UnitDamageTimed(attacker, unit, dmg, timeout, times) |
// |
// UnitDamageTimedSimple |
// The easiest of all of the functions. This function doesn't require you |
// to specify an attacker which is useful if you just want to damage a unit |
// without another unit getting the experience or whatever. |
// Parameters: |
// call UnitDamageTimed(unit, dmg, timeout, times) |
// |
// |
// GetLastCreatedPeriodicDamage() |
// Returns the last registered damagetimed struct. |
// |
// |
// DestroyPeriodicDamage(instance) |
// Removes an instance of periodic damage, which means that nore more damage |
// will be dealt to the unit. |
// |
// |
// SetPeriodicDamageValue(instance, damage) |
// Changes the damage dealt to a unit under the effect of PeriodicDamage. |
// |
// |
// SetPeriodicDamagePeriod(instance, period) |
// Changes how often the unit is damaged. |
// |
// |
// SetPeriodicDamageEffect(instance, effectmodel, attachmentpount) |
// Creates an effect on the unit each time he is damaged. |
// |
// |
// UnitDamagePointTimed |
// Damages all units within range of the given coordinates |
// |
// Credits/Requirements |
// ^^^^^^^^^^^^^^^^^^^^^^^ |
// * JassHelper (Comes with JassNewGenPack) |
// * TimerUtils |
// |
//=============================================================================================================+
library PeriodicDamage initializer onInit requires TimerUtils
globals // Configurables
private constant integer DUMMY = 039;hfoo039; // Any random unit-type (with no shadow)
private constant integer DEFAULT_PLAYER = PLAYER_NEUTRAL_PASSIVE
private constant attacktype DEFAULT_AT = ATTACK_TYPE_NORMAL
private constant damagetype DEFAULT_DT = DAMAGE_TYPE_NORMAL
private constant weapontype DEFAULT_WT = WEAPON_TYPE_WHOKNOWS
endglobals
private keyword damagetimed
globals // Don't modify below this line.
damagetimed lastCreatedPeriodicDamage = 0
private group GROUP=CreateGroup()
endglobals
struct damagetimed
unit u
unit attacker
integer times
integer c = 0
attacktype at
damagetype dt
weapontype wt
real dmg
timer t
string fx = ""
string attach = ""
static unit dummy
static method callback takes nothing returns nothing
local damagetimed d = GetTimerData(GetExpiredTimer())
call UnitDamageTarget(d.attacker, d.u, d.dmg, true, false, d.at, d.dt, d.wt)
if d.fx != "" and d.attach != "" then
call DestroyEffect(AddSpecialEffectTarget(d.fx, d.u, d.attach))
endif
set d.c = d.c + 1
if d.c == d.times then
call ReleaseTimer(d.t)
call d.destroy()
endif
endmethod
method setDamage takes real amount returns nothing
set this.dmg = amount
endmethod
method setEffect takes string fx, string attachpoint returns nothing
set this.fx = fx
set this.attach = attachpoint
endmethod
method setPeriod takes real period returns nothing
call PauseTimer(this.t)
call TimerStart(this.t, period, true, function damagetimed.callback)
endmethod
static method last takes nothing returns damagetimed
return lastCreatedPeriodicDamage
endmethod
static method create takes unit b, unit u, real a, attacktype at, damagetype dt, weapontype wt, real period, integer times returns damagetimed
local damagetimed d = damagetimed.allocate()
set d.u = u
set d.attacker = b
set d.times = times
set d.at = at
set d.wt = wt
set d.dt = dt
set d.dmg = a
set d.t = NewTimer()
call SetTimerData(d.t, d)
call TimerStart(d.t, period, true, function damagetimed.callback)
set lastCreatedPeriodicDamage = d
return d
endmethod
endstruct
function UnitDamageTimedEx takes unit b, unit u, real a, attacktype at, damagetype dt, weapontype wt, real period, integer duration returns damagetimed
return damagetimed.create(b, u, a, at, dt, wt, period, duration)
endfunction
function UnitDamageTimed takes unit attacker, unit u, real dmg, real period, integer duration returns damagetimed
return damagetimed.create(attacker, u, dmg, DEFAULT_AT, DEFAULT_DT, DEFAULT_WT, period, duration)
endfunction
function UnitDamageTimedSimple takes unit u, real dmg, real period, integer duration returns damagetimed
return damagetimed.create(damagetimed.dummy, u, dmg, DEFAULT_AT, DEFAULT_DT, DEFAULT_WT, period, duration)
endfunction
function UnitDamagePointTimed takes real x, real y, real radius, filterfunc filter, real dmg, real period, integer duration returns nothing
local unit u
call GroupEnumUnitsInRange(GROUP, x, y, radius, filter)
loop
set u = FirstOfGroup(GROUP)
exitwhen u == null
call damagetimed.create(damagetimed.dummy, u, dmg, DEFAULT_AT, DEFAULT_DT, DEFAULT_WT, period, duration)
endloop
endfunction
function DestroyPeriodicDamage takes damagetimed d returns nothing
call ReleaseTimer(d.t)
call d.destroy()
endfunction
function SetPeriodicDamageValue takes damagetimed d, real dmg returns nothing
set d.dmg = dmg
endfunction
function SetPeriodicDamageEffect takes damagetimed d, string fx, string attachpoint returns nothing
set d.fx = fx
set d.attach = attachpoint
endfunction
function SetPeriodicDamagePeriod takes damagetimed d, real period returns nothing
call PauseTimer(d.t)
call TimerStart(d.t, period, true, function damagetimed.callback)
endfunction
function GetLastCreatedPeriodicDamage takes nothing returns damagetimed
return lastCreatedPeriodicDamage
endfunction
private function onInit takes nothing returns nothing
set damagetimed.dummy = CreateUnit(Player(13), DUMMY, 0, 0, 0)
call SetUnitScale(damagetimed.dummy, .01, .01, .01)
call PauseUnit(damagetimed.dummy, true)
call UnitAddAbility(damagetimed.dummy, 039;Aloc039;)
call SetUnitOwner(damagetimed.dummy, Player(DEFAULT_PLAYER), false)
endfunction
endlibrary
For those of you who want to know how to use it.
JASS:
scope PDUsage initializer onInit
private function Actions takes nothing returns nothing
local unit tobeattacked = CreateUnit(Player(0), 039;hfoo039;, 0, 0, 0) // The unit to be damaged
local real dmg = 100 // how much damage
local real period = 1. // how often
local integer times = 3 // how many times
call UnitDamageTimedSimple(tobeattacked, dmg, period, times) // the unit will be dealt 300dmg over 3 seconds
set tobeattacked = null // clear leaks
endfunction
//===========================================================================
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEvent(t, 0.00, false)
call TriggerAddAction(t, function Actions)
endfunction
endscope