Floating Damage Indicator

To show damage overhead of player or entity.

indicator

Installation

To install just drop FloatingDamageIndicator on entity or player template. In case of entity you would need to adjust widget config to set Visibility from Remote Only to Everyone. Remote Only is enabled by default, because player likely does not need to see damage to them additionally.

Features

Attaching to OnDamage

By default package would listen in OnDamage call and use received damage (as well as causer) to display it as a floating number. You can control whether this is enabled or not using listenToDamage property on FloatingDamage script.

Several Damages

  • Each next item appears at a different position and then they float away at a different angles. Even if items are not displayed at the same time, angle change applies to each new item, until number reaches 10 or 5 seconds since last added item passed (when angle for new items would be dropped back to starting point).
  • This still has couple of quirks needed to work out - it seems like new items woudl reset animations on old ones, which might be hard to avoid since it is Gameface bug.

Show Only to Damage Causer

FloatingDamage script has onlyToCauser property, which you can turn on in order to display damage only on the client of a player, who dealt the damage.

UI Customizations

Currently font and color could be customized with properties for all of displayed damages or using custom call for every one differently.

  • font property simply defines font for all entries, pick any value from list of fonts: Using Fonts in Crayta | Crayta Developer Area. Take a part from there, which is before .ttf in font file name. For example for “Ewert-Regular.ttf” that would be “Ewert-Regular”
  • defaultDamageColor defines color for damage entries when amount is positive
  • defaultHealColor defines color for damage entries when amount is negative (i.e. healing)

Properties for color accept any CSS compatible strings that represent color.
Examples: “red” for simply red color. “rgba(200, 0, 0, 1)” for dark red. “#aa00bb” for some purpleish color.

If you want custom color or font for every item based on some game specific logic, like posion damage is green, electric blue, etc - you will firstly need to disable “listenToDamage” property. Then you need to call ShowFloatingDamage method from FloatingDamage script on the player or entity you installed template on.
Example call:

player:SendToScripts("ShowFloatingDamage", amount, causer, { color = "blue", font = "Eater-Regular"})
  • amount is a number - how much damage happened
  • causer is who caused damage - only used when onlyToCauser is set to true
  • color is any CSS compatible string that represent color
  • font is a name of font, you can pick any value from list of fonts: Using Fonts in Crayta | Crayta Developer Area. Take a part from there, which is before .ttf in font file name. For example for “Ewert-Regular.ttf” that would be “Ewert-Regular”. There is no need to pass fontname additionally, same value would be used for name as well.

Showing Sign

By default in front of usual positive damage, indicator would add minus sign, so that it would be clear that player lost some health. Same goes for negative damage (healing) - sign would be plus. If you do not want any sign shown - you can disable showSign property on FloatingDamage script - then only absolute value would be displayed.

Ignoring Zero

If by some reason in your game some damages are zero and you do not want to show them - just turn on property ignoreZero.

Roadmap:

  • allow several uninterrupted damages : done (kinda)
  • allow to show only to player, who made the damage : done
  • deduplicate damages when there is a lot of small ones
  • customizeable font size
  • add randomized variation to angle
  • scale text based on amount of damage (bigger damage - bigger size)
  • add randomized variation to scale
  • make (optional) damage item “continue” movement in the direction of damage dealt (this would make more sense for “2D” games, where camera angle is locked)

Update 2022/02/06

Added better support for several damages in a row

  • Each next item appear at a different position and then they float away at a different angles. Even if items are not displayed at the same time, angle change applies to each new item, until number reaches 10 or 5 seconds since last added item passed (when angle for new items would be dropped back to starting point).
  • This still has couple of quirks needed to work out - it seems like new items woudl reset animations on old ones, which might be hard to avoid since it is Gameface bug.

Customizeable font

  • You can set “font” property on FloatingDamage script to any value from list of fonts : Using Fonts in Crayta | Crayta Developer Area .
  • Additionally you could set font on the options passed to method ShowFloatingDamage , so that font would be different only for that item. However, this approach requires disabling automatic listening for damage (uncheck property listenToDamage) and then manually calling ShowFloatingDamage. It has following signature: ShowFloatingDamage(amount, causer, opts) . Causer should be player or user, who made the damage. Opts is a table with optional parameters, one of them is font.

Customizeable color

  • Color could be customized as a propety for two different situations - when damage is negative, it is considered healing and property “defaultHealColor” is used to define color. You can use any CSS compatible color there. For regular (positive) damage use “defaultDamageColor” property.
  • Same as font you can also customize color for specific item, in which case you can use “color” field for options table in the call to ShowFloatingDamage. Read customization for font above to know more how this works.

Showing only to damage causer

By default widget is configured to be “Remote Only” so that owner of player would not see damage to himself (because it is likely displayed differently). In addition to this, there is now property on script FloatingDamage called “onlyToCauser”.
If set to true - this will make it so that indicator only shown to causer of damage and no other user.
If you use “onlyToCauser” it is still makes sense to use “Remote Only” due to performance improvements of completely removing widget, unless it is on entity (in which case you want it to be “Everyone”).

Customize showing sign

Property “showSign” on FloatingDamage script allows to disable default behavior, when damage text would get “+” or “-” sign in front of it. If disabled - no sign will be shown and you might want to display this with color (see about customizing color above).

Ignoring zero

By default this is disabled, but if your game sends some damages with 0 values and you wanna exclude them - can turn ignoreZero property on.