Exfyre
hmm...
- Reaction score
- 60
What it does:
When a unit is damaged, this will show the damage (if it is greater than or equal to one). Setting the options will alow you to select which damage the player will be able to see.
Notes:
Jass Newgen Pack is required (or a similar vJass compiler)
Works for both units already placed on the map and units added to the map via triggers
Works with 1.24 patch
Instructions on use:
1. copy the code below
2. create a trigger in your map
3. convert the trigger to custom text
4. erase everything in the trigger
5. paste this code there
6. customize options
Options:
boolean showToAllPlayers = true (When set to false, text will only show to the player dealing the damage)
boolean showToSelected = false (When set to true, only units who are selected by the player will show their damage and showToAllPlayers must be false)
^-boolean bothWays = false (When set to true, AND showToSelected is true, this will show both the damage received and the damage dealt by the selected unit. (default of false shows only damage dealt))
Old code: (standalone but leaky)
New Code: Uses Jesus4lyf's Damage
Required:
Jass NewGen
Damage
AIDS (link is on Damage post)
Event (link is on Damage post)
When a unit is damaged, this will show the damage (if it is greater than or equal to one). Setting the options will alow you to select which damage the player will be able to see.
Notes:
Jass Newgen Pack is required (or a similar vJass compiler)
Works for both units already placed on the map and units added to the map via triggers
Works with 1.24 patch
Instructions on use:
1. copy the code below
2. create a trigger in your map
3. convert the trigger to custom text
4. erase everything in the trigger
5. paste this code there
6. customize options
Options:
boolean showToAllPlayers = true (When set to false, text will only show to the player dealing the damage)
boolean showToSelected = false (When set to true, only units who are selected by the player will show their damage and showToAllPlayers must be false)
^-boolean bothWays = false (When set to true, AND showToSelected is true, this will show both the damage received and the damage dealt by the selected unit. (default of false shows only damage dealt))
Old code: (standalone but leaky)
JASS:
scope DDetector initializer Init
globals
public boolean showToAllPlayers = true
//showToAllPlayers: When set to false, text will only show to the player dealing the damage
public boolean showToSelected = false
//showToSelected: When set to true, only units who are selected by the player will show their damage
// and showToAllPlayers must be false
public boolean bothWays = false
//bothWays: When set to true, AND showToSelected is true, this will show both the damage received and
// the damage dealt by the selected unit. (default of false shows only damage dealt)
private constant integer red = 255
private constant integer green = 0
private constant integer blue = 0
//red, green, and blue: Set out of 255 for text color
//CUSTOM AREA OVER
private integer i
endglobals
private function cc takes nothing returns boolean
local unit u = GetFilterUnit()
local boolean b = IsUnitSelected(u, Player(i))
set u = null
return b
endfunction
private function Act takes nothing returns nothing
local texttag t = CreateTextTag()
local group g
local unit source = GetEventDamageSource()
local unit hurt = GetTriggerUnit()
if GetEventDamage() >= 1 then
set i = 0
loop
set g = CreateGroup()
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Condition(function cc))
if ((GetLocalPlayer() == GetOwningPlayer(source) and showToSelected == false) or showToAllPlayers == true) or (showToSelected == true and IsUnitInGroup(source, g)) or (bothWays == true and showToSelected == true and (IsUnitInGroup(hurt, g) or IsUnitInGroup(source, g))) then
call SetTextTagText(t, I2S(R2I(GetEventDamage())), .023)
call SetTextTagPos(t, GetUnitX(hurt), GetUnitY(hurt), 0)
call SetTextTagColor(t, red, green, blue, 255)
call SetTextTagFadepoint(t, 2)
call SetTextTagLifespan(t, 3)
call SetTextTagPermanent(t, false)
call SetTextTagVelocity(t, 0, 0.071 / 2)
endif
call DestroyGroup(g)
exitwhen i == 7
set i = i+1
endloop
endif
set t = null
set source = null
set hurt = null
set g = null
endfunction
private function Actions takes nothing returns nothing
local trigger tt = CreateTrigger()
call TriggerRegisterUnitEvent(tt, GetTriggerUnit(), EVENT_UNIT_DAMAGED)
call TriggerAddAction(tt, function Act)
endfunction
private function z2 takes unit u returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_DAMAGED)
call TriggerAddAction(t, function Act)
set u = null
return
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger tt = CreateTrigger()
local group g = CreateGroup()
local unit u
local region rectRegion = CreateRegion()
call RegionAddRect(rectRegion, bj_mapInitialPlayableArea)
call TriggerRegisterEnterRegion(tt, rectRegion, null)
call TriggerAddAction(tt, function Actions)
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
call z2(u)
endloop
call DestroyGroup(g)
set g = null
set u = null
endfunction
endscope
New Code: Uses Jesus4lyf's Damage
Required:
Jass NewGen
Damage
AIDS (link is on Damage post)
Event (link is on Damage post)
JASS:
scope DDetector initializer Init
globals
public boolean showToAllPlayers = true
//showToAllPlayers: When set to false, text will only show to the player dealing the damage
public boolean showToSelected = false
//showToSelected: When set to true, only units who are selected by the player will show their damage
// and showToAllPlayers must be false
public boolean bothWays = false
//bothWays: When set to true, AND showToSelected is true, this will show both the damage received and
// the damage dealt by the selected unit. (default of false shows only damage dealt)
private constant string physicalColor = "|cffff0000"
//physicalColor: Hex color code for physical damage
private constant string spellColor = "|cff7777aa"
//physicalColor: Hex color code for spell damage
private constant real fadepoint = 2
private constant real lifespan = 3
private constant real size = 10
//CUSTOM AREA OVER
private integer i
private group g = CreateGroup()
endglobals
private function cc takes nothing returns boolean
return IsUnitSelected(GetFilterUnit(), Player(i))
endfunction
private function Act takes nothing returns nothing
local texttag t = CreateTextTag()
local unit source = GetEventDamageSource()
local unit hurt = GetTriggerUnit()
local string color
if Damage_IsPhysical() then
set color = physicalColor
elseif Damage_IsSpell() then
set color = spellColor
endif
if GetEventDamage() >= 1 then
set i = 0
loop
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Condition(function cc))
if ((GetLocalPlayer() == GetOwningPlayer(source) and showToSelected == false) or showToAllPlayers == true) or (showToSelected == true and IsUnitInGroup(source, g)) or (bothWays == true and showToSelected == true and (IsUnitInGroup(hurt, g) or IsUnitInGroup(source, g))) then
call SetTextTagText(t, color + I2S(R2I(GetEventDamage())), size * 0.023 / 10)
call SetTextTagPos(t, GetUnitX(hurt), GetUnitY(hurt), 0)
call SetTextTagFadepoint(t, fadepoint)
call SetTextTagLifespan(t, lifespan)
call SetTextTagPermanent(t, false)
call SetTextTagVelocity(t, 0, 0.071 / 2)
endif
exitwhen i == 7
set i = i+1
endloop
endif
set t = null
set source = null
set hurt = null
set g = null
endfunction
private function Init takes nothing returns nothing
local trigger tt = CreateTrigger()
call TriggerAddAction(tt, function Act)
call Damage_RegisterEvent(tt)
endfunction
endscope