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

wolfNPCInfo

Wolf Territories
string wolfNPCInfo(string what)

Reads the WolfNPC this script is in: "STATE" (intention|awake or asleep|alive or dead|health/max), "CFG" (its settings as JSON) or "INTENT" (what it is doing now). Returns "" with wolfGetLastError saying why when it cannot. Defined on Wolf_Api.wolfNPCInfo / WolfNPCModule.

Reads the WolfNPC the script is in. "STATE" gives four parts split by |: what it is doing now (roam, follow, rest, goto, sit, idle and so on), awake or asleep (it sleeps while nobody is within 96 m), alive or dead (in the region's game, until its respawn time), and its health as health/max. "INTENT" gives what it is doing and, when it is about someone, their name ("follow Luke Coda"). "CFG" gives all its kept settings as JSON, for llJsonGetValue: name, kind (animal or person), species, behaviour, home, its rules, its game and AI settings, its vehicle and route, whether it is paused. "EVENTS" gives the ids of its events running now, split by commas. For an avatar playing the region's game (when the game belongs to the NPC's owner): "FLAGS|<avatar key>" gives that player's flags, split by commas; "REP|<avatar key>|<faction or me>" their standing with a faction or with this NPC, a number from -100 to 100 (0 if never set); "QUESTS|<avatar key>" their active quests as id:step:count, split by commas. Only from a script inside the NPC that belongs to its owner. Returns "" with wolfGetLastError saying why when it cannot (for example when the script is not inside a WolfNPC). The example below is a bus driver: a person NPC who drives your bus round a route, parks, drives on and gets out, and the bus's own script lights up while it is driven (link_message with num WOLF_NPC_DRIVE in every script of the vehicle: "start" when the driver sets off, "leg|<speed in m/s>|<turn in degrees a second, more than 0 = to the left>" for each stretch of road, at most 2.5 seconds each, "park" and "exit"; id is the driver's key). The bus must be yours (the NPC's owner's), or its owner must have put wolfnpc-driver in the description of its root prim; deleting that word again refuses NPC drivers. Only people drive; an animal rides as a passenger. The driver takes the first seat (the prim with a sit target lowest in the link order), which must be free. While it drives, the region moves the bus itself, following the ground (the heights in the route do not matter) at the speed set in the WolfNPC window (8 m/s unless you change it, at most 20), slowing for bends and stopping for anyone standing in the road ahead; a physical bus is made non-physical and gets its physics back when the driver gets out. With nobody within 96 m it waits, and it drives on when someone comes. After a region restart the driver is back in the seat and carries on. Regions take it up as they restart onto the new release.

Parameters

TypeName What it does
string what "STATE", "INTENT", "CFG", "EVENTS", or for a player of the region's game "FLAGS|<avatar key>", "REP|<avatar key>|<faction or me>" or "QUESTS|<avatar key>".

How players use it, and more examples: the WolfNPC guide.

Example

// Bus driver - Wolf Territories, wolfNPC (DRIVE, PARK, EXIT), wolfNPCInfo and WOLF_NPC_DRIVE.
//
// Make a person in WolfAvatars, put them on your land with Wolf World > WolfNPC next to your bus
// (any vehicle with a seat: the first prim with a sit target is the driver's seat, the others are
// for passengers), and drop this script into the driver. Say on channel 5 (owner only):
//   /5 drive    the driver finds the bus called BUS within 20 m, gets in and drives the ROUTE
//               round and round, following the ground, slowing for bends and stopping for anyone
//               in the road
//   /5 park     stops where it is (the driver stays in the seat)
//   /5 go       drives on
//   /5 out      the driver gets out and stands beside the bus, which stays where it stopped
//   /5 where    what the driver is doing, and the route it drives
// Anyone who comes up to the bus is greeted, once each visit.
//
// Rules the grid keeps: the bus must be yours, or have wolfnpc-driver in its root prim's
// description; only people drive; the driver's seat must be free. A route has 2 to 64 points
// (region x,y,z; the heights do not matter); end it with ;back instead of ;loop to drive there
// and back again. To give the driver a new route, change ROUTE and say /5 drive again: it takes
// the new one at once, carrying on from the route point nearest the bus.

string BUS = "Bus";             // the name of your bus
string ROUTE = "40,40,22;200,40,22;200,200,22;40,200,22;loop";
integer CHANNEL = 5;

npc(string command, string value)
{
    if (!wolfNPC(command, value))
        llOwnerSay(command + " refused: " + wolfGetLastError());
}

default
{
    state_entry()
    {
        llListen(CHANNEL, "", llGetOwner(), "");
        npc("WHEN", "near|*|6|say:Hop on! Next stop, the harbour.;once=visit;id=fare");
    }

    on_rez(integer p)
    {
        llResetScript();
    }

    listen(integer ch, string name, key id, string msg)
    {
        msg = llToLower(llStringTrim(msg, STRING_TRIM));
        if (msg == "drive")
            llSensor(BUS, NULL_KEY, ACTIVE | PASSIVE | SCRIPTED, 20.0, PI);
        else if (msg == "park")
            npc("PARK", "");
        else if (msg == "go")
            npc("PARK", "0");
        else if (msg == "out")
            npc("EXIT", "");
        else if (msg == "where")
        {
            string cfg = wolfNPCInfo("CFG");
            llOwnerSay("Doing: " + wolfNPCInfo("INTENT")
                + "; route: " + llJsonGetValue(cfg, ["vehicle", "route"]));
        }
    }

    sensor(integer n)
    {
        npc("DRIVE", (string)llDetectedKey(0) + "|" + ROUTE);
    }

    no_sensor()
    {
        llOwnerSay("There is no bus called " + BUS + " within 20 m.");
    }
}

In the bus itself: an engine sound and a sign while an NPC drives it

default
{
    link_message(integer sender, integer num, string str, key id)
    {
        if (num != WOLF_NPC_DRIVE)
            return;                                   // id is the driver NPC's key
        list f = llParseString2List(str, ["|"], []);
        string what = llList2String(f, 0);
        if (what == "start")
        {
            llLoopSound("engine", 0.6);               // a sound in the bus's Contents
            llSetText("In service", <1.0, 0.8, 0.2>, 1.0);
        }
        else if (what == "leg")
        {
            float speed = llList2Float(f, 1);         // m/s for this stretch
            float turn = llList2Float(f, 2);          // degrees a second, more than 0 = left
            if (turn > 10.0) llSetText("Turning left", <1.0, 0.8, 0.2>, 1.0);
            else if (turn < -10.0) llSetText("Turning right", <1.0, 0.8, 0.2>, 1.0);
            else llSetText("In service - " + (string)llRound(speed * 3.6) + " km/h", <1.0, 0.8, 0.2>, 1.0);
        }
        else if (what == "park")
            llSetText("Stopped", <1.0, 0.8, 0.2>, 1.0);
        else if (what == "exit")
        {
            llStopSound();
            llSetText("", ZERO_VECTOR, 0.0);
        }
    }
}

Is it awake, alive, and how hurt?

list s = llParseStringKeepNulls(wolfNPCInfo("STATE"), ["|"], []);
if (llList2String(s, 2) == "dead")
    llOwnerSay("Down until its respawn time.");
else
    llOwnerSay("Health " + llList2String(s, 3) + ", " + llList2String(s, 1));
Energy 10

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

More in Wolf Territories