User talk:ZachSmith Resident: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
No edit summary
Strife Onizuka (talk | contribs)
m even out the distribution of random numbers (using round will scew the distribution) and ensure you never chat on channel zero.
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[User:ZachSmith Resident|ZachSmith Resident]] 14:52, 27 May 2012 (PDT)This is a script made for hovertext. It has a listen so it can hear chat commands to set color and text.
This is a simple example I made of the fairly new llTextBox. This is free software for anyone to use or learn with. Please use as you like just keep it free software.


<lsl>
//////////////////////////////
//Made by ZachSmith Resident//
//////////////////////////////


//Advanced hovertext script by ZachSmith Resident
//Global Variables//
//This is a very useful and easy to use advanced hovertext script.
integer listen_handle;
//Hopefully you can use this script or maybe even have it help you to better learn scripting.
string detected_name;
 
//global variables
string Htext;
vector red = <1,0,0>;
vector green = <0,1,0>;
vector blue = <0,0,1>;
vector white = <1,1,1>;
vector grey = <.5,.5,.5>;
vector black = <0,0,0>;
vector yellow = <1,1,0>;
vector cyan = <0,1,1>;
vector magenta = <1,0,1>;
vector cur_color;
 
//premade function for saying the help text
llHelp()
{
    llSay(0, "All commands are said in local chat\nChat commands:\n 'help'\n'text color red'\n'text color green'\n'text color blue'\n'text color white'\n'text color grey'\n'text color black'\n'text color yellow'\n'text color cyan'\n'text color magenta'\n'text on'\n'text off'\n'text set'");
}


//Default State//
default
default
{
{
     on_rez(integer start_params)
     //Touch_Start event for when the item is touched//
    touch_start(integer total_number)
     {
     {
         //when this item enters world say the help text
         //Set the channel to be a random float but remove the fractional portion so it's an integer since channels must be whole numbers.
         llHelp();
        //Add one so it's never zero, since channel zero is PUBLIC_CHANNEL.
        integer channel = 1 + (integer)llFrand(10000);
        //save the name of the person touching to a variable to be used later
        detected_name = llDetectedName(0);
        //set the llListen function to listen on channel for message from the key of the detected toucher
        listen_handle = llListen(channel, "", llDetectedKey(0), "");
        //give instructions on how to use
        llSay(0, "Please type your suggestion in the Text Box and then press send. You have 2 minutes");
        //Show the text box for them to put a message into
        llTextBox(llDetectedKey(0), "Type your suggestion below", channel);
        //set a timer event for 2 minutes giving them plenty of time to type a message so we can then close any listeners.
         llSetTimerEvent(120);
     }
     }
     state_entry()
     //listen event which is a result of the llListen
    listen(integer channel, string name, key id, string message)
     {
     {
         //Set cur_color to white, text to default and turn the listen on
         //Instant message the owner and tell them the name and suggestion that was just typed in the text box
         cur_color = white;
         llInstantMessage(llGetOwner(), detected_name + ": " + message);
        Htext = "Hello, Avatar!";
         //remove the listener to help reduce lag
        llListen(0, "", llGetOwner(), "");
        llListenRemove(listen_handle);
         //set the text on the prim to current text and color
        //turn the timer event to 0 so it does not continue going off every 120 seconds
         llSetText(Htext,cur_color, 1);
         llSetTimerEvent(0);
     }
     }
     listen(integer channel, string name, key id, string message)
     //timer event, result of the llSetTimerEvent
    timer()
     {
     {
         if(message == "text on")
         //tell the user that they are out of time and must click again to reopen the listen
        {
         llSay(0, "Sorry, you did not type your message fast enough and has timed out. Please try again.");
            //narrow scope and filter for only the proper chat commands.
         //remove the llListen so it will take less resources
            llSetText(Htext,cur_color, 1);
         llListenRemove(listen_handle);
            //set the text on the prim to current text and color
         //set timer event to 0 so it will not continue to say they have run out of time.
        }
         llSetTimerEvent(0);
        else if(message == "text off")
        {
            //narrow scope and filter for only the proper chat commands.
            llSetText(Htext,cur_color, 0);
            //set the text on the prim to current text and color but set the alpha so it is not seen
         }
        else if(message == "text color red")
        {
            cur_color = red;
            //set new cur_color
            llSetText(Htext,cur_color, 1);
            //set the text on the prim to current text and color
        }
        else if(message == "text color green")
        {
            cur_color = green;
            //set new cur_color
            llSetText(Htext,cur_color, 1);
            //set the text on the prim to current text and color
        }
        else if(message == "text color blue")
        {
            cur_color = blue;
            //set new cur_color
            llSetText(Htext,cur_color, 1);
            //set the text on the prim to current text and color
        }
        else if(message == "text color white")
        {
            cur_color = white;
            //set new cur_color
            llSetText(Htext,cur_color, 1);
            //set the text on the prim to current text and color
        }
         else if(message == "text color grey")
        {
            cur_color = grey;
            //set new cur_color
            llSetText(Htext,cur_color, 1);
            //set the text on the prim to current text and color
         }
        else if(message == "text color black")
        {
            cur_color = black;
            //set new cur_color
            llSetText(Htext,cur_color, 1);
            //set the text on the prim to current text and color
        }
         else if(message == "text color yellow")
        {
            cur_color = yellow;
            //set new cur_color
            llSetText(Htext,cur_color, 1);
            //set the text on the prim to current text and color
        }
        else if(message == "text color cyan")
        {
            cur_color = cyan;
            //set new cur_color
            llSetText(Htext,cur_color, 1);
            //set the text on the prim to current text and color
        }
        else if(message == "text color magenta")
        {
            cur_color = magenta;
            //set new cur_color
            llSetText(Htext,cur_color, 1);
            //set the text on the prim to current text and color
        }
        else if(message == "help")
        {
            llHelp();
            //say help message
        }
         else if(message == "text set")
        {
            llListen(7, "", llGetOwner(), "");
            //listen on channel 7 so that you can hear the new text.
            llSay(0, "Please say what you want your message to be on channel 7. EX: /7 Hello, Avatar!");
            //give instructions on how to set the new text
        }
        else
        {
            //if the message didn't fit any of the other messages above
            if(channel == 7)
            {
                //if what was said was on channel 7
                Htext = message;
                //set text to what the script heard
                llSetText(Htext,cur_color, 1);
                //set the text on the prim to current text and color
                llListenRemove(llListen(7, "", llGetOwner(), ""));
                //turn the listener on channel 7 off to reduce lag.
            }
        }
     }
     }
}
}
//string name = ZachSmith Resident;//
//integer value = TRUE;//
///////llSetAwesome(name, value);///////

