Name | Type | is_array | initial_value |
//TESH.scrollpos=9
//TESH.alwaysfold=0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~ Timer32 ~~ By Jesus4Lyf ~~ Version 1.06 ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// What is Timer32?
// - Timer32 implements a fully optimised timer loop for a struct.
// - Instances can be added to the loop, which will call .periodic every
// PERIOD until .stopPeriodic() is called.
//
// =Pros=
// - Efficient.
// - Simple.
//
// =Cons=
// - Only allows one period.
// - The called method must be named ".periodic".
//
// Methods:
// - struct.startPeriodic()
// - struct.stopPeriodic()
//
// - private method periodic takes nothing returns nothing
//
// This must be defined in structs that implement Periodic Module.
// It will be executed by the module every PERIOD until .stopPeriodic() is called.
// Put "implement T32x" BELOW this method.
//
// Modules:
// - T32x
// Has no safety on .stopPeriodic or .startPeriodic (except debug messages
// to warn).
//
// - T32xs
// Has safety on .stopPeriodic and .startPeriodic so if they are called
// multiple times, or while otherwise are already stopped/started respectively,
// no error will occur, the call will be ignored.
//
// - T32
// The original, old version of the T32 module. This remains for backwards
// compatability, and is deprecated. The periodic method must return a boolean,
// false to continue running or true to stop.
//
// Details:
// - Uses one timer.
//
// - Do not, within a .periodic method, follow a .stopPeriodic call with a
// .startPeriodic call.
//
// How to import:
// - Create a trigger named T32.
// - Convert it to custom text and replace the whole trigger text with this.
//
// Thanks:
// - Infinitegde for finding a bug in the debug message that actually altered
// system operation (when in debug mode).
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library T32 initializer OnInit
globals
public constant real PERIOD=0.03125
public constant integer FPS=R2I(1/PERIOD)
public integer Tick=0 // very useful.
//==============================================================================
private trigger Trig=CreateTrigger()
endglobals
//==============================================================================
// The standard T32 module, T32x.
//
module T32x
private thistype next
private thistype prev
private static method PeriodicLoop takes nothing returns boolean
local thistype this=thistype(0).next
loop
exitwhen this==0
call this.periodic()
set this=this.next
endloop
return false
endmethod
method startPeriodic takes nothing returns nothing
debug if this.prev!=0 or thistype(0).next==this then
debug call BJDebugMsg("T32 ERROR: Struct #"+I2S(this)+" had startPeriodic called while already running!")
debug endif
set thistype(0).next.prev=this
set this.next=thistype(0).next
set thistype(0).next=this
set this.prev=thistype(0)
endmethod
method stopPeriodic takes nothing returns nothing
debug if this.prev==0 and thistype(0).next!=this then
debug call BJDebugMsg("T32 ERROR: Struct #"+I2S(this)+" had stopPeriodic called while not running!")
debug endif
// This is some real magic.
set this.prev.next=this.next
set this.next.prev=this.prev
// This will even work for the starting element.
debug set this.prev=0
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddCondition(Trig,Condition(function thistype.PeriodicLoop))
endmethod
endmodule
//==============================================================================
// The standard T32 module with added safety checks on .startPeriodic() and
// .stopPeriodic(), T32xs.
//
module T32xs
private thistype next
private thistype prev
private boolean runningPeriodic
private static method PeriodicLoop takes nothing returns boolean
local thistype this=thistype(0).next
loop
exitwhen this==0
call this.periodic()
set this=this.next
endloop
return false
endmethod
method startPeriodic takes nothing returns nothing
if not this.runningPeriodic then
set thistype(0).next.prev=this
set this.next=thistype(0).next
set thistype(0).next=this
set this.prev=thistype(0)
set this.runningPeriodic=true
endif
endmethod
method stopPeriodic takes nothing returns nothing
if this.runningPeriodic then
// This is some real magic.
set this.prev.next=this.next
set this.next.prev=this.prev
// This will even work for the starting element.
set this.runningPeriodic=false
endif
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddCondition(Trig,Condition(function thistype.PeriodicLoop))
endmethod
endmodule
//==============================================================================
// The original T32 module, for backwards compatability only.
//
module T32 // deprecated.
private thistype next
private thistype prev
private static method PeriodicLoop takes nothing returns boolean
local thistype this=thistype(0).next
loop
exitwhen this==0
if this.periodic() then
// This is some real magic.
set this.prev.next=this.next
set this.next.prev=this.prev
// This will even work for the starting element.
debug set this.prev=0
endif
set this=this.next
endloop
return false
endmethod
method startPeriodic takes nothing returns nothing
debug if this.prev!=0 or thistype(0).next==this then
debug call BJDebugMsg("T32 ERROR: Struct #"+I2S(this)+" had startPeriodic called while already running!")
debug endif
set thistype(0).next.prev=this
set this.next=thistype(0).next
set thistype(0).next=this
set this.prev=thistype(0)
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddCondition(Trig,Condition(function thistype.PeriodicLoop))
endmethod
endmodule
//==============================================================================
// System Core.
//
private function OnExpire takes nothing returns nothing
set Tick=Tick+1
call TriggerEvaluate(Trig)
endfunction
private function OnInit takes nothing returns nothing
call TimerStart(CreateTimer(),PERIOD,true,function OnExpire)
endfunction
endlibrary
//TESH.scrollpos=8
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.1
One map, one hashtable. Welcome to NewTable 3.1
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb)
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=153
//TESH.alwaysfold=0
/*
Lightning System v1.02
by Adiktuz
Basically it allows you to easily create timed or un-timed lightning effects
Features:
->You can create lightnings between two points, two unit, or a point and a unit.
->For lightnings attached to a unit, the system automatically updates the lightning
for changes on the unit (like unit position, height etc)
->Specify the height of the lightning
->Create timed-lightnings that get automatically destroyed when their duration is over
->Supports moving points too (but the lightnings are forced to be timed)
->Allows you to add actions that will run when a lightning has ended and during
update (time of which is equal to T32's period)
Methods available
How to use: call Lightning.methodName(parameters)
unitToPoint takes unit unit1, real x, real y, real sourceZ, real targetZ, boolean timed, real duration, string leffect, integer eventkey returns thistype
unitToUnit takes unit unit1, unit unit2, real sourceZ, real targetZ, boolean timed, real duration, string leffect, integer eventkey returns thistype
pointToPoint takes real sourceX, real sourceY,real targetX, real targetY, real sourceZ, real targetZ, boolean timed, real duration, string leffect, integer eventkey returns thistype
pointToPointEx takes real sourceX, real deltaSourceX, real sourceY, real deltaSourceY, real targetX, real deltaTargetX, real targetY, real deltaTargetY, real sourceZ, real targetZ, real duration, string leffect, integer eventkey returns thistype
unitToPointEx takes unit unit1, real x, real xx, real y, real yx, real sourceZ, real targetZ, real duration, string leffect, integer eventkey returns thistype
pointToPointExZ takes real sourceX, real deltaSourceX, real sourceY, real deltaSourceY, real targetX, real deltaTargetX, real targetY, real deltaTargetY, real sourceZ, real sourceCurZ, real targetZ, real targetCurZ, real duration, string leffect, integer eventkey returns thistype
unitToPointExZ takes unit unit1, real x, real xx, real y, real yx, real sourceZ, real targetZ, real targetCurZ, real duration, string leffect, integer eventkey returns thistype
Parameters:
unit unit1 -> unit end of the lightning
unit unit2 -> other unit end of the lightning for the UTU methods
real x,y -> X,Y coordinates of the point end of the lightning for the UTP methods
real sourceX,sourceY -> X,Y coordinates of the first point of the lightning for the PTP methods
real sourceZ,targetZ -> height of the lightning at each ends (actual height is calculated as z + height of unit (if there's a unit end) + locationZ)
real deltaSourceX,deltaSourceY,deltaTargetX,deltaTargetY,sourceCurZ,targetCurZ -> for the Ex and ExZ methods, the final value of each coordinate/height
(the lightning moves from sourceX to deltaSourceX, etc through the given time)
boolean timed -> whether the lightning has a timed life or not, defaulted to true for the Ex and ExZ methods
real duration -> timed life of the lightning
string leffect -> string name of the lightning effect
integer eventkey -> a key used to determine the correct update and end functions to run if available
(if you're not using the update and end events, you're probably saf to just set it to 0)
Note: all of the above methods return the Lightning instance so you can save it in a variable
Extra/Interface/Events:
registerUpdateEvent(integer eventkey, code ToDo) returns nothing
-> allows you to register an action that will be run whenever a lightning with the
same eventkey as the one registered is updated (every T32_PERIOD)
registerEndEvent(integer eventkey, code ToDo) returns nothing
-> allows you to register an action that will be run whenever a lightning with the
same eventkey as the one registered ends
NOTE: If you're going to use the next two functions/methods, make sure you set the
corresponding boolean at the globals block to true
registerGlobalUpdateEvent(code ToDo) returns nothing
-> allows you to register an action that will be run whenever a lightning
is updated (every T32_PERIOD)
registerGlobalEndEvent(code ToDo) returns nothing
-> allows you to register an action that will be run whenever a lightning ends
To forcefully remove a lightning:
remove() returns nothing
To obtain which lightning instance triggered the events:
instance()
*/
//DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
//Note: I've set the checkvisibility field to false because the lightnings look
// weird when I set it to true (sometimes they "jump")
library LightningSystem requires T32, Table
globals
//Set this to true if you're gonna use the global update event handler
private constant boolean USE_GLOBAL_UPDATE = false
//Set this to true if you're gonna use the global end event handler
private constant boolean USE_GLOBAL_END = false
private location loc = Location(0,0)
public Table UpdateTable
public Table EndTable
private trigger globalUpdate
private trigger globalEnd
endglobals
private module init
static method onInit takes nothing returns nothing
set EndTable = Table.create()
set UpdateTable = Table.create()
static if USE_GLOBAL_UPDATE then
set globalUpdate = CreateTrigger()
endif
static if USE_GLOBAL_END then
set globalEnd = CreateTrigger()
endif
endmethod
endmodule
struct Lightning extends array
lightning light
real sourceX
real targetX
real sourceY
real targetY
real sourceZ
real targetZ
real deltaSourceX
real deltaTargetX
real deltaSourceY
real deltaTargetY
real sourceCurZ
real targetCurZ
real deltaSourceZ
real deltaTargetZ
unit u1
unit u2
integer xtype
boolean timed
boolean moving
real duration
integer eventkey
static thistype instance
private static integer instanceCount = 0
private static thistype recycle = 0
private thistype recycleNext
static method registerEndEvent takes integer eventkey, code toDo returns nothing
if not EndTable.handle.has(eventkey) then
set EndTable.trigger[eventkey] = CreateTrigger()
endif
call TriggerAddCondition(EndTable.trigger[eventkey],Filter(toDo))
endmethod
static method registerUpdateEvent takes integer eventkey, code toDo returns nothing
if not UpdateTable.handle.has(eventkey) then
set UpdateTable.trigger[eventkey] = CreateTrigger()
endif
call TriggerAddCondition(UpdateTable.trigger[eventkey],Filter(toDo))
endmethod
static method registerGlobalEndEvent takes code toDo returns nothing
call TriggerAddCondition(globalEnd,Filter(toDo))
endmethod
static method registerGlobalUpdateEvent takes code toDo returns nothing
call TriggerAddCondition(globalUpdate,Filter(toDo))
endmethod
method remove takes nothing returns nothing
call DestroyLightning(this.light)
set instance = this
if EndTable.handle.has(this.eventkey) then
call TriggerEvaluate(EndTable.trigger[this.eventkey])
endif
static if USE_GLOBAL_END then
call TriggerEvaluate(globalEnd)
endif
call this.stopPeriodic()
set this.deltaSourceZ = 0.0
set this.deltaTargetZ = 0.0
set .recycleNext=recycle
set recycle=this
endmethod
static method new takes nothing returns thistype
local thistype this
if (recycle == 0) then
set instanceCount = instanceCount + 1
return instanceCount
else
set this = recycle
set recycle = recycle.recycleNext
endif
return this
endmethod
private method periodic takes nothing returns nothing
if this.xtype == 1 then
set this.sourceX = GetUnitX(this.u1)
set this.sourceY = GetUnitY(this.u1)
call MoveLocation(loc, this.sourceX,this.sourceY)
set this.sourceCurZ = sourceZ + GetUnitFlyHeight(this.u1) + GetLocationZ(loc)
if this.moving then
set this.targetX = this.targetX + this.deltaTargetX
set this.targetY = this.targetY + this.deltaTargetY
endif
call MoveLocation(loc, this.targetX,this.targetY)
if this.deltaTargetZ != 0.0 then
set this.targetZ = this.targetZ + this.deltaTargetZ
endif
set this.targetCurZ = targetZ + GetLocationZ(loc) + this.deltaTargetZ
call MoveLightningEx(this.light,false,this.sourceX,this.sourceY,this.sourceCurZ,this.targetX,this.targetY,this.targetCurZ)
elseif this.xtype == 2 then
set this.sourceX = GetUnitX(this.u1)
set this.sourceY = GetUnitY(this.u1)
set this.targetX = GetUnitX(this.u2)
set this.targetY = GetUnitY(this.u2)
call MoveLocation(loc, this.sourceX,this.sourceY)
set this.sourceCurZ = sourceZ + GetUnitFlyHeight(this.u1) + GetLocationZ(loc)
call MoveLocation(loc, this.targetX,this.targetY)
set this.targetCurZ = targetZ + GetUnitFlyHeight(this.u2) + GetLocationZ(loc)
call MoveLightningEx(this.light,false,this.sourceX,this.sourceY,this.sourceCurZ,this.targetX,this.targetY,this.targetCurZ)
else
if this.moving then
set this.sourceX = this.sourceX + this.deltaSourceX
set this.targetX = this.targetX + this.deltaTargetX
set this.sourceY = this.sourceY + this.deltaSourceY
set this.targetY = this.targetY + this.deltaTargetY
call MoveLocation(loc, this.sourceX,this.sourceY)
if this.deltaSourceZ != 0.0 then
set this.sourceZ = this.sourceZ + this.deltaSourceZ
endif
if this.deltaTargetZ != 0.0 then
set this.targetZ = this.targetZ + this.deltaTargetZ
endif
set this.sourceCurZ = sourceZ + GetLocationZ(loc) + this.deltaSourceZ
call MoveLocation(loc, this.targetX,this.targetY)
set this.targetCurZ = targetZ + GetLocationZ(loc) + this.deltaTargetZ
call MoveLightningEx(this.light,false,this.sourceX,this.sourceY,this.sourceCurZ,this.targetX,this.targetY,this.targetCurZ)
endif
endif
set instance = this
if UpdateTable.handle.has(this.eventkey) then
call TriggerEvaluate(UpdateTable.trigger[this.eventkey])
endif
static if USE_GLOBAL_UPDATE then
call TriggerEvaluate(globalUpdate)
endif
if this.timed then
set this.duration = this.duration - T32_PERIOD
if this.duration <= 0.0 then
call this.remove()
endif
endif
endmethod
implement T32x
static method unitToPoint takes unit unit1, real x, real y, real sourceZ, real targetZ, boolean timed, real duration, string leffect, integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = unit1
set this.u2 = null
set this.sourceX = GetUnitX(this.u1)
set this.sourceY = GetUnitY(this.u1)
set this.targetX = x
set this.targetY = y
call MoveLocation(loc, this.sourceX,this.sourceY)
set this.sourceZ = sourceZ + GetUnitFlyHeight(this.u1) + GetLocationZ(loc)
call MoveLocation(loc, this.targetX,this.targetY)
set this.targetZ = targetZ + GetLocationZ(loc)
set this.timed = timed
set this.duration = duration
set this.eventkey = eventkey
set this.light = AddLightningEx(leffect,false,this.sourceX,this.sourceY,this.sourceZ,this.targetX,this.targetY,this.targetZ)
set this.xtype = 1
set this.moving = false
call this.startPeriodic()
return this
endmethod
static method unitToUnit takes unit unit1, unit unit2, real sourceZ, real targetZ, boolean timed, real duration, string leffect, integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = unit1
set this.u2 = unit2
set this.sourceX = GetUnitX(this.u1)
set this.sourceY = GetUnitY(this.u1)
set this.targetX = GetUnitX(this.u2)
set this.targetY = GetUnitY(this.u2)
call MoveLocation(loc, this.sourceX,this.sourceY)
set this.sourceZ = sourceZ + GetUnitFlyHeight(this.u1) + GetLocationZ(loc)
call MoveLocation(loc, this.targetX,this.targetY)
set this.targetZ = targetZ + GetUnitFlyHeight(this.u2) + GetLocationZ(loc)
set this.timed = timed
set this.duration = duration
set this.eventkey = eventkey
set this.light = AddLightningEx(leffect,false,this.sourceX,this.sourceY,this.sourceZ,this.targetX,this.targetY,this.targetZ)
set this.xtype = 2
set this.moving = false
call this.startPeriodic()
return this
endmethod
static method pointToPoint takes real sourceX, real sourceY,real targetX, real targetY, real sourceZ, real targetZ, boolean timed, real duration, string leffect, integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = null
set this.u2 = null
set this.sourceX = sourceX
set this.sourceY = sourceY
set this.targetX = targetX
set this.targetY = targetY
call MoveLocation(loc, this.sourceX,this.sourceY)
set this.sourceZ = sourceZ + GetLocationZ(loc)
call MoveLocation(loc, this.targetX,this.targetY)
set this.targetZ = targetZ + GetLocationZ(loc)
set this.timed = timed
set this.duration = duration
set this.eventkey = eventkey
set this.light = AddLightningEx(leffect,false,this.sourceX,this.sourceY,this.sourceZ,this.targetX,this.targetY,this.targetZ)
set this.xtype = 3
set this.moving = false
call this.startPeriodic()
return this
endmethod
static method pointToPointEx takes real sourceX, real deltaSourceX, real sourceY, real deltaSourceY, real targetX, real deltaTargetX, real targetY, real deltaTargetY, real sourceZ, real targetZ, real duration, string leffect, integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = null
set this.u2 = null
set this.sourceX = sourceX
set this.sourceY = sourceY
set this.targetX = targetX
set this.targetY = targetY
set this.deltaSourceX = (deltaSourceX - sourceX)*(T32_PERIOD/duration)
set this.deltaSourceY = (deltaSourceY - sourceY)*(T32_PERIOD/duration)
set this.deltaTargetX = (deltaTargetX - targetX)*(T32_PERIOD/duration)
set this.deltaTargetY = (deltaTargetY - targetY)*(T32_PERIOD/duration)
call MoveLocation(loc, this.sourceX,this.sourceY)
set this.sourceZ = sourceZ + GetLocationZ(loc)
call MoveLocation(loc, this.targetX,this.targetY)
set this.targetZ = targetZ + GetLocationZ(loc)
set this.timed = true
set this.duration = duration
set this.eventkey = eventkey
set this.light = AddLightningEx(leffect,false,this.sourceX,this.sourceY,this.sourceZ,this.targetX,this.targetY,this.targetZ)
set this.xtype = 3
set this.moving = true
call this.startPeriodic()
return this
endmethod
static method unitToPointEx takes unit unit1, real x, real xx, real y, real yx, real sourceZ, real targetZ, real duration, string leffect, integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = unit1
set this.u2 = null
set this.sourceX = GetUnitX(this.u1)
set this.sourceY = GetUnitY(this.u1)
set this.targetX = x
set this.targetY = y
set this.deltaTargetX = (xx - x)*(T32_PERIOD/duration)
set this.deltaTargetY = (yx - y)*(T32_PERIOD/duration)
call MoveLocation(loc, this.sourceX,this.sourceY)
set this.sourceZ = sourceZ + GetUnitFlyHeight(this.u1) + GetLocationZ(loc)
call MoveLocation(loc, this.targetX,this.targetY)
set this.targetZ = targetZ + GetLocationZ(loc)
set this.timed = true
set this.duration = duration
set this.eventkey = eventkey
set this.light = AddLightningEx(leffect,false,this.sourceX,this.sourceY,this.sourceZ,this.targetX,this.targetY,this.targetZ)
set this.xtype = 1
set this.moving = true
call this.startPeriodic()
return this
endmethod
static method pointToPointExZ takes real sourceX, real deltaSourceX, real sourceY, real deltaSourceY, real targetX, real deltaTargetX, real targetY, real deltaTargetY, real sourceZ, real sourceCurZ, real targetZ, real targetCurZ, real duration, string leffect, integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = null
set this.u2 = null
set this.sourceX = sourceX
set this.sourceY = sourceY
set this.targetX = targetX
set this.targetY = targetY
set this.deltaSourceZ = (sourceCurZ - sourceZ)*(T32_PERIOD/duration)
set this.deltaTargetZ = (targetCurZ-targetZ)*(T32_PERIOD/duration)
set this.deltaSourceX = (deltaSourceX - sourceX)*(T32_PERIOD/duration)
set this.deltaSourceY = (deltaSourceY - sourceY)*(T32_PERIOD/duration)
set this.deltaTargetX = (deltaTargetX - targetX)*(T32_PERIOD/duration)
set this.deltaTargetY = (deltaTargetY - targetY)*(T32_PERIOD/duration)
call MoveLocation(loc, this.sourceX,this.sourceY)
set this.sourceZ = sourceZ + GetLocationZ(loc)
call MoveLocation(loc, this.targetX,this.targetY)
set this.targetZ = targetZ + GetLocationZ(loc)
set this.timed = true
set this.duration = duration
set this.eventkey = eventkey
set this.light = AddLightningEx(leffect,false,this.sourceX,this.sourceY,this.sourceZ,this.targetX,this.targetY,this.targetZ)
set this.xtype = 3
set this.moving = true
call this.startPeriodic()
return this
endmethod
static method unitToPointExZ takes unit unit1, real x, real xx, real y, real yx, real sourceZ, real targetZ, real targetCurZ, real duration, string leffect, integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = unit1
set this.u2 = null
set this.sourceX = GetUnitX(this.u1)
set this.sourceY = GetUnitY(this.u1)
set this.targetX = x
set this.targetY = y
set this.deltaTargetZ = (targetCurZ - targetZ)*(T32_PERIOD/duration)
set this.deltaTargetX = (xx - x)*(T32_PERIOD/duration)
set this.deltaTargetY = (yx - y)*(T32_PERIOD/duration)
call MoveLocation(loc, this.sourceX,this.sourceY)
set this.sourceZ = sourceZ + GetUnitFlyHeight(this.u1) + GetLocationZ(loc)
call MoveLocation(loc, this.targetX,this.targetY)
set this.targetZ = targetZ + GetLocationZ(loc)
set this.timed = true
set this.duration = duration
set this.eventkey = eventkey
set this.light = AddLightningEx(leffect,false,this.sourceX,this.sourceY,this.sourceZ,this.targetX,this.targetY,this.targetZ)
set this.xtype = 1
set this.moving = true
call this.startPeriodic()
return this
endmethod
implement init
endstruct
endlibrary
//TESH.scrollpos=78
//TESH.alwaysfold=0
/*
Drain System v1.02
by Adiktuz
A system that handles draining abilities
Features:
->Can have a simultaneous life and mana drain
->Can have different values for the drain and the damage dealt to the drained unit
->Can set the attacktype and damagetype of the drain
How to use:
->Drain.methodName(parameters)
Methods that can be used for drains
life(unit u1, unit u2, real lifedrain, real duration, real breakpoint, string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey)
mana(unit u1, unit u2, real manadrain, real duration,real breakpoint,string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey)
lifeMana(unit u1, unit u2, real lifedrain, real manadrain, real duration,real breakpoint,string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey)
lifeEx(unit u1, unit u2, real lifedrain, real lifedamage, real duration, real breakpoint, string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey)
manaEx(unit u1, unit u2, real manadrain, real manadamage, real duration,real breakpoint,string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey)
lifeManaEx(unit u1, unit u2, real lifedrain, real lifedamage, real manadrain, real manadamage, real duration,real breakpoint,string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey)
Parameters:
unit u1 -> the caster
unit u2 -> the target
real lifedrain -> the amount of life added to u1 per second
real lifedamage -> the amount of life damage to u2 per second
real manadrain -> the amount of mana added to u1 per second
real manadamage -> the amount of mana damage to u2 per second
real duration -> the maximum duration of the drain
real breakpoint -> the maximum range of the drain
string lfx -> the string path of the lightning effect
string e1 -> the special effect to be attached to u1 for the duration of the drain
string e2 -> the special effect to be attached to u2 for the duration of the drain
string apoint1 -> the attachment point of e1
string apoint2 -> the attachment point of e2
attacktype at -> the attack type of the life damage
damagetype dt -> the damage type of the life damage
Note: all of these methods return the instance of the drain so you can save it in a variable
To forcibly stop a drain:
remove(integer eventtype)
integer eventtype -> determines if the drain is broken,ended or target died
-> if 1, it is broken
-> if 2, it ended
-> if 3, target died
-> use any other number if no event response should be run
Extra/Interface/Events:
registerUpdateEvent(integer eventkey, code ToDo) returns nothing
-> allows you to register an action that will be run whenever a drain with the
same eventkey as the one registered is updated (every T32_PERIOD)
registerEndEvent(integer eventkey, code ToDo) returns nothing
-> allows you to register an action that will be run whenever a drain with the
same eventkey as the one registered ends (duration ends)
registerBreakEvent(integer eventkey, code ToDo) returns nothing
-> allows you to register an action that will be run whenever a drain with the
same eventkey as the one registered is broken (the breakpoint is reached)
registerDeathEvent(integer eventkey, code ToDo) returns nothing
-> allows you to register an action that will be run whenever target unit dies
registerSelfDeathEvent(integer eventkey, code ToDo) returns nothing
-> allows you to register an action that will be run whenever the casting unit dies
NOTE: If you're going to use the next five functions/methods, make sure you set the
corresponding boolean at the globals block to true
registerGlobalUpdateEvent(code ToDo) returns nothing
-> allows you to register an action that will be run whenever a drain
is updated (every T32_PERIOD)
registerGlobalEndEvent(code ToDo) returns nothing
-> allows you to register an action that will be run whenever a drain ends
registerGlobalBreakEvent(code ToDo) returns nothing
-> allows you to register an action that will be run whenever a drain breaks
registerGlobalDeathEvent(code ToDo) returns nothing
-> allows you to register an action that will be run whenever a drain target dies
registerGlobalSelfDeathEvent(code ToDo) returns nothing
-> allows you to register an action that will be run whenever a drain user dies
To obtain the instance that run the events:
getTriggeringDrain()
See the example triggers for a better idea on how to use it
*/
library DrainSystem requires LightningSystem
globals
//Set to true if you're gonna use the global update event handler
private constant boolean USE_GLOBAL_UPDATE = false
//Set to true if you're gonna use the global end event handler
private constant boolean USE_GLOBAL_END = false
//Set to true if you're gonna use the global break event handler
private constant boolean USE_GLOBAL_BREAK = false
//Set to true if you're gonna use the global death event handler
private constant boolean USE_GLOBAL_DEATH = false
//Set to true if you're gonna use the global selfdeath event handler
private constant boolean USE_GLOBAL_SELFDEATH = false
//hbase eight of lightning for normal units
private constant real zbuffer = 50.0
//base height of lightning for flying units
//negative because flying units seem to have a default positive buffer for the lightning z
private constant real flyzbuffer = -100.0
private Table UpdateTable
private Table EndTable
private Table BreakTable
private Table DeathTable
private Table SelfDeathTable
private trigger globalUpdate
private trigger globalEnd
private trigger globalBreak
private trigger globalDeath
private trigger globalSelfDeath
endglobals
private module init
static method onInit takes nothing returns nothing
set UpdateTable = Table.create()
set EndTable = Table.create()
set BreakTable = Table.create()
set DeathTable = Table.create()
set SelfDeathTable = Table.create()
static if USE_GLOBAL_UPDATE then
set globalUpdate = CreateTrigger()
endif
static if USE_GLOBAL_END then
set globalEnd = CreateTrigger()
endif
static if USE_GLOBAL_BREAK then
set globalBreak = CreateTrigger()
endif
static if USE_GLOBAL_DEATH then
set globalDeath = CreateTrigger()
endif
static if USE_GLOBAL_SELFDEATH then
set globalSelfDeath = CreateTrigger()
endif
endmethod
endmodule
struct Drain extends array
Lightning light
unit u1
unit u2
real duration
real lifedrain
real manadrain
real lifedamage
real manadamage
real breakpoint
effect e1
effect e2
integer eventkey
string apoint1
string apoint2
attacktype at
damagetype dt
boolean isLife
boolean isMana
static thistype instance
private static integer instanceCount = 0
private static thistype recycle = 0
private thistype recycleNext
static method registerSelfDeathEvent takes integer eventkey, code toDo returns nothing
if not SelfDeathTable.handle.has(eventkey) then
set SelfDeathTable.trigger[eventkey] = CreateTrigger()
endif
call TriggerAddCondition(SelfDeathTable.trigger[eventkey],Filter(toDo))
endmethod
static method registerDeathEvent takes integer eventkey, code toDo returns nothing
if not DeathTable.handle.has(eventkey) then
set DeathTable.trigger[eventkey] = CreateTrigger()
endif
call TriggerAddCondition(DeathTable.trigger[eventkey],Filter(toDo))
endmethod
static method registerEndEvent takes integer eventkey, code toDo returns nothing
if not EndTable.handle.has(eventkey) then
set EndTable.trigger[eventkey] = CreateTrigger()
endif
call TriggerAddCondition(EndTable.trigger[eventkey],Filter(toDo))
endmethod
static method registerBreakEvent takes integer eventkey, code toDo returns nothing
if not BreakTable.handle.has(eventkey) then
set BreakTable.trigger[eventkey] = CreateTrigger()
endif
call TriggerAddCondition(BreakTable.trigger[eventkey],Filter(toDo))
endmethod
static method registerUpdateEvent takes integer eventkey, code toDo returns nothing
if not UpdateTable.handle.has(eventkey) then
set UpdateTable.trigger[eventkey] = CreateTrigger()
endif
call TriggerAddCondition(UpdateTable.trigger[eventkey],Filter(toDo))
endmethod
static method registerGlobalEndEvent takes code toDo returns nothing
call TriggerAddCondition(globalEnd,Filter(toDo))
endmethod
static method registerGlobalUpdateEvent takes code toDo returns nothing
call TriggerAddCondition(globalUpdate,Filter(toDo))
endmethod
static method registerGlobalBreakEvent takes code toDo returns nothing
call TriggerAddCondition(globalBreak,Filter(toDo))
endmethod
static method registerGlobalDeathEvent takes code toDo returns nothing
call TriggerAddCondition(globalDeath,Filter(toDo))
endmethod
static method registerGlobalSelfDeathEvent takes code toDo returns nothing
call TriggerAddCondition(globalSelfDeath,Filter(toDo))
endmethod
static method getZ takes unit u returns real
if IsUnitType(u,UNIT_TYPE_FLYING) then
return flyzbuffer
endif
return zbuffer
endmethod
static method getTriggeringDrain takes nothing returns thistype
return instance
endmethod
method remove takes integer eventtype returns nothing
call this.light.remove()
call DestroyEffect(this.e1)
call DestroyEffect(this.e2)
set instance = this
if eventtype == 1 then
if BreakTable.handle.has(this.eventkey) then
call TriggerEvaluate(BreakTable.trigger[this.eventkey])
endif
static if USE_GLOBAL_BREAK then
call TriggerEvaluate(globalBreak)
endif
elseif eventtype == 2 then
if EndTable.handle.has(this.eventkey) then
call TriggerEvaluate(EndTable.trigger[this.eventkey])
endif
static if USE_GLOBAL_END then
call TriggerEvaluate(globalEnd)
endif
elseif eventtype == 3 then
if DeathTable.handle.has(this.eventkey) then
call TriggerEvaluate(DeathTable.trigger[this.eventkey])
endif
static if USE_GLOBAL_DEATH then
call TriggerEvaluate(globalDeath)
endif
elseif eventtype == 4 then
if SelfDeathTable.handle.has(this.eventkey) then
call TriggerEvaluate(SelfDeathTable.trigger[this.eventkey])
endif
static if USE_GLOBAL_SELFDEATH then
call TriggerEvaluate(globalSelfDeath)
endif
endif
call this.stopPeriodic()
set .recycleNext=recycle
set recycle=this
endmethod
static method new takes nothing returns thistype
local thistype this = recycle
if (this == 0) then
set instanceCount = instanceCount + 1
return instanceCount
endif
set recycle = recycle.recycleNext
return this
endmethod
method periodic takes nothing returns nothing
set this.duration = this.duration - T32_PERIOD
set instance = this
if UpdateTable.handle.has(this.eventkey) then
call TriggerEvaluate(UpdateTable.trigger[this.eventkey])
endif
static if USE_GLOBAL_UPDATE then
call TriggerEvaluate(globalUpdate)
endif
if this.isLife then
call SetWidgetLife(this.u1,GetWidgetLife(this.u1) + this.lifedrain)
call UnitDamageTarget(this.u1,this.u2,this.lifedamage,false,false,this.at,this.dt,null)
endif
if this.isMana then
call SetUnitState(this.u1, UNIT_STATE_MANA, GetUnitState(this.u1,UNIT_STATE_MANA) + this.manadrain)
call SetUnitState(this.u2, UNIT_STATE_MANA, GetUnitState(this.u2,UNIT_STATE_MANA) - this.manadamage)
endif
if this.duration <= 0.0 then
call this.remove(2)
elseif ((GetUnitX(this.u1) - GetUnitX(this.u2))*(GetUnitX(this.u1) - GetUnitX(this.u2)) + (GetUnitY(this.u1) - GetUnitY(this.u2))*(GetUnitY(this.u1) - GetUnitY(this.u2))) > this.breakpoint then
call this.remove(1)
elseif GetWidgetLife(this.u2) < .405 or IsUnitType(this.u2,UNIT_TYPE_DEAD) then
call this.remove(3)
elseif GetWidgetLife(this.u1) < .405 or IsUnitType(this.u1,UNIT_TYPE_DEAD) then
call this.remove(4)
endif
endmethod
implement T32x
static method life takes unit u1, unit u2, real lifedrain, real duration, real breakpoint, string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = u1
set this.u2 = u2
set this.lifedrain = lifedrain*T32_PERIOD
set this.manadrain = 0.0
set this.duration = duration
set this.breakpoint = breakpoint*breakpoint
set this.eventkey = eventkey
set this.e1 = AddSpecialEffectTarget(e1,u1,apoint1)
set this.e2 = AddSpecialEffectTarget(e2,u2,apoint2)
set this.at = at
set this.dt = dt
set this.lifedamage = this.lifedrain
set this.manadamage = this.manadrain
set this.isLife = true
set this.isMana = false
set this.light = Lightning.unitToUnit(u1,u2,thistype.getZ(u1),thistype.getZ(u2),false,0.0,lfx,this.eventkey)
call this.startPeriodic()
return this
endmethod
static method mana takes unit u1, unit u2, real manadrain, real duration,real breakpoint,string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = u1
set this.u2 = u2
set this.lifedrain = 0.0
set this.manadrain = manadrain*T32_PERIOD
set this.duration = duration
set this.breakpoint = breakpoint*breakpoint
set this.eventkey = eventkey
set this.e1 = AddSpecialEffectTarget(e1,u1,apoint1)
set this.e2 = AddSpecialEffectTarget(e2,u2,apoint2)
set this.at = at
set this.dt = dt
set this.lifedamage = this.lifedrain
set this.manadamage = this.manadrain
set this.isLife = false
set this.isMana = true
set this.light = Lightning.unitToUnit(u1,u2,thistype.getZ(u1),thistype.getZ(u2),false,0.0,lfx,this.eventkey)
call this.startPeriodic()
return this
endmethod
static method lifeMana takes unit u1, unit u2, real lifedrain, real manadrain, real duration,real breakpoint,string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = u1
set this.u2 = u2
set this.lifedrain = lifedrain*T32_PERIOD
set this.manadrain = manadrain*T32_PERIOD
set this.duration = duration
set this.breakpoint = breakpoint*breakpoint
set this.eventkey = eventkey
set this.e1 = AddSpecialEffectTarget(e1,u1,apoint1)
set this.e2 = AddSpecialEffectTarget(e2,u2,apoint2)
set this.lifedamage = this.lifedrain
set this.manadamage = this.manadrain
set this.isLife = true
set this.isMana = true
set this.light = Lightning.unitToUnit(u1,u2,thistype.getZ(u1),thistype.getZ(u2),false,0.0,lfx,this.eventkey)
call this.startPeriodic()
return this
endmethod
static method lifeEx takes unit u1, unit u2, real lifedrain, real lifedamage, real duration,real breakpoint,string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = u1
set this.u2 = u2
set this.lifedrain = lifedrain*T32_PERIOD
set this.manadrain = 0.0
set this.duration = duration
set this.breakpoint = breakpoint*breakpoint
set this.eventkey = eventkey
set this.e1 = AddSpecialEffectTarget(e1,u1,apoint1)
set this.e2 = AddSpecialEffectTarget(e2,u2,apoint2)
set this.at = at
set this.dt = dt
set this.lifedamage = lifedamage*T32_PERIOD
set this.manadamage = this.manadrain
set this.isLife = true
set this.isMana = false
set this.light = Lightning.unitToUnit(u1,u2,thistype.getZ(u1),thistype.getZ(u2),false,0.0,lfx,this.eventkey)
call this.startPeriodic()
return this
endmethod
static method manaEx takes unit u1, unit u2, real manadrain, real manadamage, real duration,real breakpoint,string lfx, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = u1
set this.u2 = u2
set this.lifedrain = 0.0
set this.manadrain = manadrain*T32_PERIOD
set this.duration = duration
set this.breakpoint = breakpoint*breakpoint
set this.eventkey = eventkey
set this.e1 = AddSpecialEffectTarget(e1,u1,apoint1)
set this.e2 = AddSpecialEffectTarget(e2,u2,apoint2)
set this.at = at
set this.dt = dt
set this.lifedamage = this.lifedrain
set this.manadamage = manadamage*T32_PERIOD
set this.isLife = false
set this.isMana = true
set this.light = Lightning.unitToUnit(u1,u2,thistype.getZ(u1),thistype.getZ(u2),false,0.0,lfx,this.eventkey)
call this.startPeriodic()
return this
endmethod
static method lifeManaEx takes unit u1, unit u2, real lifedrain, real lifedamage, real manadrain, real manadamage,real breakpoint,string lfx, real duration, string e1, string e2, string apoint1, string apoint2, attacktype at, damagetype dt,integer eventkey returns thistype
local thistype this = thistype.new()
set this.u1 = u1
set this.u2 = u2
set this.lifedrain = lifedrain*T32_PERIOD
set this.manadrain = manadrain*T32_PERIOD
set this.duration = duration
set this.breakpoint = breakpoint*breakpoint
set this.eventkey = eventkey
set this.e1 = AddSpecialEffectTarget(e1,u1,apoint1)
set this.e2 = AddSpecialEffectTarget(e2,u2,apoint2)
set this.lifedamage = lifedamage*T32_PERIOD
set this.manadamage = manadamage*T32_PERIOD
set this.isLife = true
set this.isMana = true
set this.light = Lightning.unitToUnit(u1,u2,thistype.getZ(u1),thistype.getZ(u2),false,0.0,lfx,this.eventkey)
call this.startPeriodic()
return this
endmethod
implement init
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
//============================================================================
// SpellEffectEvent
// - Version 1.1.0.0
//
// API
// ---
// RegisterSpellEffectEvent(integer abil, code onCast)
//
// Requires
// --------
// RegisterPlayerUnitEvent: hiveworkshop.com/forums/showthread.php?t=203338
//
// Optional
// --------
// Table: hiveworkshop.com/forums/showthread.php?t=188084
//
library SpellEffectEvent requires RegisterPlayerUnitEvent optional Table
//============================================================================
private module M
static if LIBRARY_Table then
static Table tb
else
static hashtable ht = InitHashtable()
endif
static method onCast takes nothing returns nothing
static if LIBRARY_Table then
call TriggerEvaluate(.tb.trigger[GetSpellAbilityId()])
else
call TriggerEvaluate(LoadTriggerHandle(.ht, 0, GetSpellAbilityId()))
endif
endmethod
private static method onInit takes nothing returns nothing
static if LIBRARY_Table then
set .tb = Table.create()
endif
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function thistype.onCast)
endmethod
endmodule
//============================================================================
private struct S extends array
implement M
endstruct
//============================================================================
function RegisterSpellEffectEvent takes integer abil, code onCast returns nothing
static if LIBRARY_Table then
if not S.tb.handle.has(abil) then
set S.tb.trigger[abil] = CreateTrigger()
endif
call TriggerAddCondition(S.tb.trigger[abil], Filter(onCast))
else
if not HaveSavedHandle(S.ht, 0, abil) then
call SaveTriggerHandle(S.ht, 0, abil, CreateTrigger())
endif
call TriggerAddCondition(LoadTriggerHandle(S.ht, 0, abil), Filter(onCast))
endif
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/**************************************************************
*
* RegisterPlayerUnitEvent
* v5.1.0.0
* By Magtheridon96
*
* I would like to give a special thanks to Bribe, azlier
* and BBQ for improving this library. For modularity, it only
* supports player unit events.
*
* Functions passed to RegisterPlayerUnitEvent must either
* return a boolean (false) or nothing. (Which is a Pro)
*
* Warning:
* --------
*
* - Don't use TriggerSleepAction inside registered code.
* - Don't destroy a trigger unless you really know what you're doing.
*
* API:
* ----
*
* - function RegisterPlayerUnitEvent takes playerunitevent whichEvent, code whichFunction returns nothing
* - Registers code that will execute when an event fires.
* - function RegisterPlayerUnitEventForPlayer takes playerunitevent whichEvent, code whichFunction, player whichPlayer returns nothing
* - Registers code that will execute when an event fires for a certain player.
* - function GetPlayerUnitEventTrigger takes playerunitevent whichEvent returns trigger
* - Returns the trigger corresponding to ALL functions of a playerunitevent.
*
**************************************************************/
library RegisterPlayerUnitEvent // Special Thanks to Bribe and azlier
globals
private trigger array t
endglobals
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer k = 15
if t[i] == null then
set t[i] = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null)
exitwhen k == 0
set k = k - 1
endloop
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
local integer i = 260 + 16 * GetHandleId(p) + GetPlayerId(pl)
if t[i] == null then
set t[i] = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t[i], pl, p, null)
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
return t[GetHandleId(p)]
endfunction
endlibrary
//TESH.scrollpos=12
//TESH.alwaysfold=0
library FoD initializer init requires DrainSystem
globals
private constant integer abil = 'A000'
private constant string fx = "Abilities\\Spells\\Other\\SoulBurn\\SoulBurnbuff.mdl"
private constant string fx2 = "Abilities\\Spells\\Human\\InnerFire\\InnerFireTarget.mdl"
private constant string drainfx = "AFOD"
private constant string point = "overhead"
private constant string point2 = "overhead"
private unit u = null
endglobals
private function drain takes nothing returns nothing
set u = GetTriggerUnit()
call Drain.lifeEx(u,GetSpellTargetUnit(),GetUnitAbilityLevel(u,abil)*GetHeroStr(u,true),GetUnitAbilityLevel(u,abil)*GetHeroInt(u,true), 5.0,800.0,drainfx,fx2,fx,point2,point,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_DIVINE,abil)
endfunction
private function break takes nothing returns nothing
call BJDebugMsg("Finger of death was broken.")
endfunction
private function end takes nothing returns nothing
call SetUnitState(Drain.getTriggeringDrain().u2,UNIT_STATE_MANA,0.0)
endfunction
private function init takes nothing returns nothing
call RegisterSpellEffectEvent(abil,function drain)
call Drain.registerBreakEvent(abil,function break)
call Drain.registerEndEvent(abil,function end)
endfunction
endlibrary
//TESH.scrollpos=14
//TESH.alwaysfold=0
library ForkedDrain initializer init requires DrainSystem
globals
private constant integer abil = 'A001'
private constant string fx = "Abilities\\Spells\\Other\\Drain\\DrainTarget.mdl"
private constant string fx2 = "Abilities\\Spells\\Other\\Drain\\DrainTarget.mdl"
private constant string drainfx = "DRAB"
private constant string point = "overhead"
private constant string point2 = "overhead"
private constant real radius = 150.0
private constant integer TARGETS = 2
private integer maxtargs
private integer curtargs = 1
private unit u = null
private unit tmpU = null
private unit tmpUo = null
private group tmpGroup = CreateGroup()
private integer level
endglobals
private function filter takes nothing returns boolean
set tmpU = GetFilterUnit()
if IsUnitEnemy(tmpU,GetOwningPlayer(u)) and GetWidgetLife(tmpU) > .405 and (not IsUnitType(tmpU,UNIT_TYPE_STRUCTURE)) and curtargs < maxtargs and tmpU != tmpUo then
call Drain.life(u,tmpU,level*20,5.0,800.0,drainfx,fx2,fx,point2,point,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_DIVINE,abil)
set curtargs = curtargs + 1
endif
return false
endfunction
private function drain takes nothing returns nothing
set u = GetTriggerUnit()
set level = GetUnitAbilityLevel(u,abil)
set tmpUo = GetSpellTargetUnit()
call Drain.life(u,tmpUo,level*20,5.0,800.0,drainfx,fx2,fx,point2,point,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_DIVINE,abil)
set maxtargs = TARGETS*level
call GroupEnumUnitsInRange(tmpGroup, GetUnitX(tmpUo), GetUnitY(tmpUo), radius*level, Filter(function filter))
set curtargs = 1
endfunction
private function dead takes nothing returns nothing
call BJDebugMsg(GetUnitName(Drain.getTriggeringDrain().u2) + " has died from Forked Drain.")
endfunction
private function init takes nothing returns nothing
call RegisterSpellEffectEvent(abil,function drain)
call Drain.registerDeathEvent(abil,function dead)
endfunction
endlibrary