The Buff table works with the effects (buffs) of characters and monsters. The aIndex parameter is the index of a character or monster.
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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character / monster index |
buffId | integer | Buff code (must exist in the server's buff data) |
seconds | integer | Lifetime in seconds, greater than 0 |
effect1 | integer | (Optional) code of the first effect (0 to 255). Omitted: the effect from the buff data is used |
value1 | number | Value of the first effect |
effect2 | integer | Code of the second effect |
value2 | number | Value 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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character / monster index |
itemCode | integer | Item code (0 to 65535) |
seconds | integer | Duration, 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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index (not used for monsters) |
itemCode | integer | Cash Shop item code |
seconds | integer | Duration, 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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character / monster index |
buffId | integer | Buff 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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Index of an existing character / monster |
buffId | integer | Buff 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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character / monster index |
all | boolean | true = 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