Name | Type | is_array | initial_value |
//TESH.scrollpos=220
//TESH.alwaysfold=0
/************************************************
*
* OnDeathTexttag
* v3.0.0.1
* By Magtheridon96
*
* - Displays a randomly selected or predefined texttag
* over a unit when it dies based on unit characteristics.
*
* API:
* ----
*
* - struct OnDeathTexttag extends array
*
* - static method addEasy takes string s returns nothing
* - Adds an easy-kill text to the system.
* - static method addHard takes string s returns nothing
* - Adds a hard-kill text to the system.
*
* - static method getEasy takes nothing returns string
* - Gets a random easy-kill text.
* - static method getHard takes nothing returns string
* - Gets a random hard-kill text.
*
* - static method getUnit takes unit whichUnit returns string
* - Returns the unit death text.
* - static method setUnit takes unit whichUnit, string s returns nothing
* - Gives a unit a custom death text that overrides the others. This will also override the filters.
*
* - static method resetUnit takes unit whichUnit returns nothing
* - Resets a the death text of a unit so it uses the easy and hard ones.
* - static method unitHas takes unit whichUnit returns boolean
* - Determines if a unit has a custom death text or not.
*
*
* - function AddEasyDeathText takes string s returns nothing
* - Adds an easy-kill text to the system.
* - function AddHardDeathText takes string s returns nothing
* - Adds a hard-kill text to the system.
*
* - function GetEasyDeathText takes nothing returns string
* - Gets a random easy-kill text.
* - function GetHardDeathText takes nothing returns string
* - Gets a random hard-kill text.
*
* - function GetUnitDeathText takes unit whichUnit returns string
* - Returns the unit death text.
* - function SetUnitDeathText takes unit whichUnit, string s returns nothing
* - Gives a unit a custom death text that overrides the others. This will also override the filters.
*
* - function ResetUnitDeathText takes unit whichUnit returns nothing
* - Resets a the death text of a unit so it uses the easy and hard ones.
* - function UnitHasDeathText takes unit whichUnit returns boolean
* - Determines if a unit has a custom death text or not.
*
************************************************/
library OnDeathTexttag requires Table, RegisterPlayerUnitEvent
globals
// Texttag Age
private constant real AGE = 2.50
// Texttag Fading Age
private constant real FADE = 1.75
// Texttag Size
private constant real FONT = 10
// Texttag Velocity
private constant real SPEED = 16
// Texttag Angle
private constant real ANGLE = 90
// Texttag Z
private constant real HEIGHT = 32
endglobals
private function UnitFilter takes unit u returns boolean
return IsUnitType(u, UNIT_TYPE_HERO)
endfunction
private function HardUnitFilter takes unit u returns boolean
return GetUnitState(u, UNIT_STATE_MAX_LIFE) >= 1500
endfunction
private function VisibilityFilter takes player dyingPlayer, player otherPlayer returns boolean
return true
endfunction
private module Configuration
private static method onInit takes nothing returns nothing
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function thistype.run)
call addEasy("N00b!")
call addEasy("Feeder!")
call addEasy("OMG")
call addEasy("Fail")
call addEasy("xaxaxaxa")
call addEasy("Maphack!")
call addEasy("H4xx!!")
call addEasy("jajajaja")
call addEasy("Pro!")
call addEasy("*Ragequit*")
call addEasy("...")
call addEasy("trololol")
call addEasy(":@")
call addEasy("whosyourdaddy")
call addHard("Pwned")
call addHard("Owned")
call addHard("qft")
call addHard("Epic!")
call addHard("Awesome!")
call addHard(":D")
// Setting player color strings
set color[0] = "|cffff0303"
set color[1] = "|cff0042ff"
set color[2] = "|cff1ce6b9"
set color[3] = "|cff540081"
set color[4] = "|cffffff01"
set color[5] = "|cfffe8a0e"
set color[6] = "|cff20c000"
set color[7] = "|cffe55bb0"
set color[8] = "|cff959697"
set color[9] = "|cff7ebff1"
set color[10] = "|cff106246"
set color[11] = "|cff4e2a04"
set color[12] = "|cffffffff"
set color[13] = "|cffffffff"
set color[14] = "|cffffffff"
set color[15] = "|cffffffff"
set unitStrings = Table.create()
endmethod
endmodule
struct OnDeathTexttag extends array
private static string array easyStrings
private static string array hardStrings
private static Table unitStrings
private static integer easyCount = -1
private static integer hardCount = -1
private static string array color
private static constant real X = SPEED * 0.0005546875 * Cos(ANGLE * bj_DEGTORAD)
private static constant real Y = SPEED * 0.0005546875 * Sin(ANGLE * bj_DEGTORAD)
private static constant real SIZE = FONT * 0.0023
static method addEasy takes string s returns nothing
set easyCount = easyCount + 1
set easyStrings[easyCount] = s
endmethod
static method addHard takes string s returns nothing
set hardCount = hardCount + 1
set hardStrings[hardCount] = s
endmethod
static method getEasy takes nothing returns string
return easyStrings[GetRandomInt(0, easyCount)]
endmethod
static method getHard takes nothing returns string
return hardStrings[GetRandomInt(0, hardCount)]
endmethod
static method getUnit takes unit whichUnit returns string
return unitStrings.string[GetHandleId(whichUnit)]
endmethod
static method setUnit takes unit whichUnit, string s returns nothing
set unitStrings.string[GetHandleId(whichUnit)] = s
endmethod
static method resetUnit takes unit whichUnit returns nothing
set unitStrings.string[GetHandleId(whichUnit)] = null
endmethod
static method unitHas takes unit whichUnit returns boolean
return getUnit(whichUnit) != null
endmethod
private static method run takes nothing returns nothing
local unit triggerUnit = GetTriggerUnit()
local string s = unitStrings.string[GetHandleId(triggerUnit)]
local texttag text
// Check the unit filter
if UnitFilter(triggerUnit) then
// If the unit has no custom death text
if s == null then
// Check if the kill was hard or easy
if HardUnitFilter(triggerUnit) then
set s = getHard()
else
set s = getEasy()
endif
endif
elseif s == null then
// The unit wasn't accepted by any of the filters
// It also didn't have a custom death text
set triggerUnit = null
return
endif
set text = CreateTextTag()
call SetTextTagText(text, color[GetPlayerId(GetTriggerPlayer())] + s, SIZE)
call SetTextTagPosUnit(text, triggerUnit, HEIGHT)
call SetTextTagVelocity(text, X, Y)
call SetTextTagPermanent(text, false)
call SetTextTagLifespan(text, AGE)
call SetTextTagFadepoint(text, FADE)
call SetTextTagVisibility(text, VisibilityFilter(GetTriggerPlayer(), GetLocalPlayer()))
set triggerUnit = null
set text = null
endmethod
implement Configuration
endstruct
function AddEasyDeathText takes string s returns nothing
call OnDeathTexttag.addEasy(s)
endfunction
function AddHardDeathText takes string s returns nothing
call OnDeathTexttag.addHard(s)
endfunction
function GetEasyDeathText takes nothing returns string
return OnDeathTexttag.getEasy()
endfunction
function GetHardDeathText takes nothing returns string
return OnDeathTexttag.getHard()
endfunction
function SetUnitDeathText takes unit whichUnit, string s returns nothing
call OnDeathTexttag.setUnit(whichUnit, s)
endfunction
function GetUnitDeathText takes unit whichUnit returns string
return OnDeathTexttag.getUnit(whichUnit)
endfunction
function UnitHasDeathText takes unit whichUnit returns boolean
return GetUnitDeathText(whichUnit) != null
endfunction
function ResetUnitDeathText takes unit whichUnit returns nothing
call OnDeathTexttag.resetUnit(whichUnit)
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=10
//TESH.alwaysfold=0
/**************************************************************
*
* RegisterPlayerUnitEvent
* v4.2.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
* return false. They can return nothing as well.
*
* Disclaimer:
* -----------
*
* - Don't use TriggerSleepAction inside registered code.
*
* API:
* ----
*
* function RegisterPlayerUnitEvent
* takes
* playerunitevent whichEvent : The event you would like to register
* code whichFunction : The code you would like to register
* returns
* nothing
*
* - Registers code that will execute when an event fires.
*
**************************************************************/
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=12
//TESH.alwaysfold=0
library Demo requires RegisterPlayerUnitEvent
globals
private unit tester
private unit creep
private unit hero1
private unit hero2
endglobals
private struct Inits extends array
private static method rev takes nothing returns nothing
local unit u = GetTriggerUnit()
if IsUnitType(u, UNIT_TYPE_HERO) then
call ReviveHero(u, GetUnitX(u), GetUnitY(u), false)
else
call CreateUnit(GetTriggerPlayer(), GetUnitTypeId(u), GetUnitX(u), GetUnitY(u), 270)
call RemoveUnit(u)
endif
set u = null
endmethod
private static method onInit takes nothing returns nothing
local location loc = Location(0, 0)
set tester = CreateUnit(Player(0), 'Hpal', 0, 0, 270)
set creep = CreateUnit(Player(1), 'n000', 0, -512, 270)
call CreateUnit(Player(1), 'H000', 512, 512, 270)
call CreateUnit(Player(1), 'H001', -512, 512, 270)
call SetHeroLevel(tester, 10, false)
call OnDeathTexttag.setUnit(creep, "Custom Death Text!")
set bj_lastCreatedFogModifier = CreateFogModifierRadiusLoc(Player(0), FOG_OF_WAR_VISIBLE, loc, 92083, true, false)
call FogModifierStart(bj_lastCreatedFogModifier)
call RemoveLocation(loc)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function thistype.rev)
set loc = null
endmethod
endstruct
endlibrary