Skip to content

Lua register on shot hit event#4729

Open
axidal wants to merge 5 commits intodkfans:masterfrom
axidal:LuaRegisterOnShotHitEvent
Open

Lua register on shot hit event#4729
axidal wants to merge 5 commits intodkfans:masterfrom
axidal:LuaRegisterOnShotHitEvent

Conversation

@axidal
Copy link
Copy Markdown
Contributor

@axidal axidal commented May 4, 2026

Add lua function to register OnShotHitEvent and clean up previous lua code in thing_shots.c

@Loobinex Loobinex requested a review from PieterVdc May 4, 2026 20:38
Comment thread ver_defs.h Outdated
@@ -0,0 +1,7 @@
#define VER_MAJOR 1
#define VER_MINOR 2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need this file added.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it is removed now

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new Lua-triggered shot-hit event to KeeperFX’s scripting layer and refactors shot-hit handling so the existing per-shot Lua hook and the new trigger event share a common path.

Changes:

  • Added a new engine-to-Lua trigger entrypoint, OnShotHit, and exposed it through lua_triggers.
  • Refactored thing_shots.c to funnel several hit paths through a shared lua_process_shot_hit() helper.
  • Added RegisterOnShotHitEvent(...) plus trigger metadata/docs in the Lua trigger scripts.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/thing_shots.c Centralizes shot-hit Lua handling and invokes the new trigger event from shot collision paths.
src/lua_triggers.h Declares the new lua_on_shot_hit trigger bridge.
src/lua_triggers.c Implements the C-to-Lua dispatch for OnShotHit.
config/fxdata/lua/triggers/Events.lua Adds the new trigger registration helper and optional filters.
config/fxdata/lua/triggers/Builtins.lua Registers the new event type and dispatches OnShotHit into the Lua trigger system.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread config/fxdata/lua/triggers/Events.lua Outdated
Comment on lines +259 to +262
TriggerAddCondition(trigger, function(eventData, triggerData) return eventData.shooter.model == triggerData.shooter_type end)
end
if target_type then
TriggerAddCondition(trigger, function(eventData, triggerData) return eventData.target.model == triggerData.target_type end)
Comment thread config/fxdata/lua/triggers/Events.lua Outdated
TriggerAddCondition(trigger, function(eventData, triggerData) return eventData.shooter.model == triggerData.shooter_type end)
end
if target_type then
TriggerAddCondition(trigger, function(eventData, triggerData) return eventData.target.model == triggerData.target_type end)
Comment thread src/thing_shots.c
Comment on lines +1447 to +1450
short lua_ret_val = lua_process_shot_hit(shotng, target, pos->x.stl.num, pos->y.stl.num, shotst);
if (lua_ret_val < 1)
{
return lua_ret_val != 0;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is by design. I don't see any reason to restrict map makers from implementing their own logic for shots hitting other things than what's normally supported. That said, from what I can see in testing, shot_hit_shootable_thing_at doesn't seem to be called for things that can't normally be hit anyway.

---@param shooter Thing|nil the shooter of the shot.
---@param target Thing|nil what was hit, will be nil if the shot hit a wall.
---@param next_stl_x integer where the shot would have been had it not hit something. Useful if the shot hit a wall.
---@param next_stl_y integer where the shot would have been had it not hit something. Useful if the shot hit a wall.
Comment thread src/thing_shots.c
}
struct Thing *shooter = get_parent_thing(shotng);
short lua_ret_val = luafunc_shot_hit_thing_func(shotst->hit_thing_lua_func_idx, shotng, shooter, target, next_stl_x, next_stl_y);
if (lua_ret_val >= 0)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, I think this way makes more sense. The shot won't be processed in any further way after it is deleted as the shot object itself no longer exists. I added an extra comment in config function documentation to clarify that deleting the shot stops it from processing.

@axidal axidal force-pushed the LuaRegisterOnShotHitEvent branch from 99288ac to 53d8268 Compare May 5, 2026 15:56
@axidal axidal force-pushed the LuaRegisterOnShotHitEvent branch from 53d8268 to bbcdcb8 Compare May 5, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants