Custom Floating Text Function?

Cohadar

master of fugue
Reaction score
209
I was thinking of making a floating test function in a form:

function DisplayFloating takes unit someUnit, string message returns nothing

.. that will show a text above my unit (Properly CENTERED)

So I was wondering if someone did this before to save me some work....
 

Arkan

Nobody rides for free
Reaction score
92

SFilip

Gone but not forgotten
Reaction score
634
If someone did then wc3jass.com is a good place to search for it.
 

Cohadar

master of fugue
Reaction score
209
stupid one: I don't have to destroy floating text if I set it's lifespan?
 

Cohadar

master of fugue
Reaction score
209
Code:
//------------------------------------------------------------------------------
// When a player types a chat message prefixed with @
// this trigger will display that message above his hero
//------------------------------------------------------------------------------

globals
    constant integer MEAN_CHAR_WIDTH = 8
    constant integer FONT_SIZE = 10
    constant integer MAX_TEXT_SHIFT = 32
    constant integer TEXT_VELOCITY = 64
endglobals

function Is_It_Alive_Hero takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) and IsUnitAliveBJ(GetFilterUnit()) )
endfunction

function Trig_Floating_Actions takes nothing returns nothing
    local string msg = GetEventPlayerChatString()
    local string tmp
    local unit hero
    local integer shift
    local texttag floater
    local group units

    // first character must be @ or we ignore chat msg
    set tmp = SubString(msg, 0, 1) 
    // we check if hero is alive
    set units = GetUnitsOfPlayerMatching(GetTriggerPlayer(), Condition(function Is_It_Alive_Hero))
    set hero = FirstOfGroup(units)
    call DestroyGroup(units)
    set units = null
    
    // If all conditions are met we display text over hero
    if ((tmp == "@") and (hero != null)) then
        set tmp = SubString(msg, 1, StringLength(msg))
        set shift = IMinBJ(StringLength(tmp), MAX_TEXT_SHIFT)
        set floater = CreateTextTag()
        call SetTextTagTextBJ(floater, tmp, FONT_SIZE)
        call SetTextTagPos(floater,GetUnitX(hero)-shift * MEAN_CHAR_WIDTH, GetUnitY(hero),0)
        call SetTextTagColorBJ(floater, 255, 204, 0, 0)  // standard gold color
        call SetTextTagVelocityBJ( floater, TEXT_VELOCITY, 90 ) // 90 degrees = up
        call SetTextTagPermanent( floater, false )
        call SetTextTagLifespan( floater, 4.00 )
        call SetTextTagFadepoint( floater, 2.50 )
    else
    endif
    
    set msg = null
    set tmp = null
    set hero = null
    set floater = null
endfunction

//===========================================================================
function InitTrig_Floating takes nothing returns nothing
    set gg_trg_Floating = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Floating, Player(0), "@", false )
    call TriggerAddAction( gg_trg_Floating, function Trig_Floating_Actions )
endfunction

Who's da man.
 

Hero

─║╣ero─
Reaction score
250
Code:
//------------------------------------------------------------------------------
// When a player types a chat message prefixed with @
// this trigger will display that message above his hero
//------------------------------------------------------------------------------

globals
    constant integer MEAN_CHAR_WIDTH = 8
    constant integer FONT_SIZE = 10
    constant integer MAX_TEXT_SHIFT = 32
    constant integer TEXT_VELOCITY = 64
endglobals

function Is_It_Alive_Hero takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) and IsUnitAliveBJ(GetFilterUnit()) )
endfunction

function Trig_Floating_Actions takes nothing returns nothing
    local string msg = GetEventPlayerChatString()
    local string tmp
    local unit hero
    local integer shift
    local texttag floater
    local group units

    // first character must be @ or we ignore chat msg
    set tmp = SubString(msg, 0, 1) 
    // we check if hero is alive
    set units = GetUnitsOfPlayerMatching(GetTriggerPlayer(), Condition(function Is_It_Alive_Hero))
    set hero = FirstOfGroup(units)
    call DestroyGroup(units)
    set units = null
    
    // If all conditions are met we display text over hero
    if ((tmp == "@") and (hero != null)) then
        set tmp = SubString(msg, 1, StringLength(msg))
        set shift = IMinBJ(StringLength(tmp), MAX_TEXT_SHIFT)
        set floater = CreateTextTag()
        call SetTextTagTextBJ(floater, tmp, FONT_SIZE)
        call SetTextTagPos(floater,GetUnitX(hero)-shift * MEAN_CHAR_WIDTH, GetUnitY(hero),0)
        call SetTextTagColorBJ(floater, 255, 204, 0, 0)  // standard gold color
        call SetTextTagVelocityBJ( floater, TEXT_VELOCITY, 90 ) // 90 degrees = up
        call SetTextTagPermanent( floater, false )
        call SetTextTagLifespan( floater, 4.00 )
        call SetTextTagFadepoint( floater, 2.50 )
    else
    endif
    
    set msg = null
    set tmp = null
    set hero = null
    set floater = null
endfunction

//===========================================================================
function InitTrig_Floating takes nothing returns nothing
    set gg_trg_Floating = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Floating, Player(0), "@", false )
    call TriggerAddAction( gg_trg_Floating, function Trig_Floating_Actions )
endfunction

Who's da man.


Doesn't look so bad :D

Just get rid of all those ugly BJ's

Unless thats not your Function... lol
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top