1
0
Fork
You've already forked bolt-buffmodule
0
Submodule for parsing buffs and debuffs in a Bolt plugin
  • Lua 100%
Find a file
2026年01月27日 00:15:34 +00:00
buffs.lua remove outdated size check 2026年01月27日 00:15:34 +00:00
example.png rework a lot, add comments, slight API change 2025年12月23日 13:44:48 +00:00
README.md Update README.md 2025年12月23日 16:08:26 +01:00
UNLICENSE add readme and unlicense 2025年12月23日 14:33:23 +00:00

Buff Module

This module can read the details of a buff or debuff from a render2d event.

This is intended to be used as a submodule for plugins. If you're not a plugin developer, you're in the wrong place.

How to add

To clone this module to the modules/buffs directory in your repository:

git submodule add https://codeberg.org/Adamcake/bolt-buffmodule.git modules/buffs

This pins the latest commit at the time when you run the command. To update (or downgrade), cd into the directory and then use git commands as normal. To update, use git pull. To checkout a specific commit, use git checkout <commit_hash>.

How to use

Your plugin needs to identify the buff image or icon for itself. After that, pass the render2d event to this module and it will parse font and outline data and will return values telling you if it's a valid buff/debuff or not, what the text on it says, and whether the outline is green or red.

Your plugin doesn't need to validate whether the image/icon it found is actually part of a buff/debuff or not, this module will do that for you.

local bolt = require("bolt")
local buffs = require("modules.buffs.buffs") -- paths to buffs.lua from this module in your repo
bolt.onrender2d(function (event)
 local vertexcount = event:vertexcount()
 local verticesperimage = event:verticesperimage()
 for i = 1, vertexcount, verticesperimage do
 -- check if the image at index `i` is a buff/debuff image that we're interested in
 if ... then
 -- the index to start reading font and outline information from
 local detailsindex = i + verticesperimage
 -- the top-left corner of the image we just read
 -- (i + 2 is usually the top-left vertex for non-rotated images)
 local pxleft, pxtop = event:vertextargetxy(i + 2)
 -- use this module to parse all font and outline data
 -- isvalid: boolean; other params should be ignored if isvalid is false, as this is not a buff or could not be parsed
 -- number: the number shown on the buff, after multipliers - e.g. '1.5k' would return 1500; '10m' (ten minutes) would return 600 (seconds); can be nil if no text is shown at all
 -- parensnumber: the number shown in parentheses on the buff (see example.png for an example); can be nil if no parentheses are shown
 -- isbuff: boolean; true if the buff outline was green, false if it was red (i.e. debuff)
 local isvalid, number, parensnumber, isbuff = buffs:tryreadbuffdetails(event, detailsindex, pxleft, pxtop)
 end
 end
end)

You can use the same method to read buff details where the buff image is an item icon, such as in example.png. Detect the item icon in bolt.onrendericon, then catch the next onrender2d event and call tryreadbuffdetails with a starting index of 1.

When parsing the buff shown in example.png, tryreadbuffdetails would return: true, 27, 1, true.

This module fully supports all font sizes and all levels of interface scaling. However, it should go without saying that the buff or debuff must actually be shown on the user's interface to be able to read it. There's no way to read buffs or debuffs that the player has disabled in their settings.

Copying

The contents of this repository are public domain (see UNLICENSE), with the exception of example.png, which depicts images I don't own. Accreditation is appreciated but not required.