Lua register on shot hit event#4729
Conversation
| @@ -0,0 +1,7 @@ | |||
| #define VER_MAJOR 1 | |||
| #define VER_MINOR 2 | |||
There was a problem hiding this comment.
Don't think we need this file added.
There was a problem hiding this comment.
You're right, it is removed now
There was a problem hiding this comment.
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 throughlua_triggers. - Refactored
thing_shots.cto funnel several hit paths through a sharedlua_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.
| 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) |
| 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) |
| 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; |
There was a problem hiding this comment.
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. |
| } | ||
| 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) |
There was a problem hiding this comment.
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.
99288ac to
53d8268
Compare
53d8268 to
bbcdcb8
Compare
Add lua function to register OnShotHitEvent and clean up previous lua code in thing_shots.c