Add damage source info to Lua apply damage hook#4510
Draft
Shinthoras0815 wants to merge 11 commits intodkfans:masterfrom
Draft
Add damage source info to Lua apply damage hook#4510Shinthoras0815 wants to merge 11 commits intodkfans:masterfrom
Shinthoras0815 wants to merge 11 commits intodkfans:masterfrom
Conversation
Propagates damage source info through spells, shots, and powers.
There was a problem hiding this comment.
Pull request overview
This pull request adds damage source tracking to the Lua OnApplyDamage hook by introducing two new parameters: a source Thing and a source string. This enables Lua scripts to identify what caused damage, whether it's another thing (like a creature, trap, or object) or an environmental/system source (like lava, powers, or commands).
Changes:
- Extended
apply_damage_to_thingand related functions with source Thing and source string parameters - Added
caster_thing_idxfield toCastedSpellDatastructure to track spell casters - Implemented
default_src_stringhelper function to generate fallback source descriptions - Updated Lua integration to pass source information to
OnApplyDamagecallback - Updated all call sites across the codebase to provide source information
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/thing_stats.h | Added source parameters to apply_damage_to_thing function signature |
| src/thing_stats.c | Implemented default_src_string helper and updated apply_damage_to_thing to track source |
| src/thing_shots.c | Updated shot damage calls to pass damage source (parent thing) |
| src/thing_list.c | Updated electricity damage to pass source thing |
| src/thing_effects.c | Updated explosion and poison cloud damage to pass source thing |
| src/thing_creature.h | Added source parameters to damage and spell effect function signatures |
| src/thing_creature.c | Updated spell system to track caster thing in spell slots and pass source through damage chains |
| src/power_process.c | Updated power-based damage to use descriptive source strings |
| src/main.cpp | Updated physical force damage to include source string (with minor whitespace cleanup) |
| src/magic_powers.c | Updated slap and spell power damage to include source information |
| src/lua_triggers.h | Updated Lua trigger signature to include source parameters |
| src/lua_triggers.c | Implemented passing of source thing and string to Lua OnApplyDamage callback |
| src/console_cmd.c | Updated console command spells to include descriptive source strings |
| src/creature_states_pray.c | Updated prayer spell application to pass INVALID_THING as source |
| src/creature_control.h | Added caster_thing_idx field to CastedSpellData structure |
| config/fxdata/lua/triggers/Builtins.lua | Updated Lua OnApplyDamage signature and documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PieterVdc
reviewed
Jan 27, 2026
Member
|
for the string maybe go with an enum instead so it's a fixed list of possible values, that way said values can also be documented in the lua files |
also unify power types extend RegisterThingDamageEvent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pass both a source Thing and a source_string because some damage sources are not backed by a valid Thing (e.g., environment, script/command, power effects)