Triggered by chat, use llListen to enable and filter
listen( integer channel, string name, key id, string message )
Event ID: 12.
| Channel Constant | Description | |
|---|---|---|
| DEBUG_CHANNEL | 0x7FFFFFFF | Chat channel reserved for script debugging and error messages, broadcasts to all nearby users. |
| PUBLIC_CHANNEL | 0x0 | Chat channel that broadcasts to all nearby users. This channel is sometimes referred to as: open chat, local chat and public chat. |
Please make sure that you close open listeners where possible. You'll make the Second Life experience so much better when paying attention to details here.
Trivial example to listen to any chat from the object owner and respond once. To reduce lag and avoid spamming surrounding users, it is vastly preferable to listen on channels other than 0 and to trigger the listen event by chatting on an alternative channel such as '/5 hello'.
// says beep to owner the first time owner says something in main chat;
integer listen_handle;
default
{
state_entry()
{ //Registers the listen to the owner of the object at the moment of the call. This does not automatically update when the owner changes.
// Change 0 to another positive number to listen for '/5 hello' style of chat.
listen_handle = llListen(0, "", llGetOwner(), "");
}
listen( integer channel, string name, key id, string message )
{
llOwnerSay("beep");
// Stop listening until script is reset
llListenRemove(listen_handle);
}
changed(integer mask)
{ //Triggered when the object containing this script changes owner.
if(mask & CHANGED_OWNER)
{
llResetScript(); // This will ensure the script listens to the new owner, and doesn't continue listening to the creator.
}
}
}