| 12-13-2008, 03:15 AM | #1 |
Buggy. The text tag doesn't show. What's wrong? JASS:library TimedLife initializer test globals private constant real TIMED_LIFE_UPDATE_INTERVAL_DURATION = 0.01 private constant real TEXT_TAG_HEIGHT_OFFSET = 100.00 private constant real TEXT_TAG_Z_SIZE = 10.00 endglobals struct TimedLife unit u player pOwner texttag tt = CreateTextTag() real rDuration public static method ApplyTimedLife takes unit u, real duration, boolean add returns TimedLife local integer INT_Index = 0 local TimedLife New loop exitwhen INT_Index == TimedLife.intCountInst if TimedLife.Inst[INT_Index].u == u then if add then set TimedLife.Inst[INT_Index].rDuration = TimedLife.Inst[INT_Index].rDuration + duration else set TimedLife.Inst[INT_Index].rDuration = duration endif return TimedLife.Inst[INT_Index] endif set INT_Index = INT_Index + 1 endloop set New = TimedLife.allocate() set New.u = u set New.rDuration = duration call SetTextTagVisibility(New.tt, true) call SetTextTagPermanent(New.tt, true) call SetTextTagPosUnit(New.tt, New.u, GetUnitFlyHeight(New.u) + TEXT_TAG_HEIGHT_OFFSET) set New.intInstIndex = TimedLife.intCountInst set TimedLife.Inst[TimedLife.intCountInst] = New set TimedLife.intCountInst = TimedLife.intCountInst + 1 call TimedLife.ManageTimer(true) return New endmethod public static method UnapplyTimedLife takes unit u returns boolean local integer INT_Index = 0 loop exitwhen INT_Index == TimedLife.intCountInst if TimedLife.Inst[INT_Index].u == u then call DestroyTextTag(TimedLife.Inst[INT_Index].tt) set TimedLife.Inst[INT_Index].tt = null set TimedLife.intCountInst = TimedLife.intCountInst - 1 set TimedLife.Inst[TimedLife.intCountInst].intInstIndex = TimedLife.Inst[INT_Index].intInstIndex set TimedLife.Inst[TimedLife.Inst[INT_Index].intInstIndex] = TimedLife.Inst[TimedLife.intCountInst] set TimedLife.Inst[TimedLife.intCountInst] = 0 call TimedLife.ManageTimer(false) return true endif set INT_Index = INT_Index + 1 endloop return false endmethod private method Update takes nothing returns nothing set .pOwner = GetOwningPlayer(.u) if GetLocalPlayer() == .pOwner then call SetTextTagColor(.tt, 0, 100, 0, 100) else call SetTextTagColor(.tt, 0, 0, 0, 0) endif set .rDuration = .rDuration - TIMED_LIFE_UPDATE_INTERVAL_DURATION if .rDuration > 0.00 then call BJDebugMsg(I2S(R2I(.rDuration))) call SetTextTagText(.tt, I2S(R2I(.rDuration)), TEXT_TAG_Z_SIZE) else call KillUnit(.u) call TimedLife.UnapplyTimedLife(.u) endif endmethod private static timer tim = CreateTimer() private static method ManageTimer takes boolean create returns nothing if TimedLife.intCountInst == 0 then call PauseTimer(TimedLife.tim) elseif TimedLife.intCountInst == 1 and create then call TimerStart(TimedLife.tim, TIMED_LIFE_UPDATE_INTERVAL_DURATION, true, function TimedLife.RunUpdates) endif endmethod private static method RunUpdates takes nothing returns nothing local integer INT_Index = 0 loop exitwhen INT_Index == TimedLife.intCountInst call TimedLife.Inst[INT_Index].Update() set INT_Index = INT_Index + 1 endloop endmethod private static TimedLife array Inst[8190] private static integer intCountInst = 0 private integer intInstIndex endstruct private function test takes nothing returns nothing call TimedLife.ApplyTimedLife(CreateUnit(Player(0), 'Hpal', 0, 0, 0), 10, true) endfunction endlibrary |
| 12-13-2008, 04:08 AM | #2 |
I believe text tag height uses a completely different value system than what you think. Unless you've used tags before with the same values that worked, I think that could be it, the value is usually much more toned down, to something like 0.0025. |
| 12-13-2008, 04:28 AM | #3 |
Still not showin |
| 12-13-2008, 05:50 AM | #4 |
Just read "true" code, not vjass... |
| 12-13-2008, 06:25 AM | #5 |
Works now. Thx. JASS:library TimedLife globals private constant real TIMED_LIFE_UPDATE_INTERVAL_DURATION = 0.01 //Duration between TimedLife updates. private constant real TEXT_TAG_Z_OFFSET = 0.00 private constant integer TEXT_TAG_RED = 255 private constant integer TEXT_TAG_GREEN = 255 private constant integer TEXT_TAG_BLUE = 255 private constant integer TEXT_TAG_ALPHA = 255 private constant string TEXT_TAG_LABEL = "Timed Life|n " private constant string TEXT_TAG_LABEL_COLOR = "|cffB8A26E" private constant string TEXT_TAG_METER_COLOR = "|cffffffff" private constant real TEXT_TAG_SIZE = 0.023 endglobals //=====================================================================================================================// //=====================================================================================================================// //=====================================================================================================================// //=====================================================================================================================// struct TimedLife unit u //The unit for which TimedLife is applied. texttag tt = CreateTextTag() //Text tag that indicates the timed life of the unit when it is selected by its owner. real rDuration //Duration of the timed life. //Adds timed life to a unit, or updates its timed life if already has one. public static method ApplyTimedLife takes unit u, real duration, boolean add returns TimedLife local integer INT_Index = 0 local TimedLife New //If the unit already has a TimedLife, update it with the new duration value... loop exitwhen INT_Index == TimedLife.intCountInst if TimedLife.Inst[INT_Index].u == u then if add then set TimedLife.Inst[INT_Index].rDuration = TimedLife.Inst[INT_Index].rDuration + duration else set TimedLife.Inst[INT_Index].rDuration = duration endif return TimedLife.Inst[INT_Index] endif set INT_Index = INT_Index + 1 endloop //... Or create a new TimedLife object for the unit. set New = TimedLife.allocate() set New.u = u set New.rDuration = duration call SetTextTagPermanent(New.tt, true) call SetTextTagPosUnit(New.tt, New.u, TEXT_TAG_Z_OFFSET) call SetTextTagColor(New.tt, TEXT_TAG_RED, TEXT_TAG_GREEN, TEXT_TAG_BLUE, TEXT_TAG_ALPHA) call SetTextTagText(New.tt, TEXT_TAG_LABEL_COLOR + TEXT_TAG_LABEL + "|r" + TEXT_TAG_METER_COLOR + I2S(R2I(New.rDuration)) + "s|r", TEXT_TAG_SIZE) call SetTextTagPosUnit(New.tt, New.u, TEXT_TAG_Z_OFFSET) //Manage TimedLife objects/indexes. set New.intInstIndex = TimedLife.intCountInst set TimedLife.Inst[TimedLife.intCountInst] = New set TimedLife.intCountInst = TimedLife.intCountInst + 1 call TimedLife.ManageTimer(true) return New endmethod //Removes timed life from a unit. public static method UnapplyTimedLife takes unit u returns boolean local integer INT_Index = 0 //Find the TimedLife object associated with the unit and destroy it. loop exitwhen INT_Index == TimedLife.intCountInst if TimedLife.Inst[INT_Index].u == u then //Flush data. set TimedLife.Inst[INT_Index].u = null call DestroyTextTag(TimedLife.Inst[INT_Index].tt) set TimedLife.Inst[INT_Index].tt = null //Manage TimedLife objects/indexes. set TimedLife.intCountInst = TimedLife.intCountInst - 1 set TimedLife.Inst[TimedLife.intCountInst].intInstIndex = TimedLife.Inst[INT_Index].intInstIndex set TimedLife.Inst[TimedLife.Inst[INT_Index].intInstIndex] = TimedLife.Inst[TimedLife.intCountInst] set TimedLife.Inst[TimedLife.intCountInst] = 0 call TimedLife.ManageTimer(false) return true endif set INT_Index = INT_Index + 1 endloop return false endmethod //Updates TimedLife text tags and durations, and executes terminal (time's up) functions. private method Update takes nothing returns nothing local player P = GetOwningPlayer(.u) //Show the indicator to only the unit's owner if the owner has the unit selected. if GetLocalPlayer() == P and IsUnitSelected(.u , P) then call SetTextTagVisibility(.tt, true) else call SetTextTagVisibility(.tt, false) endif //Update the timed life duration. set .rDuration = .rDuration - TIMED_LIFE_UPDATE_INTERVAL_DURATION //Update the indicator if the unit still has time left and it is still alive... if .rDuration > 0.00 and GetUnitState(.u, UNIT_STATE_LIFE) > 0.00 then call SetTextTagText(.tt, TEXT_TAG_LABEL_COLOR + TEXT_TAG_LABEL + "|r" + TEXT_TAG_METER_COLOR + I2S(R2I(.rDuration)) + "s|r", TEXT_TAG_SIZE) call SetTextTagPosUnit(.tt, .u, TEXT_TAG_Z_OFFSET) //... Else, kill it - if it is still alive - and flush the TimedLife object. else if GetUnitState(.u, UNIT_STATE_LIFE) > 0.00 then call KillUnit(.u) endif call TimedLife.UnapplyTimedLife(.u) endif set P = null endmethod private static timer tim = CreateTimer() //Timer that regularly calls the function that runs runs .Update()s. //Manages the above timer. Activates it when it is to be used and deactivates it when it isn't. private static method ManageTimer takes boolean create returns nothing if TimedLife.intCountInst == 0 then call PauseTimer(TimedLife.tim) elseif TimedLife.intCountInst == 1 and create then call TimerStart(TimedLife.tim, TIMED_LIFE_UPDATE_INTERVAL_DURATION, true, function TimedLife.RunUpdates) endif endmethod //Runs .Update() for all TimedLife objects. private static method RunUpdates takes nothing returns nothing local integer INT_Index = 0 loop exitwhen INT_Index == TimedLife.intCountInst call TimedLife.Inst[INT_Index].Update() set INT_Index = INT_Index + 1 endloop endmethod private static TimedLife array Inst[8190] //TimedLife objects. private static integer intCountInst = 0 //Number of existent TimedLife objects. private integer intInstIndex //Index of a TimedLife object. endstruct endlibrary |
