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.

  1. default
  2. {
  3.  
  4.     // State Entry is what happens when a script starts up
  5.     state_entry()
  6.     {
  7.         // llSetTimerEvent(float sec)
  8.         // Sets the timer event to be triggered every sec seconds. Passing 0.0 (or just 0) stops further timer events.
  9.         // Set a timed event to see if you are online every 5 seconds
  10.         llSetTimerEvent(5);
  11.  
  12.         //llAllowInventoryDrop(integer add)
  13.         // 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.
  14.         // Let people drop inventory in.  This will not allow scripts to be dropped in
  15.         llAllowInventoryDrop(TRUE);
  16.  
  17.         //llListen(integer channel, string name, key id, string msg)
  18.         // 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.
  19.         // Setup a listen so you can force a reset.  Listen to channel 91, and only for the owner saying Reset
  20.         llListen(91, "", llGetOwner(), "Reset");
  21.  
  22.         // llOwnerSay(string message)
  23.         // 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
  24.         // Let the owner know it is ready and working
  25.         llOwnerSay("Ready!");
  26.     }
  27.  
  28.     // listen(integer channel, string name, key id, string message)
  29.     // 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.
  30.  
  31.     listen( integer channel, string name, key id, string message )
  32.     {
  33.         // Tell the owner know its reseting
  34.         llOwnerSay("Reseting … … …");
  35.  
  36.         // llResetScript()
  37.         // 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.
  38.         // Reset the script
  39.         llResetScript();
  40.     }
  41.  
  42.     // timer()
  43.     // The timer event is raised at regular time intervals set by the llSetTimerEvent function (you only need to call this function once).
  44.  
  45.     timer()
  46.     {
  47.  
  48.         // llRequestAgentData(key id, integer data)
  49.  
  50.         // 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.
  51.         // Get the owners Key
  52.         // and find out their online status
  53.         llRequestAgentData(llGetOwner(), DATA_ONLINE);
  54.     }
  55.  
  56.         // 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.
  57.  
  58.     on_rez(integer start_param)
  59.     {
  60.         // Reset the script
  61.         llResetScript();
  62.     }
  63.  
  64.     //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
  65.     dataserver(key queryid, string data)
  66.     {
  67.         // If the result is 1, then you are online, 0 is offline
  68.     if ((integer)data == 1)
  69.         {
  70.             // llSetText(string text, vector color, float alpha)
  71.             // The Text displayed over the object. (Length Limit: 254 characters)
  72.             // Set the hover text
  73.             llSetText(llKey2Name(llGetOwner()) + " is online\n \nYou can drop notecards or other inventory for me to get later",<0,1,0>, 1);
  74.  
  75.             // llSetColor(vector color, integer face)
  76.             // Sets the color of face. If face is ALL_SIDES, sets the color on all faces.
  77.             // Set the Prim Color
  78.             llSetColor(<0,1,0>, ALL_SIDES);
  79.         }
  80.     else if ((integer)data == 0)
  81.         {
  82.             // Set the hover text
  83.             llSetText(llKey2Name(llGetOwner()) + " is offline\n \nYou can drop notecards or other inventory for me to get later", <1,0,0>, 1);
  84.  
  85.             // Set Prim Color
  86.             llSetColor(<1,0,0>, ALL_SIDES);
  87.         }
  88.     }
  89. }
Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • blogmarks
  • MySpace
  • PDF
  • RSS
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Bookmarks