"Bounty" text

jomik

New Member
Reaction score
17
Heey again! :D Does anyone have a way to add some good looking text to hover above a unit when you kill it, using a trigger, or when you give gold to a player, through triggers. How'd I make it hover over a specific unit? :O

Thanks :D
 

BRUTAL

I'm working
Reaction score
118
Make a floating text over the dying unit that displays the bounty and set the colour to something goldish.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
JASS:
function GoldBountyFX takes unit u, integer gold, player p returns nothing
    local integer FLYING_GOLD_UNITTYPE = 'z000'
    local texttag t = CreateTextTag()
    local real ux = GetUnitX(u)
    local real uy = GetUnitY(u)
    local real uz = GetUnitFlyHeight(u)
    local destructable d
    local unit f
    if(IsUnitType(u, UNIT_TYPE_FLYING)) then
        set f = CreateUnit(Player(15), FLYING_GOLD_UNITTYPE, ux, uy, 0)
        call SetUnitScale(f, 1, 1, 1)
        call SetUnitFlyHeight(f, uz, 0)
        call UnitAddAbility(f, 'Aloc')
        call SetTextTagText(t, "+" + I2S(gold), 0.023)
        call SetTextTagPosUnit(t, f, -13)
        call KillUnit(f)
    else
        call SetTextTagText(t, "+" + I2S(gold), 0.024)
        call SetTextTagPos(t, ux-16, uy-16, uz)
        set d = CreateDestructableZ('OTip', ux-16, uy-16, uz, 0.00, 1, 0) //http://wc3jass.com/viewtopic.php?t=2472
        call DestroyEffect(AddSpecialEffect("UI\\Feedback\\GoldCredit\\GoldCredit.mdl", ux-16, uy-16))
        call RemoveDestructable(d)
    endif
    call SetTextTagColor(t, 255, 220, 0, 255)
    call SetTextTagVelocity(t, 0, 0.03)
    call SetTextTagVisibility(t, GetLocalPlayer() == p)
    call SetTextTagFadepoint(t, 2)
    call SetTextTagLifespan(t, 3)
    call SetTextTagPermanent(t, false)
    set t = null
    set f = null
    set d = null
endfunction


[edit 2] OK, this is as authentic as I know how to make it. It needs the special dummy unit from the attached map.
 

Attachments

  • GoldBountyUnit.w3x
    16.6 KB · Views: 209

jomik

New Member
Reaction score
17
And there's no leaks here?! :O AWESOME! Thanks dude :D
+rep clearly! :D - well if it works :p

EDIT: Works awesomely!! :D
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
OK, so, I've been testing it more since I noticed a big vertical offset that I hadn't previously seen since I'd only tested it with an overhead camera...

It's still not perfect (I've edited my previous post), but I think I'm finally on the right track. ...hate flying units, hate how there's no way to get their exact Z coordinate, hate hate hate....
 

jomik

New Member
Reaction score
17
Well it looks fine to me :O there wont be any units with normal bounty in my map, and probably not alot of flying units either, so this is awesome :D But I'll update it :D Thanks for updating it even now :O
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
//==============================================================================
//  TEXT TAG - Floating text system by Cohadar - v5.0
//==============================================================================
//
//  PURPOUSE:
//       * Displaying floating text - the easy way
//       * Has a set of useful and commonly needed texttag functions
//  
//  CREDITS:
//       * DioD - for extracting proper color, fadepoint and lifespan parameters
//         for default warcraft texttags (from miscdata.txt)
//
//  HOW TO IMPORT:
//       * Just create a trigger named TextTag
//         convert it to text and replace the whole trigger text with this one
//==============================================================================

library TextTag

globals    
    // for custom centered texttags
    private constant real MEAN_CHAR_WIDTH = 7
    private constant real MAX_TEXT_SHIFT = 200.0
    private constant real DEFAULT_HEIGHT = 16.0

    // for default texttags
    private constant real   SIGN_SHIFT = 16.0
    private constant real   FONT_SIZE = 0.024
    private constant string MISS = "miss"
    private constant string BLOCK = "block"
endglobals

//===========================================================================
//   Custom centered texttag on (x,y) position
//   color is in default wc3 format, for example "|cFFFFCC00"
//===========================================================================
public function XY takes real x, real y, string text, string color returns nothing
    local texttag tt = CreateTextTag()
    local real shift = RMinBJ(StringLength(text)*MEAN_CHAR_WIDTH, MAX_TEXT_SHIFT)
    call SetTextTagText(tt, color+text, FONT_SIZE)
    call SetTextTagPos(tt, x-shift, y, DEFAULT_HEIGHT)
    call SetTextTagVelocity(tt, 0.0, 0.04)
    call SetTextTagVisibility(tt, true)
    call SetTextTagFadepoint(tt, 2.5)
    call SetTextTagLifespan(tt, 4.0)
    call SetTextTagPermanent(tt, false)
    set tt = null
