NPC Activate Sensor

.[npcActivateSensor500] series

NPC Activate Sensor is an external support script for the IruMoto NPC Engine, for use in virtual worlds running Open Simulator 9 and later.

Purpose and functionality

The NPC Activate Sensor script can be placed in any object but is ideally dropped into the centre of a scene, such as the floor of a house, shop, or club where avatars and NPCs are likely to come together.

.[npcActivateSensor] serves several auxiliary functions for the IruMoto NPC Engine:

  • Tells offline ‘Sensor’ bot types to come online when an avatar comes into range.
  • Tells online ‘Sensor’ and ‘Trigger’ bot types to go offline and reboot when an avatar goes out of range, thus saving sim resources and keeping your NPCs fresh.
  • Provides ‘Sensor’, ‘Trigger’, and ‘Always’ bot types with a single secure region-wide communications channel for that particular scene, allowing multiple NPCs and other scripted objects to interact with each other. This lets your NPCs be controlled by other scripts such as an IruMoto Love Engine or a blue menu of your own design.
  • It is possible to have dozens of NPCs served by several NPC Activate Sensor scripts on a region, working harmoniously and causing no interference with other scripted objects.

The only botType that does not need this supplemental script is a ‘Guest’ bot. An ‘Always’ bot type can function minimally without the script, but it will be limited to one animation and no facial expressions. Essentially it will just be a prop that does nothing.

All other bots need this script placed as per above or they will not function properly.

This current series has the name format “.[npcActivateSensor500.??]” where ?? is a number then letter, representing the version. The six digit number afterwards (where listed in the version notes) is a date format: YYMMDD.

Variables

The only variable that needs changing in NPC Activate Sensor is the channel number which should be a large unique negative number.

This unique channel number (sensorChan) must be the same as that listed in the .npcConfig notecard of any NPCs that you wish it to communicate with.

There are also some minor optional parameters that are commented within the script which you should look at, but the script will work fine as is, so long as you set the unique channel number, and make sure it matches that of your NPCs in that scene.

Other components

Several other scripts, notecards and contents are necessary for the NPC Engine to function. Visit the main IruMoto NPC Engine page for full information.

Code (.[npcActivateSensor500.1a])

You may use this script for whatever purpose but must retain the commented header section.

/*
NPC ACTIVATE SENSOR - support script for IRUMOTO NPC ENGINE
developed by Xay Tomsen in DigiWorldz 2017-2021.
Script purpose and version notes are online at:
http://www.andrewt2020.com/irumoto/npc-engine/npc-activate-sensor-script/
---------------------------------------------------
*/
integer sensorChan = -190217; // large unique negative number

integer visitorState = 0; // don't touch
string parcelName; // don't touch
list parcelDetails; // don't touch
key t1; // don't touch

default
{
    state_entry()
    {
        parcelDetails = llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_NAME]);
        parcelName = llList2String(parcelDetails, 0);
/* re llSensorRepeat:
1. Include your UUID if you wish this script to only activate bots when you come into vicinity. Will not activate bots for any other avatars. Leave blank if you want the bots to come online for all avatars. I have left my UUID there to show placement. Replace with your own UUID or delete it (don't delete quotes).
2. In this sample, 16.0 is how many metres radius from the center of the prim that the sensor will check for avatars. 20.0 is how many seconds between sensor scans.
*/
        llSensorRepeat("", "cd467fd2-4b8f-4137-bd57-e6ae01445e8a", AGENT_BY_LEGACY_NAME, 16.0, PI, 20.0);
    }
    
    sensor(integer num_detected)
    {
        if (num_detected > 0) {
            if (visitorState == 0) {
                llRegionSay(sensorChan, "visitor1");
/*
If you want to receive IMs every time someone sets off your sensor, un-comment this section. Otherwise, ignore.
                t1 = llDetectedKey(0);
                if (t1 == llGetOwner()) {}
                else if (t1 != llGetOwner()) { llInstantMessage(llGetOwner(), llKey2Name(t1) + " has visited " + parcelName + "."); }
*/
                visitorState = 1; }
            else if (visitorState == 1) {
                llRegionSay(sensorChan, "visitor1");
                visitorState = 1; }
        }
        
    }
    
    no_sensor()
    {
        llRegionSay(sensorChan, "visitor0");
        visitorState = 0;
    }
}

Version notes

v3.6.2 170325 – updated to dispense with support file.
v3.6.3 190207 – added visitorState and triggerWord so props could hide/show.
v3.6.4 190510 – now includes IM when someone apart from owner visits.
v500.1a 210829 – removed triggerWord which is superfluous due to now being called by other scripts. Have also adopted 500 series numbering convention to bring into line with other NPC related scripts.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.