Latest revision as of 08:24, 27 June 2012

This is a simple example I made of the fairly new llTextBox. This is free software for anyone to use or learn with. Please use as you like just keep it free software.

<lsl> ////////////////////////////// //Made by ZachSmith Resident// //////////////////////////////

//Global Variables// integer listen_handle; string detected_name;

//Default State// default {

   //Touch_Start event for when the item is touched//
   touch_start(integer total_number)
   {
       //Set the channel to be a random float but remove the fractional portion so it's an integer since channels must be whole numbers.
       //Add one so it's never zero, since channel zero is PUBLIC_CHANNEL.
       integer channel = 1 + (integer)llFrand(10000);
       //save the name of the person touching to a variable to be used later
       detected_name = llDetectedName(0);
       //set the llListen function to listen on channel for message from the key of the detected toucher
       listen_handle = llListen(channel, "", llDetectedKey(0), "");
       //give instructions on how to use
       llSay(0, "Please type your suggestion in the Text Box and then press send. You have 2 minutes");
       //Show the text box for them to put a message into
       llTextBox(llDetectedKey(0), "Type your suggestion below", channel);
       //set a timer event for 2 minutes giving them plenty of time to type a message so we can then close any listeners.
       llSetTimerEvent(120);
   }
   //listen event which is a result of the llListen
   listen(integer channel, string name, key id, string message)
   {
       //Instant message the owner and tell them the name and suggestion that was just typed in the text box
       llInstantMessage(llGetOwner(), detected_name + ": " + message);
       //remove the listener to help reduce lag
       llListenRemove(listen_handle);
       //turn the timer event to 0 so it does not continue going off every 120 seconds
       llSetTimerEvent(0);
   }
   //timer event, result of the llSetTimerEvent
   timer()
   {
       //tell the user that they are out of time and must click again to reopen the listen
       llSay(0, "Sorry, you did not type your message fast enough and has timed out. Please try again.");
       //remove the llListen so it will take less resources
       llListenRemove(listen_handle);
       //set timer event to 0 so it will not continue to say they have run out of time.
       llSetTimerEvent(0);
   }

}

//string name = ZachSmith Resident;// //integer value = TRUE;// ///////llSetAwesome(name, value);///////