Lua functions

AddWard

Registered in this checkout as EQ2Emu_lua_AddWard; implementation found at WorldServer/Lua/LuaFunctions.cpp:7165.

Historical signature: AddWard(…) via current binding

Parameter and behavior details in the historical explanation are under review against the current implementation.

Function: AddWard(damage, keep_ward, ward_type, damage_type, absorption_percent, max_health_percent, redirect_percent, max_hits, trigger_chance, damage_type_mask)

Description: Adds or replaces the current spell's ward on each eligible entity target. Requires an active, non-resisted spell with a usable zone and caster. Replacement transfers the new record into the entity atomically and releases the replaced record. Restored recasts preserve existing wards and their active trigger accounting. A zero damage budget selects absorb-all mode.

Parameters: damage: unsigned damage budget. keep_ward: integer 1 enables keeping the ward. ward_type: 0 all, 1 physical, 2 magical. damage_type: engine damage-type byte, used for magical wards. absorption_percent and max_health_percent: unsigned percentages capped at 100. redirect_percent: unsigned percentage capped at 100. max_hits: unsigned ward/spell trigger budget. Optional trigger_chance defaults to 100 and is clamped to 0–100; optional unsigned damage_type_mask defaults to 0 and applies only to magical wards.

Returns: None.

Connection lifetime: Each player or group-member connection resolved by this function is retained through the native call. A disconnect or reconnect during a callback cannot destroy that retained connection or switch the ongoing call to a replacement. A later Lua call resolves the current connection. This does not extend the lifetime of unrelated spawn or item userdata.

Caster retirement: No ward is added when the current spell's caster cannot be acquired. An existing absorption ward keeps its remaining damage and trigger budgets after caster expiry. An interception ward with no caster is purged and does not absorb damage because there is no recipient for redirected damage.

Spell caster lifetime: When this function reads a spell's caster, it retains that allocation for the native operation. Retirement or callback reentry cannot replace its caster with a different allocation at the same address or runtime ID. A known expired or cleared caster is not rediscovered through a replacement connection. An actor already owned by the active callback remains usable through that callback. See Lua actor lifetime.

Ward and target lifetime: Target lookup acquires the actor under zone publication before checking its type or using it. Ward records have one owner; reads return value snapshots and mutations occur under the ward lock. A ward remembers its spell through a weak allocation control. Damage processing and notifications retain the acquired spell and actor owners, and notifications run after the ward lock is released so callbacks can remove or replace wards. See Lua actor lifetime.

Original spell targets: When this function uses a spell's target list, it snapshots references to the originally selected actor allocations. It skips unavailable or departed targets instead of selecting another actor with a reused runtime ID. Accepted actors remain physically retained through the active protected callback, including Lua errors; saved userdata and target records do not keep them alive between callbacks. Explicit Spawn arguments retain their existing selection behavior. See Lua actor lifetime.

Checked example

Active call in a local runtime Lua script. Argument count matches current fixed C++ readers. The binding also handles arguments dynamically. This is a contextual call pattern, not a tested standalone script.

AddWard(Effect00Value00, 1, 2, 0, 0, 0, 0, 0, 100.0, 1016)

Evidence: server/Spells/ClassicRefresh/Fighter/Brawler/Monk/OutwardCalm-2552500.lua:13; binding EQ2Emu_lua_AddWard.

Current registration: WorldServer/Lua/LuaInterface.cpp.