Modifier scripts are run on both the server, and every client in the game. A lot of the Lua API is server-side functions that the client cannot use.
And so, often times when using modifiers you will have to use Server only functions for calculations or whatever your purpose may be.
Usually the server is what handles the functionality, while the client is just for displaying information.
So if you for example gave your hero bonus damage that you calculated or stored only on the server then you would see that your hero does deal the bonus damage, but its not displayed on the UI or any Tooltips.
Example that grants 2x your primary attribute as bonus damage:
With this modifier you will run into the mentioned issue where your attack damage is not updated in the UI, but you will still deal the bonus damage.
To fix this, we need to somehow send this server-only value to the client. There are 2 primary methods for doing this, though there are other less convienient ways.
This is the most basic method, where all you need to do is Set the modifiers stack count on the server and the stack count is automatically synced to the client.
Example using this method:
Great, now the damage is applied and displayed correctly!
But, there are some limitations with using modifier stacks.
- You can only set integer values. No floats, booleans, strings, or tables.
- You can only set one stack count per modifier.
- The stack count is displayed on the modifier buff icon, and this is not always wanted.
So what can you do if you need to send one of these unsupported values or even send multiple values to the client?
Well, there are some workarounds but what you should use is Modifier Transmitters.
Modifier transmitters allow you to send any amount of any value types from the server to the client in your modifier. But they require a bit of set-up.
There are 3 functions needed to make use of transmitters.
SetHasCustomTransmitterDataThis should be called in your modifier's
OnCreatedfunction to tell the server you want your modifier to transmit data to the client
AddCustomTransmitterDataThis is where you pick the data you want to send to the client, run on server-side only
HandleCustomTransmitterDataThis is where the server data is sent to, run on client-side only.
SendBuffRefreshToClientsfor refreshing the transmitted data if needed.
Example that grants bonus damage and attack speed based on your current health.
You can find many other examples of modifier transmitters on GitHub