Forgot? Join

Scripting

LSL Guide

Every script function this grid actually runs, read straight from the region software rather than copied from a wiki — including the wolf* functions that exist only here.

Functions · Constants

wolfCallAsync

Wolf Territories
string wolfCallAsync(string name, list args)

Like wolfCall, but the answer comes later as dataserver(query, data), where query is the key this returns. For plugin functions that take time (out-of-process services are always asynchronous). Returns NULL_KEY with wolfGetLastError saying why when refused (no dataserver event then). Defined on Wolf_Api.wolfCallAsync / IWolfPluginCalls.

Like wolfCall, but for plugin functions that take time: it returns a key straight away and the answer arrives later in your script's dataserver event, with that key as the query. The answer is one string; a function that answers at once sends its values joined with "|" (split them with llParseString2List(data, ["|"], [])). Functions provided by a separate service on the grid (rather than inside the region) always answer this way. If the plugin is not there, refuses, or its service is down, you get NULL_KEY at once and wolfGetLastError says why, starting "wolfCallAsync: " - then no dataserver event comes. If a service goes away while it is working on your call, the answer is a string starting with "error: ", so your script never waits for ever.

Parameters

TypeName What it does
string name The plugin function to call, e.g. "weather.text".
list args What to give it: any list.

Example

key asked;

default
{
    touch_start(integer n)
    {
        asked = wolfCallAsync("weather.text", ["now"]);
        if (asked == NULL_KEY)
            llOwnerSay("Not asked: " + wolfGetLastError());
    }

    dataserver(key query, string data)
    {
        if (query == asked)
            llSay(0, data);   // the weather now in a sentence, or "error: ..." and why
    }
}

Wolf plugin commands on this grid

Every Wolf Territories region answers these names (the wolf-commands and wolf-hurricane plugins; the naval battle names, for The Caribbean only, are further down). With them a script anywhere on the region - rezzed on your land or worn as a HUD - runs your own WolfNPCs, a script in your own object makes it flash, and any script reads the region's weather. npc is the NPC's key (from npc.list, or its object's key); link is a link number as llSetLinkColor takes it (LINK_SET, LINK_THIS, LINK_ROOT, LINK_ALL_OTHERS, LINK_ALL_CHILDREN or a number).

wolf-commands: the names, what to give, what comes back, who may use them
NameGive itYou get backWho mayWhat it does
wolf.version[]["wolf-commands", version, 1]anyoneWhich version of these commands this region runs.
wolf.commands[]the command namesanyoneEvery command in this list that this region answers.
npc.list[] or ["all"][count, key, name, rights, ...]anyoneYour NPCs on this region, or with "all" every NPC here. Rights is "edit" (yours to run), "control" (you may stop it, send it home, animate it, make a dragon breathe) or "none". At most 80 are listed; count is all of them.
npc.info[npc] or [npc, "STATE" | "INTENT" | "EVENTS" | "CFG"][text]control; CFG: ownerSTATE is "intention|awake or asleep|alive or dead|health/max". INTENT is what it is doing, EVENTS its running events, CFG all its settings as JSON.
npc.say[npc, text]["ok"]ownerIt says the words (up to 1000 characters) in local chat. An NPC speaks at most 5 lines in ten seconds.
npc.goto[npc, <x, y, z>] or [npc, place]["ok"]ownerIt walks to that spot on this region, or to one of its own places (or tools) by name.
npc.follow[npc, key or name] or [npc, ""]["ok"]ownerIt follows an avatar or NPC on this region; "" stops following.
npc.stop[npc]["ok"]controlIt stops and stands. Its looped animations stop too.
npc.home[npc] or [npc, "here"]["ok"]control; "here": ownerIt goes home. With "here", where it stands now becomes its home.
npc.anim[npc, animation] or [npc, animation, "once" | "loop" | "stop"]["ok"]controlPlays one of the animations in its contents once (the default), keeps it looping, or stops it. [npc, "", "stop"] stops them all.
npc.breath[npc, "fire" | "ice" | "stop"] or [npc, "fire" | "ice", seconds]["ok"]controlA dragon breathes fire or ice for 0.5 to 20 seconds (0 or none = 3), the same breath as in its window.
object.flash[link, colour A, colour B] or [link, A, B, seconds each, seconds in all, face]["ok", prims, seconds each, seconds in all]your own objectFlashes prims of the script's own object between two colours, and puts their own colours back when it ends. Each colour shows 0.5 to 60 seconds (default 1); it lasts up to 3600 seconds (default 10; 0 = until stopped, at most an hour); face is ALL_SIDES (the default) or a face number. See "Flashing an object" below.
object.flash.stop[] or [link]["ok", prims stopped]your own objectStops the flash on those prims ([] = the whole object) and puts their own colours back.
weather.now[] or ["json"][name, value, name, value, ...] or [JSON]anyoneThe weather on this region now: the condition, temperature, feels-like, humidity, pressure, wind, cloud, rain or snow, thunder, the sun and moon, the place and its local time. See "Weather" below for every name and unit.
weather.forecast[], [hours] or [hours, "json"][count, 8, unix, "HH:MM", °C, condition, mm, cloud %, wind m/s, wind from °, ...] or [JSON]anyoneThe next hours, one row an hour (24 by default; the list holds up to 31 hours, JSON up to 48).
weather.text[], ["now"], ["stats"], ["later"] or [hours ahead][text]anyoneReady to say: a sentence about now ("It's 8°C in Tromsø with light rain and a fresh westerly wind. Sunset is at 15:42."), the full stats block, or the weather later ("later" = about 6 hours ahead; or 1-48 hours).
weather.set[weather] or [weather, minutes]"ok|weather|minutes" (wolfCallAsync)region holdersSets the region's weather: clear, fair, cloudy, overcast, rain, storm, snow or fog, or a pattern (settled, changeable, unsettled, stormy, wintry). With minutes (1-1440) it goes back by itself afterwards; with 0 or no minutes it stays until changed. wolfCallAsync only.
weather.auto[]"ok|live|0" (wolfCallAsync)region holdersBack to the real place's live weather. wolfCallAsync only.
weather.hurricane[] or [name, value, ...]: "category", "minutes", "form", "centre", "radius", "heading", "speed", "rain""ok|id|category|form s|mature s|decay s|radius|eye|hemisphere" (wolfCallAsync)region holdersA hurricane forms from the region's own clouds, rages, then dies away back into the region's own weather. Everyone on the region sees it. One at a time. wolfCallAsync only.
weather.hurricane.end[] or ["now"]"ok|decaying|seconds left" or "ok|gone" (wolfCallAsync)region holdersIt dies away now: after at least a minute at full strength (one still forming finishes forming first), over at most 5 minutes. With "now" it is gone at once.
weather.hurricane.state[]["none"] or [stage, category, seconds left, <eye x, y, 0>, radius, eye radius, wind m/s, organisation, eye clear, hemisphere, id]anyoneThe storm now: "forming", "mature" or "decaying", and where its eye is (region metres).

Who may

  • owner: the NPC's owner, while they may still build where it lives - they own the region or are one of its estate managers, or they own the parcel under its home (a travelling pet: anywhere). The same rule as editing it in the NPC window.
  • control: the owner as above, or the region's owner or an estate manager - what the NPC window lets them do with anyone's NPC. They can never make someone else's NPC speak, walk, follow, move its home or read its settings.
  • your own object: object.flash only ever changes the object the script is in - it takes no key - and, like every command that acts for someone, only when the script belongs to that object's owner.
  • anyone for the weather: any script may read it, because it is what everyone on the region sees. region holders: weather.set, weather.auto and the hurricane only work for the region's owner, its estate owner, an estate manager or the grid's staff (the grid checks, as the Wolf Environment window does).
  • Every command that acts for someone (npc.list and the other npc commands, object.flash, weather.set, weather.auto, weather.hurricane and weather.hurricane.end) needs the script to belong to the owner of the object it is in: someone else's script dropped into your object never acts for you. The ones that only tell you something (wolf.version, wolf.commands, weather.now, weather.forecast, weather.text and weather.hurricane.state) work from any script. Only NPCs on the same region.

Answers and limits

  • Every command answers at least one value. An empty list (wolfCall) or NULL_KEY (wolfCallAsync) means it was refused, and wolfGetLastError() says why in plain words, starting "wolfCall: " or "wolfCallAsync: " - for example "wolfCall: only its owner can do that".
  • ["ok"] means the NPC has been told; it does it straight away, even while it is asleep with nobody near.
  • With wolfCallAsync the answer comes in dataserver as one string, the values joined with "|".
  • At most 20 calls in ten seconds from one object, 60 from all of one resident's objects, and 600 from the whole region; an NPC says at most 5 lines in ten seconds. Over that, the call is refused with a message and works again a few seconds later.

Example: make your NPC come to you and say hello

// Touch: your first NPC on this region walks to you and greets you.
touch_start(integer n)
{
    if (llDetectedKey(0) != llGetOwner()) return;
    list mine = wolfCall("npc.list", []);          // [count, key, name, rights, ...]
    if (llList2Integer(mine, 0) == 0)
    {
        llOwnerSay("No NPCs of yours here. " + wolfGetLastError());
        return;
    }
    key npc = llList2Key(mine, 1);
    if (wolfCall("npc.goto", [npc, llDetectedPos(0)]) == [])
        llOwnerSay("It will not come: " + wolfGetLastError());
    else
        wolfCall("npc.say", [npc, "Hello, " + llDetectedName(0) + "!"]);
}
A whole NPC remote to wear as a HUD (wolf_npc_remote.lsl, 113 lines: show or hide)

Download wolf_npc_remote.lsl

// Wolf NPC remote - wear it as a HUD (or rez it on your land) and control your own WolfNPCs on this region.
// Uses the wolf-commands plugin through wolfCall: no region restart is ever needed for these commands.
// Touch: pick one of your NPCs, then what it should do. Only NPCs you own (and may still run here) obey you.
// Wolf Territories, 2026. Copy, change and share freely.

integer CHANNEL;
integer listener;
list npcKeys;
list npcNames;
key chosen;
string chosenName;

// Every wolf-commands call answers with a list; an empty list means "refused", and wolfGetLastError() says why.
integer tell(string what, list answer)
{
    if (llGetListLength(answer) == 0)
    {
        llOwnerSay(what + ": " + wolfGetLastError());
        return FALSE;
    }
    return TRUE;
}

listenFor(float seconds)
{
    llListenRemove(listener);
    listener = llListen(CHANNEL, "", llGetOwner(), "");
    llSetTimerEvent(seconds);
}

pickNpc()
{
    // [count, key, name, rights, key, name, rights, ...] - rights is "edit", "control" or "none".
    list r = wolfCall("npc.list", []);
    if (!tell("Your NPCs", r)) return;
    npcKeys = [];
    npcNames = [];
    integer i;
    for (i = 1; i + 2 < llGetListLength(r) && llGetListLength(npcNames) < 12; i += 3)
    {
        if (llList2String(r, i + 2) != "none")
        {
            npcKeys += llList2Key(r, i);
            npcNames += llGetSubString(llList2String(r, i + 1), 0, 23);
        }
    }
    if (npcNames == [])
    {
        llOwnerSay("You have no NPCs you can control on this region.");
        return;
    }
    listenFor(60.0);
    llDialog(llGetOwner(), "Which NPC?", npcNames, CHANNEL);
}

pickAction()
{
    listenFor(60.0);
    llDialog(llGetOwner(), chosenName + " - what should it do?",
        ["Come here", "Follow me", "Stop", "Go home", "Say hello", "Status", "Fire", "Ice"], CHANNEL);
}

default
{
    state_entry()
    {
        CHANNEL = -1 - (integer)("0x" + llGetSubString((string)llGetKey(), 0, 6));
        chosen = NULL_KEY;
    }

    touch_start(integer n)
    {
        if (llDetectedKey(0) == llGetOwner()) pickNpc();
    }

    listen(integer ch, string name, key id, string msg)
    {
        integer i = llListFindList(npcNames, [msg]);
        if (chosen == NULL_KEY || i != -1)
        {
            if (i == -1) return;
            chosen = llList2Key(npcKeys, i);
            chosenName = msg;
            pickAction();
            return;
        }
        list r;
        if (msg == "Come here") r = wolfCall("npc.goto", [chosen, llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_POS]), 0)]);
        else if (msg == "Follow me") r = wolfCall("npc.follow", [chosen, llGetOwner()]);
        else if (msg == "Stop") r = wolfCall("npc.stop", [chosen]);
        else if (msg == "Go home") r = wolfCall("npc.home", [chosen]);
        else if (msg == "Say hello") r = wolfCall("npc.say", [chosen, "Hello, " + llKey2Name(llGetOwner()) + "!"]);
        else if (msg == "Fire" || msg == "Ice") r = wolfCall("npc.breath", [chosen, llToLower(msg), 3.0]);   // dragons only
        else if (msg == "Status")
        {
            // "intention|awake or asleep|alive or dead|health/max"
            r = wolfCall("npc.info", [chosen]);
            if (tell(chosenName, r)) llOwnerSay(chosenName + ": " + llList2String(r, 0));
        }
        if (msg != "Status") tell(chosenName, r);
        chosen = NULL_KEY;
        llListenRemove(listener);
        llSetTimerEvent(0.0);
    }

    timer()
    {
        llListenRemove(listener);
        llSetTimerEvent(0.0);
        chosen = NULL_KEY;
    }
}

Flashing an object

wolfCall("object.flash", [link, colour A, colour B, seconds each, seconds in all, face]) makes prims of your object flash between two colours. The region does the flashing, so your script needs no timer, and when the flash ends - or you stop it - every face gets its own colour back. Only the first three values are needed.

  • Colours are vectors from <0, 0, 0> to <1, 1, 1>, as llSetColor takes them (values outside are cut to that range); the two must differ. The first colour shows at once. Only the colour changes: transparency, textures, glow and everything else stay as they are.
  • Seconds each colour: 0.5 to 60, default 1, rounded to the nearest quarter of a second. Seconds in all: up to 3600, default 10; 0 means until stopped, at most an hour - call it again to go on.
  • Face: ALL_SIDES (the default) or a face number; prims of the link set without that face are left out.
  • Calling it again on prims that are flashing starts a new flash on them, and their own colours are still the ones put back.

When it stops by itself

  • The time is up, or object.flash.stop is called: the colours go back.
  • The script that started it is removed, set to not running, or reset with Reset Scripts: the colours go back. A reset from inside the script (llResetScript) or saving the script again in the editor is not seen - stop the flash first, or start it again from state_entry.
  • A prim is unlinked from the object: that prim gets its colours back. If the prim holding the script is unlinked, the whole flash ends and the colours go back.
  • You (or another script) change a flashing prim's colour: your colour wins and that prim stops flashing.
  • The object is deleted or returned, or the region restarts: the flash ends. When the region saves the object while it flashes, it saves the object's own colours.

Limits

  • Rezzed objects only, not attachments or HUDs: a worn object is saved to your inventory when you take it off, teleport or log out, and it would keep the flash colour.
  • If you Take, Take Copy, duplicate or return an object while it flashes, or save the region as an OAR, that copy keeps the colour it showed at that moment. Stop the flash first.
  • At most 16 prims of one object, 32 of yours and 64 on the whole region flash at once. Every colour change is sent to every viewer that can see the prim, so these limits keep a busy region smooth for everyone.
  • The flash itself does not trigger changed(CHANGED_COLOR), so scripts in the prim are not woken twice a second.
  • When nobody is on or next to the region, nothing is sent; the flash picks up when someone arrives.
  • The calls count towards the limits above (20 calls in ten seconds from one object).

Example: flash red and blue for five seconds when touched

touch_start(integer n)
{
    // [link, colour A, colour B, seconds each colour, seconds in all, face]
    list r = wolfCall("object.flash", [LINK_SET, <1, 0, 0>, <0, 0, 1>, 0.5, 5.0, ALL_SIDES]);
    if (r == [])
        llOwnerSay("Could not flash: " + wolfGetLastError());
}
Touch to flash, touch again to stop (wolf_flash.lsl, 43 lines: show or hide)

Download wolf_flash.lsl

// Wolf Flash - touch to make this object flash between two colours; touch again to stop.
// Uses the wolf-commands plugin through wolfCall("object.flash", ...): the region does the flashing, so this script
// needs no timer, and the object's own colours come back when the flash ends or is stopped.
// Works on rezzed objects you own (not on attachments or HUDs). Wolf Territories, 2026. Copy, change and share freely.

vector COLOUR_A = <1.0, 0.0, 0.0>;   // red
vector COLOUR_B = <1.0, 1.0, 0.0>;   // yellow
float  EACH     = 0.5;               // seconds each colour shows: 0.5 to 60
float  FOR      = 0.0;               // seconds the flash lasts: 0 = until stopped (at most an hour)
integer flashing;

default
{
    touch_start(integer n)
    {
        if (llDetectedKey(0) != llGetOwner()) return;
        if (!flashing)
        {
            // [link, colour A, colour B, seconds each colour, seconds in all, face]
            list r = wolfCall("object.flash", [LINK_SET, COLOUR_A, COLOUR_B, EACH, FOR, ALL_SIDES]);
            if (llGetListLength(r) == 0)
            {
                llOwnerSay("Could not flash: " + wolfGetLastError());
                return;
            }
            // ["ok", prims flashing, seconds each colour, seconds in all]
            llOwnerSay("Flashing " + llList2String(r, 1) + " prims. Touch again to stop.");
            flashing = TRUE;
        }
        else
        {
            // ["ok", prims stopped]: their own colours are back
            wolfCall("object.flash.stop", [LINK_SET]);
            flashing = FALSE;
        }
    }

    on_rez(integer p)
    {
        llResetScript();
    }
}

Weather

Your scripts can read the weather the region shows - the real weather of its place, or the weather its owner chose - and say it, show it or act on it. It is the same report the Region API gives. Real weather comes from MET Norway; the region reads it at most every few minutes, so ask as often as you like but expect a new answer about every 5 minutes.

  • Use wolfCallAsync the first time. The region reads its weather when a script first asks; wolfCall answers straight away only once it has it (until then it is refused with "the weather is being read just now"). wolfCallAsync waits and answers in dataserver.
  • Units: temperatures in °C (and °F in the names ending _f), wind in m/s (wind_kmh in km/h), wind direction in degrees the wind comes from (0 = north, 90 = east) with a 16-point compass name, pressure in hPa at sea level, humidity, cloud, fog and chances in %, rain or snow in mm in the hour, sun and moon heights in degrees above the horizon. Times are ISO 8601 (UTC with Z, local with its offset).
  • Not known is left out. A value the weather does not have (no temperature for weather chosen by the owner, no gusts outside some areas, no visibility at all) is not in the list - check with llListFindList. In the forecast list an unknown value is "".
  • Where it comes from: source_line says it; show it with the weather. Real weather is MET Norway's (CC BY 4.0) and must be credited: "Source: MET Norway (met.no)". The thunder risk outside the Nordic countries is from Open-Meteo.com.
  • It is the region's weather. A parcel with its own weather (About Land, a parcel Wolf Environment, a wolfrain prim) is not included.

weather.now: the names

weather.now: each name, its type and unit
NamesWhat (type, unit)
available, reasoninteger 1 or 0; when 0, reason says why (string)
region, place, place_short, country, lat, lonthe region; the place its weather is for, its first part, its country (strings); latitude, longitude (float, degrees)
timezone, utc_offset, utc_offset_text, local_time, local_time24, local_time12, grid_time24the place's time zone (e.g. Europe/Oslo), its offset now (integer seconds; "UTC+1"), its time now (ISO; "08:24"; "08:24 AM"), the grid's time ("00:24")
control_by, control_mode, control_source, control_type, control_pattern, control_place_kindwhat runs the weather: wolf-environment, auto-environment, region-weather or none; source live (the real place), fixed, pattern, manual (set by hand) or none; the type or pattern chosen
condition, symbol, weather_codee.g. "Few clouds"; MET's symbol (e.g. "fair_day"); the weather id (integer, OpenWeather-style: 800 clear ... 804 overcast)
kind, level, precip_type, precipitation_mm, precipitation_chancewhat falls on the region: clear, rain or snow, level 0-4; rain, snow, sleet or none; mm in the hour (float); chance in % (integer)
temperature_c, temperature_f, feels_like_c, feels_like_f, dew_point_cfloats. Feels-like is the wind chill at or below 10 °C with wind, the heat index when hot and humid, else the air temperature
humidity, pressure_hpainteger %; float hPa at sea level
wind_ms, wind_kmh, wind_from_deg, wind_compass, wind_beaufort, wind_words, gust_msfloats m/s and km/h; integer degrees (where it comes from); "NW"; Beaufort force 0-12 (integer) and its words ("fresh breeze"); gusts m/s
cloud, cloud_low, cloud_medium, cloud_high, fog, thunder_chance, uv_index, auroraintegers in % (uv_index a float); aurora = the chance of seeing one, %
is_day, sun_elevation, sun_azimuth, sunrise, sunset, sunrise_local, sunset_local, polar, next_sun_event, next_sun_event_time, next_sun_event_localinteger 1 or 0; floats in degrees; ISO times and "HH:MM" at the place; polar = "midnight sun" or "polar night" when the sun does not rise or set; the next sunrise or sunset
moon_elevation, moon_azimuth, moon_illuminated, moon_waxing, moon_phasefloats in degrees; integer % lit; 1 or 0; e.g. "waxing gibbous"
reading_time, fetched_at, stale, synthetic, age_s, source_linethe hour MET's reading is for and when it was fetched (ISO); 1 when it is over 6 hours old; 1 for weather chosen by the owner; seconds since the region read it; the credit to show

