Moderator: Moderators
//Members of struct
//Id of projectile in stack
private integer projId
//Static values -> timer and stack of projectiles
private static Projectile array projectiles
private static integer projNum = 0
// ... later on
method allocate takes nothing returns nothing // These might as well be inlined
set .projNum = .projNum + 1
set .projectiles[.projNum] = this
set .projId = .projNum
endmethod
method deallocate takes nothing returns nothing
if .projId < .projNum then // Don't bother moving the last one to it's own slot.
// Move top projectile to slot of removed
set .projectiles[.projId] = .projectiles[.projNum]
set .projectiles[.projId].projId = .projId
endif
set .projNum = .projNum - 1
endmethod
scope DamageOverTimeEX initializer init
globals
//Configurable constants....
private constant integer Rawcode = 'A000' //inlined anyway
private constant real INTERVAL = 0.25
endglobals
//Configurable values based on level -> hero abilities mainly
private constant function Duration takes integer level returns real //inlined anyway
return 5. //Constant
endfunction
private constant function Damage takes integer level returns real //inlined anyway
return 10. + 5. * level
endfunction
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == Rawcode
endfunction
private struct Data // A struct is just a bunch of arrays, in a nice simple format
unit caster
unit target
real duration
integer level
endstruct
private function Loop takes nothing returns nothing
local timer t = GetExpiredTimer()
local Data dat = Data( GetTimerData( t ) ) //Timer utils function -> get the stored integer... (typecast the integer to struct)
call UnitDamageTarget( dat.caster, dat.target, Damage( dat.level ), false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null )
//You should probably get a damage detection system and replace this ...
set dat.duration = dat.duration - INTERVAL
if dat.duration <= 0. then
call ReleaseTimer( t ) // Timer utils function -> release timer, (will also pause)
call dat.destroy() // Release struct
endif
endfunction
private function Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit target = GetSpellTargetUnit()
local timer t = NewTimer() //Timer utils function -> replacing CreateTimer()
local Data dat = Data.create() //Allocate a struct
local integer level = GetUnitAbilityLevel( caster, Rawcode )
set dat.caster = caster
set dat.target = target
set dat.duration = Duration( level )
set dat.level = level
call SetTimerData( t, integer( dat ) ) //Timer utils function -> store integer to the timer (typecast struct to integer... don't have to do this)
call TimerStart( t, INTERVAL, true, function Loop )
set caster = null
set target = null
// Do not have to null timer, it is recycled
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT ) // This could be replaced by it's contents inlined
// Or a similair function you make yourself, it
// Doesn't really matter, as it is only run once
call TriggerAddCondition( t, Condition( function Conditions ) )
call TriggerAddAction( t, function Actions )
endfunction
endscope
library Example
// All your code goes here
private function foo takes nothing returns nothing // This function can only be used from inside this library
endfunction
function bar takes nothing returns nothing // This function can be used normally anywhere
endfunction
public function foobar takes nothing returns nothing // This function if used outside the library needs to be called by Example_foobar()
endfunction
endlibrary
library Example initializer init
function disp takes nothing returns nothing
call BJDebugMsg("EX")
endfunction
private function init takes nothing returns nothing
// this is run at map initialization
call disp()
endfunction
library Example2 initializer init needs Example
pirvate function init takes nothing returns nothing
call disp()
endfunction
Drain_Pipe wrote:couldn't they re size the model to the smallest size instead of chancing the alpha to 0? It will be like being invis, though you can select them and they won't be 100% transparent.
Users browsing this forum: No registered users and 3 guests