endfunction

//===========================================================================
//   Custom centered texttag above unit
//===========================================================================
public function Unit takes unit whichUnit, string text, string color returns nothing
    local texttag tt = CreateTextTag()
    local real shift = RMinBJ(StringLength(text)*MEAN_CHAR_WIDTH, MAX_TEXT_SHIFT)
    call SetTextTagText(tt, color+text, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit)-shift, GetUnitY(whichUnit), DEFAULT_HEIGHT)
    call SetTextTagVelocity(tt, 0.0, 0.04)
    call SetTextTagVisibility(tt, true)
    call SetTextTagFadepoint(tt, 2.5)
    call SetTextTagLifespan(tt, 4.0)
    call SetTextTagPermanent(tt, false)    
    set tt = null
endfunction

//===========================================================================
//  Standard wc3 gold bounty texttag, displayed only to killing player 
//===========================================================================
public function GoldBounty takes unit whichUnit, integer bounty, player killer returns nothing
    local texttag tt = CreateTextTag()
    local string text = "+" + I2S(bounty)
    call SetTextTagText(tt, text, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit)-SIGN_SHIFT, GetUnitY(whichUnit), 0.0)
    call SetTextTagColor(tt, 255, 220, 0, 255)
    call SetTextTagVelocity(tt, 0.0, 0.03)
    call SetTextTagVisibility(tt, GetLocalPlayer()==killer)
    call SetTextTagFadepoint(tt, 2.0)
    call SetTextTagLifespan(tt, 3.0)
    call SetTextTagPermanent(tt, false)
    set text = null
    set tt = null
endfunction

//==============================================================================
public function LumberBounty takes unit whichUnit, integer bounty, player killer returns nothing
    local texttag tt = CreateTextTag()
    local string text = "+" + I2S(bounty)
    call SetTextTagText(tt, text, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit)-SIGN_SHIFT, GetUnitY(whichUnit), 0.0)
    call SetTextTagColor(tt, 0, 200, 80, 255)
    call SetTextTagVelocity(tt, 0.0, 0.03)
    call SetTextTagVisibility(tt, GetLocalPlayer()==killer)
    call SetTextTagFadepoint(tt, 2.0)
    call SetTextTagLifespan(tt, 3.0)
    call SetTextTagPermanent(tt, false)
    set text = null
    set tt = null
endfunction

//===========================================================================
public function ManaBurn takes unit whichUnit, integer dmg returns nothing
    local texttag tt = CreateTextTag()
    local string text = "-" + I2S(dmg)
    call SetTextTagText(tt, text, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit)-SIGN_SHIFT, GetUnitY(whichUnit), 0.0)
    call SetTextTagColor(tt, 82, 82 ,255 ,255)
    call SetTextTagVelocity(tt, 0.0, 0.04)
    call SetTextTagVisibility(tt, true)
    call SetTextTagFadepoint(tt, 2.0)
    call SetTextTagLifespan(tt, 5.0)
    call SetTextTagPermanent(tt, false)    
    set text = null
    set tt = null
endfunction

//===========================================================================
public function Miss takes unit whichUnit returns nothing
    local texttag tt = CreateTextTag()
    call SetTextTagText(tt, MISS, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit), GetUnitY(whichUnit), 0.0)
    call SetTextTagColor(tt, 255, 0, 0, 255)
    call SetTextTagVelocity(tt, 0.0, 0.03)
    call SetTextTagVisibility(tt, true)
    call SetTextTagFadepoint(tt, 1.0)
    call SetTextTagLifespan(tt, 3.0)
    call SetTextTagPermanent(tt, false)
    set tt = null
endfunction

//===========================================================================
public function Block takes unit whichUnit returns nothing
    local texttag tt = CreateTextTag()
    call SetTextTagText(tt, BLOCK, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit)-SIGN_SHIFT, GetUnitY(whichUnit), 0.0)
    call SetTextTagColor(tt, 0, 255, 0, 255)
    call SetTextTagVelocity(tt, 0.0, 0.03)
    call SetTextTagVisibility(tt, true)
    call SetTextTagFadepoint(tt, 1.0)
    call SetTextTagLifespan(tt, 3.0)
    call SetTextTagPermanent(tt, false)
    set tt = null
endfunction