["json"] gives the same as one JSON string, grouped (now, place, sky, control, text, attribution, units) - read it with llJsonGetValue, e.g. llJsonGetValue(j, ["now", "temperature_c"]).

Changing the weather (region holders)

  • wolfCallAsync("weather.set", ["rain", 30]) makes it rain on the whole region for 30 minutes, then puts back the weather it had - unless someone changed the region's environment in the meantime, then theirs stays. Without minutes it stays until changed. Every viewer on the region sees it change, as when the Wolf Environment is saved.
  • It changes the region's Wolf Environment weather. A region that still runs Jimmy Olsen's Automatic Environment gets a Wolf Environment with the same place and clock (and loses it again when a timed change ends). A region whose sky is its own EEP, whose weather is set by hand in Region/Estate > Weather, or whose Wolf Environment is switched off, is refused with what to do.
  • weather.auto goes back to the real place's weather (a region with a made-up place has none, and is refused).
  • The answer comes in dataserver: ok|rain|30, or error: and the reason (for example "only the region's owner, its estate owner or an estate manager can change the region's weather").
  • At most 3 changes a minute from one resident and 6 on the region.

Example: say the weather when touched

key ask;

default
{
    touch_start(integer n)
    {
        // "now" (the default), "stats", "later" or a number of hours ahead
        ask = wolfCallAsync("weather.text", ["now"]);
        if (ask == NULL_KEY) llSay(0, wolfGetLastError());
    }

    dataserver(key q, string data)
    {
        if (q != ask) return;
        if (llGetSubString(data, 0, 5) == "error:") data = llGetSubString(data, 7, -1);
        llSay(0, data);   // It's 8°C in Tromsø with light rain and a fresh westerly wind. Sunset is at 15:42.
    }
}

Example: read single values (once the region has its weather)

list w = wolfCall("weather.now", []);
integer i = llListFindList(w, ["temperature_c"]);
if (i != -1)
    llOwnerSay("It is " + (string)llRound(llList2Float(w, i + 1)) + " °C here. "
        + llList2String(w, llListFindList(w, ["source_line"]) + 1));

What the words look like - the region TROMSO on 26 October 2026 at 08:57 there:

weather.text ["now"]:
It's 9°C in Tromsø with scattered cloud and a gentle southerly wind. Sunset is at 15:16.

weather.text ["later"]:
Later this afternoon (15:00): overcast skies.

weather.text ["stats"]:
🌍 Weather for Tromsø, Norge:
Scattered clouds
🌡 9.30 °C (48.70 °F), feels like 7 °C
💧 Humidity: 68%
⏲ Pressure: 994 hPa
🌬 Wind: 4.90 m/s @ 158° (SSE)
🌅 Sunrise 07:39, sunset 15:16
🕒 Local time: 08:57 (24h) / 08:57 AM (AM/PM) [UTC+1]
Source: MET Norway (met.no)
A weather board: the weather as floating text, rain or snow on it when it falls here (wolf_weather_board.lsl, 116 lines: show or hide)

Download wolf_weather_board.lsl

// Wolf weather board - shows this region's weather as floating text and makes it rain or snow on the board when it
// does here. Put it in a prim; it works on any Wolf Territories region. (wolf-commands 1.2.0: wolfCall weather.*)
//
// It asks every 5 minutes: the region keeps the weather for 5 minutes anyway, so asking more often only gives the
// same answer. Touch it to see the full stats in local chat.

float   REFRESH = 300.0;          // seconds between looks
key     gAsk;                     // the weather.now question waiting for its answer
key     gStats;                   // the weather.text "stats" question

string num(string json, list path, integer places)
{
    string v = llJsonGetValue(json, path);
    if (v == JSON_INVALID || v == JSON_NULL) return "?";
    float f = (float)v;
    if (places == 0) return (string)llRound(f);
    // one decimal place
    integer tenths = llRound(f * 10.0);
    string s = (string)(tenths / 10) + "." + (string)llAbs(tenths % 10);
    if (tenths < 0 && tenths > -10) s = "-" + s;
    return s;
}

falling(string kind)
{
    if (kind == "rain" || kind == "sleet")
    {
        llParticleSystem([
            PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK,
            PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE_CONE,
            PSYS_SRC_ANGLE_BEGIN, 0.0, PSYS_SRC_ANGLE_END, PI,
            PSYS_PART_START_COLOR, <0.7, 0.8, 1.0>, PSYS_PART_START_ALPHA, 0.6,
            PSYS_PART_START_SCALE, <0.03, 0.25, 0.0>,
            PSYS_SRC_ACCEL, <0.0, 0.0, -9.0>,
            PSYS_SRC_BURST_RATE, 0.05, PSYS_SRC_BURST_PART_COUNT, 6,
            PSYS_SRC_BURST_RADIUS, 1.5, PSYS_PART_MAX_AGE, 1.2,
            PSYS_SRC_BURST_SPEED_MIN, 0.1, PSYS_SRC_BURST_SPEED_MAX, 0.3]);
    }
    else if (kind == "snow")
    {
        llParticleSystem([
            PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK | PSYS_PART_WIND_MASK,
            PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE_CONE,
            PSYS_SRC_ANGLE_BEGIN, 0.0, PSYS_SRC_ANGLE_END, PI,
            PSYS_PART_START_COLOR, <1.0, 1.0, 1.0>, PSYS_PART_START_ALPHA, 0.9,
            PSYS_PART_START_SCALE, <0.08, 0.08, 0.0>,
            PSYS_SRC_ACCEL, <0.0, 0.0, -0.6>,
            PSYS_SRC_BURST_RATE, 0.1, PSYS_SRC_BURST_PART_COUNT, 3,
            PSYS_SRC_BURST_RADIUS, 1.5, PSYS_PART_MAX_AGE, 5.0,
            PSYS_SRC_BURST_SPEED_MIN, 0.05, PSYS_SRC_BURST_SPEED_MAX, 0.2]);
    }
    else llParticleSystem([]);
}

ask()
{
    // wolfCallAsync answers in dataserver when the weather is ready (the very first look on a region can take a second).
    gAsk = wolfCallAsync("weather.now", ["json"]);
    if (gAsk == NULL_KEY) llSetText("Weather: " + wolfGetLastError(), <1.0, 0.6, 0.6>, 1.0);
}

default
{
    state_entry()
    {
        llSetText("Reading the weather...", <1.0, 1.0, 1.0>, 1.0);
        ask();
        llSetTimerEvent(REFRESH);
    }

    on_rez(integer p) { llResetScript(); }

    timer() { ask(); }

    touch_start(integer n)
    {
        gStats = wolfCallAsync("weather.text", ["stats"]);
        if (gStats == NULL_KEY) llRegionSayTo(llDetectedKey(0), 0, wolfGetLastError());
    }

    dataserver(key q, string data)
    {
        if (llGetSubString(data, 0, 5) == "error:")
        {
            if (q == gAsk) llSetText("Weather: " + llGetSubString(data, 7, -1), <1.0, 0.6, 0.6>, 1.0);
            else if (q == gStats) llSay(0, llGetSubString(data, 7, -1));
            return;
        }
        if (q == gStats) { llSay(0, data); return; }
        if (q != gAsk) return;

        if (llJsonGetValue(data, ["available"]) != JSON_TRUE)
        {
            llSetText("No weather here\n" + llJsonGetValue(data, ["reason"]), <0.8, 0.8, 0.8>, 1.0);
            falling("none");
            return;
        }
        string place = llJsonGetValue(data, ["place", "short"]);
        string text = llJsonGetValue(data, ["now", "condition"]) + "\n";
        if (llJsonGetValue(data, ["now", "temperature_c"]) != JSON_NULL)
            text += num(data, ["now", "temperature_c"], 1) + " °C (feels like " + num(data, ["now", "feels_like_c"], 0) + " °C)\n";
        if (llJsonGetValue(data, ["now", "humidity"]) != JSON_NULL)
            text += "Humidity " + num(data, ["now", "humidity"], 0) + "%\n";
        text += "Wind " + num(data, ["now", "wind_ms"], 1) + " m/s from the " + llJsonGetValue(data, ["now", "wind_compass"]) + "\n";
        if (llJsonGetValue(data, ["place", "local_time24"]) != JSON_INVALID)
            text += place + " time " + llJsonGetValue(data, ["place", "local_time24"]) + "\n";
        text += llJsonGetValue(data, ["attribution", "text"]);
        llSetText(text, <1.0, 1.0, 1.0>, 1.0);

        // Rain, sleet or snow on the board while it falls here.
        string kind = llJsonGetValue(data, ["now", "precip_type"]);
        if (llJsonGetValue(data, ["now", "kind"]) == "clear") kind = "none";
        falling(kind);
    }
}
Ask it in local chat: "what's the weather?", "will it rain later?" (owner touch: on/off) (wolf_weather_ask.lsl, 96 lines: show or hide)

Download wolf_weather_ask.lsl

// Wolf weather - ask it in local chat. Say "what is the weather now", "what's the weather", "will it rain later" or
// "weather forecast" near it and it answers you. Touch it (owner only) to switch it on or off.
// Works on any Wolf Territories region. (wolf-commands 1.2.0: wolfCall weather.text)
//
// It answers only the person who asked (llRegionSayTo), at most once every 20 seconds each and once every 5 seconds in
// all, so it cannot be used to flood the chat.

integer PERSON_WAIT = 20;      // seconds before the same person gets another answer
integer ALL_WAIT    = 5;       // seconds between any two answers
integer MAX_REMEMBERED = 40;   // people remembered for PERSON_WAIT (oldest forgotten first)

integer gOn = TRUE;
integer gListen;
integer gLastAnswer;
list    gAsked;                // [avatar, unix time, ...]
list    gWaiting;              // [query key, avatar, ...] questions waiting for their answer

// What they asked for: "now", "later", "stats" - or "" when it is not a weather question.
string kindOf(string msg)
{
    string m = llToLower(msg);
    if (llSubStringIndex(m, "weather") == -1 && llSubStringIndex(m, "rain") == -1 && llSubStringIndex(m, "snow") == -1
        && llSubStringIndex(m, "forecast") == -1 && llSubStringIndex(m, "temperature") == -1) return "";
    // a question or a request, not every sentence that mentions rain
    if (llSubStringIndex(m, "?") == -1 && llSubStringIndex(m, "what") == -1 && llSubStringIndex(m, "will it") == -1
        && llSubStringIndex(m, "forecast") == -1 && llSubStringIndex(m, "how") == -1 && llSubStringIndex(m, "is it") == -1) return "";
    if (llSubStringIndex(m, "stats") != -1 || llSubStringIndex(m, "detail") != -1 || llSubStringIndex(m, "report") != -1) return "stats";
    if (llSubStringIndex(m, "later") != -1 || llSubStringIndex(m, "forecast") != -1 || llSubStringIndex(m, "tonight") != -1
        || llSubStringIndex(m, "tomorrow") != -1 || llSubStringIndex(m, "will it") != -1) return "later";
    return "now";
}

integer mayAnswer(key who)
{
    integer now = llGetUnixTime();
    if (now - gLastAnswer < ALL_WAIT) return FALSE;
    integer i = llListFindList(gAsked, [who]);
    if (i != -1)
    {
        if (now - llList2Integer(gAsked, i + 1) < PERSON_WAIT) return FALSE;
        gAsked = llDeleteSubList(gAsked, i, i + 1);
    }
    gAsked += [who, now];
    if (llGetListLength(gAsked) > MAX_REMEMBERED * 2) gAsked = llDeleteSubList(gAsked, 0, 1);
    gLastAnswer = now;
    return TRUE;
}

show()
{
    if (gOn) llSetText("Ask me about the weather", <0.7, 0.9, 1.0>, 1.0);
    else llSetText("Weather (off)", <0.6, 0.6, 0.6>, 1.0);
}

default
{
    state_entry()
    {
        gListen = llListen(0, "", NULL_KEY, "");
        show();
    }

    on_rez(integer p) { llResetScript(); }

    touch_start(integer n)
    {
        if (llDetectedKey(0) != llGetOwner()) return;
        gOn = !gOn;
        llListenControl(gListen, gOn);
        show();
        llOwnerSay("Weather answers " + llList2String(["off", "on"], gOn) + ".");
    }

    listen(integer ch, string name, key id, string msg)
    {
        if (!gOn || llGetAgentSize(id) == ZERO_VECTOR) return;     // people only, not objects
        string kind = kindOf(msg);
        if (kind == "" || !mayAnswer(id)) return;
        // "later" is about six hours ahead; weather.text also takes a number of hours (1-48).
        key q = wolfCallAsync("weather.text", [kind]);
        if (q == NULL_KEY) { llRegionSayTo(id, 0, wolfGetLastError()); return; }
        gWaiting += [q, id];
        if (llGetListLength(gWaiting) > 20) gWaiting = llDeleteSubList(gWaiting, 0, 1);
    }

    dataserver(key q, string data)
    {
        integer i = llListFindList(gWaiting, [q]);
        if (i == -1) return;
        key who = llList2Key(gWaiting, i + 1);
        gWaiting = llDeleteSubList(gWaiting, i, i + 1);
        if (llGetSubString(data, 0, 5) == "error:") data = "Sorry, I can't tell just now: " + llGetSubString(data, 7, -1);
        llRegionSayTo(who, 0, data);
    }
}

Hurricanes

