Build, Learn, Shop, Hangout
How to: Make an Online/Offline Indicator
Learn how to script an online/offline indicator that accepts inventory from people. The information about the different commands is embedded directly in the code.
This begining level scrip will cover some basics of the following commands
- llSetTimerEvent
- llAllowInventoryDrop
- llListen
- llOwnerSay
- llResetScript
- llRequestAgentData
- llGetOwner
- llKey2Name
- llSetText
- llSetColor
and the following event handlers
- listen
- timer
- on_rez
- dataserver
Information will primarly pertain to the specifics needed for this event.
-
default
-
{
-
-
// State Entry is what happens when a script starts up
-
state_entry()
-
{
-
// llSetTimerEvent(float sec)
-
// Sets the timer event to be triggered every sec seconds. Passing 0.0 (or just 0) stops further timer events.
-
// Set a timed event to see if you are online every 5 seconds
-
llSetTimerEvent(5);
-
-
//llAllowInventoryDrop(integer add)
-
// If add is true, all users, even those who do not have modify permissions, can drop inventory items onto the object. If add is false the system forbids all users except those with modify permissions from dropping items onto the object.
-
// Let people drop inventory in. This will not allow scripts to be dropped in
-
llAllowInventoryDrop(TRUE);
-
-
//llListen(integer channel, string name, key id, string msg)
-
// Sets a filter for listening to the specified chat channel while the current state persists. If a message is heard that meets the specified criteria, the object’s listen() event handler is invoked.
-
// Setup a listen so you can force a reset. Listen to channel 91, and only for the owner saying Reset
-
llListen(91, "", llGetOwner(), "Reset");
-
-
// llOwnerSay(string message)
-
// Says message to only the owner of the object running the script if the owner has been within the object’s simulator since logging into Second Life, regardless of where they may be in-world
-
// Let the owner know it is ready and working
-
llOwnerSay("Ready!");
-
}
-
-
// listen(integer channel, string name, key id, string message)
-
// The listen() event handler is invoked whenever a chat message matching the constraints passed in the llListen function is heard. The channel the chat was picked up on, the name and id of the speaker and the message are passed.
-
-
listen( integer channel, string name, key id, string message )
-
{
-
// Tell the owner know its reseting
-
llOwnerSay("Reseting … … …");
-
-
// llResetScript()
-
// All variables are reset to their default values. All pending events are cleared. The default state becomes active and its state_entry is triggered. This is the same function as clicking "reset" in the script editor.
-
// Reset the script
-
llResetScript();
-
}
-
-
// timer()
-
// The timer event is raised at regular time intervals set by the llSetTimerEvent function (you only need to call this function once).
-
-
timer()
-
{
-
-
// llRequestAgentData(key id, integer data)
-
-
// This function requests information of type data (see constants below) about agent id. The information is returned via the dataserver event. The key returned by this function is the query id for the dataserver event.
-
// Get the owners Key
-
// and find out their online status
-
llRequestAgentData(llGetOwner(), DATA_ONLINE);
-
}
-
-
// Triggered in an object whenever it is rezzed from inventory or by another object, or in an attachment when its owner logs in while wearing it, or attaches it from inventory. on_rez is not triggered when an object is rezzed after a teleport.
-
-
on_rez(integer start_param)
-
{
-
// Reset the script
-
llResetScript();
-
}
-
-
//This event handler is triggered when the requested data is returned to the script. Data may be requested using the llGetNotecardLine, llGetNumberOfNotecardLines, llRequestAgentData, llRequestInventoryData, and llRequestSimulatorData functions
-
dataserver(key queryid, string data)
-
{
-
// If the result is 1, then you are online, 0 is offline
-
if ((integer)data == 1)
-
{
-
// llSetText(string text, vector color, float alpha)
-
// The Text displayed over the object. (Length Limit: 254 characters)
-
// Set the hover text
-
llSetText(llKey2Name(llGetOwner()) + " is online\n \nYou can drop notecards or other inventory for me to get later",<0,1,0>, 1);
-
-
// llSetColor(vector color, integer face)
-
// Sets the color of face. If face is ALL_SIDES, sets the color on all faces.
-
// Set the Prim Color
-
llSetColor(<0,1,0>, ALL_SIDES);
-
}
-
else if ((integer)data == 0)
-
{
-
// Set the hover text
-
llSetText(llKey2Name(llGetOwner()) + " is offline\n \nYou can drop notecards or other inventory for me to get later", <1,0,0>, 1);
-
-
// Set Prim Color
-
llSetColor(<1,0,0>, ALL_SIDES);
-
}
-
}
-
}
| Print article | This entry was posted by Arthur Fermi on March 5, 2010 at 5:13 pm, and is filed under Arthur Fermi, How To. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |