Name | Type | is_array | initial_value |
//TESH.scrollpos=100
//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=24
//TESH.alwaysfold=0
/**************************************************************
*
* RegisterPlayerUnitEvent
* v5.1.0.1
* 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 = 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=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=15
//TESH.alwaysfold=0
library IsDestructableTree
//* ============================================================================ *
//* Made by PitzerMike *
//* *
//* I made this to detect if a destructable is a tree or not. It works not only *
//* for the standard trees but also for custom destructables created with the *
//* object editor. It uses a locust as a dummy with the ghoul's harvest ability. *
//* ============================================================================ *
globals
private constant integer HARVEST_ABIL = 'Ahrl' // ghouls harvest
private constant integer HARVEST_ID = 0xD0032 // harvest order ID
private constant integer DUMMY_ID = 'uloc' // locust unit type
private unit u = null
endglobals
function IsDestructableTree takes destructable d returns boolean
return IssueTargetOrderById(u, HARVEST_ID, d)
endfunction
private module M
private static method onInit takes nothing returns nothing
set u = CreateUnit(Player(15), DUMMY_ID, 0, 0, 0) // unselectable, untargetable, can't be enumerated
call ShowUnit(u, false) //Invisible
call UnitAddAbility(u, HARVEST_ABIL)
call UnitRemoveAbility(u, 'Amov') // the unit can never follow through with order, so
endmethod // you don't need to pause/unpause the unit.
endmodule
private struct S extends array
implement M
endstruct
endlibrary
//TESH.scrollpos=253
//TESH.alwaysfold=0
library CTL /* v1.2.0.2
*************************************************************************************
*
* CTL or Constant Timer Loop provides a loop for constant merged timers of timeout .03125
*
* Similar to T32 but pauses timer when no structs have instances and removes structs
* from timer trigger when those structs have no instances.
*
* This can also create new timers after destroying a previous timer and generates less
* code in the module. It also generates no triggers so long as the module is implemented
* at the top of the struct.
*
************************************************************************************
*
* module CTL
*
* Allows creation/destruction of timers in a struct. Provides instancing of those timers.
*
* - static method create takes nothing returns thistype
* - method destroy takes nothing returns nothing
*
* CTL (optional)
* local variables, code before running any timers
* CTLExpire (not optional)
* timer code
* CTLNull (optional)
* null any locals, runs after all timers
* CTLEnd (not optional)
*
* module CT32
*
* Converts struct into a timer group. Allows the timer group to be started and stopped.
* Instancing and looping through active timers is up to the user.
*
* - static method start takes nothing returns nothing
* - static method stop takes nothing returns nothing
*
* CT32 (not optional)
* timer code
* CT32End (not optional)
*
* struct TimerGroup32 extends array
*
* Allows for the creation of timer groups. Timer instancing and looping is entirely up
* to the user.
*
* - static method create takes code func returns thistype
* - method destroy takes nothing returns nothing
* - method start takes nothing returns nothing
* - method stop takes nothing returns nothing
*
************************************************************************************/
globals
private integer tgc = 0 //timer group count
private integer array tgr //timer group recycler
private integer ic=0 //instance count
private integer tc=0 //timer count
private integer array rf //root first
private integer array n //next
private integer array p //previous
private integer array th //timer head
private integer array ns //next stack
private trigger t=CreateTrigger()
private timer m=CreateTimer()
private triggercondition array ct
private conditionfunc array rc
private boolean array e32 //enabled
private integer array i32r //ct32 recycler
private integer i32cr = 0 //ct32 count recycler
private boolean array ir32 //is recycling
private boolean array id32 //is destroying
endglobals
private function E takes nothing returns nothing
local integer i=ns[0]
set ns[0]=0
loop
exitwhen 0==i
if (0==p[i]) then
if (0==n[i]) then
call TriggerRemoveCondition(t,ct[th[i]])
set ct[th[i]]=null
set tc=tc-1
set rf[th[i]]=0
else
set rf[th[i]]=n[i]
set p[n[i]]=0
endif
else
set p[n[i]]=p[i]
set n[p[i]]=n[i]
endif
set n[i]=n[0]
set n[0]=i
set i=ns[i]
endloop
loop
exitwhen 0 == i32cr
set i32cr = i32cr - 1
set i = i32r[i32cr]
if (not e32[i]) then
call TriggerRemoveCondition(t,ct[i])
set ct[i] = null
if (id32[i]) then
set tgr[i] = tgr[0]
set tgr[0] = i
set id32[i] = false
endif
set ir32[i] = false
endif
endloop
if (0==tc) then
call PauseTimer(m)
else
call TriggerEvaluate(t)
endif
endfunction
private function CT takes integer r returns integer
local integer i
local integer f
if (0==n[0]) then
set i=ic+1
set ic=i
else
set i=n[0]
set n[0]=n[i]
endif
set th[i]=r
set ns[i]=-1
set f=rf[r]
if (0==f) then
set n[i]=0
set p[i]=0
set rf[r]=i
set ct[r]=TriggerAddCondition(t,rc[r])
//set ct[r] = null
if (0==tc) then
call TimerStart(m,.031250000,true,function E)
endif
set tc=tc+1
else
set n[i]=f
set p[i]=0
set p[f]=i
set rf[r]=i
endif
return i
endfunction
private function DT takes integer t returns nothing
debug if (0>ns[t]) then
set ns[t]=ns[0]
set ns[0]=t
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"TIMER LOOP ERROR: ATTEMPT TO DESTROY NULL TIMER")
debug endif
endfunction
private function A takes code c returns integer
local integer i = tgr[0]
if (0 == i) then
set i = tgc + 1
set tgc = i
else
set tgr[0] = tgr[i]
endif
set rc[i]=Condition(c)
return i
endfunction
private function A32 takes integer i returns nothing
if (not (e32[i] or id32[i])) then
if (ir32[i]) then
set ir32[i] = false
else
set ct[i] = TriggerAddCondition(t, rc[i])
endif
if (0 == tc) then
call TimerStart(m,.031250000,true,function E)
endif
set tc = tc + 1
set e32[i] = true
endif
endfunction
private function SR32 takes integer i returns nothing
if (e32[i]) then
if (not (ir32[i] or id32[i])) then
set i32r[i32cr] = i
set i32cr = i32cr + 1
set ir32[i] = true
endif
set e32[i] = false
set tc = tc - 1
endif
endfunction
private function DT32 takes integer i returns nothing
if (not id32[i]) then
if (not ir32[i]) then
set ir32[i] = true
set tc = tc - 1
set i32r[i32cr] = i
set i32cr = i32cr + 1
set e32[i] = false
endif
set id32[i] = true
endif
endfunction
private keyword r
private keyword e
module CTL
static integer rctl32
static method create takes nothing returns thistype
return CT(rctl32)
endmethod
method destroy takes nothing returns nothing
call DT(this)
endmethod
static method ectl32 takes nothing returns boolean
local thistype this=rf[rctl32]
endmodule
module CTLExpire
implement CTL
loop
exitwhen 0==this
endmodule
module CTLNull
set this=n[this]
endloop
endmodule
module CTLEnd
implement CTLNull
return false
endmethod
private static method onInit takes nothing returns nothing
set rctl32 = A(function thistype.ectl32)
endmethod
endmodule
module CT32
static integer rctl32
static method ectl32 takes nothing returns boolean
endmodule
module CT32End
return false
endmethod
static method start takes nothing returns nothing
call A32(rctl32)
endmethod
static method stop takes nothing returns nothing
call SR32(rctl32)
endmethod
private static method onInit takes nothing returns nothing
set rctl32 = A(function thistype.ectl32)
endmethod
endmodule
struct TimerGroup32 extends array
static method create takes code c returns thistype
return A(c)
endmethod
method destroy takes nothing returns nothing
call DT32(this)
endmethod
method start takes nothing returns nothing
call A32(this)
endmethod
method stop takes nothing returns nothing
call SR32(this)
endmethod
endstruct
endlibrary
//TESH.scrollpos=31
//TESH.alwaysfold=0
library RSEPluginVL requires CTL
struct RSEPluginVL
effect e
unit c = null
destructable d
real time
implement CTLExpire
if c != null then
if time < 0. or IsUnitType(c,UNIT_TYPE_DEAD) or GetUnitTypeId(c) == 0 then
call DestroyEffect(e)
set e = null
set c = null
call destroy()
else
set time = time - VortexLightning_PERIODIC
endif
else
if time < 0. or GetWidgetLife(d) < 0.425 then
call DestroyEffect(e)
set e = null
set d = null
call destroy()
else
set time = time - VortexLightning_PERIODIC
endif
endif
implement CTLEnd
static method addTarget takes unit u,string eff,string attach,real dur returns nothing
local thistype this = create()
set c = u
set e = AddSpecialEffectTarget(eff,c,attach)
set time = dur
endmethod
static method addPoint takes string eff,destructable des,real x,real y,real dur returns nothing
local thistype this
set e = AddSpecialEffect(eff,x,y)
set d = des
set time = dur
endmethod
endstruct
endlibrary
//TESH.scrollpos=84
//TESH.alwaysfold=0
library RLPluginVL requires CTL
//
globals
//
private constant group G = CreateGroup()
//
endglobals
//
struct RLPluginVL
unit c
//
player p
//
real reach
real maxdis
real damage
real within
real speed
real xx
real yy
real angle
//
string ef
//
attacktype attack
damagetype dam
weapontype weapon
//
lightning ll
//
implement CTL
//
local real x
local real y
local unit f
//
implement CTLExpire
if reach < maxdis and speed > 0 then
set reach = reach + speed
//
set x = xx + reach * Cos(angle*0.01747)
set y = yy + reach * Sin(angle*0.01747)
//
call MoveLightning(ll,true,x,y,xx,yy)
//
call GroupEnumUnitsInRange(G,x,y,within,null)
loop
set f = FirstOfGroup(G)
exitwhen f == null
if IsUnitEnemy(f,p) and not IsUnitType(f,UNIT_TYPE_DEAD) or GetUnitTypeId(f) != 0 then
set speed = -1
call UnitDamageTarget(c,f,damage,true,false,attack,dam,weapon)
endif
call GroupRemoveUnit(G,f)
endloop
else
set x = xx + reach * Cos(angle*0.01747)
set y = yy + reach * Sin(angle*0.01747)
call DestroyEffect(AddSpecialEffect(ef,x,y))
call DestroyLightning(ll)
set ll = null
set c = null
set p = null
set attack = null
set weapon = null
set dam = null
call destroy()
endif
implement CTLNull
implement CTLEnd
public static method add takes unit caster,real x,real y,real sp,real da,real dis,real hit,string l,string eff,attacktype a,damagetype d,weapontype w returns nothing
//
local thistype this = create()
//
set c = caster
set p = GetOwningPlayer(c)
set maxdis = dis
set within = hit
set damage = da
set speed = sp
set ef = eff
set xx = x
set yy = y
set ll = AddLightning(l,true,xx,yy,xx,yy)
set angle = GetRandomReal(0,360)
set reach = 0.
//
set attack = a
set dam = d
set weapon = w
//
endmethod
endstruct
endlibrary
//TESH.scrollpos=26
//TESH.alwaysfold=0
library DDPluginVL requires RSEPluginVL,CTL
struct DDPluginVL
//
destructable d
//
real ti
real dmg
real intevar = 0.
real time
//
implement CTLExpire
//
if ti > 0. or GetWidgetLife(d) > 0.425 then
set ti = ti - VortexLightning_PERIODIC
if intevar < time then
set intevar = intevar + VortexLightning_PERIODIC
else
set intevar = 0.
call SetWidgetLife(d,GetWidgetLife(d)-dmg)
endif
else
set d = null
call destroy()
endif
//
implement CTLEnd
static method add takes destructable dest, string eff,real damage,real duration,real periodic returns nothing
//
local thistype this = create()
//
set d = dest
set dmg = damage
call RSEPluginVL.addPoint(eff,dest,GetDestructableX(d),GetDestructableY(d),duration)
set ti = duration
set time = periodic
//
endmethod
endstruct
//
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library DOTPluginVL requires RSEPluginVL,CTL
struct DOTPluginVL
//
unit c
unit d
//
real ti
real dmg
real intevar = 0.
real time
//
attacktype att
damagetype dam
weapontype wea
//
implement CTLExpire
//
if ti < 0. or IsUnitType(d,UNIT_TYPE_DEAD) or GetUnitTypeId(d) == 0 then
set d = null
set c = null
call destroy()
else
set ti = ti - VortexLightning_PERIODIC
endif
//
if intevar < time then
set intevar = intevar + VortexLightning_PERIODIC
else
set intevar = 0.
call UnitDamageTarget(c,d,dmg,true,false,att,dam,wea)
endif
//
implement CTLEnd
static method add takes unit caster,unit target, string eff,string attach,real damage,real duration,real periodic,attacktype a,damagetype dd,weapontype w returns nothing
//
local thistype this = create()
//
set c = caster
set d = target
set dmg = damage
set att = a
set dam = dd
set wea = w
call RSEPluginVL.addTarget(d,eff,attach,duration)
set ti = duration
set time = periodic
//
endmethod
endstruct
//
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library BoundSentinel initializer init
//*************************************************
//* BoundSentinel
//* -------------
//* Don't leave your units unsupervised, naughty
//* them may try to get out of the map bounds and
//* crash your game.
//*
//* To implement, just get a vJass compiler and
//* copy this library/trigger to your map.
//*
//*************************************************
//==================================================
globals
// High enough so the unit is no longer visible, low enough so the
// game doesn't crash...
//
// I think you need 0.0 or soemthing negative prior to patch 1.22
//
private constant real EXTRA = 500.0
endglobals
//=========================================================================================
globals
private real maxx
private real maxy
private real minx
private real miny
endglobals
//=======================================================================
private function dis takes nothing returns nothing
local unit u=GetTriggerUnit()
local real x=GetUnitX(u)
local real y=GetUnitY(u)
if(x>maxx) then
set x=maxx
elseif(x<minx) then
set x=minx
endif
if(y>maxy) then
set y=maxy
elseif(y<miny) then
set y=miny
endif
call SetUnitX(u,x)
call SetUnitY(u,y)
set u=null
endfunction
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
local region r=CreateRegion()
local rect rc
set minx=GetCameraBoundMinX() - EXTRA
set miny=GetCameraBoundMinY() - EXTRA
set maxx=GetCameraBoundMaxX() + EXTRA
set maxy=GetCameraBoundMaxY() + EXTRA
set rc=Rect(minx,miny,maxx,maxy)
call RegionAddRect(r, rc)
call RemoveRect(rc)
call TriggerRegisterLeaveRegion(t,r, null)
call TriggerAddAction(t, function dis)
//this is not necessary but I'll do it anyway:
set t=null
set r=null
set rc=null
endfunction
endlibrary
//TESH.scrollpos=326
//TESH.alwaysfold=0
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
// V O R T E X L I G H T N I N G
// - Spell Create By:
// + Elphis
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
library VortexLightning /*
*/ requires /*
// -*/ CTL /* http://www.wc3c.net/showthread.php?t=101322
// -*/ SpellEffectEvent /* http://www.hiveworkshop.com/forums/jass-resources-412/snippet-spelleffectevent-187193/
// -*/ Table /* http://www.wc3c.net/showthread.php?t=101246
// -*/ IsDestructableTree /* http://www.wc3c.net/showthread.php?t=103927
// -*/ RLPluginVL /* Spell Plugin
// -*/ DOTPluginVL /* Spell Plugin
// -*/ RLPluginVL /* Spell Plugin */
// Optional:
// NuclearExplosion.mdx - http://www.hiveworkshop.com/forums/models-530/nuclearexplosion-51829/?prev=search%3DNuclear%26d%3Dlist%26r%3D20
// BoundSentinel - http://www.wc3c.net/showthread.php?t=102576 (You must adding it, this library help you prevent crash the game when lightning outside XY of map.
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
// - Spell Information:
// - Use power of the earth, calling a powerful vortex of lightning accumulation in the soil and launched on ground
// spending a little time to make power, when done, it release a powerful lightning discharge on ground
// when enemies within 100 range it will shock enemies
// and deals 50/100/150/200 damage, when electric release 50/60/70/80 lightning
// this vortex will causes an explotion deals 50 damage to enemies unit and destructable around
// 500 range in 5 seconds.
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
// - Installation:
// - Import/copy the required libraries and Vortex Lightning code to your map
// - Import/copy the custom ability and unit to your map and change the SPELL_ID if needed
// - Export model NuclearExplosion.mdx, dummy.mdx and import it into your map
// - You may view the raw ID of the objects by pressing CTRL+D in the object editor
// - You may play with the configurables below
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//================================CONFIGURABLE================================
globals
//==============================SPELL SETTINGS========================================
//Spell rawcode, change if needed
private constant integer SPELL_ID = 'A000'
//Dummy rawcode, change if needed
private constant integer LIGHTNING_DUMMY = 'e000'
//Periodic of spell
public constant real PERIODIC = .031250000
//========================================================================
////////////////////////////////////////////////////////////////////////////////////////////
//Count of lightning release (Spell expire when reach this count)
private constant integer L_R_COUNT = 5
//Color of lightning increase per periodic
private constant integer COLOR_INC = 5
//Max distance when lightning release
private constant real MAX_DISTANCE = 1000.
//Min distance when lightning release
private constant real MIN_DISTANCE = 500.
//Max distance of vortex lightning
private constant real ORB_M_DISTANCE = 500.
//Distance increase per periodic
private constant real ORB_REACH = 5.
//Lightning powerful center size
private constant real CENTER_SIZE = 3.
//Size increase of center lightning per periodic
private constant real CENTER_SIZE_INC = 0.2
//Lightning release speed outside
private constant real RELEASE_SPEED = 10.
//Range hit enemies, don't increase this value too much because it very powerful
private constant real WIHTHIN_RANGE = 100.
//Lightning release intevar
private constant real RELEASE_INTEVAR = 0.1
//Damage when release lightning hit enemies unit
private constant real DAMAGE_BASE = 50.
//Damage fire deals to enemies unit within range of explotion
private constant real DAMAGE_FIRE = 50.
//Duration of fire damage to enemies unit and destructable
private constant real FIRE_DURATION = 5.
//Model of lightning vortex
private constant string MODEL = "Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl"
//Effect causes explore when lightning reach max distance
private constant string EXPLORE_MODEL = "Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl"
//Explotion model when spell expire
private constant string M_EXPLOTION = "war3mapImported\\NuclearExplosion.mdx"
//Fire effect to enemies unit and destructable
private constant string FIRE_EFFECT = "Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeDamageTarget.mdl"
//Lightning attachment
private constant string ATTACH = "origin"
//Enemies attachment
private constant string ENE_ATTACH = "chest"
//Vortex lightning model
private constant string LIGHTNING_ALT = "DRAM"
//Release lightning model
private constant string L_RELEASE = "CLPB"
// ======DAMAGE SETTINGS======
private constant attacktype ATTACKTYPE = ATTACK_TYPE_HERO
private constant damagetype DAMAGETYPE = DAMAGE_TYPE_COLD
private constant weapontype WEAPONTYPE = WEAPON_TYPE_METAL_HEAVY_BASH
// ======NON CONFIGURATION======
private constant group G = CreateGroup()
private rect RECT = Rect(0, 0, 0, 0)
//
endglobals
//
private struct VortexLightning extends array
//
player p
//
unit caster
unit dummy
//
real damage
real xx
real yy
real an
real reach
real sinc
real in
//
integer cl
integer count
//Table Installing
Table tab
//This function deals damage to destructable
static method damageDestructable takes nothing returns boolean
local destructable dummy = GetFilterDestructable()
//
if IsDestructableTree(dummy) then
call DDPluginVL.add(dummy,FIRE_EFFECT,DAMAGE_FIRE,FIRE_DURATION,1.)
endif
//
set dummy = null
//
return false
endmethod
//
static method onCount takes unit caster returns integer
return L_R_COUNT+GetUnitAbilityLevel(caster,SPELL_ID)*10 // Total count of vortex discharge lightning
endmethod
//
static method onDamage takes unit caster returns real
return DAMAGE_BASE*GetUnitAbilityLevel(caster,SPELL_ID) // Damage of lightning when hit enemies unit
endmethod
//
implement CTL
local integer i = 0
local real x
local real y
local real dd
local unit f
implement CTLExpire
//
set an = an + 5.
//
loop
exitwhen i > 10
//
set x = xx + reach * Cos((tab.real[10+i]+an)*0.01747)
set y = yy + reach * Sin((tab.real[10+i]+an)*0.01747)
//
call SetUnitX(tab.unit[i],x)
call SetUnitY(tab.unit[i],y)
//
call SetUnitVertexColor(tab.unit[i],cl,cl,cl,cl)
//
call MoveLightning(tab.lightning[20+i],true,x,y,xx,yy)
//
set i = i + 1
endloop
set i = 0
//
if count > 0 then
if reach < ORB_M_DISTANCE then
set reach = reach + ORB_REACH
else
//
if cl < 255 then
set cl = cl + COLOR_INC
elseif sinc < CENTER_SIZE then
set sinc = sinc + CENTER_SIZE_INC
call SetUnitScale(dummy,sinc,0.,0.)
else
if in < RELEASE_INTEVAR then
set in = in + PERIODIC
else
//
set in = 0.
//
set dd = GetRandomReal(MIN_DISTANCE,MAX_DISTANCE)
//
set count = count - 1
//This line release lightning
call RLPluginVL.add(caster,xx,yy,RELEASE_SPEED,damage,dd,WIHTHIN_RANGE,L_RELEASE,EXPLORE_MODEL,ATTACKTYPE,DAMAGETYPE,WEAPONTYPE)
endif
endif
endif
else
//
if reach > 0. then
//
set reach = reach - ORB_REACH
//
loop
exitwhen i > 10
//
set x = xx + reach * Cos((tab.real[10+i]+an)*0.01747)
set y = yy + reach * Sin((tab.real[10+i]+an)*0.01747)
//
call SetUnitX(tab.unit[i],x)
call SetUnitY(tab.unit[i],y)
//
call MoveLightning(tab.lightning[20+i],true,x,y,xx,yy)
//
set i = i + 1
endloop
elseif sinc > 0 then
set sinc = sinc - CENTER_SIZE_INC*2
//
call SetUnitScale(dummy,sinc,0.,0.)
//
set i = 0
//
loop
exitwhen i > 10
//
call SetUnitScale(tab.unit[i],sinc,0.,0.)
//
set i = i + 1
endloop
else
//Enum destructable
call SetRect(RECT, xx-ORB_M_DISTANCE, yy-ORB_M_DISTANCE, xx+ORB_M_DISTANCE, yy+ORB_M_DISTANCE)
//
call GroupEnumUnitsInRect(G,RECT,null)
loop
set f = FirstOfGroup(G)
exitwhen f == null
if IsUnitEnemy(f,p) or not IsUnitType(f,UNIT_TYPE_DEAD) then
//This line deals damage to enemies
call DOTPluginVL.add(caster,f,FIRE_EFFECT,ENE_ATTACH,DAMAGE_FIRE,FIRE_DURATION,1.,ATTACKTYPE,DAMAGETYPE,WEAPONTYPE)
endif
call GroupRemoveUnit(G,f)
endloop
//
call EnumDestructablesInRect(RECT,function thistype.damageDestructable,null)
//
set i = 0
//
loop
exitwhen i > 10
//
call DestroyLightning(tab.lightning[20+i])
call DestroyEffect(tab.effect[30+i])
call RemoveUnit(tab.unit[i])
//
set tab.unit[i] = null
set tab.lightning[20+i] = null
set tab.effect[30+i] = null
//
set i = i + 1
endloop
//
call DestroyEffect(AddSpecialEffect(M_EXPLOTION,xx,yy))
//
call RemoveUnit(dummy)
//
call tab.flush()
call tab.destroy()
//
set caster = null
set dummy = null
set p = null
//
call destroy()
//
endif
//
endif
//
implement CTLEnd
static method onCast takes nothing returns boolean
local thistype this = create()
local integer i = 0
local real x
local real y
//
set caster = GetTriggerUnit()
set p = GetTriggerPlayer()
//
set xx = GetSpellTargetX()
set yy = GetSpellTargetY()
set damage = onDamage(caster)
set count = onCount(caster)
set an = 0.
set reach = 0.
set sinc = 0.
set in = 0.
set cl = 0
//Table create
set tab = Table.create()
//
loop
exitwhen i > 10
//
set x = xx + 100. * Cos(0.01747*i*36)
set y = yy + 100. * Sin(0.01747*i*36)
//
set tab.unit[i] = CreateUnit(p,LIGHTNING_DUMMY,x,y,0.)
set tab.real[10+i] = 57.29582 * Atan2(y - yy, x - xx)
set tab.lightning[20+i] = AddLightning(LIGHTNING_ALT,true,x,y,xx,yy)
set tab.effect[30+i] = AddSpecialEffectTarget(MODEL,tab.unit[i],ATTACH)
call SetUnitVertexColor(tab.unit[i],0,0,0,0)
//
set i = i + 1
endloop
//
set dummy = CreateUnit(p,LIGHTNING_DUMMY,xx,yy,0.)
call SetUnitScale(dummy,0.,0.,0.)
//
return false
endmethod
static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(SPELL_ID,function thistype.onCast)
endmethod
//
endstruct
//
endlibrary