//********************************************************************************
//********************************************************************************
//********************************************************************************
//********************************************************************************
//********************************************************************************
// 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
[/HIDDEN]