From 07eeca713bace298303abd3625709ab188a01a03 Mon Sep 17 00:00:00 2001 From: NginxL <8777777+NginxL@users.noreply.github.com> Date: Sat, 5 Dec 2026 14:21:28 +0800 Subject: [PATCH] Show order targets and order hooks in rules example (#749) --- docs/guide/scripting.md | 2 +- docs/guide/what-mods-can-do.md | 1 + examples/mods/README.md | 2 +- examples/mods/rules/rules.luau | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/guide/scripting.md b/docs/guide/scripting.md index caa7542fd..b4b73e6b2 100644 --- a/docs/guide/scripting.md +++ b/docs/guide/scripting.md @@ -98,7 +98,7 @@ Each example mod shows one part of the scripting. Its files have comments: | [`interceptor`](../../examples/mods/interceptor) | A mod's ship type, flown in a [game mode](#game-modes) | | [`main-menu`](../../examples/mods/main-menu) | [Replacing a screen](#replacing-a-screen) of the front end | | [`music`](../../examples/mods/music) | A piece of music that replaces the game's and keeps its [loop point](modding.md#music), and a track of [the CD player](#the-cd-players-tracks) that plays it, from a load script | -| [`rules`](../../examples/mods/rules) | [Hooks](#hooks) on the game's functions | +| [`rules`](../../examples/mods/rules) | [Hooks](#hooks) on damage and orders, [order targets](#targets), and mission events | | [`strafe-run`](../../examples/mods/strafe-run) | A custom order, a [HUD display](#hud-displays), a [camera view](#camera-views), a [screen](#screens) and [actions](#keys-and-actions), through the [built-in interfaces](#built-in-interfaces) | | [`tally`](../../examples/mods/tally) | [Saved games](#saved-games), [storage](#storage) and [timers](#timers) | | [`teapot`](../../examples/mods/teapot) | A mod's ship type with its own model, and the [`radio_say`](#changing-what-the-radio-says) hook | diff --git a/docs/guide/what-mods-can-do.md b/docs/guide/what-mods-can-do.md index b57e07597..146f0b15e 100644 --- a/docs/guide/what-mods-can-do.md +++ b/docs/guide/what-mods-can-do.md @@ -74,6 +74,7 @@ A mod never changes the files of the game on disk. On the mods screen, players t | A mod can | Read | Example | |---|---|---| | Hook the functions of the game, such as damage, shots, missile launches, orders and the commands of the mission script, to change or stop them | [Hooks](scripting.md#hooks) | [`rules`](../../examples/mods/rules) | +| Inspect an order's target and react when orders are pushed or popped | [Targets](scripting.md#targets) | [`rules`](../../examples/mods/rules) | | React to the events of the mission, such as a destroyed or docked ship | [Mission and engine events](scripting.md#mission-and-engine-events) | [`rules`](../../examples/mods/rules), [`tally`](../../examples/mods/tally) | | Change what the radio says | [Changing what the radio says](scripting.md#changing-what-the-radio-says) | [`arena`](../../examples/mods/arena), [`teapot`](../../examples/mods/teapot) | | Run a script on each ship of a class or a type | [Object scripts](scripting.md#object-scripts) | [`wingmen`](../../examples/mods/wingmen) | diff --git a/examples/mods/README.md b/examples/mods/README.md index 6bda721ca..4daa9d325 100644 --- a/examples/mods/README.md +++ b/examples/mods/README.md @@ -22,7 +22,7 @@ or go away in any release. Copy one as a starting point for your own mod. | [`interceptor`](interceptor) | A new ship type, based on the Predator, flown in a game mode | | [`main-menu`](main-menu) | A main menu of the mod's own in place of the game's | | [`music`](music) | A piece of music in place of the main menu's, which loops back where the game's does, and a track of the CD player that plays it | -| [`rules`](rules) | Hooks on the game's functions | +| [`rules`](rules) | Hooks on damage and orders, order targets, and mission events | | [`strafe-run`](strafe-run) | A custom order with a HUD display, a chase camera and rebindable actions | | [`tally`](tally) | Storage kept with each saved game and across every game | | [`teapot`](teapot) | A ship type with a model of its own, built from OBJ (`sltool shp from-obj`), and its own cockpit, display pictures and engine sound, offered on the loadout screen | diff --git a/examples/mods/rules/rules.luau b/examples/mods/rules/rules.luau index d88d314aa..f49153a6b 100644 --- a/examples/mods/rules/rules.luau +++ b/examples/mods/rules/rules.luau @@ -32,6 +32,23 @@ for _, name in { "object_damage", "object_armor_damage", "component_damage" } do end) end +-- Show the target of orders pushed for the player's ship. The target table can +-- also name a flight group or a squadron, and every field is nil without one. +hooks.add("order_push", function(e) + if e.object.is_player then + local target = e.target.object and "a ship" or "no ship object" + print("Order pushed: " .. tostring(e.order) .. "; target: " .. target) + end +end) + +-- order_pop has no order or target fields. It runs when an order ends, and its +-- result says whether the object had an order to pop. +hooks.add("order_pop", function(e) + if e.object.is_player then + print("Order popped for the player's ship") + end +end) + -- The player's kill streak in this mission, from the mission's event destroyed. local streak = 0 hooks.add("destroyed", function(e)