46 Commits
Author SHA1 Message Date
Boutros Tawaifi 49464c56f6 Add an "On Ship Damage" script hook (#7894)
* Add an "On Ship Damage" script hook

Runs after resolved damage has been applied to a ship (lethal hits run before
the destruction callback). Hook variables: Target, Source, Attacker,
WeaponClass, WeaponSubtype, SourceKind (PROJECTILE, BEAM, SHOCKWAVE, COLLISION,
OTHER), DamageType, ShieldDamage, HullDamage, Quadrant, Ballistic, BeamWeapon
and LethalHit. Conditions can filter on the target ship. Nothing is computed
unless a script has registered the hook.

* Move the On Ship Damage hook call out of a lambda

ship_do_damage() now calls a file-level static function, ship_run_damage_hook(), that takes the values it needs as arguments instead of capturing the function state. Hook behaviour is unchanged.

* Report subsystem damage in the On Ship Damage hook

Adds SubsystemDamage, the total subsystem strength a damage application removed, so a hit absorbed by subsystems no longer looks like a small hull hit. The hook description now says it only runs where damage is applied, which excludes multiplayer clients.

* Address On Ship Damage review comments

- Remove WeaponClass, WeaponSubtype, Ballistic and BeamWeapon from the
  hook. Scripts read these from Source when it is a weapon.
- Add a "Weapon class" condition for the On Ship Damage hook. It matches
  only when the damage source is a weapon of that class; a weapon name
  that does not exist never matches.
- SubsystemDamage is now a table keyed by subsystem handle that lists only
  the subsystems that lost strength. The total is removed.
- Rename PROJECTILE to NON_BEAM_WEAPON.
- Classify SourceKind by damage source: COLLISION for ship, debris and
  asteroid collisions; EXPLOSION for ship-death and docked-ship blasts and
  asteroid blasts; WASH for engine wash; SELF for kills where the ship
  damages itself; OTHER for other ship-sourced damage.
- Reword the hook description.

* Key On Ship Damage SubsystemDamage by canonical name

Lua tables cannot use subsystem handles as keys in a usable way, so key
the SubsystemDamage table by each subsystem's CanonicalName instead.

* Tag ship-vs-prop damage as a collision and use in_bounds

The ship-vs-prop collision call didn't pass DamageSource::Collision, so
the On Ship Damage hook reported those hits as OTHER. Every other
collision path was already tagged.

Also use SCP_vector::in_bounds() for the Weapon_info and Damage_types
index checks in ship_run_damage_hook().
2026-11-06 18:41:29 -05:00
Mike NelsonandJohn Fernandez 880bfb11a7 Upgrade lua enumeration handling (#7423)
* upgrade lua enumeration handling

* some cleanup

* add lua enum descriptions

* minor fixes

* Update code/scripting/api/objs/enums.cpp

Co-authored-by: John Fernandez <[email protected]>

* include name

---------

Co-authored-by: John Fernandez <[email protected]>
2026-06-05 11:33:42 +02:00
Mike Nelson f4d84ec47a Support Rearm Pool, Limits, and Other Features (#7249)
* framework for support ship rearm pool and flags

* scripting api

* FRED support

* QtFRED support

* do not save non-player-allowed weapons

* tvt and mission versioning

* fix variable name

* minor fixes and clarity

* oops

* add qtfred help docs

* fixes and cleanup

* clang and readability

* address feedback

* address feedback
2026-06-05 11:33:19 +02:00
Mike Nelson 31f77e5a32 Mines weapon type & weapon proximity triggers (#7461)
* new mine weapon type

* some fixes and cleanup

* fix some parsing issues

* make sure mines get plotted

* make mine spawned objects can get a correct target

* some cleanup and additional features

* chasing mines

* some Lua tweaks

* generalize proximity detonations

* minor tweaks

* collapse namespace

* address feedback
2026-06-05 14:06:00 +09:00
Mike Nelson 36d05ba9d8 Implement Photo Mode (#7287)
* Implement Photo Mode

* fix gr string errors

* return raw char array

* control conflict groups and better photo param defines

* better param identification in real time

* make photo mode hude dynamically sized

* fix xstrs after all changes

* missed a few

* use modern loop
2026-04-08 10:33:51 -04:00
Mike NelsonandAsteroth 070a8e18fa Adds Props as a new object type (#6836)
* First draft of prop object type

* Add prop editor dialog in FRED

* prop sexps

* lua table prop support

* lab support

* lua mission access to props

* prop collision support

* use std::optional so the object->instance id is always valid

* allow props to block suns

* minor cleanup and remove arbitrary limit. Still limited to 500 objects.

* Sort props by category

* cleanup

* implement collision hooks

* parse prop flags and further ensure props are inited and closed correctly

* Add Cyborg's multi suggestions

* fix missing header

* add props to empty slots if available

* add multi signature

* fix rebase issues and match collisions to the new multithread style

* appease Clang the Conquerer

* save/parse mission prop classes by name

* Clean up comments and finish TODOs

* fix string errors

* clang wants this to be static now

* address feedback

* address feedback

* Use model num from prop info instead

* merge prop and ship collision group sexps together

* fix rebase bug

* address feedback

* fix name shadowing

* ship heavy submodel

* clang

---------

Co-authored-by: Asteroth <[email protected]>
2026-02-16 14:41:34 +01:00
Goober5000 fff480e101 tweak ship_cleanup
The object and ship indexes held by the ship registry do not actually need to be cleared until `ship_cleanup` completes.  This will allow the ship to be referenced in any functions (via script hooks or otherwise) that are called during cleanup.

Tweak related script documentation while we're at it.

Follow-up to #7120.  Fixes #7122.
2025-11-21 02:32:20 -05:00
Mike Nelson 4c209f83ad Add mission name as hook variable (#6699) 2025-04-25 11:09:48 -04:00
Mike Nelson 7c38273f5b Lua hooks for the comm board (#6450)
* lua access to the comm board menu

* On Order Issued Lua Hook

* Some cleanup and safety checks

* Add mn.sendBuiltinMessage and perform more cleanup

* Send the correct ship to the hook for Sender

* clang cleanup

* address feedback

* fix build errors introduced from upstream

* basic hook conditions

* properly link the condition and the oswpt struct

* some requested cleanup

* allow for sending custom built-in messages

* address more feedback

* more prefix
2025-04-03 00:55:20 +02:00
wookieejedi ff85d13709 Create scripting hooks On HUD Config Menu Close and On Control Config Menu Close (#6608) 2025-02-26 19:30:34 -05:00
wookieejedi dd9144f3f6 Create scripting hook: 'On Options Menu Closed' (#6604)
* Create scripting hook: 'On Options Menu Closed'

Complements #6591. This PR creates a hook, 'On Options Menu Closed' that provides a hook variable of `hv.OptionsAccepted` which is true if the options are accepted/saved, false if the options are discarded and not accepted/saved.
2025-02-23 12:59:02 -05:00
wookieejedi 7f506377bf Create scripting hook: 'On Options Menu Tab Changed' (#6591)
* Create scripting hook: 'On Options Menu Tab Changed'

It would be very useful to know which options tab is active (IE Options, Multi, Detail) but it's all under one single Game State `GS_STATE_OPTIONS_MENU`.

This PR creates a hook,  'On Options Menu Tab Changed'  that returns the value of the newly switched to options tab. Lafiel and I both discussed making this an ENUM, but the ENUM list is already quite bloated and this integer value seems like the cleanest solution.

Tested and works as expected.

* fix description typo
2025-02-14 21:37:47 -05:00
Birk Magnussen 1f2a8dce2a remove optional 2025-02-01 13:17:26 +01:00
Mike Nelson bcea174509 Mission goals hook (#6534)
* mission goals hook

* Change hook name

* text
2025-01-18 08:03:50 -05:00
Mike Nelson f94e12db4a Add missed popup for on dialog frame and add text hook var (#6522)
* add missed popup for on dialog frame and add text hook var

* int to bool

* redundant bool
2025-01-15 09:42:58 -05:00
Goober5000 3d8fbc0e97 add pre-movie hook
Add an `$On Movie About To Play:` hook to match `$On Intro About To Play:`.  Also make the two hooks overridable, since that might be useful.

Additionally, change a few (nonexhaustive) `name` parameters to `filename` to make it clearer that the string is a filename.
2024-10-09 14:39:34 -04:00
BMagnu 01bb406b3d Allow overriding low-level keypresses (#6174)
* Clean unneeded properties

* properly queue-ify keys

* Refactor key checking to use functions instead of globals

* Update hooks and cache checked-against key

* Documentation and Naming

* match tilde

* only remove control not debug
2024-05-31 14:53:39 +02:00
Mike Nelson 4b1476c101 on loading complete hook (#6085) 2024-04-07 08:09:51 -04:00
Goober5000 f26643c43d add ShipBSubmodel to ship collisions
Since the On Ship Collision hook can potentially be called twice, with the ships reversed, it is necessary for both parameters to have submodels specified.  Otherwise +Override would not be able to handle both cases.

Followup to #6035.
2024-03-20 21:15:33 -04:00
Goober5000 671fe21a75 additional collision info
* Add the submodel that was hit to the On Ship Collision scripting hook.  (This will only be non-nil if the ship was the "heavy object".)
* Add a `getModel()` function to the scripted submodel object.
* Fix some incorrect documentation in `OnShipCollision`.
2024-03-12 13:02:58 -04:00
Goober5000 f207d2d12c add new On Splash End hook for scripts that have been doing post-splash stuff in On Game Init 2024-01-18 17:00:02 -05:00
mjn-mixael fb1ffd8413 fred on mission load hook 2023-11-29 09:14:07 -06:00
Mike Nelson 691ec74406 Mission custom strings (#5544) 2023-11-26 19:15:30 -05:00
wookieejedi b25e76cb65 Fix documentation error in On State Start (#5789) 2023-11-10 19:46:55 -05:00
Sébastien Noel f149c36b44 Fix a few typos (#5598) 2023-10-24 20:33:45 -04:00
Tyler Blount dc7fc774b8 Merge pull request #5662 from MjnMixael/on_intro_hook
Intro about to play hook
2023-10-18 00:24:44 -07:00
Goober5000 e132fcf74c Merge pull request #5585 from Goober5000/beam_api_stuff
additional beam-related features for Lua
2023-10-15 12:41:05 -04:00
Mike Nelson 0def45b381 add death message as a dialog hv (#5542) 2023-10-15 05:40:05 +09:00
mjn-mixael 1ce9d46822 Intro about to play hook 2023-10-04 11:16:48 -05:00
Goober5000 8b8daece46 additional beam-related features for Lua
1. Add a `vanish()` function for beam objects, to be consistent with other object types
2. Add a `BeamFree` virtvar, analogous to `TurretLocked`
3. Add timestamp variants of TurretLocked and BeamFree to be consistent with sexps
4. Add `BeamLife`, `BeamWarmup`, and `BeamWarmdown` virtvars so scripts can access table properties
5. Add "On Beam Death", "On Beam Warmup", and "On Beam Warmdown" hooks
6. Clarify some existing documentation and patch a couple things
2023-09-06 00:28:07 -04:00
Goober5000 59a5d2642c add hooks for comm menu opening and closing
Implements #5420.
2023-05-26 12:51:34 -04:00
Asteroth 15b1ed8822 fix name (#5225) 2023-03-02 10:23:49 +00:00
Goober5000 8d406c2167 Merge pull request #5069 from MjnMixael/popup_shortcut_var
Pass shortcut key character to Lua as a hook variable
2023-02-16 22:32:44 -05:00
mjn-mixael 0c5342b875 Match documentation to actual hook names. 2023-02-16 09:05:30 -06:00
BMagnu 8731ad1448 Add option to deprecate hooks (#5184)
* Add hook deprecation to calls

* Deprecate hooks properly

* Change OnSplashScreen hook callig

* Check for deprecated hooks at script time

* include hooks directly

* Check deprecation for lua added hooks

* Write deprecation notice to docs

* rescope Target_version

* fix typo
2023-02-15 17:12:25 +09:00
mjn-mixael 8360bae5af on asteroid created hook 2023-01-26 11:24:33 -06:00
mjn-mixael 8cf7796809 Pass shortcut key character to Lua as a hook variable 2023-01-01 18:04:05 -06:00
Fabian Woltermann 18c182acc8 script hooks must be declared within global_hooks so that both FRED and FSO can see them (#5031) 2022-12-20 11:55:36 +01:00
BMagnu 66becc983e Fix OnBeamCollision oversight (#5021) 2022-12-18 01:04:59 +00:00
BMagnu af1f0eaeca Rework Script Conditions (#4960)
* add skeleton for hook condition API

* Begin Scripting Hook refactor

* Program Hook Conditions for current new-style hooks

* Replace more hooks

* Fully transition global hooks

* Convert legacy hooks pt. 1

* Convert legacy hooks pt. 2

* Convert legacy hooks pt. 3

* Post-conversion cleanup

* restore parsing

* Add Documentation and fix parsing

* Fixup engine ingame hook adding

* Fixup engine ingame hook adding again

* Fix warnings

* Fix GCC unqualified template base lookup

* unqualified lookup v2

* Virtual Destrcutors

* Fix Clang

* Fix ship objp hook condition shadow

* Remove global hook include in ship.h

* Incorporate Feedback

* Incorporate Feedback 2

* Add revision to inline version specififer
2022-12-14 03:51:27 +09:00
Kiloku 4106176aab Cheat framework allowing for custom cheats, sexp for cheat used and On Cheat lua hook (#4387)
* Add SpawnShipCheat and convert Bravos spawning to it

* Clean-up and add canUseCheat() check

* Move some stuff to parent CustomCheat class

* Add cheat-used SEXP and On Cheat scripting hook

* Add cheat tbls and tbms, fix custom cheat detection, move cheat hooks to global hooks

* Add a default virtual destructor to CustomCheats for its derived classes to use

* Initialize buffers with memset so clang will calm down, also move cheat check a bit to keep old cheats

* Attempt to appease MSVC

* Clean-up and formatting

* Ensure custom cheats fit in the cheat code buffer

* Fix a merge mistake

* Move pre-set cheat to embedded cheats table

* Use appropriate types for stuff_string

* Remove unnecessary copying of the cheat buffer

* Explicit nullchecking

* Avoid copying values for initializing CustomCheat

* move cheat checking function to cheats_table.h, fix a typo

* Clarify OP_USED_CHEAT sexp description

* Remove unnecessary casting

* Use list initalization for Ship Cheats

* Move a few method definitions from the .h to .cpp

* Change buffer to const char*
2022-11-29 01:30:54 +09:00
BMagnu f76048b269 Enhance OnDialogX Hooks to encompass Death Popups (#4938)
* Add Scripting hooks to death popups

* Fix type

* cleanup
2022-11-27 19:01:50 +09:00
BMagnu 8a3a99ccbd UI Popup Scripting Hook (#4806)
* Add Popup Init Hook

* Finish popup hooks

* Fix warnings

* Fix fallthrough

* feedback
2022-10-27 16:23:23 +09:00
Goober5000 2b582676a6 make OnShipDeath overridable, per request 2022-08-21 20:53:04 -04:00
Goober5000 ba36ad69f5 add new hooks for each object type
Splits the existing On Death hook into independent hooks for each relevant type.  Adds On Ship Death, On Missile Death, etc.  Also adds On Missile Death Started to complement On Ship Death Started.
2022-08-21 20:53:04 -04:00
Goober5000 3a4794305f Convert some Lua hooks to the new style to add documentation
This takes a few of the existing hooks and converts them to the new style of hook definition which can include more extensive documentation and enumeration of supported hook variables.

This is an updated version of #3151 to work with the latest codebase.

NOTE: Before this can be integrated into the codebase, it needs an implementation for `bool script_state::IsActiveAction(int hookId)` which apparently only has support for old-style script hooks.
2022-06-05 16:38:03 -04:00