//TESH.scrollpos=0
//TESH.alwaysfold=0
Name | Type | is_array | initial_value |
e | unit | Yes | |
u | unit | No | |
uu | unit | No |
//TESH.scrollpos=16
//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=0
//TESH.alwaysfold=0
library ErrorMessage /* v1.0.1.4
*************************************************************************************
*
* Issue THW Compliant Error Messages
*
************************************************************************************
*
* debug function ThrowError takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
* - In the event of an error the game will be permanently paused
*
* debug function ThrowWarning takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
*
************************************************************************************/
static if DEBUG_MODE then
private struct Fields extends array
static constant string COLOR_RED = "|cffff0000"
static constant string COLOR_YELLOW = "|cffffff00"
static string lastError = null
endstruct
private function Pause takes nothing returns nothing
call PauseGame(true)
endfunction
private function ThrowMessage takes string libraryName, string functionName, string objectName, integer objectInstance, string description, string errorType, string color returns nothing
local string str
local string color_braces = "|cff66FF99"
local string orange = "|cffff6600"
set str = "->\n-> " + color_braces + "{|r " + "Library" + color_braces + "(" + orange + libraryName + color_braces + ")"
if (objectName != null) then
if (objectInstance > 0) then
set str = str + "|r.Object" + color_braces + "(" + orange + objectName + color_braces + " (|rinstance = " + orange + I2S(objectInstance) + color_braces + ") )" + "|r." + "Method" + color_braces + "(" + orange + functionName + color_braces + ")"
else
set str = str + "|r.Object" + color_braces + "(" + orange + objectName + color_braces + ")|r." + "Method" + color_braces + "(" + orange + functionName + color_braces + ")"
endif
else
set str = str + "|r." + "Function" + color_braces + "(" + orange + functionName + color_braces + ")"
endif
set str = str + color_braces + " }|r " + "has thrown an exception of type " + color_braces + "(" + color + errorType + color_braces + ")|r."
set Fields.lastError = str + "\n->\n" + "-> " + color + description + "|r\n->"
endfunction
function ThrowError takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
if (Fields.lastError != null) then
set objectInstance = 1/0
endif
if (expression) then
call ThrowMessage(libraryName, functionName, objectName, objectInstance, description, "Error", Fields.COLOR_RED)
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,Fields.lastError)
call TimerStart(CreateTimer(), 0, true, function Pause)
set objectInstance = 1/0
endif
endfunction
function ThrowWarning takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
if (Fields.lastError != null) then
set objectInstance = 1/0
endif
if (expression) then
call ThrowMessage(libraryName, functionName, objectName, objectInstance, description, "Warning", Fields.COLOR_YELLOW)
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,Fields.lastError)
set Fields.lastError = null
endif
endfunction
endif
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Alloc /* v1.0.0.1
*************************************************************************************
*
* */uses/*
*
* */ ErrorMessage /* hiveworkshop.com/forums/submissions-414/snippet-error-message-239210/
*
************************************************************************************
*
* module Alloc
*
* static method allocate takes nothing returns thistype
* method deallocate takes nothing returns nothing
*
************************************************************************************/
module Alloc
private static integer array recycler
private static integer instanceCount = 0
static method allocate takes nothing returns thistype
local thistype this = recycler[0]
if (this == 0) then
debug call ThrowError(instanceCount == 8191, "Alloc", "allocate", "thistype", 0, "Overflow.")
set this = instanceCount + 1
set instanceCount = this
else
set recycler[0] = recycler[this]
endif
debug set recycler[this] = -1
return this
endmethod
method deallocate takes nothing returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "deallocate", "thistype", this, "Attempted To Deallocate Null Instance.")
set recycler[this] = recycler[0]
set recycler[0] = this
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//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=60
//TESH.alwaysfold=0
//********************************************************************************
//********************************************************************************
//********************************************************************************
//********************************************************************************
//********************************************************************************
// M A N A/H P B A R S S Y S T E M
// =======
// System created by:
// - Elphis
// - Special thanks to Bowser499 for help me improve this system.
// What system does:
// This system allow you to create a mana bars on unit :)
//
// HOW TO USES:
//! novjass
struct Manabars......
//===========================ALL ABOUT HELPING METHOD===========================
//**This method help you to hide mana bars for player**
method hideBarsToPlayer takes /*
*/player p /* Which player you want to hide
*/boolean hide /* Boolean hide bars
*/ returns nothing /*
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsToPlayer(Player(0),true) /*
//if you want to show again
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarstoPlayer(Player(0),false) /*
//This method help to hide bars to all enemies of this player, that mean, only you and your allies can see this bars
*/method hideBarsToEnemies takes /*
*/boolean hide /* Boolean hide bars
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsToEnemies(true) /*
//if you want to show again
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsToEnemies(false) /*
//This method help to hide bars to all player, that mean, only you can see this bars
*/method hideBarsAllPlayers takes /*
*/boolean hide /* Boolean hide bars
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsAllPlayers(true) /*
//if you want to show again
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsAllPlayers(false) /*
**This method help you to destroy data and also destroy bars**
*/ method removeBars takes nothing returns nothing /*
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.removeBars()
//******************************************************************************
// MAIN SYSTEM
//******************************************************************************
//This method add bars to unit
static method add takes /*
*/ unit u /* Which unit you want to add
*/ real scale /* Scale (Size) of unit
*/ integer data /* Save data of bars with number, very important ( Like Hastable )
*/ boolean hpbaractivator /* Allow to create hp bar to unit
*/ boolean mpbaractivator /* Allow to create mana bar to unit
*/ boolean hidebars /* if = true, only you can see this bars
*/ boolean hidebarsenemies /* if = true, only you and your allies can see this bars
*/ returns nothing
//NOW FOR EXAMPLE
call Manabars.add(udg_u,1.,50,false,true /*that mean, only you and your allies can see this bars :)*/)
/*Save this bars with number 50, when you want to destroy this bars or stuff, you need to use this number*/
//This method help you chage data of bars to another unit.
method changeData takes /*
*/ unit u /* Which unit you want to change bars
*/ real scale /* Scale (Size) of unit
*/ integer savenumber /* With data number
*/ return nothing /*
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call changeData(GetTriggerUnit(),GetHandleId(GetTriggerUnit())
//
//! endnovjass
//TESH.scrollpos=0
//TESH.alwaysfold=0
//********************************************************************************
//********************************************************************************
//********************************************************************************
//********************************************************************************
//********************************************************************************
// M A N A & H E A T H B A R S Y S T E M
// =======
// System created by:
// - Elphis
// - Special thanks to Bowser499 for help me improve this system.
// What system does:
// This system allow you to create a mana bars on unit :)
//
// HOW TO USES:
//! novjass
struct Manabars......
//===========================ALL ABOUT HELPING METHOD===========================
//**This method help you to hide mana bars for player**
method hideBarsToPlayer takes /*
*/player p /* Which player you want to hide
*/boolean hide /* Boolean hide bars
*/ returns nothing /*
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsToPlayer(Player(0),true) /*
//if you want to show again
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarstoPlayer(Player(0),false) /*
//This method help to hide bars to all enemies of this player, that mean, only you and your allies can see this bars
*/method hideBarsToEnemies takes /*
*/boolean hide /* Boolean hide bars
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsToEnemies(true) /*
//if you want to show again
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsToEnemies(false) /*
//This method help to hide bars to all player, that mean, only you can see this bars
*/method hideBarsAllPlayers takes /*
*/boolean hide /* Boolean hide bars
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsAllPlayers(true) /*
//if you want to show again
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.hideBarsAllPlayers(false) /*
**This method help you to destroy data and also destroy bars**
*/ method removeBars takes nothing returns nothing /*
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call m.removeBars()
//******************************************************************************
// MAIN SYSTEM
//******************************************************************************
//This method add bars to unit
static method add takes /*
*/ unit u /* Which unit you want to add
*/ real scale /* Scale (Size) of unit
*/ integer data /* Save data of bars with number, very important ( Like Hastable )
*/ boolean hpbaractivator /* Allow to create hp bar to unit
*/ boolean mpbaractivator /* Allow to create mana bar to unit
*/ boolean hidebars /* if = true, only you can see this bars
*/ boolean hidebarsenemies /* if = true, only you and your allies can see this bars
*/ returns nothing
//NOW FOR EXAMPLE
call Manabars.add(udg_u,1.,50,false,true /*that mean, only you and your allies can see this bars :)*/)
/*Save this bars with number 50, when you want to destroy this bars or stuff, you need to use this number*/
//This method help you chage data of bars to another unit.
method changeData takes /*
*/ unit u /* Which unit you want to change bars
*/ real scale /* Scale (Size) of unit
*/ integer savenumber /* With data number
*/ return nothing /*
//NOW FOR EXAMPLE:
*/ local Manabars m = BARS_TAB[<whichdata>] /*
*/ call changeData(GetTriggerUnit(),GetHandleId(GetTriggerUnit())
//
//! endnovjass
//
//
// H O W T O I M P O R T
// 1: Export LightningData.slk, nhocklanhox6-Elphis.blp, nhocklanhox6-Nyuu.blp, Elphis-Nyuu and import it into your map
// 2: Change path of LightningData.slk = Splats\LightningData.slk
// 3: Change path of nhocklanhox6-Nyuu.blp = ReplaceableTextures\Manabar\nhocklanhox6-Nyuu.blp
// 4: Change path of nhocklanhox6-Elphis.blp = ReplaceableTextures\Manabar\nhocklanhox6-Elphis.blp
// 5: Change path of Elphis-Nyuu = ReplaceableTextures\HitPointBar\Elphis-Nyuu.blp
// WARNING: DO NOT CHANGE THIS PATH, IF YOU CHAGE THIS PATH, ALL LIGHTNING WILL CRASH
// 5: Copy trigger Mana bars and all trigger of folder Resources into your map
// 6: Read how to use
// 7: Enjoy :D
//********************************************************************************
//********************************************************************************
//********************************************************************************
//********************************************************************************
//********************************************************************************
//********************************************************************************
library Manabars/*
*/ requires /*
*/ CTL /*
*/ Table /*
*/ Alloc
//
globals
//===================================CONFIGURATION===================================
//***********************************SYSTEM SETTINGS*********************************
//System Periodic
private constant real PERIODIC = 0.031250000
//Location you want to move when unit dead
private constant real DEAD_LOC = 0.
//
//==================================NON-CONFIGURATION=================================
private location barLocation = Location(0.,0.)
//
private constant string MP_MODEL = "ELPH"
private constant string HP_MODEL = "ICEF"
private constant string MP_EMPTY = "NYUU"
//
private constant real Z_OFFSET = 181.
private constant real MP_LONG = 66.
private constant real SAFE_MP = 20.
private constant real Z_HP_OFFSET = 21.
//
Table BARS_TAB
//*************************************************************************************
endglobals
//====================================DO NOT CHANGE ANYTHING BELOW====================================
struct Manabars extends array
implement Alloc
private boolean release
private unit caster
private integer barsData
private real unitScale
private lightning firstLightning
private lightning secondLightning
private lightning thirdLightning
private lightning fourthLightning
private static boolean array barsHidden
method changeData takes unit whichUnit, real newScale, integer saveNumber returns boolean
local boolean dataExist = BARS_TAB.has(barsData)
if dataExist then
call BARS_TAB.remove(barsData)
set unitScale = newScale
set caster = whichUnit
set BARS_TAB[barsData] = this
else
debug call BJDebugMsg("Can't change data.")
endif
return dataExist
endmethod
method removeBars takes nothing returns boolean
local boolean barsRemoved = caster != null
if barsRemoved then
set release = true
call BARS_TAB.remove(barsData)
call DestroyLightning(firstLightning)
call DestroyLightning(secondLightning)
call DestroyLightning(thirdLightning)
call DestroyLightning(fourthLightning)
set firstLightning = null
set secondLightning = null
set caster = null
call this.deallocate()
else
debug call BJDebugMsg("Can't remove bars: the unit does not exist.")
endif
return barsRemoved
endmethod
method isHidden takes player whichPlayer returns boolean
return barsHidden[GetPlayerId(whichPlayer)]
endmethod
method hideBarsToPlayer takes player whichPlayer, boolean doHide returns nothing
local real alphaNum = 1
local integer playerId = GetPlayerId(whichPlayer)
if caster != null then
set barsHidden[playerId] = doHide
// Special case: hidden units.
if not doHide and IsUnitHidden(caster) then
debug call BJDebugMsg("Can't show bars: the unit is hidden.")
else
if doHide then
set alphaNum = 0
endif
if GetLocalPlayer() == whichPlayer then
call SetLightningColor(firstLightning ,1.,1.,1.,alphaNum)
call SetLightningColor(secondLightning,1.,1.,1.,alphaNum)
call SetLightningColor(thirdLightning,1.,1.,1.,alphaNum)
call SetLightningColor(fourthLightning,1.,1.,1.,alphaNum)
endif
endif
else
debug call BJDebugMsg("Can't operate bars: the unit does not exist.")
endif
endmethod
method hideBarsAllPlayers takes boolean doHide returns nothing
local integer i = 0
local player casterOwner = GetOwningPlayer(caster)
local player curPlayer
if caster != null then
loop
exitwhen i > 11
set curPlayer = Player(i)
call hideBarsToPlayer(curPlayer,curPlayer != casterOwner)
set i = i + 1
endloop
else
debug call BJDebugMsg("Can't operate bars: the unit does not exist.")
endif
endmethod
method hideBarsToEnemies takes boolean doHide returns nothing
local integer i = 0
local player casterOwner = GetOwningPlayer(caster)
local player curPlayer
if caster != null then
loop
exitwhen i > 11
set curPlayer = Player(i)
call hideBarsToPlayer(curPlayer,IsPlayerEnemy(curPlayer,casterOwner))
set i = i + 1
endloop
else
debug call BJDebugMsg("Can't operate bars: the unit does not exist.")
endif
endmethod
//Periodic of this system.
implement CTL
local real locX = 0.
local real locY = 0.
local real locZ = 0.
local real barX = 0.
local real barZ = 0.
local real indX = 0.
local real ind2X = 0.
local real percentage
implement CTLExpire
if GetUnitTypeId(caster) == 0 or release then
call removeBars()
elseif IsUnitType(caster,UNIT_TYPE_DEAD) then
call MoveLightning(firstLightning ,true,DEAD_LOC,DEAD_LOC,DEAD_LOC,DEAD_LOC)
call MoveLightning(secondLightning,true,DEAD_LOC,DEAD_LOC,DEAD_LOC,DEAD_LOC)
call MoveLightning(thirdLightning,true,DEAD_LOC,DEAD_LOC,DEAD_LOC,DEAD_LOC)
call MoveLightning(fourthLightning,true,DEAD_LOC,DEAD_LOC,DEAD_LOC,DEAD_LOC)
else
set locX = GetWidgetX(caster)
set locY = GetWidgetY(caster)
call MoveLocation(barLocation,locX,locY)
set locZ = GetLocationZ(barLocation)
set percentage = GetCameraField(CAMERA_FIELD_TARGET_DISTANCE)/(bj_CAMERA_DEFAULT_DISTANCE+250)
set barX = locX - MP_LONG*percentage
set barZ = locZ + GetUnitFlyHeight(caster) + Z_OFFSET*unitScale - SAFE_MP
set indX = barX + percentage*MP_LONG*2*GetUnitState(caster,UNIT_STATE_MANA)/GetUnitState(caster,UNIT_STATE_MAX_MANA)
set ind2X = locX + MP_LONG*percentage
call MoveLightningEx(secondLightning,true,ind2X,locY,barZ,barX,locY,barZ)
call MoveLightningEx(thirdLightning,true,ind2X,locY,barZ+Z_HP_OFFSET,barX,locY,barZ+Z_HP_OFFSET)
call MoveLightningEx(firstLightning,true,barX,locY,barZ,indX,locY,barZ)
call MoveLightningEx(fourthLightning,true,barX,locY,barZ+Z_HP_OFFSET,indX,locY,barZ+Z_HP_OFFSET)
endif
implement CTLEnd
static method add takes unit u,real scale,integer data,boolean hpbaractivator,boolean mpbaractivator,boolean hidebars,boolean hidebarsenemies returns nothing
local thistype this
local real x
local real y
local player p
local integer i = 0
//
if not hpbaractivator and not mpbaractivator then
return
endif
//
if BARS_TAB.has(data) then
debug call BJDebugMsg("Can't add bars")
else
set this = create()
set p = GetOwningPlayer(u)
//Save data with number
set BARS_TAB[data] = this
set caster = u
set barsData = data
set unitScale = scale
set release = false
set x = GetWidgetX(caster)
set y = GetWidgetY(caster)
if mpbaractivator then
set firstLightning = AddLightning(MP_MODEL,true,x,y,x,y)
set secondLightning = AddLightning(MP_EMPTY,true,x,y,x,y)
else
set firstLightning = null
set secondLightning = null
endif
//
if hpbaractivator then
set thirdLightning = AddLightning(MP_EMPTY,true,x,y,x,y)
set fourthLightning = AddLightning(HP_MODEL,true,x,y,x,y)
else
set thirdLightning = null
set fourthLightning = null
endif
if hidebars then
call hideBarsAllPlayers(hidebars)
elseif hidebarsenemies then
call hideBarsToEnemies(hidebarsenemies)
endif
endif
endmethod
private static method onInit takes nothing returns nothing
//Table install
set BARS_TAB = Table.create()
endmethod
endstruct
endlibrary