luorax
Invasion in Duskwood
- Reaction score
- 67
Timed Buffs System v2.1.0 - LAST EDIT: 10-17-2010
I've heard that modifying the buff's duration is impossible. I think it isn't true. With some nice systems everything is possible. That's why i decided to create this system. It's quite simple, but it should be usefull, and combined with a buffstruct system gives you the way to control the buff times (and once i finish my next project you should manage your units' custom stats [what you give them.. like spell vampirism etc]). But we don't need any more words.
Requires:
-AIDS
-TimerUtils (purple)
And the system:
Bug reports, and feedbacks are welcomed!
I've heard that modifying the buff's duration is impossible. I think it isn't true. With some nice systems everything is possible. That's why i decided to create this system. It's quite simple, but it should be usefull, and combined with a buffstruct system gives you the way to control the buff times (and once i finish my next project you should manage your units' custom stats [what you give them.. like spell vampirism etc]). But we don't need any more words.
Requires:
-AIDS
-TimerUtils (purple)
And the system:
JASS:
//---------------------TIMED---BUFFS---SYSTEM-----------------------
//---------------------------BY---LUORAX----------------------------
//------------------------VERSION----2.1.0--------------------------
//----------------------- _____ ___ ___-----------------------------
//-----------------------|_ _| _ ) __|----------------------------
//-------------------------| | | _ \__ \----------------------------
//-------------------------|_| |___/___/----------------------------
//------------------------------------------------------------------
//------------------------------------------------------------------
//
// - REQUIREMENTS -
//
// -Timer Utils by Vexorian
// -AIDS by Jesus4Lyf
//
// - AND WHAT IS TBS REALLY? -
//
// TBS means Timed Buffs System. TBS was designed to show the
// remaining time of the buff for the players.
//
// - WHY TBS? AND WHEN NOT? -
//
// Using TBS is quite simple. You have to modify 1 row in the
// "Game Interface" menu, and to create 1 dummy abil and a buff.
// You call a function, and you're done! But be careful! You
// have to change all old buffs' icon to "NONE". So they won't
// be shown in the buff bar.
//
// - API -
//
// -function ApplyTimedBuff takes unit whichUnit, real time, integer whichBuff, integer dummyAbil returns boolean
// Applies a dummy buff on the target.
// = whichUnit == The unit targeted by the buff.
// = time == The duration of the buff.
// = whichBuff == The rawcode of the applied buff.
// = dummyAbil == The dummy ability used by to place the buff on the target.
//
// -function ApplyTimedBuffEx takes unit whichUnit, real time, integer whichBuff, integer dummyAbil, integer dummyUnitID, string orderString returns boolean
// A more configurable version of the basic function
// = whichUnit == The unit targeted by the buff.
// = time == The duration of the buff.
// = whichBuff == The rawcode of the applied buff.
// = dummyAbil == The dummy ability used by to place the buff on the target.
// = dummyUnitID == The id of the dummy unit used to place the buff.
// = orderString == The order string used to order the dummy unit to place the buff on the target.
//
// -function SetBuffTime takes unit whichUnit, integer whichBuff, real newtime returns boolean
// Sets the time of a buff for the targeted unit.
// = whichUnit == The unit targeted by the buff.
// = newtime == The new duration of the buff.
// = whichBuff == The rawcode of the buff what you want to change.
//
// -function RemoveTimedBuff takes unit whichUnit, integer whichBuff returns nothing
// Removes a timed buff from the target unit.
// = whichUnit == The unit what you want to refresh.
// = whichBuff == The rawcode of the buff what you want to remove.
//
// -function GetTimedBuffTime takes unit whichUnit, integer whichBuff returns integer
// Returns the remaining time of the buff. Returns 0 if the unit doesn't have the specified buff.
// = whichUnit == The owner unit of the buff.
// = whichBuff == The rawcode of the buff what you want to check.
//
// -function GetTimedBuffBasicTime takes unit whichUnit, integer whichBuff returns real
// Returns the total time of the buff. Returns 0 if the unit doesn't have the specified buff.
// = whichUnit == The owner unit of the buff.
// = whichBuff == The rawcode of the buff what you want to check.
//
//
//
// - IMPLEMENTING -
//
// Copy this trigger into your map, and the other libraries if they aren't installed yet.
// Then go to the "Advenced --> Game Interface" and modify the line called
// "Text - General - 'Level: |CFFFFFFFF%d|R'" to "|cff00ffffRemaining Time:|r |CFFFFFFFF%d|R",
// or use whatever you want, it's optional for us. Create a dummy ability with 20/30
// levels (or more for longer durations), null it's stats and set its duration to
// 1.5/2.5/3.5 and so on. Then create a buff for it with the icon waht you want
// to show, and set the last created dummy ability's placed buff to the dummy buff. Then
// call the "ApplyTimedBuff" or "ApplyTimedBuffEx" function for the target unit and you're done!
//
// P.S. : You can use the "Inner Fire" for positive and the "Cripple" for negative buffs.
//
//
//------------------------------------------------------------------
//------------------------------------------------------------------
//----------------------- _____ ___ ___-----------------------------
//-----------------------|_ _| _ ) __|----------------------------
//-------------------------| | | _ \__ \----------------------------
//-------------------------|_| |___/___/----------------------------
//------------------------VERSION----2.1.0--------------------------
//---------------------------BY---LUORAX----------------------------
//---------------------TIMED---BUFFS---SYSTEM-----------------------
//
//
// ------ HERE BEGINS THE SYSTEM ------
//
library TimedBuffSystem requires TimerUtils, AIDS
globals
//OPTIONS
private constant integer DUMMY_ID = 039;e000039; //The ID of the basic dummy unit used to place the buff
private constant string ORDER = "lightningshield" //And the basic order id
endglobals
//SYSTEM CODE! DON'T TOUCH THEM IF YOU DONT KNOW (v)JASS!
private struct TimedBuff
unit u
unit dummy
integer buffcode = 0
integer buffabil = 0
string order = ORDER
integer time = 0
real ttime = 0.00
timer t
integer sid
endstruct
private function R2IR takes real r returns integer
if R2I(r + 0.555555) == R2I(r) then
return R2I(r)
endif
return R2I(r) + 1
endfunction
globals
private TimedBuff array TB
private integer id = 0
endglobals
private function GetStruct takes unit u, integer buffcode returns TimedBuff
local integer li = 0
local TimedBuff tb
loop
exitwhen li > id
set tb = TB[li]
if tb.u == u and tb.buffcode == buffcode then
return tb
else
set li = li + 1
endif
endloop
return 0
endfunction
private function Buff_Loop takes nothing returns nothing
local timer t = GetExpiredTimer()
local TimedBuff tb = GetTimerData(t)
local TimedBuff tba
if GetUnitAbilityLevel(tb.u, tb.buffcode) != 1 then
set id = id - 1
set tba = TB[id]
set tba.sid = tb.sid
set TB[tb.sid] = TB[id]
call ReleaseTimer(t)
call UnitApplyTimedLife(tb.dummy, 039;BTLF039;, 0.1)
call tb.destroy()
else
if tb.time - 1 == 0 then
set id = id - 1
set tba = TB[id]
set tba.sid = tb.sid
set TB[tb.sid] = TB[id]
call UnitRemoveAbility(tb.u, tb.buffcode)
call ReleaseTimer(t)
call UnitApplyTimedLife(tb.dummy, 039;BTLF039;, 0.1)
call tb.destroy()
elseif tb.time - 1 >= 1 then
call SetUnitAbilityLevel(tb.dummy, tb.buffabil, tb.time - 1)
call SetUnitPosition(tb.dummy, GetUnitX(tb.u), GetUnitY(tb.u))
call IssueTargetOrder(tb.dummy, tb.order, tb.u)
set tb.time = tb.time - 1
endif
endif
set t = null
endfunction
function GetTimedBuffTime takes unit u, integer buffcode returns integer
local TimedBuff tb
if GetUnitAbilityLevel(u, buffcode) != 1 then
return 0
else
set tb = GetStruct(u, buffcode)
return tb.time
endif
endfunction
function GetTimedBuffBasicTime takes unit u, integer buffcode returns real
local TimedBuff tb
if GetUnitAbilityLevel(u, buffcode) != 1 then
return 0.0
else
set tb = GetStruct(u, buffcode)
return tb.ttime
endif
endfunction
function SetBuffTime takes unit u, integer buffcode, real newtime returns boolean
local TimedBuff tb
if GetUnitAbilityLevel(u, buffcode) == 1 and newtime > 0.0 then
set tb = GetStruct(u, buffcode)
call PauseTimer(tb.t)
set tb.time = R2IR(newtime)
set tb.ttime = newtime
call SetUnitAbilityLevel(tb.dummy, tb.buffabil, R2IR(newtime))
call IssueTargetOrder(tb.dummy, tb.order, u)
call TimerStart(tb.t, 1.0, true, function Buff_Loop)
return true
endif
return false
endfunction
function RemoveTimedBuff takes unit u, integer buffcode returns boolean
local TimedBuff tb
local TimedBuff tba
if GetUnitAbilityLevel(u, buffcode) == 1 then
set tb = GetStruct(u, buffcode)
set id = id - 1
set tba = TB[id]
set tba.sid = tb.sid
set TB[tb.sid] = TB[id]
call UnitRemoveAbility(u, buffcode)
call ReleaseTimer(tb.t)
call UnitApplyTimedLife(tb.dummy, 039;BTLF039;, 0.1)
call tb.destroy()
return true
endif
return false
endfunction
function ApplyTimedBuff takes unit u, real time, integer buffcode, integer buffabil returns boolean
local timer t
local TimedBuff tb
if GetWidgetLife(u) > 0.405 then
if GetUnitAbilityLevel(u, buffcode) == 1 then
set tb = GetStruct(u, buffcode)
call PauseTimer(tb.t)
set tb.time = R2IR(time)
set tb.ttime = time
call SetUnitAbilityLevel(tb.dummy, buffabil, R2IR(time))
call IssueTargetOrder(tb.dummy, ORDER, u)
call TimerStart(tb.t, 1.0, true, function Buff_Loop)
else
set t = NewTimer()
set tb = tb.create()
set tb.u = u
set tb.t = t
set tb.dummy = CreateUnit(GetOwningPlayer(u), DUMMY_ID, GetUnitX(u), GetUnitY(u), 0.0)
set tb.buffcode = buffcode
set tb.buffabil = buffabil
set tb.time = R2IR(time)
set tb.ttime = time
set tb.sid = id
call SetTimerData(t, tb)
call UnitAddAbility(tb.dummy, buffabil)
call SetUnitAbilityLevel(tb.dummy, buffabil, R2IR(time))
call IssueTargetOrder(tb.dummy, ORDER, u)
set TB[id] = tb
set id = id + 1
call TimerStart(t, 1.0, true, function Buff_Loop)
endif
set t = null
return true
endif
set t = null
return false
endfunction
function ApplyTimedBuffEx takes unit u, real time, integer buffcode, integer buffabil, integer dummyid, string order returns boolean
local timer t
local TimedBuff tb
if GetWidgetLife(u) > 0.405 then
if GetUnitAbilityLevel(u, buffcode) == 1 then
set tb = GetStruct(u, buffcode)
call PauseTimer(tb.t)
set tb.time = R2IR(time)
set tb.ttime = time
call SetUnitAbilityLevel(tb.dummy, buffabil, R2IR(time))
call IssueTargetOrder(tb.dummy, order, u)
call TimerStart(tb.t, 1.0, true, function Buff_Loop)
else
set t = NewTimer()
set tb = tb.create()
set tb.u = u
set tb.t = t
set tb.dummy = CreateUnit(GetOwningPlayer(u), dummyid, GetUnitX(u), GetUnitY(u), 0.0)
set tb.buffcode = buffcode
set tb.buffabil = buffabil
set tb.time = R2IR(time)
set tb.ttime = time
set tb.order = order
set tb.sid = id
call SetTimerData(t, tb)
call UnitAddAbility(tb.dummy, buffabil)
call SetUnitAbilityLevel(tb.dummy, buffabil, R2IR(time))
call IssueTargetOrder(tb.dummy, order, u)
set TB[id] = tb
set id = id + 1
call TimerStart(t, 1.0, true, function Buff_Loop)
endif
set t = null
return true
endif
set t = null
return false
endfunction
endlibrary
JASS:
//---------------------TIMED---BUFFS---SYSTEM-----------------------
//---------------------------BY---LUORAX----------------------------
//------------------------VERSION----2.1.0--------------------------
//----------------------- _____ ___ ___-----------------------------
//-----------------------|_ _| _ ) __|----------------------------
//-------------------------| | | _ \__ \----------------------------
//-------------------------|_| |___/___/----------------------------
//------------------------------------------------------------------
//------------------------------------------------------------------
//
// - CHANGELOG -
//
// v1.0.0 - 10-09-2010
// The First Release
//
// v1.1.0 - 10-09-2010
// Fixed a bug around the buff removing
//
// v2.0.0 - 10-10-2010
// The complete system is reworked. Now uses the AIDS, the
// Timer Utils (purple) and structs.
// Added the changelog
//
// v2.0.1 - 10-10-2010
// Minor bugfixes, and added some return value
//
// v2.1.0 - 10-17-2010
// The system has been redesigned, now supports reals,
// doesn't use any hashtable, and added/redesigned some function
//
//------------------------------------------------------------------
//------------------------------------------------------------------
//----------------------- _____ ___ ___-----------------------------
//-----------------------|_ _| _ ) __|----------------------------
//-------------------------| | | _ \__ \----------------------------
//-------------------------|_| |___/___/----------------------------
//------------------------VERSION----2.1.0--------------------------
//---------------------------BY---LUORAX----------------------------
//---------------------TIMED---BUFFS---SYSTEM-----------------------
Bug reports, and feedbacks are welcomed!