//===========================================================================
public function CriticalStrike takes unit whichUnit, integer dmg returns nothing
    local texttag tt = CreateTextTag()
    local string text = I2S(dmg) + "!"
    call SetTextTagText(tt, text, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit), GetUnitY(whichUnit), 0.0)
    call SetTextTagColor(tt, 255, 0, 0, 255)
    call SetTextTagVelocity(tt, 0.0, 0.04)
    call SetTextTagVisibility(tt, true)
    call SetTextTagFadepoint(tt, 2.0)
    call SetTextTagLifespan(tt, 5.0)
    call SetTextTagPermanent(tt, false)
    set text = null
    set tt = null    
endfunction

//===========================================================================
public function ShadowStrike takes unit whichUnit, integer dmg, boolean initialDamage returns nothing
    local texttag tt = CreateTextTag()
    local string text = I2S(dmg)
    if initialDamage then
        set text = text + "!"
    endif
    call SetTextTagText(tt, text, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit), GetUnitY(whichUnit), 0.0)
    call SetTextTagColor(tt, 160, 255, 0, 255)
    call SetTextTagVelocity(tt, 0.0, 0.04)
    call SetTextTagVisibility(tt, true)
    call SetTextTagFadepoint(tt, 2.0)
    call SetTextTagLifespan(tt, 5.0)
    call SetTextTagPermanent(tt, false)    
    set text = null
    set tt = null
endfunction

//###########################################################################
//  Custom TextTags for Pyramidal Defence
//###########################################################################

//===========================================================================
public function BonusDamage takes unit whichUnit, integer dmg returns nothing
    local texttag tt = CreateTextTag()
    local string text = I2S(dmg)
    if dmg > 0 then
        set text = "+"+text
    endif
    call SetTextTagText(tt, text, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit)-SIGN_SHIFT, GetUnitY(whichUnit), 0.0)
    call SetTextTagColor(tt, 255, 0, 0, 255)
    call SetTextTagVelocity(tt, 0.0, 0.04)
    call SetTextTagVisibility(tt, true)
    call SetTextTagFadepoint(tt, 2.0)
    call SetTextTagLifespan(tt, 4.0)
    call SetTextTagPermanent(tt, false)
    set text = null
    set tt = null    
endfunction

//===========================================================================
public function Monster takes unit whichUnit, string text returns nothing
    local texttag tt = CreateTextTag()
    local real shift = RMinBJ(StringLength(text)*MEAN_CHAR_WIDTH, MAX_TEXT_SHIFT)
    call SetTextTagText(tt, text, FONT_SIZE)
    call SetTextTagPos(tt, GetUnitX(whichUnit)-shift, GetUnitY(whichUnit), DEFAULT_HEIGHT)
    call SetTextTagColor(tt, 255, 0, 0, 255)
    call SetTextTagVelocity(tt, 0.0, 0.04)
    call SetTextTagVisibility(tt, true)
    call SetTextTagFadepoint(tt, 2.5)
    call SetTextTagLifespan(tt, 4.0)
    call SetTextTagPermanent(tt, false)    
    set tt = null
endfunction

endlibrary


This is more nice, is it?
 

jomik

New Member
Reaction score
17
@King, ahh nope :S It says -X and theres no gold effect :O I prefer Weep's then :D
But your updated version doesn't work, it says undeclared variable text...
 

BRUTAL

I'm working
Reaction score
118
Because he forgot to put ' "+" + I2S(gold) ' in where it says text i presume.
Try this.
JASS:
function GoldBountyFX takes unit u, integer gold, player p returns nothing
	local texttag t = CreateTextTag()
	local real ux = GetUnitX(u)
	local real uy = GetUnitY(u)
	if(IsUnitType(GetTriggerUnit(), UNIT_TYPE_FLYING)) then
		// NOTE: For perfect accuracy in a later revision, this is going to need a non-tilting 0-size flying dummy unit, I think. 
		call SetTextTagText(t, "+" + I2S(gold), 0.023)
		call SetTextTagPosUnit(t, u, -100)
		call DestroyEffect(AddSpecialEffectTarget("UI\\Feedback\\GoldCredit\\GoldCredit.mdl", u, "origin"))
	else
		call SetTextTagText(t, "+" + I2S(gold), 0.025)
		call SetTextTagPos(t, ux-16, uy-16, 0)
		call DestroyEffect(AddSpecialEffect("UI\\Feedback\\GoldCredit\\GoldCredit.mdl", ux, uy))
	endif
	call SetTextTagColor(t, 255, 220, 0, 255)
	call SetTextTagVelocity(t, 0, 0.03)
	call SetTextTagVisibility(t, GetLocalPlayer() == p)
	call SetTextTagFadepoint(t, 2)
	call SetTextTagLifespan(t, 3)
	call SetTextTagPermanent(t, false)
	set t = null
endfunction


