The Buff table works with the effects (buffs) of characters and monsters. The aIndex parameter is the index of a character or monster.

The functions that change buffs (Add, AddItem, AddCashShop, Remove, Clear): for a character, the character must be in game (PLAYING), not inside onPlayerLogout, and the script must not be in restricted mode; for a monster, they are only blocked when the script is in restricted mode. The maximum duration of a buff is 10 years. Buff.Has is read only, so the limits above do not apply to it.

Buff.Add

Adds a buff to a character / monster; up to two of the buff's effects can be overridden.

Buff.Add(aIndex, buffId, seconds [, effect1, value1, effect2, value2]) -> boolean
ParameterTypeDescription
aIndexintegerCharacter / monster index
buffIdintegerBuff code (must exist in the server's buff data)
secondsintegerLifetime in seconds, greater than 0
effect1integer(Optional) code of the first effect (0 to 255). Omitted: the effect from the buff data is used
value1numberValue of the first effect
effect2integerCode of the second effect
value2numberValue of the second effect

Returns: true if the object has that buff after adding; false if the buff code does not exist, seconds is not positive or the object is not eligible. A buff added with this function is a combat buff: it is removed by Buff.Clear by default. Short name: EffectAdd(aIndex, mode, effect, seconds); when mode = 1, seconds is interpreted as the expiry time (timestamp) and is converted to the remaining number of seconds.

Buff.Add(aIndex, 16, 60)           -- buff 16 for 60 seconds using the buff data
Buff.Add(aIndex, 16, 60, 1, 500)   -- override the first effect

Buff.AddItem

Adds the buff of an item (potion, cake...) by item code.

Buff.AddItem(aIndex, itemCode, seconds) -> boolean
ParameterTypeDescription
aIndexintegerCharacter / monster index
itemCodeintegerItem code (0 to 65535)
secondsintegerDuration, seconds, greater than 0

Returns: true if the item has a buff and it was added; false otherwise.

Buff.AddItem(aIndex, 14 * 512 + 100, 1800)

Buff.AddCashShop

Adds the buff of a Cash Shop item to a character. The buff is saved to the database, so it remains when the character logs in again.

Buff.AddCashShop(aIndex, itemCode, seconds) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index (not used for monsters)
itemCodeintegerCash Shop item code
secondsintegerDuration, seconds, greater than 0

Returns: true if added; false if the object is not a character, the parameters are wrong or the item has no buff.

Buff.AddCashShop(aIndex, itemCode, 7 * 86400)

Buff.Remove

Removes a buff.

Buff.Remove(aIndex, buffId) -> boolean
ParameterTypeDescription
aIndexintegerCharacter / monster index
buffIdintegerBuff code

Returns: true if removed; false if the object does not have that buff or is not eligible. Short name: EffectDel.

Buff.Remove(aIndex, 16)

Buff.Has

Checks whether the object currently has a buff.

Buff.Has(aIndex, buffId) -> boolean
ParameterTypeDescription
aIndexintegerIndex of an existing character / monster
buffIdintegerBuff code (0 to 65535)

Returns: true if it has the buff; otherwise false. Short name: EffectCheck (returns 1 / 0).

if Buff.Has(aIndex, 16) then Buff.Remove(aIndex, 16) end

Buff.Clear

Removes the object's buffs. By default only combat buffs are removed; Cash Shop buffs can be removed too.

Buff.Clear(aIndex [, all]) -> boolean
ParameterTypeDescription
aIndexintegerCharacter / monster index
allbooleantrue = also remove Cash Shop buffs; false or omitted = combat buffs only

Returns: true if the object is valid and eligible; false otherwise. Short name: EffectClear(aIndex) (removes combat buffs only).

Buff.Clear(aIndex)         -- remove combat buffs
Buff.Clear(aIndex, true)   -- remove everything