Moderator
M
Moderator
21 Nov 2011
Bribe: This is a clear and simple resource. Nice to work with and has good configurable options.
Bribe: This is a clear and simple resource. Nice to work with and has good configurable options.
/************************************************
*
* 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