Name | Type | is_array | initial_value |
BombFallSpeed | real | No | |
BombInterval | real | No | |
RoflAbility | abilcode | No | |
RoflAllyDmg | boolean | No | |
RoflAoE | real | No | |
Roflcopters | group | No | |
RoflDmg | real | Yes | |
RoflDummy | unitcode | No | |
RoflGroup | group | No | |
RoflHash | hashtable | No | |
RoflMax | real | No | |
RoflSpeed | real | No | |
RoflUnit | unit | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
/**************************************************************
*
* RegisterPlayerUnitEvent
* v4.1.1.0
* By Magtheridon96
*
* This library was made to replace that GTrigger
* monster by Jesus4Lyf at TheHelper. 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
* return false. They can return nothing as well.
*
* API:
* ----
*
* function RegisterPlayerUnitEvent
* takes
* playerunitevent whichEvent : The event that will be registered.
* code whichFunction : The function that will fire when the event occurs.
* returns
* nothing
*
**************************************************************/
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
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table // made by Bribe, special thanks to Nestharus, version 3.0.0.0
/*
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 hashtable ht = InitHashtable() //The last hashtable you need
private integer more = 2 //Index generation for Tables (above 2)
private integer less = 0 //Index generation for TableArrays (below 0)
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return 1
endmethod
static method operator list takes nothing returns Table
return 2
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
//! 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 type-syntax
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 = a[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
endmethod
// set a[389034] = 8192
method operator []= takes integer key, Table a returns nothing
call SaveInteger(ht, this, key, a)
endmethod
// set b = a.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
// call a.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 a = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set more = more + 1
set this = more
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this)
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call a.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
endstruct
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 a = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = a[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 less = less - array_size
set this = less
else
set a[0] = a[this] //Set the last destroyed to the last-last destroyed
call a.remove(this) //Clear hash 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
//da[integer a].unit[integer b] = unit u
//da[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; assumed you'd call .flush()
//if you want it flushed too. This is public so that if you are flushing
//instances the whole time you don't waste efficiency when disposing the
//TableArray.
//
method destroy takes nothing returns nothing
local Table a = 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 a == 0 then
//Create an array to index recycled instances with their array size
set a = Table.create()
set dex.size[this.size] = a
endif
call dex.size.remove(this) //Clear the array size from hash memory
set a[this] = a[0]
set a[0] = this
endmethod
//All you need to know about this one is that it won't hit the op limit.
private static method clean takes Table a, integer end returns nothing
local integer i = a + 5000
if i < end then
call clean.evaluate(i, end)
set end = i
endif
loop
call a.flush()
set a = a + 1
exitwhen a == 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
local integer end = this.size + this
debug if this == end then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
call clean.evaluate(this, end)
call this.destroy()
endmethod
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
library TimerUtils initializer init
//*********************************************************************
//* TimerUtils (red+blue+orange flavors for 1.24b+) 2.0
//* ----------
//*
//* To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//* To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass) More scripts: htt://www.wc3c.net
//*
//* For your timer needs:
//* * Attaching
//* * Recycling (with double-free protection)
//*
//* set t=NewTimer() : Get a timer (alternative to CreateTimer)
//* set t=NewTimerEx(x) : Get a timer (alternative to CreateTimer), call
//* Initialize timer data as x, instead of 0.
//*
//* ReleaseTimer(t) : Relese a timer (alt to DestroyTimer)
//* SetTimerData(t,2) : Attach value 2 to timer
//* GetTimerData(t) : Get the timer's value.
//* You can assume a timer's value is 0
//* after NewTimer.
//*
//* Multi-flavor:
//* Set USE_HASH_TABLE to true if you don't want to complicate your life.
//*
//* If you like speed and giberish try learning about the other flavors.
//*
//********************************************************************
//================================================================
globals
//How to tweak timer utils:
// USE_HASH_TABLE = true (new blue)
// * SAFEST
// * SLOWEST (though hash tables are kind of fast)
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = true (orange)
// * kinda safe (except there is a limit in the number of timers)
// * ALMOST FAST
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = false (red)
// * THE FASTEST (though is only faster than the previous method
// after using the optimizer on the map)
// * THE LEAST SAFE ( you may have to tweak OFSSET manually for it to
// work)
//
private constant boolean USE_HASH_TABLE = false
private constant boolean USE_FLEXIBLE_OFFSET = true
private constant integer OFFSET = 0x100000
private integer VOFFSET = OFFSET
//Timers to preload at map init:
private constant integer QUANTITY = 256
//Changing this to something big will allow you to keep recycling
// timers even when there are already AN INCREDIBLE AMOUNT of timers in
// the stack. But it will make things far slower so that's probably a bad idea...
private constant integer ARRAY_SIZE = 8190
endglobals
//==================================================================================================
globals
private integer array data[ARRAY_SIZE]
private hashtable ht
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
static if(USE_HASH_TABLE) then
// new blue
call SaveInteger(ht,0,GetHandleId(t), value)
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-VOFFSET]=value
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-OFFSET]=value
endif
endfunction
function GetTimerData takes timer t returns integer
static if(USE_HASH_TABLE) then
// new blue
return LoadInteger(ht,0,GetHandleId(t) )
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-VOFFSET]
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-OFFSET]
endif
endfunction
//==========================================================================================
globals
private timer array tT[ARRAY_SIZE]
private integer tN = 0
private constant integer HELD=0x28829022
//use a totally random number here, the more improbable someone uses it, the better.
private boolean didinit = false
endglobals
private keyword init
//==========================================================================================
// I needed to decide between duplicating code ignoring the "Once and only once" rule
// and using the ugly textmacros. I guess textmacros won.
//
//! textmacro TIMERUTIS_PRIVATE_NewTimerCommon takes VALUE
// On second thought, no.
//! endtextmacro
function NewTimerEx takes integer value returns timer
if (tN==0) then
if (not didinit) then
//This extra if shouldn't represent a major performance drawback
//because QUANTITY rule is not supposed to be broken every day.
call init.evaluate()
set tN = tN - 1
else
//If this happens then the QUANTITY rule has already been broken, try to fix the
// issue, else fail.
debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, make sure all timers are getting recycled correctly")
set tT[0]=CreateTimer()
static if( not USE_HASH_TABLE) then
debug call BJDebugMsg("In case of errors, please increase it accordingly, or set TimerUtils_USE_HASH_TABLE to true")
static if( USE_FLEXIBLE_OFFSET) then
if (GetHandleId(tT[0])-VOFFSET<0) or (GetHandleId(tT[0])-VOFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
else
if (GetHandleId(tT[0])-OFFSET<0) or (GetHandleId(tT[0])-OFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
endif
endif
endif
else
set tN=tN-1
endif
call SetTimerData(tT[tN],value)
return tT[tN]
endfunction
function NewTimer takes nothing returns timer
return NewTimerEx(0)
endfunction
//==========================================================================================
function ReleaseTimer takes timer t returns nothing
if(t==null) then
debug call BJDebugMsg("Warning: attempt to release a null timer")
return
endif
if (tN==ARRAY_SIZE) then
debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
//stack is full, the map already has much more troubles than the chance of bug
call DestroyTimer(t)
else
call PauseTimer(t)
if(GetTimerData(t)==HELD) then
debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
return
endif
call SetTimerData(t,HELD)
set tT[tN]=t
set tN=tN+1
endif
endfunction
private function init takes nothing returns nothing
local integer i=0
local integer o=-1
local boolean oops = false
if ( didinit ) then
return
else
set didinit = true
endif
static if( USE_HASH_TABLE ) then
set ht = InitHashtable()
loop
exitwhen(i==QUANTITY)
set tT[i]=CreateTimer()
call SetTimerData(tT[i], HELD)
set i=i+1
endloop
set tN = QUANTITY
else
loop
set i=0
loop
exitwhen (i==QUANTITY)
set tT[i] = CreateTimer()
if(i==0) then
set VOFFSET = GetHandleId(tT[i])
static if(USE_FLEXIBLE_OFFSET) then
set o=VOFFSET
else
set o=OFFSET
endif
endif
if (GetHandleId(tT[i])-o>=ARRAY_SIZE) then
exitwhen true
endif
if (GetHandleId(tT[i])-o>=0) then
set i=i+1
endif
endloop
set tN = i
exitwhen(tN == QUANTITY)
set oops = true
exitwhen not USE_FLEXIBLE_OFFSET
debug call BJDebugMsg("TimerUtils_init: Failed a initialization attempt, will try again")
endloop
if(oops) then
static if ( USE_FLEXIBLE_OFFSET) then
debug call BJDebugMsg("The problem has been fixed.")
//If this message doesn't appear then there is so much
//handle id fragmentation that it was impossible to preload
//so many timers and the thread crashed! Therefore this
//debug message is useful.
elseif(DEBUG_MODE) then
call BJDebugMsg("There were problems and the new timer limit is "+I2S(i))
call BJDebugMsg("This is a rare ocurrence, if the timer limit is too low:")
call BJDebugMsg("a) Change USE_FLEXIBLE_OFFSET to true (reduces performance a little)")
call BJDebugMsg("b) or try changing OFFSET to "+I2S(VOFFSET) )
endif
endif
endif
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
// Instance Iterator by Garfield1337
// Iterates struct instances, for more info, check T32
// Usage:
// -Implement II module
// -Add a method named "execute" above the module implementation that doesn't
// take any arguments, this method will be called each iteration
// -call start() method to start iterating an instance
// -call end() method to stop
library II
globals
private trigger t = CreateTrigger()
private integer C = 0 //Global instance count
private timer l = CreateTimer()
endglobals
private function e takes nothing returns nothing
call TriggerEvaluate(t)
endfunction
module II
private static thistype array I
private static integer c = 0 //Struct type individual instance count
private integer i //Instance's index, position in array
private boolean b = false
method start takes nothing returns boolean
if not .b then
if C==0 then
call TimerStart(l,0.031250000,true,function e) //ResumeTimer() doesn't seem to work on a looping timer
endif
set C=C+1
set .c=.c+1
set .I[.c]=this
set .i=.c
set .b=true
return true
endif
return false
endmethod
method end takes nothing returns boolean
if .b then
set C=C-1
if C==0 then
call PauseTimer(l)
elseif .i!=.c then //If the instance is not last in the array, the last one is moved to it's position
set .I[.i] =.I[.c]
set .I[.i].i=.i
endif
set .c=.c-1
set .b=false
return true
endif
return false
endmethod
private static method p takes nothing returns boolean
local integer n=.c
loop
exitwhen n==0
call .I[n].execute()
set n=n-1
endloop
return false
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddCondition(t,Condition(function thistype.p))
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Z
globals
private location l = Location(0.00,0.00)
endglobals
function GetUnitZ takes unit u returns real //If there's another GetUnitZ function in the map, you may delete this one
call MoveLocation(l,GetUnitX(u),GetUnitY(u))
return GetLocationZ(l) + GetUnitFlyHeight(u)
endfunction
function GetZ takes real x, real y returns real
call MoveLocation(l,x,y)
return GetLocationZ(l)
endfunction
endlibrary
//TESH.scrollpos=239
//TESH.alwaysfold=0
library Roflcopter initializer Init requires TimerUtils, II, SpellEffectEvent, Z
//Configurables and whatnot
globals
private constant integer SPELL_RAW = 'A000'
private constant string EXPLOSION_EFFECT = "Abilities\\Weapons\\CannonTowerMissile\\CannonTowerMissile.mdl"
private constant real HEIGHT = 350.0 //Roflcopter height
private constant real SPIN_PERIOD = 0.16 //Period between each propeller change
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
endglobals
private constant function DAMAGE takes unit caster,integer lvl returns real
return lvl * 50. //Damage dependency of level.
//You can also make damage depend on caster's stats by refering to unit variable 'caster'
endfunction
private constant function TRAVEL_LENGTH takes integer lvl returns real
return 1400. //How long does roflcopter fly
endfunction
private constant function BOMB_PERIOD takes integer lvl returns real
return 0.5 //How often will roflcopter throw bombs
endfunction
private constant function BOMB_AOE takes integer lvl returns real
return 200. //Area of effect for bomb explosion
endfunction
private constant function ROFLCOPTER_SPEED takes integer lvl returns real
return 7. //Movement speed or roflcopter
endfunction
private constant function BOMB_SPEED takes integer lvl returns real
return 7. //Fall speed of bombs
endfunction
private function FILTER takes unit caster,unit target,integer lvl returns boolean
//Filters which units will be damaged on explosion
return IsPlayerEnemy(GetOwningPlayer(caster),GetOwningPlayer(target)) /*
*/ and IsUnitType(target,UNIT_TYPE_GROUND) /*
*/ and not IsUnitType(target,UNIT_TYPE_DEAD)
endfunction
private function EFFECTS takes unit caster,unit target,real x,real y,real z,integer lvl returns nothing
//You can add here anything you want to happen on explosion given the above arguments
//For example, you can set damaged targets on fire with a spell casted by dummy or something
endfunction
//Don't change stuff below
//===================================================================
globals
private constant string R1 = "ROFL:ROFL:LOL\n ^\n ---------------\\ L\n / [ ] ===== O\n / / L\n [_________/\n I I\n \\-----------------"
private constant string R2 = " LOL:ROFL:ROFL\n ^\n ---------------\\\n / [ ] ===== LOL\n / /\n [_________/\n I I\n \\-----------------"
private constant string R3 = " ROFL:ROFL:LOL\n ^\n /---------------\nLOL ===== [ ] \\\n \\ \\\n \\_________]\n I I\n -----------------/"
private constant string R4 = " LOL:ROFL:ROFL\n ^\n L /---------------\n O ===== [ ] \\\n L \\ \\\n \\_________]\n I I\n -----------------/"
private constant real DEVIATION = 100.0
endglobals
private keyword roflcopter
private struct instance
integer n
unit u
real bs
real rs
real d
real a
integer lv
method add takes nothing returns nothing
set .n = .n + 1
endmethod
method sub takes nothing returns nothing
set .n = .n - 1
if .n == 0 then
call .destroy()
endif
endmethod
static method create takes unit u,real x,real y returns thistype
local thistype this = thistype.allocate()
local integer l = GetUnitAbilityLevel(u,SPELL_RAW)
set .u = u
set .bs = BOMB_SPEED(l)
set .rs = ROFLCOPTER_SPEED(l)
set .d = DAMAGE(u,l)
set .a = BOMB_AOE(l)
set .lv = l
call roflcopter.create(this,x,y,TRAVEL_LENGTH(l),BOMB_PERIOD(l))
return this
endmethod
endstruct
private keyword bomb
private struct roflcopter
texttag t = CreateTextTag()
instance i
real x
real y
real l
real a
timer bp
timer sp
integer p
method execute takes nothing returns nothing
set .x = .x + .i.rs * Cos(.a)
set .y = .y + .i.rs * Sin(.a)
call SetTextTagPos(.t,.x - DEVIATION,.y,HEIGHT)
set .l = .l - .i.rs
if .l <= 0 then
call .destroy()
endif
endmethod
implement II
static method bombdrop takes nothing returns nothing
local thistype this = thistype(GetTimerData(GetExpiredTimer()))
call bomb.create(.i,.x,.y,HEIGHT)
endmethod
static method spin takes nothing returns nothing
local thistype this = thistype(GetTimerData(GetExpiredTimer()))
if .p == 1 then
call SetTextTagText(.t,R2,0.023)
set .p = 2
elseif .p == 2 then
call SetTextTagText(.t,R1,0.023)
set .p = 1
elseif .p == 3 then
call SetTextTagText(.t,R4,0.023)
set .p = 4
else
call SetTextTagText(.t,R3,0.023)
set .p = 3
endif
endmethod
static method create takes instance i,real x,real y,real l,real p returns thistype
local thistype this = thistype.allocate()
local real a = Atan2(y - GetUnitY(i.u),x - GetUnitX(i.u))
if a < 0 then
set a = 2 * bj_PI + a
endif
set .i = i
set .l = l
set .a = a + bj_PI / 2
set .bp = NewTimer()
call TimerStart(.bp,p,true,function thistype.bombdrop)
call SetTimerData(.bp,this)
set .sp = NewTimer()
call TimerStart(.sp,SPIN_PERIOD,true,function thistype.spin)
call SetTimerData(.sp,this)
call SetTextTagPermanent(.t,false)
call SetTextTagVisibility(.t,true)
set .x = x + l / 2 * Cos(a - bj_PI / 2) - DEVIATION
set .y = y + TRAVEL_LENGTH(i) / 2 * Sin(a - bj_PI / 2)
call SetTextTagPos(.t,.x,.y,HEIGHT)
if a < bj_PI then
set .p = 1
call SetTextTagText(.t,R1,0.023)
else
set .p = 3
call SetTextTagText(.t,R3,0.023)
endif
call .start()
call .i.add()
return this
endmethod
method destroy takes nothing returns nothing
call DestroyTextTag(.t)
call ReleaseTimer(.bp)
call ReleaseTimer(.sp)
call .end()
call .i.sub()
call .deallocate()
endmethod
endstruct
private struct bomb
static thistype This
static group g = CreateGroup()
texttag t = CreateTextTag()
instance i
real x
real y
real h
method execute takes nothing returns nothing
set .h = .h - .i.bs
call SetTextTagPos(.t,.x,.y,.h)
if .h <= 3.00 then
call .destroy()
endif
endmethod
implement II
static method create takes instance i,real x,real y,real h returns thistype
local thistype this = thistype.allocate()
set .i = i
set .x = x
set .y = y
set .h = h
call SetTextTagPermanent(.t,false)
call SetTextTagVisibility(.t,true)
call SetTextTagPos(.t,x,y,h)
call SetTextTagText(.t,"*",0.04)
call .start()
call .i.add()
return this
endmethod
static method explosion takes nothing returns boolean
local thistype this = .This
local unit u = GetFilterUnit()
local real x
local real y
local real z
local real z2
if FILTER(.i.u,u,.i.lv) then
set x = GetUnitX(u) - .x
set y = GetUnitY(u) - .y
set z2 = GetZ(.x,.y) + .h
set z = GetUnitZ(u) - z2
if x*x+y*y+z*z <= .i.a*.i.a then
call UnitDamageTarget(.i.u,u,.i.d,false,false,ATTACK_TYPE,DAMAGE_TYPE,WEAPON_TYPE)
call EFFECTS(.i.u,u,.x,.y,z2,.i.lv)
endif
endif
set u = null
return false
endmethod
method destroy takes nothing returns nothing
call DestroyTextTag(.t)
call DestroyEffect(AddSpecialEffect(EXPLOSION_EFFECT,.x,.y))
set .This = this
call GroupEnumUnitsInRange(.g,.x,.y,.i.a,Filter(function thistype.explosion))
call .end()
call .i.sub()
call .deallocate()
endmethod
endstruct
private function Cast takes nothing returns nothing
call instance.create(GetTriggerUnit(),GetSpellTargetX(),GetSpellTargetY())
endfunction
private function Init takes nothing returns nothing
call RegisterSpellEffectEvent(SPELL_RAW, function Cast)
endfunction
endlibrary