API Sample


// SedSens Creator API v2.5.7 Example
// The Creator API script and this controller script belong in the same linkset.
// Replace TARGET_AVATAR with the avatar UUID selected by the furniture controller.

integer API_SEND = 7337;
integer API_REPLY = 7367;
string TARGET_MODE = "SEATED";
key TARGET_AVATAR = NULL_KEY;

api(string command, string param)
{
    llMessageLinked(LINK_THIS, API_SEND, command, param);
}

default
{
    state_entry()
    {
        api("SET_TARGET_MODE", TARGET_MODE);
    }

    touch_start(integer total_number)
    {
        // This example starts the setup chain. A real furniture controller
        // should set TARGET_AVATAR from its selected sitter or device user.
        api("SET_PROP", "crop");
    }

    link_message(integer sender_num, integer num, string str, key id)
    {
        if (num != API_REPLY) return;

        list response = llParseStringKeepNulls((string)id, ["|"], []);
        string status = llList2String(response, 0);
        string data = llDumpList2String(llList2List(response, 1, -1), "|");

        if (status == "OK")
        {
            llOwnerSay(str + " succeeded: " + data);

            if (str == "SET_PROP")
            {
                if (TARGET_AVATAR == NULL_KEY)
                {
                    llOwnerSay("Set TARGET_AVATAR before requesting a target.");
                    return;
                }
                api("SET_TARGET", (string)TARGET_AVATAR);
            }
            else if (str == "SET_TARGET")
            {
                // Body part, hit level, optional alpha hits.
                api("HIT", "b1,1");
            }
        }
        else
        {
            llOwnerSay(str + " failed: " + (string)id);
        }
    }
}

// Furniture mode, which is also the Creator API default:
// TARGET_MODE = "SEATED";
// The target must be seated on this same furniture linkset.

// Explicit device mode for products intentionally used without sitting:
// TARGET_MODE = "DEVICE";
// The controller must still supply one specific nearby avatar UUID.
// The Creator API never selects a nearby avatar automatically.