get_buff

Look up and return back the given buff ID from the entity in case that it is attached to it or an error otherwise.

Arguments

A string representing a buff UUID.

Errors

  • If a buff with the given buff_id can not be found in the entity.

Returns

  • Buff - if a buff with the given buff_id is found in the entity

Signature

---@param buff_id string @UUID of the buff to lookup for
---@return Buff
function Entity:get_buff(buff_id)

Example of Usage

-- bind the exposed entity UserData to a local variable
local entityAPI = alacrity.Entity

-- create a new random unique user ID
local e = entityAPI.new({
    id = id
    name = "Ad-Hoc Test Entity",
    description = "Ad-Hoc test entity",
    attributes = {},
    properties = {
        { name = "level", value = 10, hide_from_conditions = false },
    },
    buffs = {
        "06169055-04d9-41d9-93e5-b3746cb359fb",
    }
})

-- this buff does not exists
local ok, result = pcall(function()
    local buff = entity:get_buff("9949a823-50de-4501-ae85-35d97ed18562")
    return buff
end)

assert(not ok and string.find(tostring(err), "not found on entity"))

-- this buff exists
local ok, result = pcall(function()
    local buff = entity:get_buff("06169055-04d9-41d9-93e5-b3746cb359fb")
    return buff
end)

assert(ok and result ~= nil)
assert(result.id == "9949a823-50de-4501-ae85-35d97ed18562")