feat(lua): add trap related lua hooks#9686
Merged
Merged
Conversation
Member
|
related: #7722 |
Contributor
|
Autofix has formatted code style violation in this PR. I edit commits locally (e.g: git, github desktop) and want to keep autofix
I do not want the automated commit
If you don't do this, your following commits will be based on the old commit, and cause MERGE CONFLICT. |
…into feat/add-lua-traps # Conflicts: # src/item.cpp # src/trapfunc.cpp
…into feat/add-lua-traps # Conflicts: # src/trapfunc.cpp
…lua-traps # Conflicts: # src/catalua_icallback_actor.cpp # src/trapfunc.cpp
…lua-traps # Conflicts: # src/catalua.cpp # src/trap.h
ChrisLR
commented
Jun 28, 2026
| } | ||
|
|
||
| void resolve_lua_bionic_and_mutation_callbacks() | ||
| void resolve_extra_lua_callbacks() |
Contributor
Author
There was a problem hiding this comment.
Renamed this, wasn't sure if another function would be better.
# Conflicts: # src/trap.h
Contributor
Author
|
should be fixed now |
WishDuck
approved these changes
Jul 1, 2026
WishDuck
left a comment
Collaborator
There was a problem hiding this comment.
Compiled and load tested
Traps appear to work
No crash on quitting anymore it seems
Saveload appears to work
Green checkymarky
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.
Purpose of change (The Why)
Currently traps are very hard coded, would be nice to see what would be done with proper mod supported traps.
Describe the solution (The How)
Added itrap
can_triggeron_triggeron_trigger_aftermathhooks by copying off iranged.Also adds a
luatrapfunc so behavior can be driven entirely by lua.Describe alternatives you've considered
Testing
Tested with: The Beer Trap
Add in a mod's items.json
{ "type": "trap", "id": "tr_beertrap", "trigger_weight": "200 g", "name": "beer trap", "color": "blue", "symbol": "^", "visibility": 2, "avoidance": 7, "difficulty": 0, "action": "lua", "//": "trigger_items isn't needed for this action, since trap behavior is tied to the target freeing themselves.", "remove_on_trigger": true, "drops": [ "beertrap" ], "vehicle_data": { "damage": 300, "sound_volume": 8, "sound": "SNAP!", "sound_type": "trap", "sound_variant": "bear_trap", "remove_trap": true, "spawn_items": [ "beertrap" ] } }, { "id": "beertrap", "type": "GENERIC", "category": "deployables", "name": { "str": "beer trap" }, "description": "This is a spring-loaded pair of steel jaws connected to a sensitive pressure plate. Use it to set it on the ground, creating a trap that will ensnare and damage anything that steps on it. If you are carrying a shovel, you will have the option of burying it.", "weight": "14000 g", "volume": "1500 ml", "price": "60 USD", "price_postapoc": "10 USD", "to_hit": -2, "bashing": 9, "cutting": 1, "material": "steel", "symbol": ";", "color": "light_gray", "use_action": { "type": "place_trap", "allow_underwater": true, "bury_question": "Bury the beertrap?", "bury": { "trap": "beertrap", "moves": 275, "practice": 7, "done_message": "You don't bury the beertrap." }, "trap": "tr_beertrap", "moves": 200, "practice": 4, "done_message": "You set the beertrap." } }Then register in the lua mod's preload
and implement the functions in main.lua
FYI, its likely an existing bug to be forced to set the charges to zero, an error pops up after reloading if we don't.
Additional context
Checklist
Mandatory
closes #1234in Summary of the PR so it can be closed automatically.Optional
Assisted-by:trailer to every AI-assisted commit in the Linux kernel format.portscope to the PR title.Co-Authored-Byin the commit message.docs/folder.lang/bn_extract_json_strings.shscript if it does not support them yet.docs/folder.data/json/obsoletion/folder or use some other migration process for existing saves.modsscope to the PR title.mod_nameindata/mods/<mod_name>matchesidinmodinfo.json.luascope to the PR title.Build Artifacts
PR build for commit a7b23af (Clear lua_itrap_actors in lua_state_deleter) on 2026-07-02 00:20:42