A script can bring a hurricane over the region. It forms from the clouds already in the sky: they gather, thicken and start to turn, spiral rain bands wind in, a dense overcast builds over the middle, then the eye clears inside its eyewall. It rages for a while, crossing the region, then dies away and the region's own weather comes back exactly as it was. It turns anticlockwise in the northern hemisphere and clockwise in the southern, by the latitude of the region's weather place.

  • Everything follows it: the region's wind (llWind, and the wind every viewer gets: particles, flexi prims, trees, boats) circulates round the eye at the category's speed; heavy rain and thunder in the eyewall and bands, none in the eye; the sky darkens; the sea gets up where the Wolf Environment's water follows the wind. WolfViewer and WolfStorm draw the storm itself (the bands, the eye, the eyewall); other viewers see the darker, stormy sky, the rain and the wind. Clouds never cover anyone's builds.
  • Options (all optional, name then value): "category" a whole number 1-5 (3, not 3.0; Saffir-Simpson, default 1); "minutes" 5-300 in all (default 40); "form" 2-60 minutes forming (default 10; it dies away over a quarter of its time, 2-30 minutes); "centre" <x, y, 0> where the eye passes, in region metres (default the middle); "radius" 1000-60000 metres (default: a standard storm about 1500 metres across from its eye to its edge, a little bigger or smaller each time, 1125-1875, the same on every region so you see the whole storm come in, pass and go); "heading" 0-360, the way it moves (default downwind, else west); "speed" 0-30 m/s (default: it crosses twice its own radius in its lifetime, so it arrives, passes over the centre half way through and leaves; 0 = it stays); "rain" TRUE or FALSE (a whole number: 1 or 0, not 1.0). "center" works as well as "centre", and the names are not case-sensitive.
  • Sizes and speeds: a real hurricane's shape shrunk to a size you can see from the region (the eye 15 % of the storm's radius, about 170-280 metres for the standard storm), with real winds (category 1 about 38 m/s, category 5 about 70 m/s at the eyewall, from the NHC's Saffir-Simpson scale) and real rain rates.
  • Who: the region's owner, its estate owner, an estate manager or the grid's staff (the grid checks, as for weather.set); the script must belong to its object's owner. Anyone's script can read weather.hurricane.state, at most 20 times in ten seconds from one object. At most 3 starts or ends a minute from one resident and 6 on the region.
  • Where: as weather.set, a region whose sky is run by its Wolf Environment or by the automatic environment. A region whose sky is its own EEP, whose weather is set by hand, or whose Wolf Environment is switched off, is refused with what to do. One hurricane per region: a second one is refused until the first has ended.
  • The answer comes in dataserver: ok|..., or error: and the reason. Saving the Wolf Environment window while a storm runs keeps it.

Example: a category 3 hurricane, 60 minutes, crossing the region from the east

key ask;

default
{
    touch_start(integer n)
    {
        if (llDetectedKey(0) != llGetOwner()) return;
        ask = wolfCallAsync("weather.hurricane", ["category", 3, "minutes", 60, "form", 15, "heading", 270]);
        if (ask == NULL_KEY) llOwnerSay(wolfGetLastError());
    }

    dataserver(key q, string data)
    {
        if (q == ask) llOwnerSay(data);   // ok|5d0c...|3|900|1800|900|4000|400|1  or  error: ...
    }
}
A hurricane button: a menu to start one (category 1-5), let it die away or end it, and its state as floating text (wolf_hurricane.lsl, 84 lines: show or hide)

Download wolf_hurricane.lsl

// Wolf Territories - a hurricane button (wolf-hurricane, wolfCall weather.hurricane*).
// Put it in a prim on your region. Touch it (its owner only) for a menu: start a hurricane of category 1 to 5, let it die
// away now, or take it away at once. While a storm runs the prim shows its stage, the time left and the wind as floating
// text. Only the region's owner, its estate owner or an estate manager can make a hurricane (the grid checks); anyone's
// script can read its state.
integer CHANNEL;
integer listener;
key ask;
string asked;

show()
{
    list s = wolfCall("weather.hurricane.state", []);
    if (llGetListLength(s) == 0 || llList2String(s, 0) == "none")
    {
        llSetText("No hurricane\n(touch for the menu)", <0.8, 0.9, 1.0>, 1.0);
        llSetTimerEvent(0.0);            // nothing to watch: no timer while no storm runs
        return;
    }
    // [stage, category, seconds left, <eye x, y, 0>, radius, eye radius, wind now, organisation, eye clear, hemisphere, id]
    string stage = llList2String(s, 0);
    if (stage == "decaying") stage = "dying away";
    integer left = llList2Integer(s, 2);
    llSetText("Category " + llList2String(s, 1) + " hurricane: " + stage
        + "\n" + (string)(left / 60) + " min " + (string)(left % 60) + " s left"
        + "\nstrongest wind now " + (string)llRound(llList2Float(s, 6)) + " m/s"
        + "\nwind here " + (string)llRound(llVecMag(llWind(ZERO_VECTOR))) + " m/s", <1.0, 0.8, 0.4>, 1.0);
}

default
{
    state_entry()
    {
        CHANNEL = -1 - (integer)("0x" + llGetSubString((string)llGetKey(), 0, 6));
        llSetTimerEvent(5.0);
        show();
    }

    on_rez(integer p) { llResetScript(); }

    touch_start(integer n)
    {
        if (llDetectedKey(0) != llGetOwner()) return;
        llListenRemove(listener);
        listener = llListen(CHANNEL, "", llGetOwner(), "");
        llDialog(llGetOwner(), "Hurricane over this region\n\nStart one (it forms from the clouds over 10 minutes and lasts 40), let the one now die away, or take it away at once.",
                 ["Cat 1", "Cat 2", "Cat 3", "Cat 4", "Cat 5", "Die away", "Gone now", "Close"], CHANNEL);
        llSetTimerEvent(5.0);
    }

    listen(integer ch, string name, key id, string msg)
    {
        llListenRemove(listener);
        if (llGetSubString(msg, 0, 3) == "Cat ")
        {
            asked = msg;
            // every option is optional: "minutes" 5-300 in all, "form" 2-60, "centre" <x, y, 0>, "radius" 1000-60000 m,
            // "heading" 0-360 (degrees it moves towards), "speed" 0-30 m/s, "rain" TRUE/FALSE
            ask = wolfCallAsync("weather.hurricane", ["category", (integer)llGetSubString(msg, 4, -1), "minutes", 40, "form", 10]);
        }
        else if (msg == "Die away") { asked = msg; ask = wolfCallAsync("weather.hurricane.end", []); }
        else if (msg == "Gone now") { asked = msg; ask = wolfCallAsync("weather.hurricane.end", ["now"]); }
        else return;
        if (ask == NULL_KEY) llOwnerSay(asked + ": " + wolfGetLastError());
    }

    dataserver(key q, string data)
    {
        if (q != ask) return;
        // "ok|id|category|form s|mature s|decay s|radius|eye|hemisphere", "ok|decaying|seconds left", "ok|gone" or "error: why"
        list d = llParseStringKeepNulls(data, ["|"], []);
        if (llList2String(d, 0) != "ok") llOwnerSay(asked + ": " + data);
        else if (llGetListLength(d) == 9)
            llOwnerSay("A category " + llList2String(d, 2) + " hurricane is forming: " + (string)(llList2Integer(d, 3) / 60) + " minutes forming, "
                + (string)(llList2Integer(d, 4) / 60) + " at full strength, " + (string)(llList2Integer(d, 5) / 60) + " dying away; "
                + "reaching " + llList2String(d, 6) + " m from its eye, turning " + llList2String(["clockwise (south)", "anticlockwise (north)"], llList2Integer(d, 8) > 0) + ".");
        else llOwnerSay(asked + ": " + data);
        llSetTimerEvent(5.0);
        show();
    }

    timer() { show(); }
}

Only The Caribbean answers these names (the wolf-naval plugin). Anywhere else the call is refused, and wolfGetLastError says wolfCall: no plugin function "naval.battle" on this region. Each one acts on the ship or shore cannon the calling script is in (its whole linkset), whoever owns the script.

wolf-naval, The Caribbean only: the names, what to give, what comes back, who may use them
NameGive itYou get backWho mayWhat it does
naval.battle["on", class], ["off"] or ["status"][seq, state, health, port guns, starboard guns, sail, turn, struck, protected s, last event], or ["off"]a script in the shipThe Caribbean only. Puts this ship or shore cannon into battle mode (class, e.g. "frigate_pallas" or "shore_cannon"; an unknown class is refused with the list of known ones), takes it out (it goes off after 60 seconds; firing, or "on" again, cancels that) or reads its state. At most 12 ships and 8 shore cannons in battle mode on the region, and 2 ships and 4 cannons of any one owner. Not for a worn object.
naval.fire[side, elevation, shot] or [side, elevation, shot, captain]["fired", guns, "prim,prim,...", seconds until the next is ready]a script in the shipThe Caribbean only. A broadside: every loaded gun on "port" or "starboard" fires. Elevation in degrees (default 3, held to each gun's limits); shot "round" (the default), "chain" or "grape" (grape only where the region has player damage); captain = the key of the avatar giving the order, counted only while they sit aboard.
naval.gun[gun prim, elevation, traverse, gunner, shot]["fired", gun prim, reload seconds, elevation, traverse]a script in the shipThe Caribbean only. One gun fired by its crew. The gunner's key must be sitting on the object; elevation and traverse are held to that gun's limits.
naval.crew["gun,gun,...", magazine 0 or 1][crewed guns]a script in the shipThe Caribbean only. Which guns are crewed (a crewed gun reloads in 20 seconds, not 35) and whether the magazine is manned (reloads take a quarter less time). [0] when not in battle mode.
naval.status[]the same as naval.battlea script in the shipThe Caribbean only. The state now, at most twice a second (naval.watch tells you of every change). State is off, on, sinking, sunk:seconds, silenced:seconds or switching_off:seconds; health is "section=now/max,..."; each gun side is "ready/total/seconds" (a shore cannon's guns are in the port place, starboard is "0/0/0").
naval.watch[last seq]the state as one "|" string (wolfCallAsync)a script in the shipThe Caribbean only. Answers as soon as anything has changed since that sequence number, or after 240 seconds with nothing new. At most 4 scripts watch one ship. wolfCallAsync only.
naval.score[]["hits", n, "sinks", n, "damage_taken", n] or ["off"]a script in the shipThe Caribbean only. This ship's hits and sinks on others, and the damage it has taken, while in battle mode.
naval.booty[] or [avatar]"hoard|doubloons|ships sunk|battles won|best haul|rank|season doubloons|season rank" (wolfCallAsync), or "error:why"any scriptThe Caribbean only. A resident's booty (the object's owner when no key is given); rank 0 = not on the board yet. Gold doubloons are game treasure, not WT$ or Wolf Credits. wolfCallAsync only; an object may ask once every 10 seconds, and answers are kept a minute.
naval.leaderboard[] or [how many 1-10, "season" or "all"]"board|season or all|n|rank|name|doubloons|ships sunk|..." (wolfCallAsync), or "error:why"any scriptThe Caribbean only. The Top Pirates (default: the top 10 this season; a season is a calendar quarter). Four fields a pirate after the first three. The same board as wolf-grid.com/top-pirates. wolfCallAsync only, once every 10 seconds an object, kept a minute.

Booty. When a ship strikes or sinks, the ship that did her the most damage takes her prize in gold doubloons (40 + 8 a gun of her class, half as much again for an NPC pirate), shared among everyone sitting aboard: the captain named in naval.fire two shares, every hand one. Her ship then gets a booty event in naval.watch: booty:<beaten ship>;<avatar>,<granted>,<hoard>,<rank>;.... Limits and the board: Top Pirates.

Dogfights (wolf-air)

Only regions with the wolf-air plugin answer these names; it is being tried first on Sandbox and Sandbox 2. Anywhere else the call is refused, and wolfGetLastError says wolfCall: no plugin function "air.dogfight" on this region. Each one acts on the aircraft the script is in. Dogfight mode is a switch on each aircraft, like battle mode on a ship: two aircraft with it on can fight on any region, and an aircraft with it off can never fire or be hit. Nobody can fire or be hit in safe airspace near an airport.

The bombers' and airliners' words - the crew's air.fire words (turret, doors, bombs, feather, extinguish and autopilot), the 6th value of count, air.range, air.seat and the engines value - come with wolf-air 1.7. A region still on an older wolf-air refuses the new words and names (wolfGetLastError says why), its count has 5 values and its state has no engines value.

wolf-air: the names, what to give, what comes back, who may use them
NameGive itYou get backWho mayWhat it does
air.dogfight["on", class(, same era only 1 or 0)], ["on", "custom", nose axis 0-3, "x,y,z,type;..."], ["off"], ["status"], ["carry"] or ["resume", token(, nose axis, guns)][seq, state, health, guns, cannon, power, roll, pitch, yaw, lift, fuel leak, fire, protected s, safe, last event, engines], ["off"], or ["carry", token]a script in the aircraftPuts this aircraft into dogfight mode (any region with wolf-air): only aircraft in dogfight mode can fire on each other or be hit; nobody else is ever touched. "custom" is for ANY aircraft: her hit boxes come from her own size; the nose axis is 0 = +X, 1 = -X, 2 = +Y, 3 = -Y of her root; the guns are muzzle positions in her root's frame with a type mg, hmg or cannon (empty: two machine guns in the nose; at most 8). Same era only (1) means she fights only aircraft of her own era; modern jets default to 1, every other era to 0, and the practice drones fight any era. While she fights, call ["carry"] every few seconds; after CHANGED_REGION, ["resume", token] keeps her damage and ammunition in the next region (the same object, within 20 seconds). Off takes 30 seconds and firing cancels it. 16 aircraft a region, 3 an owner. State is off, on, switching_off:seconds, down or wreck:seconds. Engines (the 16th value) is filled only for an aircraft with more than one engine, for example "eng=1/0.6/0/1;fire=0/0/0/1;bottle=1/1/0/1;feather=0/1/0/0": each engine's power 0-1, whether it is on fire, whether its extinguisher bottle is still there (1) or used (0), and whether it is feathered. Power is then the mean of her engines, and fire is 1 for an engine fire too. A single-engine aircraft leaves it empty (llParseString2List drops it). An airliner (the classes concorde and b747_400) is refused with "an airliner is unarmed: she never joins a dogfight": she is never in a fight, so rounds and bombs pass through her.
air.fire[what, pilot, seconds 0.1-0.5]: what is "guns", "cannon", "all", "missile", "radar", "flare", "chaff" or "count" (the crew's words "turret", "doors", "bombs", "feather", "extinguish" and "autopilot" are the next rows)guns: ["fired", rounds, guns ammo, cannon ammo, guns heat %, cannon heat %]; missile or radar: ["launched", missiles left, target name]; flare or chaff: ["decoy", kind, left, missiles pulled off]; count: ["count", infra-red missiles, radar missiles, flares, chaff, bombs left]a script in the aircraftGuns: a burst from that group. Hold the trigger by calling it 4 times a second with 0.25 seconds each (at most 4 a second). A gun jams at 100 % heat and clears at 40 %: fire short bursts. Missile (infra-red) or radar: one missile from her pylons, only with a lock - a target in dogfight mode within the seeker's cone ahead of her nose and the missile's reach; one launch a second, at most 4 of hers in flight. Flare or chaff: a salvo of decoys; flares pull infra-red missiles off her, chaff radar ones, with a chance that a newer seeker lowers. Count: what she has left (no pilot needed); bombs left is the 6th value, 0 for an aircraft that carries none. The pilot must be sitting in her; in an aircraft with crew positions (a bomber) her own guns, missiles and decoys are the pilot's alone, from the pilot's (root) seat. Refused in safe airspace near an airport, or with nothing left to fire.
air.fire["turret", gunner, seconds 0.1-0.5, turret name, azimuth deg, elevation deg]["fired", rounds, ammunition left in this turret, heat %, azimuth, elevation]: the aim actually used, in the turret's frame to 0.1 degreea script in the aircraftA burst from one of a bomber's gun turrets, in dogfight mode. Only the gunner sitting on that turret's seat prim can fire it. The turret turns at its own rate from its last aim, inside its arcs, so the answer says where it really points. The burst rules are the guns': hold the trigger by calling it 4 times a second with 0.25 seconds each, and each firer has their own budget. The interrupter stops a gun that would hit her own airframe, and when it stops them all the call is refused with the part in the way. Refused in safe airspace, out of ammunition or jammed.
air.fire["doors", bomb aimer or pilot, 1 open or 0 shut] or ["bombs", bomb aimer, how many or "all", spacing ms 0-1000]doors: ["doors", 1 or 0, seconds until open]; bombs: ["released", how many, bombs left]a script in the aircraftA bomber's bomb doors and bombs. The bomb aimer or the pilot works the doors; they take 4 seconds to open and will not open above her limiting speed. Only the bomb aimer, on their seat prim, releases the bombs (the pilot, in an aircraft the pilot aims, such as the Mosquito); "all" drops everything she can drop now (wing bombs, and the bay's once the doors are open), spaced along her track. At most 16 of one aircraft's bombs and 64 on the region fall at once. A bomb that lands near a range target (an object whose root description is "wolfair:range Name 50", put out by the region owner or a manager) scores, and the aimer and the pilot are told in chat, for example "Bomb 3: 18 m short and 4 m left of Target A - 60 points". Practice: with dogfight mode off, one of our bombers (her linkset data wolfair_class names a class with bombs, and her linkset has its prims) may still open her doors, drop and count her bombs. These are practice bombs: they fall, explode and score exactly as live ones but harm nobody, and she stays out of every fight. In dogfight mode the same bombs damage any aircraft in dogfight mode within their blast. Bombs come back on the ground with the guns' rearm rule, and at respawn. Refused in safe airspace.
air.fire["feather", pilot or flight engineer, engine 1-N (or "engine3"), 1 or 0] or ["extinguish", pilot or flight engineer, engine]feather: ["feather", engine, 1 or 0]; extinguish: ["extinguished", engine, 1 out or 0 still burning]a script in the aircraftA multi-engine aircraft's engines one by one, in dogfight mode: the pilot, or a flight engineer on a seat with the engines panel. Feather tells wolf-air an engine is stopped and feathered (or running again). The extinguisher works only on a burning engine that is stopped and feathered first; it puts the fire out 85 times in 100, and each engine has one bottle until she is rearmed on the ground or respawns. A fire left burning spreads to her wing after 20 seconds.
air.fire["autopilot", pilot, 1 or 0]["autopilot", 1 or 0]a script in the aircraftThe autopilot is in (1) or out (0). Only the avatar on the pilot's (root) seat can put it in; any script of hers can take it out, with any key or NULL_KEY, even with the pilot's seat empty. It works with dogfight mode off, and is kept for her across regions. With it in and anyone else aboard, the pilot can bail out and she flies on. In dogfight mode, a class without an autopilot is refused.
air.status[]the same as air.dogfighta script in the aircraftThe state now, at most twice a second (air.watch tells you of every change).
air.watch[last seq]the state as one "|" string (wolfCallAsync)a script in the aircraftAnswers as soon as anything has changed since that sequence number, or after 240 seconds with nothing new. At most 4 scripts watch one aircraft. The 15th value is the last event, "kind:words" (hit, hit_given, kill, down, wreck, respawn, fire, engine_dead, pilot_hit, rearmed, dogfight_on, switching_off, dogfight_off; from wolf-air 1.7, for bombers and multi-engine aircraft, also doors, bombs, bomb, range_run, engine_fire, feather, extinguished, autopilot, seat, crew_bailout and pilot_bailout). A practice bomber with dogfight mode off is answered too (state off), so a bombsight hears its bomb events.
air.bailout[pilot, parachute key or ""]["ok"]a script in the aircraftThe pilot jumps: stood up and seated on the parachute (an object the aircraft rezzed, described wolfair:parachute, owned by her owner, within 20 m), or just stood up. She is then down: a kill for whoever hit her in the last minute.
air.crash[impact speed m/s]the statea script in the aircraftShe has hit the ground. A crash within a minute of being hit is the attacker's kill ("forced down"). She lies as a wreck for 30 seconds, then respawns at home with full health and ammunition, protected for 20 seconds.
air.home[position, rotation]["ok"]a script in the aircraftWhere she respawns (on this region). Without it: where she was when dogfight mode went on.
air.score[]["kills", n, "deaths", n, "hits", n, "damage_taken", n] or ["off"]a script in the aircraftThis aircraft's score while in dogfight mode.
air.feed[last seq]"seq" then one "seq|unix time|killer|killer plane|victim|victim plane|how" line a kill (wolfCallAsync)any scriptThis region's kill feed (the last 30): answered when someone is shot down after that sequence number. Give -1 for everything kept. At most 16 scripts a region wait on it.
air.leaderboard[] or [how many 1-10]"board|n" then one "rank|name|kills|deaths" line an ace (wolfCallAsync), or "error:why"any scriptThe grid's top aces.
air.safe[]["safe", 0 or 1, name, metres to the edge]any scriptWhether this object is in safe airspace: 800 m round each of the region's airports, up to 300 m above the ground, and any wolfair:safe|radius|height marker the region owner or a manager has put out. Nobody can fire or be hit there.
air.drones["on", how many 1-4, "target" or "enemy", skill "easy", "average" or "ace"], ["off"] or ["status"]["on" or "off", how many, "target" or "enemy", in the air, "awake" or "asleep", skill]a script owned by the region owner or a managerPractice drones flown by the region: targets fly a circuit and evade; enemies pursue aircraft in dogfight mode and fire short bursts. Enemy drones fly like a pilot of that skill (average if you leave it out): an easy one sees your breaks late, aims loosely and breaks off often; an ace tracks hard but still breaks off, extends and can overshoot. They only fly while someone is on the region and an aircraft is in dogfight mode, and cost nobody anything (no AI credits: they are rule-based). Also "/74 drones on [1-4] [target|enemy] [easy|average|ace]", "/74 drones off" or "/74 drones status" in local chat.
air.traffic["on"], ["off"] or ["status"]["on" or "off", planes in the air, "awake" or "asleep"]status: any script; on and off: a script owned by the region owner or a managerPeaceful air traffic on autopilot passing over the region, with navigation and landing lights at night. Never in a dogfight, never hit. Also "/74 traffic on|off|status" in local chat.
air.range["scores"] or ["targets"]scores: ["scores", "target|aircraft|bomb aimer|points|best metres|unix time", ...]; targets: ["targets", "name|x,y,z|radius", ...]any scriptThe region's bombing range. Scores: today's best 20 runs (the day is UTC), best first; a run scores its best bomb plus the mean of all its bombs. Rings round a target: 10 m 100 points, 25 m 60, 50 m 30, 100 m 10, 300 m 1. Targets: the range markers wolf-air reads every minute (at most 32), each an object whose ROOT description is exactly "wolfair:range" or "wolfair:range Name radius", put out by the region owner or a manager. The radius is only reported; scoring always uses the rings.
air.seat[avatar, seat prim name]["seated", seat prim name]a script in the aircraftMoves someone already aboard her to another seat prim without standing up, so a crew can change places in flight. Refused for someone not aboard her, a prim with no sit target, a seat that is taken, the seat they are already in, or more than one move a second. Works with dogfight mode off.

Make any aircraft dogfight-ready. Drop the Wolf Dogfight script (below) into the root prim of any aircraft - one you bought, made or were given. It works beside her own flight script, which keeps flying her. Touch her (as the owner) and the setup walks you through it: sit in the pilot's seat, say which way her nose points (or let it learn on your first flight), choose where her guns are (prims named gun..., two in the nose, four in the wings or a nose cannon), the fire key (the left mouse button in mouselook, Shift+arrows or chat) and, if you like, the script that flies her. Then say dogfight on, or press DOGFIGHT on the WolfViewer flight deck. Add an object called "Wolf Parachute" (with the parachute script) to her contents so the pilot can say bail.

What it cannot do. Damage cannot slow another maker's flight script: with the kit she smokes and burns, the panel shows her damage, and she flies at full strength until she is shot down. Then the kit stops her flight script, lets her fall, and starts the script again when she respawns at home. Our own Wolf Air planes fly the Wolf flight model, so their damage is felt.

Wolf Dogfight: makes any aircraft dogfight-ready (drop it in her root prim and touch her) (wolf_dogfight.lsl, 1140 lines: show or hide)

Download wolf_dogfight.lsl

// Wolf Dogfight 1.1.0 - makes ANY aircraft able to dogfight on Wolf Territories (the wolf-air plugin), 2026-11-01.
// Copyright (C) 2026 IntelligentWolf Ltd. Free to use in any aircraft on Wolf Territories.
//
// Paul 2026-11-01: "need extra scripting so someone can enable any aircraft". Drop this script into the ROOT prim of your
// aircraft (bought, home-made, from any creator). It works BESIDE her own flight script, which keeps flying her.
// Design: region-terrain-work/aircraft-dogfight-2026-11-01/a-research/DESIGN.md s3.2 (calls), s3.5 (bail out), s4 (this kit),
// s2 (the WolfAir1 lines to the WolfViewer dogfight panel). Calls answered by the wolf-air plugin (c-wolf-air/src).
//
// Touch her (owner) the first time: a short setup walks you through the pilot's seat, which way her nose points, where the
// guns are, the fire key and (optionally) her flight script. Then say "dogfight on" (or press DOGFIGHT on the flight deck).
//
// Chat (channel 0 from the owner or the pilot, or on her channel, 7 unless set):
//   dogfight on | dogfight off | status | fire (one second of fire) | bail | guns | cannon | all guns | home here | setup
//   [1.3.0 jets] fox2 / missile (an infra-red missile) | fox3 / radar (a radar missile) | flare / flares | chaff
//   (the flight deck sends the same as "hud missile", "hud radar", "hud flare", "hud chaff")
// Keys: the fire key you chose in setup (the left mouse button in mouselook by default). Her own flight script still gets
//   every key: OpenSim sends a control event to EVERY script that took that key (ScenePresence.cs:6534-6590
//   SendControlsToScripts loops over all of them), whatever its pass_on.
//
// Our own Wolf Air planes carry this same script beside their helm (wolf_plane_helm*). The generator sets the linkset data
// "wolfair_class" (her class) and the link messages below connect the two (README.md "Link protocol"):
//   7300 helm -> kit  "fire|1" / "fire|0", "crash|<impact m/s>[|land|water]", "bail"
//   7301 kit -> helm  "factors|<power>|<roll>|<pitch>|<yaw>|<lift>|<fire 0/1>|<state>"
//   7302 kit -> helm  "down|<cause>" / "respawn|<pos>|<rot>"   (also read by wolf_crash_fx; cause: DownCause below)
//   7305 kit -> fx    "dmg|<smoke>|<fire>|<8 section %>|<state>", "impact|<m/s>|land|water|<1: the plugin made its explosion>"
// [1.1.0 2026-11-01] With wolf_crash_fx in her root (e-lsl-commands/lsl/wolf_crash_fx.lsl) the smoke, fire, the fall's cause
// and the crash are shown by it, on her own parts; without it this script shows its own smoke and fire on the root as before.
//   7304 kit -> helm  "hud|ammo=<g>/<c>|heat=<g>/<c>|dmg=<8 parts %>|fire=<0/1>|smoke=<0/1>|df=<state>|safe=<0/1>"
// With a helm aboard the helm speaks "hi" and "st" to the viewer (it knows speed, throttle, gear); this script then speaks
// only the "hit", "kill", "down" and "respawn" lines. Without one, it speaks all of them.

string  VER = "1.4.0";
// [1.4.0 2026-11-02] Multi-engine aircraft (a-research/DESIGN_BOMBERS.md s3.4, s4, s10): the plugin's WatchData gains a 16th
// field "eng=<p1>/<p2>/..;fire=<..>;bottle=<..>;feather=<..>" (empty for a single engine). The kit hands it to the helm as
// it came, at the end of its 7304 "hud|..." line, and the per-engine powers "<p1>/<p2>/.." as the 9th 7301 "factors" field.
// A single-engine aircraft (no such field, or an empty one) gets exactly the 1.3.0 lines.
// [1.2.0 2026-11-01] Region crossings (Paul: "its okay for people to fly jets and keep going"): every CARRY_EVERY s in dogfight
// mode she keeps a signed copy of her state from the plugin ("air.dogfight carry"); on CHANGED_REGION she hands it to the new
// region's plugin ("air.dogfight resume"), so the fight goes on with her damage, ammunition and heat. Her respawn point there
// is where she came in (on the ground below), until she is back on the region her owner set her home on.
integer HELLO_CH = 7;                 // DESIGN s2: the viewer shouts "hud hello 1" on channel 7 until "hi" names her channel
string  HUD = "WolfAir1|";
float   BURST = 0.25;                 // DESIGN s3.3: a burst is the trigger held for 0.25 s ...
float   FIRE_TICK = 0.26;             // ... and air.fire is called at most 4 times a second (AirRules.MAX_FIRE_PER_S = 4)
float   FALL_TICK = 0.2;              // the fall's keyframes: a 0.2 s tick and 0.3 s frames (hms_wolfy_helm_template.lsl DT/FRAME)
float   FALL_FRAME = 0.3;
float   TERMINAL = 70.0;              // GAME TUNING: a falling wreck goes no faster than this (m/s)
float   SPIN = 1.0;                   // GAME TUNING: rad/s of yaw while she spins down
float   LEARN_MS = 10.0;              // DESIGN s4 step 2: the nose is learned above 10 m/s
list    SECTIONS = ["engine", "fuel", "cockpit", "fuselage", "wing_left", "wing_right", "tail", "fin"];   // AirRules.SECTIONS

// ── settings (linkset data, so they survive a re-rez) ──
string  gClass;        // "" = custom (her own size), else our generator's class (linkset data "wolfair_class")
integer gPilotLink;    // the pilot seat prim (0 = the first to sit)
string  gAxis;         // "auto" or "0".."3" = +X, -X, +Y, -Y (the nose axis air.dogfight custom takes)
string  gGuns;         // "x,y,z,type;..." in her root's frame (types mg, hmg, cannon)
string  gFireKey;      // "ml" (mouselook left button), "shift" (Shift+Left/Right), "chat"
string  gScript;       // her flight script (stopped when she is shot down, reset at the respawn), "" = every other script here
integer gCh;           // her channel (7 unless set)
string  gGroup;        // "all", "guns", "cannon"

// ── state ──
key     gOwner;
key     gPilot = NULL_KEY;
integer gHelm;         // a Wolf helm is in this prim
integer gFx;           // [1.1.0] wolf_crash_fx is in this prim: it shows the damage and the crash
string  gFxSent = "";  // the last "dmg" line sent to it
integer gOn;           // dogfight mode wanted
string  gState = "off";
integer gSeq = -1;
string  gHealth = "";
string  gGunsSt = "0/0/0";
string  gMsl = "0/0/0/0";     // [1.3.0] infra-red missiles / radar missiles / flares / chaff left (air.fire "count")
float   gWarnUntil;           // [1.3.0] a missile warning is shown until then
string  gCannonSt = "0/0/0";
string  gEng = "";            // [1.4.0] WatchData field 15 as it came ("" for a single engine or an older plugin)
float   gPower = 1.0;
float   gRoll = 1.0;
string  gRollS = "1";   // as the plugin wrote it: "L" or "R" after it = she rolls towards that weaker wing (AirEngine.WatchData)
float   gPitch = 1.0;
float   gYaw = 1.0;
float   gLift = 1.0;
integer gFire;
integer gSafe;
integer gSmoke;
string  gEvent = "";
key     gWatchQ = NULL_KEY;
float   gWatchAt;
float   gWatchRetry;
integer gTrigger;      // the fire key is held (or the panel's FIRE)
float   gTriggerUntil; // chat "fire": until then
float   gLastWhy;      // when the pilot was last told why a burst was refused
list    gHud;          // avatars who said hello (seated)
integer gMenuCh;
integer gMenuL;
integer gZeroL;
integer gZeroPilotL;
integer gChL;
integer gHelloL;
string  gStep = "";    // the setup step on show
list    gScriptsShown;
vector  gHomeP;
rotation gHomeR;
integer gHaveHome;
// the fall (no helm aboard)
integer gFalling;
vector  gFallV;
list    gStopped;      // scripts this kit stopped
list    gGunLinks;     // gun prims whose +Z lies along her nose (they draw particle tracers)
list    gGlowSave;     // [link, glow] while gun prims are shown in setup
integer gEvSeq = -1;   // the seq whose event was last acted on
integer gTracersOn;
float   gLastPub;
float   gLastHitTold;
float   CARRY_EVERY = 4.0;      // [1.2.0] s between "carry" calls (the plugin takes a token for 20 s: AirCarry.CARRY_MAX_AGE_S)
string  gCarry = "";            // [1.2.0] her last signed state
float   gCarryAt = -100.0;

// ─────────────────────────────────────────────────────────────── small helpers
Tell(key a, string s) { if (a != NULL_KEY) llRegionSayTo(a, 0, s); }
TellBoth(string s) { if (gPilot != NULL_KEY && gPilot != gOwner) Tell(gPilot, s); Tell(gOwner, s); }

string Why() {
    string e = wolfGetLastError();
    if (llSubStringIndex(e, "no plugin function") != -1)
        return "this region has no dogfight plugin yet (wolf-air) - dogfights work only where it is loaded";
    if (e == "") e = "the guns did not answer";
    return e;
}

string Lsd(string k, string dflt) { string v = llLinksetDataRead(k); if (v == "") return dflt; return v; }

LoadSettings() {
    gClass = llLinksetDataRead("wolfair_class");
    gPilotLink = (integer)Lsd("wolfair_pilot", "0");
    gAxis = Lsd("wolfair_axis", "auto");
    gGuns = llLinksetDataRead("wolfair_guns");
    gFireKey = Lsd("wolfair_firekey", "ml");
    gScript = llLinksetDataRead("wolfair_script");
    gCh = (integer)Lsd("wolfair_ch", "7");
    gGroup = Lsd("wolfair_group", "all");
    string h = llLinksetDataRead("wolfair_home");
    gHaveHome = FALSE;
    if (h != "") {
        list p = llParseString2List(h, ["|"], []);
        gHomeP = (vector)llList2String(p, 0);
        gHomeR = (rotation)llList2String(p, 1);
        gHaveHome = TRUE;
    }
}

integer Ready() {
    if (gClass != "") return TRUE;                       // our own planes: the generator set everything
    return llLinksetDataRead("wolfair_ready") == "1";
}

integer IsHelmHere() {
    integer n = llGetInventoryNumber(INVENTORY_SCRIPT);
    integer i;
    for (i = 0; i < n; ++i)
        if (llSubStringIndex(llGetInventoryName(INVENTORY_SCRIPT, i), "wolf_plane_helm") == 0) return TRUE;
    return FALSE;
}

// The avatars sitting on her: link numbers after the prims.
integer Seated(key a) {
    integer n = llGetNumberOfPrims();
    integer l;
    for (l = llGetObjectPrimCount(llGetKey()) + 1; l <= n; ++l) if (llGetLinkKey(l) == a) return TRUE;
    return FALSE;
}

key FindPilot() {
    if (gPilotLink > 0) {
        key k = llAvatarOnLinkSitTarget(gPilotLink);
        if (k != NULL_KEY) return k;
        return NULL_KEY;
    }
    integer first = llGetObjectPrimCount(llGetKey()) + 1;
    if (llGetNumberOfPrims() >= first) return llGetLinkKey(first);
    return NULL_KEY;
}

// The nose in her root's frame (the axis air.dogfight custom is told).
vector Nose() {
    if (gAxis == "1") return <-1.0, 0.0, 0.0>;
    if (gAxis == "2") return <0.0, 1.0, 0.0>;
    if (gAxis == "3") return <0.0, -1.0, 0.0>;
    return <1.0, 0.0, 0.0>;
}

string F2(float f) { return (string)((float)llRound(f * 100.0) / 100.0); }
string V3(vector v) { return F2(v.x) + "," + F2(v.y) + "," + F2(v.z); }

// ─────────────────────────────────────────────────────────────── guns
// Prims whose name starts "gun": their positions in the root's frame; their description names the type (mg, hmg, cannon;
// anything else is mg). Only prims whose own +Z lies along the nose draw particle tracers (a particle source fires along
// its prim's +Z: llviewerpartsource.cpp, part_dir_vector (0,0,1) * the prim's rotation).
string GunPrims() {
    string out = "";
    integer n = llGetNumberOfPrims();
    integer l;
    integer count = 0;
    for (l = 2; l <= n && count < 8; ++l) {                // AirRules.MAX_CUSTOM_GUNS = 8
        string nm = llToLower(llGetLinkName(l));
        if (llGetSubString(nm, 0, 2) == "gun") {
            list p = llGetLinkPrimitiveParams(l, [PRIM_POS_LOCAL, PRIM_DESC]);
            string t = llToLower(llStringTrim(llList2String(p, 1), STRING_TRIM));
            if (t != "hmg" && t != "cannon") t = "mg";
            if (out != "") out += ";";
            out += V3(llList2Vector(p, 0)) + "," + t;
            ++count;
        }
    }
    return out;
}

FindGunLinks() {
    gGunLinks = [];
    integer n = llGetNumberOfPrims();
    integer l;
    vector nose = Nose();
    for (l = 2; l <= n; ++l) {
        if (llGetSubString(llToLower(llGetLinkName(l)), 0, 2) == "gun") {
            rotation r = llList2Rot(llGetLinkPrimitiveParams(l, [PRIM_ROT_LOCAL]), 0);
            if (<0.0, 0.0, 1.0> * r * nose > 0.94) gGunLinks += [l];      // within 20 degrees of the nose
        }
    }
}

// Presets from her own bounding box (llGetBoundingBox: the linkset's box in the root's frame, LSL_Api.cs:11694-11697).
string Preset(string which) {
    list bb = llGetBoundingBox(llGetKey());
    vector mn = llList2Vector(bb, 0);
    vector mx = llList2Vector(bb, 1);
    vector nose = Nose();
    vector side = <0.0, 0.0, 1.0> % nose;          // her left
    float front = mx * nose;
    if (mn * nose > front) front = mn * nose;   // the far end along the nose (the nose may point down an axis)
    float half = llFabs((mx - mn) * side) * 0.5;
    float midz = (mn.z + mx.z) * 0.5;
    vector c = (mn + mx) * 0.5;
    vector ahead = nose * front;
    vector up = <0.0, 0.0, midz>;
    vector centre = c - nose * (c * nose) - <0.0, 0.0, c.z>;      // the centre line across her, at the root's height
    if (which == "nose2")
        return V3(centre + ahead * 0.85 + side * 0.25 + up) + ",mg;" + V3(centre + ahead * 0.85 - side * 0.25 + up) + ",mg";
    if (which == "wing4")
        return V3(centre + ahead * 0.2 + side * half * 0.35 + up) + ",mg;" + V3(centre + ahead * 0.2 + side * half * 0.5 + up) + ",mg;"
             + V3(centre + ahead * 0.2 - side * half * 0.35 + up) + ",mg;" + V3(centre + ahead * 0.2 - side * half * 0.5 + up) + ",mg";
    return V3(centre + ahead * 0.95 + up) + ",cannon";
}

integer CountGuns(string type) {
    list g = llParseString2List(gGuns, [";"], []);
    integer i;
    integer n = 0;
    for (i = 0; i < llGetListLength(g); ++i) {
        string t = llList2String(llParseString2List(llList2String(g, i), [","], []), 3);
        if ((type == "cannon") == (t == "cannon")) ++n;
    }
    return n;
}

// The setup preview: "Wolf gun marker" objects (temporary red spheres) at each gun if the marker is in her contents,
// otherwise the gun prims glow for 20 s.
ShowGuns(string guns) {
    list g = llParseString2List(guns, [";"], []);
    integer i;
    integer have = llGetInventoryType("Wolf gun marker") == INVENTORY_OBJECT;
    for (i = 0; i < llGetListLength(g) && have; ++i) {
        list p = llParseString2List(llList2String(g, i), [","], []);
        vector local = <(float)llList2String(p, 0), (float)llList2String(p, 1), (float)llList2String(p, 2)>;
        vector at = llGetPos() + local * llGetRot();
        if (llVecDist(at, llGetPos()) < 10.0) llRezObject("Wolf gun marker", at, ZERO_VECTOR, ZERO_ROTATION, 20);
    }
    if (!have) {
        integer n = llGetNumberOfPrims();
        integer l;
        for (l = 2; l <= n; ++l)
            if (llGetSubString(llToLower(llGetLinkName(l)), 0, 2) == "gun") {
                gGlowSave += [l, llList2Float(llGetLinkPrimitiveParams(l, [PRIM_GLOW, 0]), 0)];
                llSetLinkPrimitiveParamsFast(l, [PRIM_GLOW, ALL_SIDES, 0.6]);
            }
    }
}

UnshowGuns() {
    integer i;
    for (i = 0; i < llGetListLength(gGlowSave); i += 2)
        llSetLinkPrimitiveParamsFast(llList2Integer(gGlowSave, i), [PRIM_GLOW, ALL_SIDES, llList2Float(gGlowSave, i + 1)]);
    gGlowSave = [];
}

// ─────────────────────────────────────────────────────────────── particles
Tracers(integer on) {
    if (on == gTracersOn) return;
    gTracersOn = on;
    integer i;
    for (i = 0; i < llGetListLength(gGunLinks); ++i) {
        integer l = llList2Integer(gGunLinks, i);
        if (!on) llLinkParticleSystem(l, []);
        else llLinkParticleSystem(l, [
            PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK | PSYS_PART_FOLLOW_VELOCITY_MASK | PSYS_PART_INTERP_COLOR_MASK,
            PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE_CONE,
            PSYS_SRC_ANGLE_BEGIN, 0.0, PSYS_SRC_ANGLE_END, 0.01,
            PSYS_SRC_BURST_SPEED_MIN, 250.0, PSYS_SRC_BURST_SPEED_MAX, 255.0,   // llpartdata.cpp:255-256 unpackFixed 8.8: 255 is the most
            PSYS_SRC_BURST_RATE, 0.08, PSYS_SRC_BURST_PART_COUNT, 1,
            PSYS_PART_MAX_AGE, 1.2,
            PSYS_PART_START_SCALE, <0.12, 2.5, 0.0>, PSYS_PART_END_SCALE, <0.08, 2.0, 0.0>,
            PSYS_PART_START_COLOR, <1.0, 0.85, 0.45>, PSYS_PART_END_COLOR, <1.0, 0.55, 0.2>,
            PSYS_PART_START_ALPHA, 1.0, PSYS_PART_END_ALPHA, 0.6,
            PSYS_PART_START_GLOW, 0.4, PSYS_PART_END_GLOW, 0.2]);
    }
}

// Smoke from a damaged engine, flames when she burns (on the root; her own particles come back when she is mended only if
// her own scripts set them again - README "Limits").
integer gPartsShown = -1;
Damage(integer smoke, integer fire) {
    if (gFx) {
        string d = "dmg|" + (string)smoke + "|" + (string)fire + "|" + Pct() + "|" + gState;
        if (d != gFxSent) { gFxSent = d; llMessageLinked(LINK_THIS, 7305, d, NULL_KEY); }
        return;
    }
    integer want = smoke + fire * 2;
    if (want == gPartsShown) return;
    gPartsShown = want;
    if (want == 0) { llParticleSystem([]); return; }
    vector c1 = <0.35, 0.35, 0.35>;
    vector c2 = <0.15, 0.15, 0.15>;
    float glow = 0.0;
    if (fire) { c1 = <1.0, 0.55, 0.15>; c2 = <0.2, 0.2, 0.2>; glow = 0.15; }
    llParticleSystem([
        PSYS_PART_FLAGS, PSYS_PART_INTERP_COLOR_MASK | PSYS_PART_INTERP_SCALE_MASK | PSYS_PART_WIND_MASK,
        PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE,
        PSYS_SRC_BURST_SPEED_MIN, 0.2, PSYS_SRC_BURST_SPEED_MAX, 0.8,
        PSYS_SRC_BURST_RATE, 0.05, PSYS_SRC_BURST_PART_COUNT, 3, PSYS_SRC_BURST_RADIUS, 0.5,
        PSYS_PART_MAX_AGE, 4.0,
        PSYS_PART_START_SCALE, <0.8, 0.8, 0.0>, PSYS_PART_END_SCALE, <3.5, 3.5, 0.0>,
        PSYS_PART_START_COLOR, c1, PSYS_PART_END_COLOR, c2,
        PSYS_PART_START_ALPHA, 0.8, PSYS_PART_END_ALPHA, 0.0,
        PSYS_PART_START_GLOW, glow, PSYS_PART_END_GLOW, 0.0]);
}

MuzzleFlash() {
    if (gGunLinks != []) return;
    llParticleSystem([
        PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK | PSYS_PART_INTERP_COLOR_MASK,
        PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE,
        PSYS_SRC_BURST_SPEED_MIN, 0.5, PSYS_SRC_BURST_SPEED_MAX, 1.5, PSYS_SRC_BURST_RADIUS, 0.2,
        PSYS_SRC_BURST_RATE, 0.05, PSYS_SRC_BURST_PART_COUNT, 2, PSYS_SRC_MAX_AGE, 0.3,
        PSYS_PART_MAX_AGE, 0.15,
        PSYS_PART_START_SCALE, <0.6, 0.6, 0.0>, PSYS_PART_END_SCALE, <0.2, 0.2, 0.0>,
        PSYS_PART_START_COLOR, <1.0, 0.85, 0.4>, PSYS_PART_END_COLOR, <1.0, 0.45, 0.1>,
        PSYS_PART_START_GLOW, 0.5, PSYS_PART_END_GLOW, 0.0]);
    gPartsShown = -1;
}

// ─────────────────────────────────────────────────────────────── the viewer's dogfight panel (WolfAir1, DESIGN s2)
Line(string s) {
    integer i;
    for (i = 0; i < llGetListLength(gHud); ++i) llRegionSayTo(llList2Key(gHud, i), 0, HUD + s);
}

string Pct() {
    list h = llParseString2List(gHealth, [","], []);
    list out = [];
    integer s;
    for (s = 0; s < llGetListLength(SECTIONS); ++s) {
        integer pct = 100;
        integer i;
        for (i = 0; i < llGetListLength(h); ++i) {
            list kv = llParseString2List(llList2String(h, i), ["=", "/"], []);
            if (llList2String(kv, 0) == llList2String(SECTIONS, s)) {
                float m = (float)llList2String(kv, 2);
                if (m > 0.0) pct = llRound(100.0 * (float)llList2String(kv, 1) / m);
            }
        }
        out += [pct];
    }
    return llDumpList2String(out, ",");
}

string Field(string st, integer i) { return llList2String(llParseStringKeepNulls(st, ["/"], []), i); }

string HudFields() {
    return "ammo=" + Field(gGunsSt, 0) + "/" + Field(gCannonSt, 0) + "|heat=" + Field(gGunsSt, 1) + "/" + Field(gCannonSt, 1)
         + "|dmg=" + Pct() + "|fire=" + (string)gFire + "|smoke=" + (string)gSmoke + "|df=" + gState + "|safe=" + (string)gSafe
         + "|msl=" + Field(gMsl, 0) + "/" + Field(gMsl, 1) + "|cm=" + Field(gMsl, 2) + "/" + Field(gMsl, 3)
         + "|warn=" + (string)(llGetTime() < gWarnUntil);
}

// [1.3.0] what is left of the missiles and decoys (AirMissiles.cs Count)
Counts() {
    list r = wolfCall("air.fire", ["count"]);
    if (llList2String(r, 0) == "count") gMsl = llList2String(r, 1) + "/" + llList2String(r, 2) + "/" + llList2String(r, 3) + "/" + llList2String(r, 4);
}

// [1.3.0] one missile ("missile" infra-red, "radar") or one decoy salvo ("flare", "chaff") - AirMissiles.cs Launch / Decoy
Special(string what) {
    if (gPilot == NULL_KEY || !Seated(gPilot) || !CanFire()) { if (gPilot != NULL_KEY) Tell(gPilot, "Dogfight mode is off."); return; }
    list r = wolfCall("air.fire", [what, gPilot, BURST]);
    if (r == []) { Tell(gPilot, llList2String(["Missile", "Decoys"], what == "flare" || what == "chaff") + ": " + Why() + "."); return; }
    if (llList2String(r, 0) == "launched") Tell(gPilot, llList2String(["Fox two", "Fox three"], what == "radar") + " - at " + llList2String(r, 2) + ", " + llList2String(r, 1) + " left.");
    else if (llList2String(r, 0) == "decoy") {
        string t = llList2String(r, 1) + "s away, " + llList2String(r, 2) + " left";
        if ((integer)llList2String(r, 3) > 0) t += " - the missile took them!";
        Tell(gPilot, t + ".");
    }
    Counts();
    Publish();
}

Hi(key a) {
    if (gHelm) return;          // the helm says hi (it knows her flight numbers)
    string cls = gClass;
    if (cls == "") cls = "custom";
    llRegionSayTo(a, 0, HUD + "hi|ver=1|plane=" + llGetObjectName() + "|class=" + cls + "|ch=" + (string)gCh
        + "|vs=0|vne=0|gmax=0|guns=" + (string)CountGuns("guns") + "|cannon=" + (string)CountGuns("cannon") + "|wolfair=1");
}

Publish() {
    gLastPub = llGetTime();
    gSmoke = (gPower < 1.0) || gState == "down";
    string f = "factors|" + F2(gPower) + "|" + gRollS + "|" + F2(gPitch) + "|" + F2(gYaw) + "|" + F2(gLift)
        + "|" + (string)gFire + "|" + gState;
    string h = "hud|" + HudFields();
    if (gEng != "") { f += "|" + EngPowers(); h += "|" + gEng; }        // [1.4.0] multi-engine only
    llMessageLinked(LINK_THIS, 7301, f, NULL_KEY);
    if (gHelm) llMessageLinked(LINK_THIS, 7304, h, NULL_KEY);
    else if (gHud != []) Line("st|" + HudFields() + "|say=");
    if (gState == "off") Damage(0, 0);
    else Damage(gSmoke, gFire);
}

// [1.4.0] the per-engine powers from the WatchData eng field: "eng=<p1>/<p2>/..;..." -> "<p1>/<p2>/.."
string EngPowers() {
    list parts = llParseString2List(gEng, [";"], []);
    integer i;
    for (i = 0; i < llGetListLength(parts); ++i) {
        string s = llList2String(parts, i);
        if (llGetSubString(s, 0, 3) == "eng=") return llGetSubString(s, 4, -1);
    }
    return "";
}

// ─────────────────────────────────────────────────────────────── the plugin (wolf-air)
Watch() {
    if (!gOn && gState == "off") { gWatchQ = NULL_KEY; return; }
    gWatchQ = wolfCallAsync("air.watch", [gSeq]);
    gWatchAt = llGetTime();
    if (gWatchQ == NULL_KEY) gWatchRetry = llGetTime() + 15.0;
}

// STATE: seq|state|health|guns|cannon|power|roll|pitch|yaw|lift|fuel_leak|fire|protected s|safe|last event (DESIGN s3.2)
Absorb(string data) {
    list p = llParseStringKeepNulls(data, ["|"], []);
    if (llGetListLength(p) < 15) return;
    string was = gState;
    gSeq = (integer)llList2String(p, 0);
    gState = llList2String(p, 1);
    gHealth = llList2String(p, 2);
    gGunsSt = llList2String(p, 3);
    gCannonSt = llList2String(p, 4);
    gPower = (float)llList2String(p, 5);
    gRollS = llList2String(p, 6);
    gRoll = (float)gRollS;
    gPitch = (float)llList2String(p, 7);
    gYaw = (float)llList2String(p, 8);
    gLift = (float)llList2String(p, 9);
    gFire = (integer)llList2String(p, 11);
    gSafe = (integer)llList2String(p, 13);
    string ev = llList2String(p, 14);
    gEng = "";
    if (llGetListLength(p) >= 16) gEng = llStringTrim(llList2String(p, 15), STRING_TRIM);     // [1.4.0]
    // a new event whenever the seq moves on (two hits can read the same); the answer to "on" carries seq -1
    if (gSeq > gEvSeq && ev != "") { gEvSeq = gSeq; gEvent = ev; Happened(ev); }
    if (gState != was) { if (gState == "on") Counts(); Changed(was); }
    Publish();
}

// The event's own words: "<kind>:<text>". Kinds read here: hit, down, respawn (README "Event kinds").
Happened(string ev) {
    integer c = llSubStringIndex(ev, ":");
    string kind = ev;
    string text = "";
    if (c != -1) { kind = llGetSubString(ev, 0, c - 1); text = llGetSubString(ev, c + 1, -1); }
    if (kind == "hit") {
        // "<part> hit for <n> by <name>"
        list w = llParseString2List(text, [" "], []);
        string by = "";
        integer b = llSubStringIndex(text, " by ");
        if (b != -1) by = llGetSubString(text, b + 4, -1);
        string dmg = "";
        integer f = llListFindList(w, ["for"]);
        if (f != -1) dmg = llList2String(w, f + 1);
        Line("hit|by=" + by + "|part=" + llList2String(w, 0) + "|dmg=" + dmg);
    }
    if (kind == "missile_warning") { gWarnUntil = llGetTime() + 6.0; Line("warn|" + text); }    // [1.3.0] her RWR / missile warner
    if (kind == "rearmed" || kind == "respawn" || kind == "dogfight_on") Counts();
    if (kind == "kill") {
        // "you shot down <name> (<how>)" (AirEngine.cs ShotDown). The region's whole kill feed reaches every Wolf viewer as
        // the plugin's own "WolfAir" message (AirEngine.AddFeed W.Broadcast), so this line is only her own kills.
        string v = text;
        if (llGetSubString(v, 0, 13) == "you shot down ") v = llGetSubString(v, 14, -1);
        string how = "";
        integer o = llSubStringIndex(v, " (");
        if (o != -1) { how = llGetSubString(v, o + 2, -2); v = llGetSubString(v, 0, o - 1); }
        Line("kill|killer=" + llGetObjectName() + "|victim=" + v + "|how=" + how);
    }
    if (gPilot == NULL_KEY || kind == "fired" || kind == "hit_given") return;
    if (kind == "hit") {                     // the dogfight panel shows hits; in chat at most one every 2 s
        if (gHud != [] || llGetTime() < gLastHitTold + 2.0) return;
        gLastHitTold = llGetTime();
    }
    Tell(gPilot, llGetObjectName() + ": " + text);
}

Changed(string was) {
    if (gState == "down") {
        // "down:shot down by <name>: <how>" (AirEngine.cs Event(t, "down", ...))
        string by = "";
        integer b = llSubStringIndex(gEvent, " by ");
        if (b != -1) {
            by = llGetSubString(gEvent, b + 4, -1);
            integer c = llSubStringIndex(by, ": ");
            if (c != -1) by = llGetSubString(by, 0, c - 1);
        }
        Line("down|by=" + by);
        Trigger(FALSE);
        // [1.1.0] the cause goes with it: the helm flies her down by it, wolf_crash_fx shows it
        llMessageLinked(LINK_THIS, 7302, "down|" + DownCause(), NULL_KEY);
        if (!gHelm) FallStart();
    }
    if (llGetSubString(gState, 0, 4) == "wreck") {
        FallStop();
        UnsitAll();
    }
    if (gState == "on" && (llGetSubString(was, 0, 4) == "wreck" || was == "down")) Respawn();
    if (gState == "off" && was != "off") { gOn = FALSE; llLinksetDataWrite("wolfair_df", "off"); Trigger(FALSE); gEng = ""; }
}

// [1.1.0] Why she is going down, from the plugin's "down" event (AirEngine.cs ShotDown(t, how): "the left wing folded",
// "the right wing folded", "the pilot is out", "she broke up", "she burned", "the pilot bailed out"; CallBailout "abandoned")
string DownCause() {
    string e = gEvent;
    if (llSubStringIndex(e, "left wing folded") != -1) return "wing_left";
    if (llSubStringIndex(e, "right wing folded") != -1) return "wing_right";
    if (llSubStringIndex(e, "pilot is out") != -1) return "cockpit";
    if (llSubStringIndex(e, "broke up") != -1) return "fuselage";
    if (llSubStringIndex(e, "burned") != -1) return "fire";
    if (llSubStringIndex(e, "bailed out") != -1 || llSubStringIndex(e, "abandoned") != -1) return "bail";
    if (gFire) return "fire";
    if (gPower <= 0.0) return "engine";
    return "other";
}

// [1.1.0] What she came down on: the region's water over the ground under her (llWater is the region's one water height,
// LSL_Api.cs llWater - prim water and Wolf custom water are not seen)
string SurfaceHere() {
    float w = llWater(ZERO_VECTOR);
    if (w > llGround(ZERO_VECTOR) && llGetPos().z < w + 8.0) return "water";
    return "land";
}

// [1.1.0] The crash: the plugin (in dogfight mode) and wolf_crash_fx are told
Crashed(float impact, string surface) {
    integer plugin = FALSE;
    if (gState != "off") {
        list r = wolfCall("air.crash", [impact, surface]);
        if (r != []) { plugin = TRUE; Absorb(llDumpList2String(["-1"] + llList2List(r, 1, -1), "|")); }
    }
    llMessageLinked(LINK_THIS, 7305, "impact|" + F2(impact) + "|" + surface + "|" + (string)plugin, NULL_KEY);
}

Dogfight(key a, integer on, integer quiet) {
    if (a != gOwner && a != gPilot && !quiet) { Tell(a, "Only her owner or her pilot may switch dogfight mode."); return; }
    list r;
    if (on) {
        if (!Ready()) { Tell(a, "She is not set up for dogfights yet - touch her (owner) to set her up."); return; }
        if (gClass != "") r = wolfCall("air.dogfight", ["on", gClass]);
        else {
            if (gAxis == "auto") { Tell(a, "Fly her straight for a few seconds first so I can learn which way her nose points (or pick it in the setup)."); return; }
            r = wolfCall("air.dogfight", ["on", "custom", (integer)gAxis, gGuns]);
        }
    }
    else r = wolfCall("air.dogfight", ["off"]);
    if (r == []) { if (!quiet) Tell(a, "Dogfight mode: " + Why() + "."); return; }
    gOn = on;
    if (on) llLinksetDataWrite("wolfair_df", "on"); else llLinksetDataWrite("wolfair_df", "off");
    if (llGetListLength(r) >= 15) Absorb(llDumpList2String(["-1"] + llList2List(r, 1, -1), "|"));
    else { gState = "off"; gEng = ""; Publish(); }
    gSeq = -1;
    Watch();
    if (on) {
        if (!gHaveHome) SetHome();
        else wolfCall("air.home", [gHomeP, gHomeR]);
        FindGunLinks();
        if (!quiet) Tell(a, llGetObjectName() + ": DOGFIGHT MODE ON. Any aircraft in dogfight mode may now fire on her, and she on them "
            + "(never inside safe airspace near an airport). " + FireHelp());
    }
    else if (!quiet) Tell(a, llGetObjectName() + ": dogfight mode goes off in 30 seconds (firing cancels it).");
    TakeKeys();
    Tick();
}

string FireHelp() {
    if (gFireKey == "ml") return "Fire: the left mouse button in mouselook (M), or say fire.";
    if (gFireKey == "shift") return "Fire: Shift+Left or Shift+Right, or say fire.";
    return "Fire: say fire.";
}

SetHome() {
    gHomeP = llGetPos();
    gHomeR = llGetRot();
    gHaveHome = TRUE;
    llLinksetDataWrite("wolfair_home", (string)gHomeP + "|" + (string)gHomeR);
    llLinksetDataWrite("wolfair_home_region", llGetRegionName());      // [1.2.0]
    wolfCall("air.home", [gHomeP, gHomeR]);
}

// [1.2.0] Her respawn point on this region: her own home when this is the region it was set on (or an older home with no
// region), else where she came in, on the ground or water below.
HomeForRegion() {
    LoadSettings();
    string hr = llLinksetDataRead("wolfair_home_region");
    if (gHaveHome && (hr == "" || hr == llGetRegionName())) return;
    vector p = llGetPos();
    float g = llGround(ZERO_VECTOR); float w = llWater(ZERO_VECTOR); if (w > g) g = w;
    vector e = llRot2Euler(llGetRot());
    gHomeP = <p.x, p.y, g + 2.0>;
    gHomeR = llEuler2Rot(<0.0, 0.0, e.z>);
    gHaveHome = TRUE;
}

// [1.2.0] She has flown into another region: the fight comes with her if she was in it.
Crossed() {
    gWatchQ = NULL_KEY; gSeq = -1; gEvSeq = -1; gEng = "";
    HomeForRegion();
    if (!(gOn || gState != "off") || !Ready()) { gState = "off"; return; }
    list r = wolfCall("air.dogfight", ["resume", gCarry, (integer)gAxis, gGuns]);
    if (r == []) {
        string e = Why();
        gState = "off";
        if (llSubStringIndex(wolfGetLastError(), "no plugin function") != -1) {
            // no dogfights here: she flies on; the wish stays, so she joins again where the plugin is
            Publish();
            TellBoth(llGetObjectName() + ": no dogfights over " + llGetRegionName() + " (" + e + ").");
            return;
        }
        // the state could not follow (too old, or this build cannot carry): she joins this region's fight afresh
        Dogfight(gOwner, TRUE, TRUE);
        TellBoth(llGetObjectName() + ": dogfight mode restarted over " + llGetRegionName() + " (" + e + ").");
        return;
    }
    gOn = TRUE;
    if (llGetListLength(r) >= 15) Absorb(llDumpList2String(["-1"] + llList2List(r, 1, -1), "|"));
    Watch();
    wolfCall("air.home", [gHomeP, gHomeR]);
    gCarry = ""; gCarryAt = -100.0;
    TellBoth(llGetObjectName() + ": the dogfight goes on over " + llGetRegionName() + ".");
    Tick();
}

// [1.2.0] Keeps her signed state fresh while she fights (called from the timer).
Carry() {
    if (gState == "off" || llGetTime() - gCarryAt < CARRY_EVERY) return;
    gCarryAt = llGetTime();
    list r = wolfCall("air.dogfight", ["carry"]);
    if (llList2String(r, 0) == "carry") gCarry = llList2String(r, 1);
}

Burst() {
    if (gPilot == NULL_KEY || !Seated(gPilot)) { Trigger(FALSE); return; }
    list r = wolfCall("air.fire", [gGroup, gPilot, BURST]);
    if (r == []) {
        if (llGetTime() > gLastWhy + 3.0) { Tell(gPilot, "Guns: " + Why() + "."); gLastWhy = llGetTime(); }
        Tracers(FALSE);
        return;
    }
    // ["fired", rounds, guns ammo, cannon ammo, guns heat %, cannon heat %]
    if ((integer)llList2String(r, 1) > 0) { Tracers(TRUE); MuzzleFlash(); }
    else Tracers(FALSE);
    gGunsSt = llList2String(r, 2) + "/" + llList2String(r, 4) + "/" + Field(gGunsSt, 2);
    gCannonSt = llList2String(r, 3) + "/" + llList2String(r, 5) + "/" + Field(gCannonSt, 2);
    if (llGetTime() > gLastPub + 0.5) Publish();      // the panel's ammo and heat while firing, twice a second
}

// On, or switching off: firing then keeps dogfight mode on (AirEngine.Fire, the review)
integer CanFire() { return gState == "on" || llGetSubString(gState, 0, 12) == "switching_off"; }

Trigger(integer on) {
    if (on == gTrigger) return;
    gTrigger = on;
    if (!on) { Tracers(FALSE); Publish(); }
    Tick();
}

Bail() {
    if (gPilot == NULL_KEY) return;
    if (gState == "off" || llGetSubString(gState, 0, 4) == "wreck") {
        llUnSit(gPilot);                        // nothing to fight about: she just steps out
        return;
    }
    if (llGetInventoryType("Wolf Parachute") == INVENTORY_OBJECT) {
        // above the cockpit, inside llRezObject's 10 m reach
        llRezObject("Wolf Parachute", llGetPos() + <0.0, 0.0, 3.0>, ZERO_VECTOR, ZERO_ROTATION, 1);
        return;                                 // object_rez sends air.bailout with its key
    }
    BailWith("");
}

BailWith(string chute) {
    // the parachute sets its own seat in its first moments (wolf_parachute.lsl state_entry / on_rez), and object_rez can
    // come first: a refusal about the parachute is tried again, up to 6 times over ~1.8 s (rare: a bail-out)
    list r = wolfCall("air.bailout", [gPilot, chute]);
    integer tries = 0;
    while (r == [] && chute != "" && tries < 6) {
        string w = wolfGetLastError();
        if (llSubStringIndex(w, "seat") == -1 && llSubStringIndex(w, "not a Wolf parachute") == -1 && llSubStringIndex(w, "not on the region") == -1) tries = 99;
        else { llSleep(0.3); ++tries; r = wolfCall("air.bailout", [gPilot, chute]); }
    }
    if (r == []) Tell(gPilot, "Bail out: " + Why() + ".");
}

// ─────────────────────────────────────────────────────────────── shot down, without a Wolf helm aboard
StopFlight() {
    gStopped = [];
    integer n = llGetInventoryNumber(INVENTORY_SCRIPT);
    integer i;
    string me = llGetScriptName();
    for (i = 0; i < n; ++i) {
        string s = llGetInventoryName(INVENTORY_SCRIPT, i);
        if (s != me && (gScript == "" || s == gScript) && llGetScriptState(s)) {
            llSetScriptState(s, FALSE);
            gStopped += [s];
        }
    }
}

StartFlight() {
    integer i;
    for (i = 0; i < llGetListLength(gStopped); ++i) {
        string s = llList2String(gStopped, i);
        if (llGetInventoryType(s) == INVENTORY_SCRIPT) {
            if (s == gScript) llResetOtherScript(s);   // her flight script starts afresh, parked
            llSetScriptState(s, TRUE);
        }
    }
    gStopped = [];
}

FallStart() {
    gFallV = llGetVel();
    StopFlight();
    llSetStatus(STATUS_PHYSICS, FALSE);
    gFalling = TRUE;
    Tick();
}

FallStop() {
    if (!gFalling) return;
    gFalling = FALSE;
    llSetKeyframedMotion([], []);
}

FallStep() {
    vector pos = llGetPos();
    gFallV.z -= 9.80665 * FALL_TICK;
    if (llVecMag(gFallV) > TERMINAL) gFallV = llVecNorm(gFallV) * TERMINAL;
    vector move = gFallV * FALL_FRAME;
    vector next = pos + move;
    vector size = osGetRegionSize();       // OSSL_Api.cs:3663 osGetRegionSize, CheckThreatLevel() with no level: always allowed
    if (next.x < 2.0 || next.y < 2.0 || next.x > size.x - 2.0 || next.y > size.y - 2.0) { gFallV.x = 0.0; gFallV.y = 0.0; move.x = 0.0; move.y = 0.0; next = pos + move; }
    float floor = llGround(move);
    float w = llWater(move);
    if (w > floor) floor = w;
    float bottom = llList2Vector(llGetBoundingBox(llGetKey()), 0) * <0.0, 0.0, 1.0>;
    if (next.z + bottom <= floor) {
        float impact = llVecMag(gFallV);
        llSetKeyframedMotion([], []);
        gFalling = FALSE;
        llSetRegionPos(<next.x, next.y, floor - bottom>);
        string surface = "land";
        if (w > llGround(move)) surface = "water";
        Crashed(impact, surface);
        return;
    }
    rotation spin = llEuler2Rot(<0.0, 0.0, SPIN * FALL_FRAME>);
    llSetKeyframedMotion([move, spin, FALL_FRAME], []);
}

UnsitAll() {
    integer n = llGetNumberOfPrims();
    integer l;
    for (l = n; l > llGetObjectPrimCount(llGetKey()); --l) llUnSit(llGetLinkKey(l));
}

Respawn() {
    FallStop();
    Damage(0, 0);
    Line("respawn");
    // the helm moves her home; wolf_crash_fx puts her parts back (it reads this too, with or without a helm)
    llMessageLinked(LINK_THIS, 7302, "respawn|" + (string)gHomeP + "|" + (string)gHomeR, NULL_KEY);
    if (gHelm) return;
    if (gHaveHome) { llSetRegionPos(gHomeP); llSetRot(gHomeR); }
    StartFlight();
}

// ─────────────────────────────────────────────────────────────── keys and the timer
TakeKeys() {
    if (gPilot == NULL_KEY || gFireKey == "chat") return;
    if (llGetPermissionsKey() == gPilot && (llGetPermissions() & PERMISSION_TAKE_CONTROLS)) Grab();
    else llRequestPermissions(gPilot, PERMISSION_TAKE_CONTROLS);
}

Grab() {
    integer c = CONTROL_ML_LBUTTON;
    if (gFireKey == "shift") c = CONTROL_LEFT | CONTROL_RIGHT;
    // accept, do not pass on. NOT pass_on TRUE: with accept and pass_on both TRUE OpenSim CLEARS the avatar's ignored
    // controls for every key (ScenePresence.cs:6401-6403 IgnoredControls = CONTROL_ZERO), undoing her own flight script's
    // llTakeControls(..., TRUE, FALSE). Every script that took a key still gets it (SendControlsToScripts).
    llTakeControls(c, TRUE, FALSE);
}

Tick() {
    float t = 0.0;
    if (gOn || gState != "off") t = 5.0;
    if (gAxis == "auto" && gClass == "" && gPilot != NULL_KEY) t = 1.0;
    if ((gTrigger || llGetTime() < gTriggerUntil) && CanFire()) t = FIRE_TICK;
    if (gFalling) t = FALL_TICK;
    llSetTimerEvent(t);
}

Learn() {
    vector v = llGetVel() / llGetRot();      // her velocity in her own frame
    if (llVecMag(<v.x, v.y, 0.0>) < LEARN_MS) return;
    if (llFabs(v.x) >= llFabs(v.y)) { if (v.x > 0.0) gAxis = "0"; else gAxis = "1"; }
    else { if (v.y > 0.0) gAxis = "2"; else gAxis = "3"; }
    llLinksetDataWrite("wolfair_axis", gAxis);
    Tell(gOwner, llGetObjectName() + ": I have learned which way her nose points (" + llList2String(["+X", "-X", "+Y", "-Y"], (integer)gAxis) + "). Dogfight mode can go on now.");
    Tick();
}

Pilot() {
    key p = FindPilot();
    if (p == gPilot) return;
    if (gZeroPilotL) { llListenRemove(gZeroPilotL); gZeroPilotL = 0; }
    gPilot = p;
    Trigger(FALSE);
    if (p != NULL_KEY) {
        if (p != gOwner) gZeroPilotL = llListen(0, "", p, "");
        TakeKeys();
        if (Ready() && gState == "off") Tell(p, llGetObjectName() + " can dogfight: say \"dogfight on\". " + FireHelp());
    }
    Tick();
}

// ─────────────────────────────────────────────────────────────── the setup helper (paul-games-need-setup-helper)
Menu(string step, string text, list buttons) {
    gStep = step;
    if (gMenuL) llListenRemove(gMenuL);
    gMenuL = llListen(gMenuCh, "", gOwner, "");
    llDialog(gOwner, text, buttons, gMenuCh);
}

SetupStart() {
    Menu("pilot", "Let's get " + llGetObjectName() + " ready for dogfights!\n\nStep 1 of 5: sit in the PILOT's seat, then press \"Pilot seat\".",
         ["Pilot seat", "Skip", "Cancel"]);
}

SetupNose() {
    Menu("nose", "Step 2 of 5: which way does her nose point?\n\"Auto\" learns it the first time you fly her faster than 10 m/s.",
         ["Auto", "+X", "-X", "+Y", "-Y", "Back"]);
}

SetupGuns() {
    integer prims = llGetListLength(llParseString2List(GunPrims(), [";"], []));
    string t = "Step 3 of 5: where are her guns?";
    if (prims > 0) t += "\nShe has " + (string)prims + " prims named gun... (type from each one's description: mg, hmg or cannon).";
    Menu("guns", t, ["Gun prims", "2 in the nose", "4 in the wings", "Nose cannon", "Back"]);
}

SetupGunsCheck(string guns) {
    gGuns = guns;
    ShowGuns(guns);
    Menu("gunscheck", "The guns are shown (red markers or glowing prims) for 20 seconds. Is that right?", ["Yes", "Back"]);
}

SetupFireKey() {
    Menu("firekey", "Step 4 of 5: the fire key.", ["Mouse (mouselook)", "Shift+arrows", "Chat only", "Back"]);
}

SetupScript() {
    gScriptsShown = [];
    integer n = llGetInventoryNumber(INVENTORY_SCRIPT);
    integer i;
    for (i = 0; i < n && llGetListLength(gScriptsShown) < 9; ++i) {
        string s = llGetInventoryName(INVENTORY_SCRIPT, i);
        if (s != llGetScriptName()) gScriptsShown += [s];
    }
    list b = ["None", "Back"];
    string t = "Step 5 of 5 (optional): which script flies her? It is stopped when she is shot down and started again when she respawns.\n";
    for (i = 0; i < llGetListLength(gScriptsShown); ++i) { t += "\n" + (string)(i + 1) + ". " + llList2String(gScriptsShown, i); b += [(string)(i + 1)]; }
    Menu("script", t, b);
}

SetupDone() {
    llLinksetDataWrite("wolfair_ready", "1");
    gStep = "";
    if (gMenuL) { llListenRemove(gMenuL); gMenuL = 0; }
    FindGunLinks();
    string more = "";
    if (gAxis == "auto") more = " First fly her straight for a few seconds so I can learn which way her nose points.";
    Tell(gOwner, "Your aircraft is ready! Say \"dogfight on\" (or press DOGFIGHT on the flight deck) to fight." + more + " " + FireHelp());
}

SetupAnswer(string m) {
    if (m == "Cancel") { gStep = ""; UnshowGuns(); return; }
    if (gStep == "pilot") {
        if (m == "Skip") { SetupNose(); return; }
        integer n = llGetObjectPrimCount(llGetKey());
        integer l;
        integer found = -1;
        for (l = 1; l <= n; ++l) if (llAvatarOnLinkSitTarget(l) == gOwner) found = l;
        if (found == -1 && Seated(gOwner)) found = 0;        // seated, but not on a sit target: "the first to sit"
        if (found == -1) { Menu("pilot", "You are not sitting on her yet. Sit in the pilot's seat, then press \"Pilot seat\".", ["Pilot seat", "Skip", "Cancel"]); return; }
        gPilotLink = found;
        llLinksetDataWrite("wolfair_pilot", (string)found);
        SetupNose();
        return;
    }
    if (gStep == "nose") {
        if (m == "Back") { SetupStart(); return; }
        integer i = llListFindList(["Auto", "+X", "-X", "+Y", "-Y"], [m]);
        if (i == -1) return;
        if (i == 0) gAxis = "auto"; else gAxis = (string)(i - 1);
        llLinksetDataWrite("wolfair_axis", gAxis);
        SetupGuns();
        return;
    }
    if (gStep == "guns") {
        if (m == "Back") { SetupNose(); return; }
        string g;
        if (m == "Gun prims") {
            g = GunPrims();
            if (g == "") { Menu("guns", "She has no prims named gun... - pick one of the others.", ["2 in the nose", "4 in the wings", "Nose cannon", "Back"]); return; }
        }
        else {
            if (gAxis == "auto") { Menu("guns", "The places in the nose or the wings need her nose direction: go Back and pick it (or use her gun prims).", ["Gun prims", "Back"]); return; }
            if (m == "2 in the nose") g = Preset("nose2");
            else if (m == "4 in the wings") g = Preset("wing4");
            else g = Preset("cannon");
        }
        SetupGunsCheck(g);
        return;
    }
    if (gStep == "gunscheck") {
        UnshowGuns();
        if (m == "Back") { SetupGuns(); return; }
        llLinksetDataWrite("wolfair_guns", gGuns);
        SetupFireKey();
        return;
    }
    if (gStep == "firekey") {
        if (m == "Back") { SetupGuns(); return; }
        if (m == "Mouse (mouselook)") gFireKey = "ml";
        else if (m == "Shift+arrows") gFireKey = "shift";
        else gFireKey = "chat";
        llLinksetDataWrite("wolfair_firekey", gFireKey);
        SetupScript();
        return;
    }
    if (gStep == "script") {
        if (m == "Back") { SetupFireKey(); return; }
        if (m == "None") gScript = "";
        else gScript = llList2String(gScriptsShown, (integer)m - 1);
        llLinksetDataWrite("wolfair_script", gScript);
        SetupDone();
    }
}

// ─────────────────────────────────────────────────────────────── orders
Order(key a, string m) {
    m = llToLower(llStringTrim(m, STRING_TRIM));
    integer mine = (a == gOwner || a == gPilot);
    if (m == "hud hello 1" || m == "hud hello") {
        if (!Seated(a)) return;
        if (llListFindList(gHud, [a]) == -1 && llGetListLength(gHud) < 12) gHud += [a];
        Hi(a);
        Publish();
        return;
    }
    if (m == "hud bye") { integer i = llListFindList(gHud, [a]); if (i != -1) gHud = llDeleteSubList(gHud, i, i); return; }
    if (!mine) return;
    if (m == "dogfight on" || m == "hud dogfight on") Dogfight(a, TRUE, FALSE);
    else if (m == "dogfight off" || m == "hud dogfight off") Dogfight(a, FALSE, FALSE);
    else if (m == "hud fire on" && a == gPilot) Trigger(TRUE);
    else if (m == "hud fire off" && a == gPilot) Trigger(FALSE);
    else if (m == "fire" && a == gPilot) { gTriggerUntil = llGetTime() + 1.0; Tick(); }
    else if ((m == "bail" || m == "bail out" || m == "hud bail") && a == gPilot) Bail();
    else if ((m == "fox2" || m == "missile" || m == "hud missile") && a == gPilot) Special("missile");      // [1.3.0]
    else if ((m == "fox3" || m == "radar" || m == "hud radar") && a == gPilot) Special("radar");
    else if ((m == "flare" || m == "flares" || m == "hud flare") && a == gPilot) Special("flare");
    else if ((m == "chaff" || m == "hud chaff") && a == gPilot) Special("chaff");
    else if (m == "guns" || m == "cannon" || m == "all guns") {
        gGroup = llList2String(["guns", "cannon", "all"], llListFindList(["guns", "cannon", "all guns"], [m]));
        llLinksetDataWrite("wolfair_group", gGroup);
        Tell(a, "Firing: " + gGroup + ".");
    }
    else if (m == "home here" && a == gOwner) { SetHome(); Tell(a, "She respawns here now."); }
    else if (m == "setup" && a == gOwner) SetupStart();
    else if (m == "status") Tell(a, Status());
}

string Status() {
    string s = llGetObjectName() + " (Wolf Dogfight " + VER + "): dogfight mode " + gState;
    if (!Ready()) return s + ". Not set up yet: touch her (owner).";
    if (gState != "off") s += ". Damage: " + llDumpList2String(llParseString2List(gHealth, [","], []), " ")
        + ". Guns " + Field(gGunsSt, 0) + " rounds, " + Field(gGunsSt, 1) + "% hot; cannon " + Field(gCannonSt, 0) + " rounds.";
    if (gSafe) s += " In safe airspace.";
    return s;
}

Listens() {
    if (gChL) llListenRemove(gChL);
    if (gHelloL) llListenRemove(gHelloL);
    if (gZeroL) llListenRemove(gZeroL);
    gHelloL = llListen(HELLO_CH, "", NULL_KEY, "");
    gChL = 0;
    if (gCh != HELLO_CH) gChL = llListen(gCh, "", NULL_KEY, "");
    gZeroL = llListen(0, "", gOwner, "");
}

Init() {
    gOwner = llGetOwner();
    gHelm = IsHelmHere();
    gFx = llGetInventoryType("wolf_crash_fx") == INVENTORY_SCRIPT;
    gMenuCh = -1 - (integer)llFrand(1.0e9);
    LoadSettings();
    Listens();
    gOn = FALSE;
    gState = "off";
    FindGunLinks();
    Pilot();
    if (llLinksetDataRead("wolfair_df") == "on" && Ready()) Dogfight(gOwner, TRUE, TRUE);
    Tick();
}

default {
    state_entry() { Init(); }
    on_rez(integer p) { llResetScript(); }

    changed(integer c) {
        if (c & CHANGED_OWNER) { llLinksetDataWrite("wolfair_df", "off"); llLinksetDataDelete("wolfair_home"); llLinksetDataDelete("wolfair_home_region"); llResetScript(); }
        if (c & CHANGED_LINK) Pilot();
        if (c & CHANGED_INVENTORY) { gHelm = IsHelmHere(); gFx = llGetInventoryType("wolf_crash_fx") == INVENTORY_SCRIPT; gPartsShown = -1; gFxSent = ""; }
        if (c & CHANGED_REGION) Crossed();      // [1.2.0]
        if (c & CHANGED_REGION_START) {     // a region restart ends every dogfight (DESIGN s3.10): she rejoins
            gState = "off"; gSeq = -1; gEvSeq = -1; gEng = "";
            if (llLinksetDataRead("wolfair_df") == "on" && Ready()) Dogfight(gOwner, TRUE, TRUE);
        }
    }

    touch_start(integer n) {
        key a = llDetectedKey(0);
        if (a != gOwner) { Tell(a, Status()); return; }
        if (!Ready()) SetupStart();
        else Menu("main", Status(), ["Dogfight on", "Dogfight off", "Set up again", "Home here", "Close"]);
    }

    run_time_permissions(integer p) { if (p & PERMISSION_TAKE_CONTROLS) Grab(); }

    control(key id, integer level, integer edge) {
        if (id != gPilot) return;
        integer c = CONTROL_ML_LBUTTON;
        if (gFireKey == "shift") c = CONTROL_LEFT | CONTROL_RIGHT;
        if (gFireKey == "chat") return;
        Trigger((level & c) != 0 && CanFire());
    }

    listen(integer ch, string name, key id, string m) {
        if (ch == gMenuCh) {
            if (gStep == "main") {
                gStep = "";
                if (m == "Dogfight on") Dogfight(id, TRUE, FALSE);
                else if (m == "Dogfight off") Dogfight(id, FALSE, FALSE);
                else if (m == "Set up again") SetupStart();
                else if (m == "Home here") { SetHome(); Tell(id, "She respawns here now."); }
                return;
            }
            SetupAnswer(m);
            return;
        }
        if (llGetAgentSize(id) == ZERO_VECTOR) return;           // people only
        Order(id, m);
    }

    link_message(integer from, integer num, string s, key k) {
        if (num != 7300) return;
        list p = llParseString2List(s, ["|"], []);
        string w = llList2String(p, 0);
        if (w == "fire") Trigger((integer)llList2String(p, 1) && CanFire());
        else if (w == "bail") Bail();
        else if (w == "crash") {
            string surface = llList2String(p, 2);
            if (surface != "water" && surface != "land") surface = SurfaceHere();      // an older helm says only the speed
            Crashed((float)llList2String(p, 1), surface);
        }
    }

    object_rez(key id) {
        if (llKey2Name(id) == "Wolf Parachute") BailWith((string)id);
    }

    dataserver(key q, string data) {
        if (q == gWatchQ) {
            gWatchQ = NULL_KEY;
            if (llGetSubString(data, 0, 5) == "error:") { gWatchRetry = llGetTime() + 5.0; return; }
            Absorb(data);
            Watch();
            return;
        }
    }

    timer() {
        float now = llGetTime();
        if (gFalling) FallStep();
        if (gAxis == "auto" && gClass == "" && gPilot != NULL_KEY) Learn();
        if (CanFire() && (gTrigger || now < gTriggerUntil)) Burst();
        else Tracers(FALSE);
        // the watch: lost, refused or stale (an idle watch is answered within 240 s, AirRules.WATCH_HEARTBEAT_S)
        if ((gOn || gState != "off") && gWatchQ == NULL_KEY && now >= gWatchRetry) Watch();
        if (gWatchQ != NULL_KEY && now - gWatchAt > 300.0) Watch();
        Carry();
        Tick();
    }
}
A scoreboard: the grid's top aces and this region's latest kills as floating text (wolf_air_scoreboard.lsl, 65 lines: show or hide)

Download wolf_air_scoreboard.lsl

// Wolf Air scoreboard - the grid's top aces as floating text, and this region's latest kills (wolf-air, 2026-11-01).
// Put it in any prim on a region with the wolf-air plugin. Touch it to refresh the aces.
// air.leaderboard answers "board|n" then one "rank|name|kills|deaths" line an ace (AirEngine.cs BoardText).
// air.feed answers "<seq>" then one "seq|unix|killer|killer plane|victim|victim plane|how" line a kill (AirEngine.cs FeedData).
key     gBoardQ = NULL_KEY;
key     gFeedQ = NULL_KEY;
integer gFeedSeq = -1;
string  gAces = "Asking for the aces...";
list    gKills;              // the last 5 kills seen here

Show() {
    string t = "WOLF AIR - TOP ACES\n" + gAces;
    if (gKills != []) t += "\n\nLATEST HERE\n" + llDumpList2String(gKills, "\n");
    llSetText(t, <1.0, 0.85, 0.4>, 1.0);
}

AskBoard() {
    gBoardQ = wolfCallAsync("air.leaderboard", [5]);
    if (gBoardQ == NULL_KEY) { gAces = "No dogfights here: " + wolfGetLastError(); Show(); }
}

AskFeed() {
    gFeedQ = wolfCallAsync("air.feed", [gFeedSeq]);     // answered when someone is shot down here
}

default {
    state_entry() { AskBoard(); AskFeed(); llSetTimerEvent(600.0); Show(); }
    on_rez(integer p) { llResetScript(); }
    touch_start(integer n) { AskBoard(); }
    timer() { AskBoard(); if (gFeedQ == NULL_KEY) AskFeed(); }
    dataserver(key q, string data) {
        if (q == gBoardQ) {
            gBoardQ = NULL_KEY;
            if (llGetSubString(data, 0, 5) == "error:") { gAces = llGetSubString(data, 6, -1); Show(); return; }
            list lines = llParseString2List(data, ["\n"], []);
            gAces = "";
            integer i;
            for (i = 1; i < llGetListLength(lines); ++i) {
                list f = llParseStringKeepNulls(llList2String(lines, i), ["|"], []);
                gAces += llList2String(f, 0) + ". " + llList2String(f, 1) + " - " + llList2String(f, 2) + " kills\n";
            }
            if (gAces == "") gAces = "Nobody has shot anyone down yet.";
            Show();
        }
        else if (q == gFeedQ) {
            gFeedQ = NULL_KEY;
            if (llGetSubString(data, 0, 5) == "error:") return;
            list lines = llParseString2List(data, ["\n"], []);
            integer i;
            for (i = 1; i < llGetListLength(lines); ++i) {
                list f = llParseStringKeepNulls(llList2String(lines, i), ["|"], []);
                if ((integer)llList2String(f, 0) > gFeedSeq || gFeedSeq == -1) {
                    string who = llList2String(f, 2);
                    if (who == "") who = "(nobody)";
                    gKills += [who + " downed " + llList2String(f, 4) + " (" + llList2String(f, 6) + ")"];
                }
            }
            if (llGetListLength(gKills) > 5) gKills = llList2List(gKills, -5, -1);
            gFeedSeq = (integer)llList2String(lines, 0);
            Show();
            AskFeed();
        }
    }
}
A bombing range board: today's best runs on this region's range as floating text (touch it for the full list) (wolf_air_range_board.lsl, 73 lines: show or hide)

Download wolf_air_range_board.lsl

// Wolf Air range board 1.0.0 - today's best bombing runs on this region's range, as floating text (wolf-air 1.7.0), 2026-11-02.
// Copyright (C) 2026 IntelligentWolf Ltd.
//
// Put it in the score board prim of a bombing range (k-bombing-range/) or in any prim on a region with the wolf-air plugin.
// Contract: a-research/DESIGN_BOMBERS.md s3.3: air.range ["scores"] -> ["scores", "<target>|<aircraft>|<aimer>|<points>|<best m>|<unix>", ...]
// (at most 20, the best of the day). Touch it: the board is asked again and you are told all of them in chat.
// It asks every 60 s, and only while an avatar is within 30 m (one sensor sweep a minute: nothing runs for an empty range).
// Floating text holds at most 254 bytes (SceneObjectPart.cs:4106 SetText: new osUTF8(text, 254)), so the board shows the top
// runs that fit and the touch gives the full list.

float   EVERY = 60.0;             // s3.3: the board script calls it every 60 s while someone is near
float   NEAR_M = 30.0;            // s3.3 / the brief: only while an avatar is within 30 m
integer TEXT_MAX = 254;           // SceneObjectPart.cs:4106
vector  COLOUR = <1.0, 0.85, 0.4>;
list    gRows;                    // the answer's lines

string Clock(integer unix) {
    integer s = unix % 86400;
    string h = (string)(s / 3600); if (llStringLength(h) < 2) h = "0" + h;
    string m = (string)((s % 3600) / 60); if (llStringLength(m) < 2) m = "0" + m;
    return h + ":" + m;
}

string Row(integer i) {
    list f = llParseStringKeepNulls(llList2String(gRows, i), ["|"], []);
    return (string)(i + 1) + ". " + llList2String(f, 2) + " (" + llList2String(f, 1) + ") on " + llList2String(f, 0) + " - "
        + llList2String(f, 3) + " points, best " + llList2String(f, 4) + " m, " + Clock((integer)llList2String(f, 5)) + " UTC";
}

string Short(integer i) {
    list f = llParseStringKeepNulls(llList2String(gRows, i), ["|"], []);
    return (string)(i + 1) + ". " + llList2String(f, 2) + " " + llList2String(f, 3) + " pts (" + llList2String(f, 4) + " m)";
}

Ask() {
    list r = wolfCall("air.range", ["scores"]);
    if (r == []) {
        string e = wolfGetLastError();
        if (llSubStringIndex(e, "no plugin function") != -1) e = "this region has no Wolf Air plugin (wolf-air)";
        llSetText("BOMBING RANGE\n" + llGetSubString(e, 0, 200), COLOUR, 1.0);
        gRows = [];
        return;
    }
    gRows = llList2List(r, 1, -1);
    string t = "BOMBING RANGE - TODAY'S BEST";
    if (gRows == []) t += "\nNo bombs on the range yet today.";
    integer i;
    for (i = 0; i < llGetListLength(gRows); ++i) {
        string add = "\n" + Short(i);
        if (llStringLength(t + add) > TEXT_MAX) i = 99;     // UTF-8 names are rare; the server cuts at 254 bytes anyway
        else t += add;
    }
    llSetText(t, COLOUR, 1.0);
}

default {
    state_entry() { llSetText("BOMBING RANGE\nTouch for today's best runs.", COLOUR, 1.0); llSetTimerEvent(EVERY); }
    on_rez(integer p) { llResetScript(); }

    touch_start(integer n) {
        key a = llDetectedKey(0);
        Ask();
        if (gRows == []) { llRegionSayTo(a, 0, "No bombing runs scored here today yet."); return; }
        integer i;
        llRegionSayTo(a, 0, "Today's best bombing runs on " + llGetRegionName() + ":");
        for (i = 0; i < llGetListLength(gRows); ++i) llRegionSayTo(a, 0, Row(i));
    }

    timer() { llSensor("", NULL_KEY, AGENT, NEAR_M, PI); }
    sensor(integer n) { Ask(); }
    no_sensor() { }
}

Trains (wolf-rail)

Run your own train on any line of guide prims you are allowed to lay. The region drives it: the engine runs along the guides, and every carriage is kept in its place behind it, on the line the engine actually ran. A carriage does not follow the one in front of it, so a region border, a slow crossing or a busy region can no longer leave it behind. Riders cross borders the same way they do in any vehicle. Only your own objects can be in your train, and only when the script in them is yours.

To make a train: lay the guides (objects named exactly Guide, about 10 metres apart, each one's red arrow along the line; describe the station ones Station). A train follows only guides that are yours, or the land's - laid by the owner of the parcel they stand on, or by the region's estate owner or an estate manager - so nobody else can turn your train off its line. Put the Wolf Rail engine script in your engine and the Wolf Rail carriage script in each carriage, with the same train name. Stand the engine on the guides, rez the carriages behind it, and touch the engine. Engines and carriages must be ordinary (not physical, not worn) objects.

wolf-rail: the names, what to give, what comes back, who may use them
NameGive itYou get backWho mayWhat it does
train.start[train name, metres a second] and any of "front", "back", "bogie", "ride" (metres), "announce", TRUE, "cab" ("front", "rear", "both" or "none"), "faces" ("front" or "rear") and "turnback", TRUE["ok", "started"] or ["ok", "running"]a script in the engineMakes this object the engine of your train and sets it off along the guide prims (objects named exactly "Guide"; their red arrow, +X, points along the line). A guide whose description has "station" in it is a station: the train stops for 30 seconds, and waits on while anyone is standing beside it (at most 3 minutes). A guide described "stop" ends its run. Speed up to 30 m/s. The sizes are measured from the engine itself if you leave them out; "announce", TRUE makes it say the station lines. Called again in a running engine it changes the speed and carries on. (wolf-rail 1.3) "cab" says where its cab is - at its own front (+X) end, its rear, both (the default) or none. "turnback", TRUE is for a train with a cab at each end: with nobody driving it, at the stop guide of a platform (a guide described "platform name" further back on the same line) it waits as at a station, changes ends and goes back out the way it came.
train.attach[train name, gap in metres] and any of "order" (1-32), "front", "back", "bogie", "ride", "cab", "faces", "power", TRUE and "unit", TRUE["ok", place in the train] (wolfCallAsync: "ok|place")a script in the vehicleThis object joins your train: it is kept "gap" metres (0-10) behind the vehicle in front of it, on the very line the engine ran - in whatever region it is, so it never loses the train at a border. Vehicles line up in the order they join, or by "order". When the engine is in another region use wolfCallAsync. A vehicle that joins a standing train is put straight onto its place. (wolf-rail 1.3) Rez it the way it should look: one rezzed turned round (its red arrow towards the back of the train) runs facing backwards, and "faces", "front" or "rear" says so outright. "cab" gives a cab car its cab ("front" is its own +X end); "power", TRUE for a car that drives the train; "unit", TRUE for a car coupled for good to the one in front (a tender, a car of a multiple unit).
train.detach[]["ok", "detached"] or, in the engine, ["ok", "ended"]a script in the vehicle or engineA vehicle leaves its train and stands where it is. In the engine it ends the train: every vehicle stands where it is.
train.speed[train name, metres a second]["ok"]a script of the owner, in the engine's regionChanges the speed (0 to 30); 0 brakes the train to a stand and it stays stopped until a new speed is given.
train.hold[train name, seconds]["ok"]a script of the owner, in the engine's regionHolds the whole train (it brakes to a stand) for up to 600 seconds, wherever its vehicles are; 0 lets it go at once.
train.info[train name][state, speed now, line speed, region of the engine, vehicles, engine key, why] (wolfCallAsync: the same joined with "|")a script of the ownerState is "running", "held" (a station, a hold, a border crossing) or "stopped". From another region than the engine's use wolfCallAsync. (wolf-rail 1.3.4) For a terminus's service, why also says what the terminus is doing with it: routed into a platform, held at its signal and why, changing ends.
train.where[train name][state, region of the engine, its place in that region (vector), its place in grid metres (vector), heading in degrees, speed m/s, odometer m, seconds old] (wolfCallAsync: the same joined with "|")a script of the ownerWhere your train is now - its engine's root prim. Heading is a compass bearing: 0 = north, 90 = east (-1 when it cannot be told). Speed is 0 unless the state is "running". The odometer is the metres the train has run since it started; "seconds old" is how long ago its region last told the grid (0 when the engine is in your region; elsewhere the place is worked on along the line from its speed, as the carriages do). Its place in its region is ZERO_VECTOR when the grid cannot say it just now (the train has just run on over the region's edge, say); the place in grid metres is always given. Just as the engine crosses a border the call is refused: ask again in a few seconds. From another region than the engine's use wolfCallAsync. Only your own trains: for anyone else's you are told there is no such train.
train.driver[train name, avatar key] (NULL_KEY gives the cab back), or (wolf-rail 1.3.2) [train name, avatar key, "shunt"]["ok"]a script in the engine, or (wolf-rail 1.3) in a cab car of the trainLets that avatar drive your train. They must be sitting on that object (its cab seat); FORWARD then means towards the front of that cab, whichever end of the train it is at. With WolfViewer or WolfStorm the Train Cab opens for them: power, brake, forward / neutral / reverse, Easy driving (one lever: the train keeps a share of its line speed and stops at stations by itself) and the horn - the engine's own sound called "horn", else "whistle". The region reads their controls itself. It never lets the train run faster than the speed train.start set, and always brakes in time for the end of the line and for a guide described "stop". A driven train crosses region borders with its driver: the next region takes the cab over. If the region ahead cannot take a driven train, the train stops before the border and the driver keeps the cab. When the driver stands up or leaves, the train stops. A viewer without the Train Cab is told after a few seconds to touch the engine for its menu instead, and the train stands. After a stop guide the power must be let go once before the train sets off again. NULL_KEY gives the cab back: the train runs itself again as train.start set it. train.start and train.speed also take the cab back. AUTO in the cab makes the train drive itself - its line speed, the stations, the signals and points as set - until the driver takes a lever or presses AUTO again; a driver who stands up in Auto leaves it running by itself as a timetable train (stations, signals and all) until someone drives it or you stop it (train.speed 0, train.control or train.detach). With the train standing, the reverser at reverse and some power back it along its line, the protection still on: it stops before the end of the line behind and short of another train, and backs into the next region only when that region can take it. Easy driving has FORWARD and BACK: BACK backs it slowly, for leaving a platform. One press of POINTS in the cab changes the next points drivers may change (described "points name driver"), within 200 m, and the cab says how they are set now. Trains keep their line speed over region borders: each region shares its track near its edges, so the train sees the line ahead in the next region (it slows only for what it cannot know from there - a signal, or the shorter line at points - and as before where a region has not shared its track yet). With "shunt" the driver may also couple and uncouple the train (COUPLE and UNCOUPLE in the cab); without it they may not - so a resident driving your train never couples or uncouples your stock unless you let them.
train.control[train name, power 0-1, brake 0-1, reverser -1, 0 or 1] or [train name, "auto"]["ok"]a script of the owner, in the engine's regionDrives your train from a script - a touch menu, a timetable of your own. Power pulls, the brake slows it, both up to the train's own rates. Nothing faster than its line speed, and the end of the line is always protected. Reverser -1 with power backs the train once it is standing. The values hold until the next train.control, train.driver, train.speed or train.start. Refused while someone is driving - except "auto": with a driver in the cab it switches on Auto (the train drives itself until they take a lever; refused while the train is still backing); with nobody driving the train runs itself again.
train.cab[train name][driver key, mode, speed m/s, line speed, power, brake, reverser, next stop ("station", "stop" or ""), metres to it (-1: none), metres of line ahead, protecting (1: braking for the line), and (wolf-rail 1.3) lead (1: the cab is at the leading end, 0: it propels), ends (1: it can change ends now), couple side ("ahead", "behind" or "": your own standing stock on the line it goes along) and metres to it (-1: none), vehicles, and (wolf-rail 1.3.7) the name of the turntable whose deck-edge stop the engine stands at ("" if none), and 1 if only one car of the train has a cab (it has no Change ends)]a script of the owner, in the engine's regionWhat the cab shows, for your own displays. Mode is "driver" or "easy" (someone drives), "auto" (it drives itself with the driver aboard), "script" (train.control) or "timetable" (it runs itself - also once its driver has left it in Auto: power 0, brake 0 and reverser 1 are shown then). While the train backs, the metres of line are the line behind it.
train.points[points name] or [points name, "left", "right", "toggle" or "auto"][setting]anyone reads; the owner of the points guide sets them (the estate owner or a manager for the land's points)Points are a guide described "points name" (add "driver" to let drivers change them from the cab). Left or right picks the branch to that side; "auto" is the nearest guide on, as always. Points are their guide's owner's: your own guide with the same name as someone else's is your own points. They do not change while a train is on them or coming onto them. Kept when the region restarts. (wolf-rail 1.3.1) For points at real track centres, describe the first guide of each branch "branch name left" and "branch name right" (both branches, the points' own name): left or right then takes the guide marked for that side, "auto" the straighter of the two, and the points change with a train on the road beside them - only a train on or coming onto either branch holds them. Where two one-way lines join, "points name" on the join guide picks the line a train backing over the join takes. (wolf-rail 1.3.4) Points a terminus route has set are locked: nobody changes them - not a script, not the cab's POINTS - until the route is released. (wolf-rail 1.3.5) Points a terminus junction service sets train by train are refused the same way, with an answer that says so, until that terminus is paused or deleted; reading them is never refused.
train.signal[signal name] or [signal name, "green" or "auto"][aspect: "red", "yellow" or "green"]anyone reads; the owner of the signal guide sets it (the estate owner or a manager for the land's signals)A signal is a guide described "signal name": every train stops short of it while another train is on the line to the next signal (red); yellow means the next signal is red. A train in the block holds the signal red for as long as it is there, moving or stopped. "green" clears it whatever is on the line - the way past a train left standing, or out when two trains wait for each other - and "auto" puts it back. A block ends at the region's edge. (wolf-rail 1.3.4) At a terminus (train.terminus) its own signals stay red until it has set a route for the train waiting there, and while a route is set every other signal whose line runs onto it is red for every other train; "green" does not clear those - use train.route.
train.turn[train name]["ok", key of the new engine] (wolf-rail 1.2.1)a script of the owner, in the engine's regionFor a train with a cab at each end at a dead-end platform: the train is turned round to leave from its other end. The last vehicle becomes the engine, the old engine becomes the last vehicle and the others are in the opposite order, with the same spaces between them. Every vehicle is turned to face the new way (so a cab car or engine that looks different at each end should change its own looks: its script can ask train.info, whose engine key says which vehicle leads now). The train stays stopped, keeping its line speed: train.speed sets it off. Guides only lead one way, so lay a line of guides facing the way out over the platform road. Refused while the train moves, while someone drives it or sits on it, or while any of its vehicles is in another region.
train.ends[train name]["ok", key of the new head, key of the cab now in use] (wolf-rail 1.3)a script of the owner, in the engine's regionChanges ends at a dead-end platform: the other end of the train becomes its head and it will run back out the way it came. Nothing moves and nothing turns round - every car looks just as it did, so a cab car at the far end leads now. Passengers stay in their seats. Someone driving walks to the cab at the other end and sits in it to drive on (they have 2 minutes; the touch menu of wolf_train_cab.lsl does this). With someone driving, the call counts as their own press of Change ends. Refused while the train moves, while a script drives it (train.speed 0 first), while any of it is in another region, or where no guides lead the other way. A train with a car facing backwards crosses only into regions that run wolf-rail 1.3 or later; before others it waits at the border. train.turn is still there for trains that look the same at both ends.
train.go[train name, "forward" or "back", metres a second, a place's name or ""]["ok"] (wolf-rail 1.3.1)a script of the owner, in the engine's regionA shunting move: the train runs that way at that speed (at most its line speed; backwards at most 4.5 m/s), calls at no station, stops at red signals and 2 m short of another train, and ends at the stop guide of the place (a guide described "platform name", "siding name", "shed name" or "turntable name", the place's road running on to its "stop"), at a stop guide it meets first, or at the end of the line. Backwards it follows the guides laid the way it backs, with their points as set; where a road has guides one way only it backs along them to the end of the line. It never crosses into another region: it stops before the border. train.speed, train.start or a driver taking the train ends the move.
train.couple[train name, "forward" or "back"]with wolfCallAsync: "ok|train name" or "error: why" (wolf-rail 1.3.2)a script of the owner, in the engine's regionCouples the standing train to your own standing stock on the line ahead (or behind), within 200 m: it runs up to it, slowing to 1 m/s for the last 20 m and 0.6 m/s at the end, stops at the gap and the two become one train under this name. It stops at red signals on the way, except one that is red only because of that stock. Refused when the nearest stock on the line is someone else's (another resident's stock is never coupled to), when that stock moves or is being driven, when either train is partly in another region, when it would pass 32 vehicles, or when a stop guide comes first. With someone driving, the call counts as their press of COUPLE: only with train.driver's "shunt". The answer comes within 2 minutes.
train.uncouple[train name, units from the cab end (1-32) or a vehicle's key, new train name]["ok", new name] (wolf-rail 1.3.2; with wolfCallAsync "ok|name" once the grid has taken it)a script of the owner, in the engine's regionSplits the standing train behind that many units, counted from the end with the cab in use (an engine and its tender, or cars joined with "unit", are never split), or behind the unit of the vehicle you name. The part with the cab keeps the name and its driver; the other part is a new train of yours under the new name. A part with nothing that has power is a rake: it never moves by itself (train.speed, train.go, train.start and train.control refuse it) until an engine couples to it, and like any standing train it holds its signal at danger and other trains stop 2 m short of it. Refused while it moves, while any of it is in another region, or when the region has no room for one more train. If the grid does not take it, the train stays as it was and train.info says why.
train.turntable[train name, turntable name, road number or "opposite"]; the estate: [turntable name, "deck", the deck's key or NULL_KEY]with wolfCallAsync: "ok" or "error: why" (wolf-rail 1.3.3); the estate's form ["ok", deck key]a script of the owner, in the engine's region; the deck is named by the estate owner or an estate manager, or (wolf-rail 1.3.7) by the owner of the land it stands onTurns an engine on a turntable. The engine (with its tender, attached with "unit") stands at the edge of the turntable on one of its roads - at the stop guide where that road meets the deck - with nobody driving it. It is drawn slowly onto the deck until its middle is over the centre, turned with the deck at 6 degrees a second so that its front faces the road you name, then drawn off until its front bogie is on that road's first guide. It then stands: train.go or train.speed takes it along the road. Roads are numbered clockwise from north, 1 being the first; "opposite" turns it half round, so it goes back out the way it came, facing the other way. Passengers stay in their seats and go round with it. The whole train must be no longer than the deck less 1 metre and wholly in this region. Refused while it moves, while another train is on the deck or stands over its edge, or on the road it is to leave by. With someone driving, the call counts as their own press of TURNTABLE in the cab (wolf-rail 1.3.7): they stay in their seat and go round with it, and drive it off when it has turned. While the turntable is in use, signals on the lines that lead onto it show red to every other train. The track is the estate's: a guide described "turntable name" at the deck's centre, roads whose first guide (pointing out from the centre) lies within the deck's radius and 2 metres of it, each road ending in a "stop" at the deck's edge on the way in; the deck is one object of the estate's, its root at the centre and its rails along its own X, named once with [turntable name, "deck", its key]. (wolf-rail 1.3.7) On your own land you may name your own deck too: the deck must be yours, and its whole circle, its centre guide and the first guide of every road must lie on parcels you own (a parcel deeded to a group does not count). A turntable named by someone else is theirs to change; the estate owner or a manager may name or clear any. The deck's circle ends the line for every train: no train runs onto the deck except when the turntable itself draws it on and off. If the region restarts part way, the engine is turned on to its road when the region is back. A turn that cannot be finished within 5 minutes is given up and the engine stands where it is.
train.terminus[name, "config", part 1-16, the JSON text], [name, "commit"], [name, "status"], [name, "pause"], [name, "resume"] or [name, "delete"]["ok", parts so far]; commit ["ok", routes found, platforms]; status [text] (wolf-rail 1.3.4)the estate owner or an estate manager; status: anyoneMakes a terminus of the region's land-laid track: the station works its own throat. Send the configuration as JSON, in parts if it is long (at most 60,000 characters in all), then commit: {"entries": the signals arriving trains wait at, "starters": the signals at the platforms' far ends trains leave by, "platforms": their names, "services": the trains it looks after, "route_timeout_s": 30-600 (120 if left out)}. Each platform is a guide described "platform name" - the first guide inside the platform on the arriving lay - and runs on to the next "stop"; a through platform with no stop is not one. Each service is {"owner": the owner's key, "train": its name, "kind": "turnback", "platforms": the ones it may use, first choice first, "dwell_s": 10-600, "out": "west", "east", "south" or "north"}. On commit it finds every route from each entry to each platform and from each starter out to the region's edge, and which routes cannot be set together. Then, for a service that comes up to an entry, it picks the first free platform long enough for it, sets the points and locks them, and clears the signal for that train alone; any other train waits at the red signal. Once the train is in the platform the route is freed. A double-ended set changes ends there after its dwell, and when it comes up to the starter the terminus sets the route out. With a driver aboard (Auto too) the train stops and the driver is asked to change ends - it never does so by itself. A route not used within its time-out is freed. Its routes are kept when the region restarts. Pause stops it setting routes (they can still be set by hand); a configuration is committed or deleted only while no route is set. Every route stays inside this region: lines over a border are not interlocked by it. (wolf-rail 1.3.5) A service may instead be a junction: {"owner", "train", "kind": "junction", "points": the land's points by name, "set": "left" or "right"} - as that train stands at a station whose next points are those, the terminus sets them for it, reads them back and holds the train there until they are right (never while another train is on them, coming onto them or running up to them, nor while a route has locked them). The first train to stand is served first. A configuration of junction services alone needs no entries or platforms. While it is not paused those points are set only by it.
train.route[terminus], [terminus, route] or [terminus, "cancel", route][each route and its state] or ["ok"] (wolf-rail 1.3.4)anyone lists; the estate owner or an estate manager sets and cancelsThe terminus's routes, named "signal>platform" or "signal>west" and so on, with what each is doing. Setting one by hand sets its points and locks them as the terminus does; the first train that comes up to its signal takes it, and it is freed after the time-out if none does. A route is set only when no route it cannot share track with is set, no other train is on it or on its way onto it, and its points are free to move. Cancel frees a route, but not while its train is moving on it or too close to the signal to stop.
train.limits[] or ["engines", number] and / or ["vehicles", number], or ["default"][engines allowed, vehicles allowed, engines here now, vehicles here now, highest engines, highest vehicles] (wolf-rail 1.2.1)anyone reads; only the estate owner or an estate manager sets themHow many trains this region runs at once. Unless changed, 40 engines and 320 vehicles; at most 64 and 512. Kept when the region restarts. Lowering them stops nothing that is already running: no more trains start or come in until there is room (a train arriving at a full region waits at the border and comes in as soon as there is). There is no separate share for each resident.
train.version[]["wolf-rail", version, plugin API]anyoneWhich wolf-rail this region runs.

Sizes. "front" and "back" are the metres from the root prim to each end (buffer to buffer), "bogie" the metres from the root to each set of wheels the vehicle turns on, and "ride" how high the root stands above the guides. Left out, they are measured from the object: its ends, wheels at 35 % of its length either side, and its lowest point on the guides. "gap" is the space between two vehicles' ends (0 to 10 m). Each size is at most 50 m; "bogie" is at least 0.25 m.

Limits. 20 calls in ten seconds from one object and 60 from all of one resident's objects; up to 32 vehicles in a train, 200 trains a resident across the grid; in one region, as many engines and vehicles at once as its estate owner allows (train.limits: 40 engines and 320 vehicles unless they change it, at most 64 and 512). There is no separate share for each resident. When the engine crosses a border it stops for a moment, as every vehicle does, and the train closes up again just after.

Wolf Rail engine: put it in the engine, touch to start or stop the train (wolf_train_engine.lsl, 32 lines: show or hide)

Download wolf_train_engine.lsl

// Wolf Rail engine - put this in the ROOT prim of your engine. Touch it (you, the owner) to start or stop the train.
// The region drives the train along the guide prims (objects named exactly "Guide", each one's red arrow, its +X,
// along the line; a guide whose description has "station" in it is a station stop; one described "stop" ends the run).
// Every carriage joins with the Wolf Rail carriage script and the same train name. They are placed behind the engine
// by the region, across region borders too, so they never lose the train.
// Uses the wolf-rail plugin through wolfCall("train.start", ...). Wolf Territories, 2026. Copy, change and share freely.

string  TRAIN    = "My train";   // the same name in every carriage; up to 64 letters, no |
float   SPEED    = 8.0;          // metres a second between stations (up to 30)
integer TURNBACK = FALSE;        // wolf-rail 1.3: TRUE for a train with a cab at both ends (a DMU, a high-speed set): at a
                                 // platform's stop guide it changes ends by itself and goes back out the way it came

default
{
    touch_start(integer n)
    {
        if (llDetectedKey(0) != llGetOwner()) return;
        // ["state", speed now, line speed, region, vehicles, engine, why]: is it running?
        list info = wolfCall("train.info", [TRAIN]);
        if (info != [] && llList2String(info, 0) != "stopped")
        {
            wolfCall("train.speed", [TRAIN, 0.0]);           // 0 brakes it to a stand
            llOwnerSay(TRAIN + " is stopping.");
            return;
        }
        // the sizes are taken from the engine itself; give them for a better fit, e.g. "bogie", 4.3, "ride", 2.3
        list r = wolfCall("train.start", [TRAIN, SPEED, "announce", TRUE, "turnback", TURNBACK]);
        if (r == []) llOwnerSay("Could not start " + TRAIN + ": " + wolfGetLastError());
        else llOwnerSay(TRAIN + " " + llList2String(r, 1) + ". Touch again to stop it.");
    }
}
Wolf Rail carriage: put it in each carriage; it joins the train of the same name (wolf_train_carriage.lsl, 39 lines: show or hide)

Download wolf_train_carriage.lsl

// Wolf Rail carriage - put this in the ROOT prim of each carriage (or tender, or wagon). It joins the train of the same
// name; the region then keeps it in its place behind the vehicle in front, on the line the engine ran, across region
// borders too. Rez the carriages behind the engine (stopped) in the order you want, or give each an "order".
// Uses the wolf-rail plugin through wolfCallAsync("train.attach", ...). Wolf Territories, 2026. Copy, change and share freely.

// Rez it the way it should look: one rezzed turned round (its red arrow, +X, towards the back of the train) is seen as
// facing backwards and runs that way by itself. A car that drives the train (a power car, a DMU car) has POWER TRUE; a
// tender or a car of a multiple unit, coupled for good to the one in front, has UNIT TRUE. Its cab, if it has one: CAB
// "front" (at its own +X end), "rear" (its -X end) or "both" - then use the Wolf Rail cab script (wolf_train_cab.lsl, HEAD
// FALSE) instead, so a driver can sit in it.

string  TRAIN = "My train";   // the engine's train name
float   GAP   = 0.5;          // metres of space between this carriage and the one in front (0 to 10)
integer POWER = FALSE;        // TRUE: it drives the train too (wolf-rail 1.3)
integer UNIT  = FALSE;        // TRUE: coupled for good to the vehicle in front (a tender, a multiple unit's car)
string  CAB   = "none";       // where its cab is: "none", "front", "rear" or "both"
string  FACES = "";           // "" = as it stands; "front" or "rear" to say which way its +X points

join()
{
    // the line that matters: [train, gap] and, if you like, "order", 2 / "bogie", 6.5 / "ride", 2.1 ...
    list opts = [TRAIN, GAP, "power", POWER, "unit", UNIT, "cab", CAB];
    if (FACES != "") opts += ["faces", FACES];
    if (wolfCallAsync("train.attach", opts) == NULL_KEY) llOwnerSay("Could not join " + TRAIN + ": " + wolfGetLastError());
}

default
{
    state_entry() { join(); }
    on_rez(integer p) { join(); }

    // "ok|<place in the train>" or "error: <why>"
    dataserver(key q, string data)
    {
        if (llGetSubString(data, 0, 5) == "error:") llOwnerSay(TRAIN + ": " + llGetSubString(data, 7, -1));
        else llOwnerSay("In " + TRAIN + " as vehicle " + llList2String(llParseString2List(data, ["|"], []), 1) + ".");
    }
}

Example: where is my train? (from any region)

key ask;

default
{
    touch_start(integer n)
    {
        ask = wolfCallAsync("train.where", ["My train"]);
        if (ask == NULL_KEY) llOwnerSay(wolfGetLastError());
    }

    dataserver(key q, string data)
    {
        if (q != ask) return;
        // running|Wolf Territories|<800.20000, 213.06000, 22.64000>|<1279776.20000, 1281237.06000, 22.64000>|0.000000|11.000000|6353.580000|0.400000  or  error: ...
        list a = llParseString2List(data, ["|"], []);
        llSay(0, "My train is in " + llList2String(a, 1) + " at " + llList2String(a, 2));
    }
}
Where is my train? Touch it and it says in chat where your train is, which way it is going and how fast (wolf_train_where.lsl, 48 lines: show or hide)

Download wolf_train_where.lsl

// Wolf Rail "where is my train?" - put this in any object of yours, in any region. Touch it and it says in local chat
// where your train's engine is: the region, the spot in that region, which way it is heading, its speed and whether it
// is running, standing at a station or stopped. It only knows about trains you own.
// Uses the wolf-rail plugin through wolfCallAsync("train.where", ...). Wolf Territories, 2026. Copy, change and share freely.

string TRAIN = "My train";   // your train's name, as in its engine script

key gAsk;

// compass degrees (0 = north, 90 = east) to one of 8 directions
string Compass(float deg)
{
    list names = ["north", "north-east", "east", "south-east", "south", "south-west", "west", "north-west"];
    return llList2String(names, ((integer)llRound(deg / 45.0)) % 8);
}

default
{
    touch_start(integer n)
    {
        gAsk = wolfCallAsync("train.where", [TRAIN]);
        if (gAsk == NULL_KEY) llSay(0, "Sorry, I cannot ask about " + TRAIN + " just now: " + wolfGetLastError());
    }

    // "state|region|<local position>|<world position>|heading|speed|odometer|age" or "error: <why>"
    // (local position is ZERO_VECTOR when the grid cannot say where in its region the train is just now)
    dataserver(key q, string data)
    {
        if (q != gAsk) return;
        if (llGetSubString(data, 0, 5) == "error:") { llSay(0, TRAIN + ": " + llGetSubString(data, 7, -1)); return; }
        list a = llParseString2List(data, ["|"], []);
        string what = llList2String(a, 0);
        vector here = (vector)llList2String(a, 2);
        float speed = (float)llList2String(a, 5);
        string doing = "is stopped";
        float heading = (float)llList2String(a, 4);   // -1 when not known
        if (what == "running")
        {
            doing = "is running at " + (string)llRound(speed * 3.6) + " km/h";
            if (heading >= 0.0) doing += ", heading " + Compass(heading);
        }
        else if (what == "held") doing = "is standing (a station stop or crossing into the next region)";
        string spot = "";
        if (here != ZERO_VECTOR) spot = " at " + (string)llRound(here.x) + ", " + (string)llRound(here.y);
        llSay(0, TRAIN + " " + doing + ", in " + llList2String(a, 1) + spot + ".");
    }
}

Driving. Sit in the cab of an engine whose script calls train.driver for you and the Train Cab opens at the bottom of the screen. Take your time: there are no countdowns, and the train looks after the end of the line itself. Easy driving is one lever - Stop, Slow, Go. AUTO lets the train drive itself, the cab shows the next signal and points, one press of POINTS changes points drivers may set, and Easy driving has a slow BACK for leaving a platform. With other viewers, touch the engine for its menu (train.control). At the end of a platform, touch the cab and choose Change ends, then walk to the cab at the other end and sit in it - you drive the train back out from there (wolf-rail 1.3). Backing, a train follows the guides laid the way it goes and stops at their signals and stop guides, and every train stops 2 m short of another train on its line (wolf-rail 1.3.1). With the owner's leave to shunt, COUPLE in the cab couples to the stock ahead (reverser forward) or behind (reverse), and UNCOUPLE leaves the rest of the train standing as a rake (wolf-rail 1.3.2). At an engine shed, train.turntable turns the engine on the turntable for you (wolf-rail 1.3.3). When a stop guide halts you where the line ends, the cab says so: press BACK (or set the reverser to reverse), or CHANGE ENDS, to drive out. Stopped where a road meets a turntable, TURNTABLE in the cab (or Turntable in the touch menu) turns the engine round with you aboard (wolf-rail 1.3.7). Changing ends doesn't turn the engine round - use a turntable for that. A train with only one cab, such as a shunter, has no Change ends: drive it back with the reverser. After a change of ends the cab says which way FORWARD now goes. At a terminus the station's own signals clear only once it has set the route into a free platform, or out from one, for your train (wolf-rail 1.3.4).

Drivable engine: sit in the cab to drive (the Train Cab), or touch it for Go / Coast / Stop / Auto / Turntable (wolf_train_cab.lsl, 216 lines: show or hide)

Download wolf_train_cab.lsl

// Wolf Rail drivable engine or cab car - put this in the ROOT prim of your engine (HEAD TRUE), or of a cab car at the other
// end of a double-ended train (HEAD FALSE: a DMU's second car, a high-speed set's rear power car), with the train's name.
// Sit in the cab (the root prim's seat) to drive: with WolfViewer or WolfStorm the Train Cab opens at the bottom of the
// screen (power, brake, forward / neutral / reverse, Easy driving, AUTO, POINTS, horn). The region reads the driver's
// controls itself and keeps the train from running past the end of its line. Stand up and the train stops - or, in
// AUTO (the train drives itself), runs on by itself as a timetable train until its owner stops it (Stop below).
// FORWARD always means "towards the front of the cab you sit in", whichever end of the train that is.
// At the end of a platform: touch the cab and choose "Change ends", then walk to the cab at the other end and sit in it -
// you drive on from there (nothing turns round: the train just goes back out the way it came).
// Changing ends doesn't turn the engine round - use a turntable for that. An engine with only one cab in its train (a
// shunter driven either way from its one cab) has no "Change ends": drive it back with the reverser (wolf-rail 1.3.7).
// Everyone may drive it when PUBLIC is TRUE; otherwise only you, the owner.
// Other viewers: touch the cab for Go / Coast / Stop / Auto / Change ends (train.control drives it from the script).
// Shunting (wolf-rail 1.3, stage 3): touch for "Couple ahead" / "Couple behind" (the train creeps onto the stock and
// couples) and "Uncouple" (the last unit behind the cab is left standing as a rake of its own, named "<TRAIN> rake").
// Only the owner, or someone the owner has given the "shunt" grant, may couple or uncouple (the region checks).
// Turntable (wolf-rail 1.3.7): stopped at the stop where a road meets a turntable's deck, touch for "Turntable" - the engine
// is drawn onto the deck, turned round and drawn off facing the other way. The driver stays in the seat and goes round too.
// Rez every car the way it should look. CAB is where this object's cab is in its OWN frame: "front" at its +X end (red
// arrow), "rear" at its -X end (a car built turned round with its root along the line), "both". A car rezzed turned round
// (nose out at the back) is seen as facing backwards by itself; give FACES "rear" or "front" only to say so outright.
// Uses the wolf-rail plugin through wolfCall("train.start" / "train.attach" / "train.driver" / "train.control" /
// "train.cab" / "train.ends" / "train.couple" / "train.uncouple" / "train.turntable", ...). Wolf Territories, 2026. Copy, change
// and share freely.

string  TRAIN    = "My train";  // the same name in every car; up to 64 letters, no |
integer HEAD     = TRUE;        // TRUE: this object starts the train (its engine); FALSE: a cab car joining it
float   SPEED    = 12.0;        // (HEAD) the fastest it may go, metres a second (up to 30)
integer TURNBACK = FALSE;       // (HEAD) TRUE: with nobody driving, it changes ends by itself at a platform's stop and goes back out
string  CAB      = "front";     // where this object's cab is: "front", "rear" or "both"
float   GAP      = 0.5;         // (cab car) metres of space to the car in front of it (0 to 10)
string  FACES    = "";          // (cab car) "" = as it stands; "front" or "rear" to say which way its +X points
integer UNIT     = FALSE;       // (cab car) TRUE: coupled for good to the car in front (a multiple unit's car)
integer PUBLIC   = FALSE;       // TRUE: anyone who sits in the cab may drive
integer MENU     = -7412;       // the touch menu's channel
key     gDriver;
key     gCoupleQ;               // train.couple's answer comes later (wolfCallAsync)
key     gCoupleBy;              // who asked for it
key     gTurnQ;                 // train.turntable's answer comes later too (wolfCallAsync)
key     gTurnBy;

// Who drives it from the Train Cab now (train.cab's first value; NULL_KEY: nobody), and is it moving? (the region lets a
// viewer without the cab go after a few seconds and tells them to use this touch menu)
list Cab() { return wolfCall("train.cab", [TRAIN]); }
key Driver(list cab) { if (cab == []) return NULL_KEY; return llList2Key(cab, 0); }

TakeCab(key who)
{
    if (!PUBLIC && who != llGetOwner())
    {
        llRegionSayTo(who, 0, "Only the owner drives this train.");
        llUnSit(who);
        return;
    }
    // from this object's own cab (the engine, or a cab car of the train: wolf-rail 1.3)
    if (wolfCall("train.driver", [TRAIN, who]) == []) llRegionSayTo(who, 0, "The cab is not ready: " + wolfGetLastError());
    else { gDriver = who; llRegionSayTo(who, 0, "You are driving " + TRAIN + ". Take your time."); }
}

Ready()
{
    llSitTarget(<0.0, 0.0, 1.0>, ZERO_ROTATION);    // the driver's seat (change it to fit your cab)
    gDriver = NULL_KEY;
    if (!HEAD)
    {
        // a cab car joins the train (its engine may be in another region: the answer comes by dataserver)
        list opts = [TRAIN, GAP, "cab", CAB, "power", TRUE, "unit", UNIT];
        if (FACES != "") opts += ["faces", FACES];
        if (wolfCallAsync("train.attach", opts) == NULL_KEY) llOwnerSay("Could not join " + TRAIN + ": " + wolfGetLastError());
        return;
    }
    // the train must be on the line before anyone can drive it: start it, then hold it on the brake
    // (train.start also takes the cab back from anyone driving, so a driver still seated is given it again below)
    if (wolfCall("train.start", [TRAIN, SPEED, "cab", CAB, "turnback", TURNBACK]) == []) { llOwnerSay("Could not start " + TRAIN + ": " + wolfGetLastError()); return; }
    wolfCall("train.control", [TRAIN, 0.0, 1.0, 1]);
    key who = llAvatarOnSitTarget();
    if (who != NULL_KEY) TakeCab(who);
}

ChangeEnds(key id)
{
    list cab = Cab();
    if (cab != [] && llList2Float(cab, 2) > 0.05) { llRegionSayTo(id, 0, "Stop the train first, then change ends."); return; }
    // nobody in the Train Cab: this menu's own controls are given back first (train.speed 0: it stays standing)
    if (Driver(cab) == NULL_KEY) wolfCall("train.speed", [TRAIN, 0.0]);
    // ["ok", the new head's key, the cab now in use]
    list r = wolfCall("train.ends", [TRAIN]);
    if (r == []) llRegionSayTo(id, 0, "Cannot change ends: " + wolfGetLastError());
    else if (llList2Key(r, 2) == llGetKey()) llRegionSayTo(id, 0, "Changed ends: this cab now leads.");
    else llRegionSayTo(id, 0, "Changed ends: walk to the cab at the other end and sit in it to drive on.");
}

// Source: wolf-rail src/RailRules.cs train.couple [train, "forward" | "back"] (async) and train.uncouple [train, units
// from the cab end in use 1-32 or a vehicle's key, the new train's name] (README 1.3.2).
Couple(key id, string way)
{
    gCoupleBy = id;
    gCoupleQ = wolfCallAsync("train.couple", [TRAIN, way]);
    if (gCoupleQ == NULL_KEY) llRegionSayTo(id, 0, "Cannot couple: " + wolfGetLastError());
    else llRegionSayTo(id, 0, "Coupling " + way + ": the train creeps up to the stock. Wait for it.");
}

Uncouple(key id)
{
    string rake = llGetSubString(TRAIN + " rake", 0, 63);
    if (wolfCall("train.uncouple", [TRAIN, 1, rake]) == []) llRegionSayTo(id, 0, "Cannot uncouple: " + wolfGetLastError());
    else llRegionSayTo(id, 0, "Uncoupled: the last unit stands as \"" + rake + "\".");
}

// Source: wolf-rail src/Turntable.cs train.turntable [train, turntable name, road 1-32 or "opposite"] (async: "ok" or
// "error: why"); train.cab's 17th value (index 16, wolf-rail 1.3.7) is the turntable whose deck-edge stop the engine stands
// at, "" for none (an older region sends no 17th value: "" too). With a driver aboard the call counts as their own press.
Turntable(key id)
{
    list cab = Cab();
    if (cab == []) { llRegionSayTo(id, 0, "Cannot turn: " + wolfGetLastError()); return; }
    if (llList2Float(cab, 2) > 0.05) { llRegionSayTo(id, 0, "Stop the train first, then turn it."); return; }
    string tt = llList2String(cab, 16);
    if (tt == "") { llRegionSayTo(id, 0, "Drive up to the stop where the road meets a turntable first, then choose Turntable."); return; }
    // nobody in the Train Cab: this menu's own controls are given back first (train.speed 0: it stays standing)
    if (Driver(cab) == NULL_KEY) wolfCall("train.speed", [TRAIN, 0.0]);
    gTurnBy = id;
    gTurnQ = wolfCallAsync("train.turntable", [TRAIN, tt, "opposite"]);
    if (gTurnQ == NULL_KEY) llRegionSayTo(id, 0, "Cannot turn: " + wolfGetLastError());
    else llRegionSayTo(id, 0, "Turning " + TRAIN + " round on the turntable " + tt + ". Stay in your seat: you go round with it.");
}

default
{
    state_entry() { Ready(); llListen(MENU, "", NULL_KEY, ""); }
    on_rez(integer p) { llResetScript(); }

    changed(integer c)
    {
        if (c & CHANGED_REGION_START) Ready();
        if (!(c & CHANGED_LINK)) return;
        key who = llAvatarOnSitTarget();
        if (who != NULL_KEY && who != gDriver) TakeCab(who);
        else if (who == NULL_KEY && gDriver != NULL_KEY)
            gDriver = NULL_KEY;   // the region has already let the cab go: the train stops (in Auto: it runs on by itself)
    }

    // (cab car) "ok|<place in the train>" or "error: <why>"
    dataserver(key q, string data)
    {
        if (q == gCoupleQ)
        {
            gCoupleQ = NULL_KEY;
            if (llGetSubString(data, 0, 5) == "error:") llRegionSayTo(gCoupleBy, 0, "Cannot couple: " + llGetSubString(data, 7, -1));
            else llRegionSayTo(gCoupleBy, 0, "Coupled.");
            return;
        }
        if (q == gTurnQ)
        {
            gTurnQ = NULL_KEY;
            if (llGetSubString(data, 0, 5) == "error:") llRegionSayTo(gTurnBy, 0, "Cannot turn: " + llGetSubString(data, 7, -1));
            else llRegionSayTo(gTurnBy, 0, "Turned: " + TRAIN + " now faces the other way. Take the power to drive off.");
            return;
        }
        if (llGetSubString(data, 0, 5) == "error:") llOwnerSay(TRAIN + ": " + llGetSubString(data, 7, -1));
    }

    touch_start(integer n)
    {
        key t = llDetectedKey(0);
        list cab = Cab();
        key drv = Driver(cab);
        // train.cab's 18th value (index 17, wolf-rail 1.3.7): 1 when only one object of the train has a cab - no "Change ends"
        list ends = ["Change ends"];
        if (llList2Integer(cab, 17) == 1) ends = [];
        if (drv != NULL_KEY)
        {
            // someone drives from the Train Cab: only they get the touch menu (the cab has the same buttons in WolfViewer and
            // WolfStorm: CHANGE ENDS, COUPLE, UNCOUPLE, TURNTABLE)
            if (t == drv) llDialog(t, "Drive " + TRAIN + " from here", ends + ["Couple ahead", "Couple behind", "Uncouple", "Turntable"], MENU);
            return;
        }
        if (!PUBLIC && t != llGetOwner()) return;
        llDialog(t, "Drive " + TRAIN + " from here", ["Go", "Coast", "Stop", "Auto"] + ends + ["Couple ahead", "Couple behind", "Uncouple", "Turntable"], MENU);
    }

    listen(integer ch, string name, key id, string msg)
    {
        key drv = Driver(Cab());
        if (msg == "Change ends")
        {
            if (drv == id || (drv == NULL_KEY && (PUBLIC || id == llGetOwner()))) ChangeEnds(id);
            return;
        }
        if (msg == "Turntable")
        {
            // the driver, or (nobody driving) the owner / anyone when PUBLIC (as Change ends)
            if (drv == id || (drv == NULL_KEY && (PUBLIC || id == llGetOwner()))) Turntable(id);
            return;
        }
        if (msg == "Couple ahead" || msg == "Couple behind" || msg == "Uncouple")
        {
            // the driver, or (nobody driving) the owner / anyone when PUBLIC; the region also checks the shunt grant
            if (!(drv == id || (drv == NULL_KEY && (PUBLIC || id == llGetOwner())))) return;
            if (msg == "Couple ahead") Couple(id, "forward");
            else if (msg == "Couple behind") Couple(id, "back");
            else Uncouple(id);
            return;
        }
        if ((!PUBLIC && id != llGetOwner()) || drv != NULL_KEY) return;
        // [train, power 0-1, brake 0-1, reverser -1 / 0 / 1]: the line's end is always protected
        if (msg == "Go")         wolfCall("train.control", [TRAIN, 1.0, 0.0, 1]);   // full power, up to SPEED
        else if (msg == "Coast") wolfCall("train.control", [TRAIN, 0.0, 0.0, 1]);   // keeps its speed
        else if (msg == "Stop")  wolfCall("train.control", [TRAIN, 0.0, 1.0, 1]);   // full brake
        else if (msg == "Auto")  wolfCall("train.control", [TRAIN, "auto"]);       // drives itself: stations, signals
        // [driver, mode, speed, line speed, power, brake, reverser, next stop, its metres, line ahead, protecting, lead, ends, ...]
        list cab = Cab();
        if (cab != []) llRegionSayTo(id, 0, TRAIN + ": " + (string)llRound(llList2Float(cab, 2) * 3.6) + " km/h");
    }
}
Energy 10

Ours alone. Grid features you will not find on any other OpenSimulator grid.

More in Wolf Territories