• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Texttag problem

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
Why does this give a "|c" in the start of the texttag where i create the bar?

JASS:
library BarSystem needs ARGB, Table

    globals
        private integer DEFAULT_BACKGROUND_COLOR = 0xFF808080
        private integer DEFAULT_BAR_COLOR        = 0xFFFF0000
    endglobals

    interface BarInterface
        
    endinterface

    struct Bar extends BarInterface
        texttag Text
    
        unit Target
        
        integer BarSize
        integer PlayerIndex
        
        real TextSize
        
        string Txt
        string PText
        
        string BarType
        
        ARGB Color
        ARGB BackColor
        
        private boolean Locked = false
        private static integer Index = 0
        private static integer array IndexStack
        private static timer Time = CreateTimer()
        
        static method create takes string BarType,  integer BarSize, real TextSize, real x, real y returns thistype
            local thistype this  = thistype.allocate()
            
            set .Text            = CreateTextTag()
            set .BarSize         = BarSize
            set .BarType         = BarType
            set .Color           = ARGB(DEFAULT_BAR_COLOR)
            set .BackColor       = ARGB(DEFAULT_BACKGROUND_COLOR)
            set .TextSize        = TextSize
            
            call .BuildBar()
            
            call SetTextTagText(.Text, .PText, .TextSize)
            call SetTextTagColor(.Text, .BackColor.red, .BackColor.green, .BackColor.blue, .BackColor.alpha)
            call SetTextTagPos(.Text, x, y, -400)
            
            return this
        endmethod
        
        method BuildBar takes nothing returns nothing
            local integer index = 0
            
            set .PText           = ""
            
            loop
                exitwhen index >= .BarSize
                
                set .PText       = .PText + .BarType
                
                set index       = index + 1
            endloop
        endmethod
        
        method operator Value= takes integer value returns nothing
            
            if value > .BarSize then
                set value   = .BarSize
                debug call BJDebugMsg(SCOPE_PREFIX+" value > then BarSize")
            endif
            
            set .Txt        = ""
            
            set .Txt        = .Color.str(SubString(.PText,0, value))
            set .Txt        = .Txt + SubString(.PText, value, .BarSize)
            
            call SetTextTagText(.Text, .Txt, .TextSize)
        endmethod
            
        method LockToUnit takes unit u returns nothing
            set .Target = u
            set .Locked = true
            
            set .IndexStack[.Index] = this
            set .Index = .Index + 1
            
            if .Index == 1 then
                call BJDebugMsg("START")
                call TimerStart(.Time, 0.03,true,function thistype.MoveBar)
            endif
        endmethod
        
        static method MoveBar takes nothing returns nothing
            local thistype this
            local integer index = .Index - 1
            
            loop
                exitwhen index < 0
                
                set this = .IndexStack[index]
                
                call SetTextTagPos(.Text,GetUnitX(.Target),GetUnitY(.Target),-400)
                
                set index = index - 1
            endloop
        endmethod

endlibrary
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
You may eventually need to set the height-offset of those text tags depending on the elevation. I don't know how SetTextTagPos works so it could already factor in elevation, though to be sure, this is the model you would use:

JASS:
globals
    private location loc = Location(0.0, 0.0)
endglobals

        static method MoveBar takes nothing returns nothing
            local thistype this
            local integer index = .Index - 1
            local real x
            local real y
            
            loop
                exitwhen index < 0
                
                set this = .IndexStack[index]
                
                set x = GetUnitX(.Target)
                set y = GetUnitY(.Target)
                call MoveLocation(loc, x, y)
                call SetTextTagPos(.Text, x, y, GetLocationZ(loc) - 400.0)
                
                set index = index - 1
            endloop
        endmethod
 
Status
Not open for further replies.
Top