• 🏆 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!

[Solved] [Solved] Problem with a Library that moves a TextTag periodically

Status
Not open for further replies.
Level 6
Joined
Jan 4, 2014
Messages
227
Good Day, The Goal of the folowing 2 JASS triggers is to create a TextTag and store it in a hashtable, then move it every 33 ms using the second trigger, have a look :

JASS:
//Health, Mana and Vision Dummy
library HMVD // v 0.0.0.1
    
    globals
        hashtable HMVDHash = InitHashtable()
        integer HMVDCount = 0       
    endglobals
    
    function HMVDAdd takes unit u returns nothing
        local player p
        local string color
        local string s
        local location l
        local texttag t
        local force f
        if u != null then
            set p = GetOwningPlayer(u)
            set f = GetPlayersAll()
            set HMVDCount = HMVDCount + 1
            call SaveUnitHandle(HMVDHash, 1, HMVDCount, u)
            
            if IsPlayerAlly(p , Player(0)) then 
                set color = "|c00ff0303"
            elseif IsPlayerAlly(p, Player(6)) then 
                set color = "|c0020c000"
            endif
            set s = color + "100%" + "|r" + " / " + "|c00540081" + "100%" + "|r"
            
            set l = GetUnitLoc(u)
            //set t = 
            call SaveTextTagHandle(HMVDHash, 2, HMVDCount, CreateTextTagLocBJ(s, l, 196.00, 10, 100, 100, 100, 50.00))
            call ShowTextTagForceBJ(true, LoadTextTagHandle(HMVDHash, 2, HMVDCount), f)
            call SetTextTagPermanent(LoadTextTagHandle(HMVDHash, 2, HMVDCount), true)
            //call SaveBoolean(HMVDHash, 4, HMVDCount, false)
            //call SaveStr(HMVDHash, 5, HMVDCount, s)
        endif
    endfunction
    
endlibrary

JASS:
function HMVDLoop takes nothing returns nothing
    local integer i
    local unit u
    local location L1
    local location L2
    local texttag tt
    local player p
    local string s
    local string color
    if HMVDCount > 0 then
        set i = 1
        loop
            exitwhen i > HMVDCount
            
            
            set u = LoadUnitHandle(HMVDHash, 1, i)
            set p = GetOwningPlayer(u)
            set L1 = GetUnitLoc(u)
            set L2 = PolarProjectionBJ(L1, 64, 180)
            set tt = LoadTextTagHandle(HMVDHash, 2, i)
            call SetTextTagPos(tt, GetLocationX(L2), GetLocationY(L2), 196)
            //===================================================================
            if IsPlayerAlly(p , Player(0)) then 
                set color = "|c00ff0303"
            elseif IsPlayerAlly(p, Player(6)) then 
                set color = "|c0020c000"
            endif
            set s = color + "100%" + "|r" + " / " + "|c00540081" + "100%" + "|r"
            //===================================================================
            call SetTextTagText(tt, s, 10)
            
            call BJDebugMsg(s)
            call BJDebugMsg("HMVDLoop = "+I2S(i)+" On "+GetUnitName(u))
            
            set i = i + 1
            
        endloop
    endif
endfunction

//===========================================================================
function InitTrig_HMVDLoop takes nothing returns nothing
    set gg_trg_HMVDLoop = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_HMVDLoop, udg_Timer30 )
    call TriggerAddAction( gg_trg_HMVDLoop, function HMVDLoop )
endfunction

[SOLVED] The problem is that i see no text over my character, what could be the problem.

Also, i need to know if is it possible to merge the two triggers into one "library"? so that it can be configurable and usable in any other map.

Thanks :)

================================

Problem 1 solved : changed the text size from 10 to 0.023, Thanks to wietlol :)
 
Last edited:
Level 22
Joined
Feb 6, 2014
Messages
2,466
Here

Hope you learn some coding techniques from there ;)

JASS:
library HMV

    globals
        private constant real TEXT_HEIGHT = 50
        private constant real TIMEOUT = 0.03125
        
        
        private unit array u
        private texttag array tt
        private integer i = -1
        private timer periodic = CreateTimer()
    endglobals
    
    private function HMVPeriodic takes nothing returns nothing
        local integer j = 0
        loop
            exitwhen j > i
            call SetTextTagPos(tt[j], GetUnitX(u[j]), GetUnitY(u[j]), TEXT_HEIGHT)
            set j = j + 1
        endloop
    endfunction
    
    //O(n) remove
    function RemoveHMV takes unit whichUnit returns nothing
        local integer j = 0
        loop
            exitwhen j > i
            if u[j] == whichUnit then
                //deindex
                set u[j] = u[i]
                set tt[j] = tt[i]
                call SetTextTagPermanent(tt[i], false)
                call DestroyTextTag(tt[i])
                set i = i - 1
                if i == -1 then
                    call PauseTimer(periodic)
                endif
                exitwhen true
            endif
            set j = j + 1
        endloop
    endfunction
    
    function AddHMV takes unit whichUnit returns nothing
        local string s
        local player p
        local string color
        if whichUnit != null then
            set p = GetOwningPlayer(whichUnit)
            set i = i + 1
            call BJDebugMsg(GetUnitName(whichUnit) + " is added to HMV")
            set u[i] = whichUnit
            
            //Texttag String
            if IsPlayerAlly(p , Player(0)) then 
                set color = "|c00ff0303"
            elseif IsPlayerAlly(p, Player(6)) then 
                set color = "|c0020c000"
            endif
            set s = color + "100%" + "|r" + " / " + "|c00540081" + "100%" + "|r"
            
            //Texttag
            set tt[i] = CreateTextTag()
            call SetTextTagPermanent(tt[i], true)
            call SetTextTagVisibility(tt[i], true)
            call SetTextTagPos(tt[i], GetUnitX(whichUnit), GetUnitY(whichUnit), TEXT_HEIGHT)
            call SetTextTagText(tt[i], s, 0.024)
            
            
            
            
            if i == 0 then
                call TimerStart(periodic, TIMEOUT, true, function HMVPeriodic)
            endif
        endif
        call BJDebugMsg("HMV ends")
    endfunction


endlibrary

EDIT: O(n) on removal but no hashtable needed. It's up to you to decide what's more important
 

Attachments

  • HMV.w3m
    17.7 KB · Views: 58
Last edited:
Level 6
Joined
Jan 4, 2014
Messages
227
Thanks man ! instead of copying it ready, i'm gonna do it in y library step by step, trust me :)

just a question, why dont you use a hashtable ??
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
Thanks man ! instead of copying it ready, i'm gonna do it in y library step by step, trust me :)
That's good, you will learn it by doing it.


just a question, why dont you use a hashtable ??
Because in the 'child key' (which is HMVDCount) you are using does not exceed 8192 so you can use arrays instead. Hashtable are like two dimensional arrays that can have an index much greater than 8192. Plus, it is best to avoid using Hashtable if you can because it is limited to 256 (or 255?) per map.

Edut: My bad, on the Remove HVM function, I forgot to destroy the text tag..
 
Status
Not open for further replies.
Top