I removed the following parts cause they seemed stupid as hell.
JASS:
else
		call SetUnitX(u, ux - 16) // This.
		call SetUnitY(u, uy - 16) // And this.
		call SetTextTagText(t, "+" + I2S(gold), 0.025)
		call SetTextTagPos(t, ux-16, uy-16, 0)
		call SetUnitX(u, ux) // These two as well. 
		call SetUnitY(u, uy)// <
		call DestroyEffect(AddSpecialEffect("UI\\Feedback\\GoldCredit\\GoldCredit.mdl", ux, uy))
	endif

The SetTextTagPos already had ux-16, and uy-16 in the line anyways, so that is why the commented lines are odd.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Because he forgot to put ' "+" + I2S(gold) ' in where it says text i presume.
Yeah, a victim of copy/paste and not enough proofreading. :p

The SetTextTagPos already had ux-16, and uy-16 in the line anyways, so that is why the commented lines are odd.
Indeed, I had been using that to offset the text when it was using SetTextTagPosUnit(), but then I realized that for ground units it should just use SetTextTagPos() (the text appears from their feet, not overhead) and I forgot to take out those lines. That's what I get for editing the code madly late at night... :nuts:

Edited the original post.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
OK, I edited the previous post again. This is as close to exactly matching the in-game bounty FX and text as I know how.

flying units and effects at a z offset with no tilting FFFFFFFFF
 

jomik

New Member
Reaction score
17
Oww thanks dude :D Is it MUI? I'll be having like... 100++ units that gives this bounty or something? :O So not sure if a dummy is a good idea :O
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Oww thanks dude :D Is it MUI? I'll be having like... 100++ units that gives this bounty or something? :O So not sure if a dummy is a good idea :O
Heh, WC3 can only display 100 texttags at a time anyway. Yeah, it's MUI.

The unit is only made if the dying unit is a flying unit; it's the only way to accurately do anything at a flying unit's actual height (eg. if it's over trees).

If your map has no trees or buildings or cliffs, or you don't care, you could also use:
JASS:
function GoldBountyFX takes unit u, integer gold, player p returns nothing
    local texttag t = CreateTextTag()
    local real ux = GetUnitX(u)
    local real uy = GetUnitY(u)
    local real uz = GetUnitFlyHeight(u)
    local destructable d
    if(IsUnitType(u, UNIT_TYPE_FLYING)) then
        call SetTextTagText(t, "+" + I2S(gold), 0.023)
        call SetTextTagPos(t, ux, uy, uz)
    else
        call SetTextTagText(t, "+" + I2S(gold), 0.024)
        call SetTextTagPos(t, ux-16, uy-16, uz)
    endif
    set d = CreateDestructableZ('OTip', ux-16, uy-16, uz, 0.00, 1, 0) //http://wc3jass.com/viewtopic.php?t=2472
    call DestroyEffect(AddSpecialEffect("UI\\Feedback\\GoldCredit\\GoldCredit.mdl", ux-16, uy-16))
    call RemoveDestructable(d)
    call SetTextTagColor(t, 255, 220, 0, 255)
    call SetTextTagVelocity(t, 0, 0.03)
    call SetTextTagVisibility(t, GetLocalPlayer() == p)
    call SetTextTagFadepoint(t, 2)
    call SetTextTagLifespan(t, 3)
    call SetTextTagPermanent(t, false)
    set t = null
    set d = null
endfunction
 

jomik

New Member
Reaction score
17
It'll have trees, buildings and cliffs, but no flying units :p
- It can display 100 per player right? :D
I might do it in another way though, with a multiboard or something...
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
- It can display 100 per player right? :D
Maybe?

Also, that business with the destructible is only needed if any of the ground units have a height other than 0 (like most default hovering units). Without that it would be:

JASS:
function GoldBountyStrictGroundFX takes unit u, integer gold, player p returns nothing
    local texttag t = CreateTextTag()
    local real ux = GetUnitX(u)
    local real uy = GetUnitY(u)
    call SetTextTagText(t, "+" + I2S(gold), 0.024)
    call SetTextTagPos(t, ux-16, uy-16, GetUnitFlyHeight(u)) //Meh.
    call DestroyEffect(AddSpecialEffect("UI\\Feedback\\GoldCredit\\GoldCredit.mdl", ux-16, uy-16))
    call SetTextTagColor(t, 255, 220, 0, 255)
    call SetTextTagVelocity(t, 0, 0.03)
    call SetTextTagVisibility(t, GetLocalPlayer() == p)
    call SetTextTagFadepoint(t, 2)
    call SetTextTagLifespan(t, 3)
    call SetTextTagPermanent(t, false)
    set t = null
endfunction
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Yeah. It'll "work" for flying unit too, just that the bounty FX will be on the ground. :p
 
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