Forums


OSSL

Creating scripts

OSSL

Postby Graham Mills » Wed Jan 14, 2015 10:24 pm

I thought I would start an occasional thread for scripts that make use of the OpenSim-specific OSSL commands.

The first one is very simple and helps your avatar walk faster (or, alternatively, much faster). Rez a prim and add the following script.

Code: Select all
default
{
    touch_start(integer i)
    {
        osSetSpeed(llDetectedKey(0), 5.0);
    }
}


Touch the prim and enjoy super-fast walking. You can cancel the effect by changing 5.0 to 1.0 or by relogging.
Graham Mills
 
Posts: 860
Joined: Sun Dec 23, 2012 2:26 pm
Has liked: 517 times
Been liked: 646 times

Joining a group

Postby Graham Mills » Sat Feb 14, 2015 12:04 pm

Another simple one. Create an object with a suitable texture or hovertext, deed it to the group in question and add the following code. In Firestorm touching the object will show a Join/Decline/Info dialog for the object's group. The user is IM'd instructions and notified if there is an issue. Very useful for classes where preregistration isn't feasible. Hopefully the groups system will make it redundant in due course.

Code: Select all
default
{
    touch_start(integer i)
    {
        integer n = osInviteToGroup(llDetectedKey(0));
        if (n==0)
        {
            llInstantMessage(llDetectedKey(0), "You are invited to join the group. Press the Join button.");
        }
        else
        {
             llInstantMessage(llDetectedKey(0), "Problem joining group, e.g. already joined");
        }
    }
}


PS: Yes, it's a bit lazy because I'm assuming only one avatar touches at a time.
Graham Mills
 
Posts: 860
Joined: Sun Dec 23, 2012 2:26 pm
Has liked: 517 times
Been liked: 646 times

Putting text on a prim with wordwrap

Postby Graham Mills » Fri Aug 28, 2015 9:02 pm

This code mainly comes from Nebadon Izumi's Noteboard v2.0 which does a fine job of displaying 31 lines of 50 characters from a notecard but not afaik wrapping it. Accordingly I have added some wordwrap code from JasX together with a few other minor changes.

Paragraphs are best represented on the notecard with two linebreaks, i.e. a blank line between paragraphs. I have no idea how you stop text appearing on all sides -- the easiest fix is to hide it with other prims or set the face to the same colour as the text.

Code: Select all
// NoteBoard Script v2.0
// Updated 2014-06-19
// Created by Michael Emory Cerquoni
// Modified by Graham Mills_2 @ Kitely
// This script requires Deva Vu Sans Mono font be installed (http://dejavu-fonts.org/wiki/Main_Page)
// on linux put the .ttf files in ~/.fonts and restart simulator
// on windows place .ttf files in c:\windows\fonts and restart simulator
//Adds word wrap to INPUT, specified by ROWLENGTH and returns a string separated by SEPARATOR (recommended

string name;

//jasx
//http://jasx.org/?p=libjas
string WrapText(string input, integer rowlength){
    list para = llParseString2List(input,["\n\n"],[]);
    integer n; string input2;
    integer i; list rows; string thisrow;
    string separator = "\n";
    for(n=0;n<llGetListLength(para);n++)
    {
        input2 = llList2String(para, n);
        list words = llParseString2List(input2,[" "],[]);
        while(i<llGetListLength(words))
        {
            string this = llList2String(words,i)+" ";
            if((llStringLength(this)+llStringLength(thisrow)) <= rowlength && i+1 != llGetListLength(words))
            {
                thisrow+=this;
            }
            else
            {
                if(i+1 == llGetListLength(words))thisrow+=this;
                rows+=[thisrow];
                thisrow = this;
            }
            i++;
        }
    }
    return llDumpList2String(rows, separator);
}

draw_text()
{
// get the first notecard in inventory (default max is 255 lines and would not show in std chat)
    // each Line Return is reflected in output
    string name = llGetInventoryName(INVENTORY_NOTECARD,0);
    if(name == "")
    {
        llSay(0,"There is no notecard in prim inventory.  Please place a notecard with some text in the prim to display it's contents");
        return;
    }
    if(osGetNumberOfNotecardLines(name) > 31)
    {
        llSay(0,"Too Many Lines in your notecard, limit is 31 and you have " + (string)osGetNumberOfNotecardLines(name));
        return;
    }
    else
    {
        string output;
        integer m;
        string txt;
        for(m=0;m<osGetNumberOfNotecardLines(name);m++)
        {
            txt = osGetNotecardLine(name, m);
            if(llStringLength(txt)>3)
            {
                output += WrapText(txt, 50)+"\n\n";
            }
            else
            {
                output+=txt;
            }
        }           
        string CommandList = ""; // Storage for our drawing commands
        string FontName = "DejaVu Sans Mono"; // Arial is the default font used, if unspecified
        integer FontSize = 24;     // default to 24 point for sample

        CommandList = osSetFontName(CommandList, FontName);
        CommandList = osSetFontSize(CommandList, FontSize);
        CommandList = osMovePen(CommandList, 10, 15);
        CommandList = osDrawText(CommandList, output);

    // Now draw the image
        osSetDynamicTextureData( "", "vector", CommandList, "width:1024,height:1024", 0 );
    }
}

default
{
    state_entry()
    {
         llSay(0,"Touch to see osGetNotecard read in a notecard and display the text retrieved");
    }
   
    touch_end(integer num)
    {
        draw_text();
    }
   
    on_rez(integer start_param)
    {
        draw_text();
    }
   
    changed(integer c)
    {
        if (c & CHANGED_REGION_START)
        {
            draw_text();
        }
    }
}
Graham Mills
 
Posts: 860
Joined: Sun Dec 23, 2012 2:26 pm
Has liked: 517 times
Been liked: 646 times

Re: OSSL

Postby Graham Mills » Fri Mar 17, 2017 1:36 pm

One potential source of annoyance or embarrassment is the presence of an under-dressed avatar. The following script outlines a possible strategy for handling this by teleporting the avatar to a changing room. The script would require substantial modification to work satisfactorily at world-scale -- this is just proof-of-concept code that requires the avatar to touch a prim containing the script. The prim needs to be owned by the World Manager or Owner.

The script works by creating an appearance card in the prim for the avatar, counting the number of lines in the card and teleporting the avatar if the count is below a set limit. Again, the figure of 100 is somewhat arbitrary and requires further investigation. You could also use osGetGender to make the teleport destination conditional.

Code: Select all
string NAME;
key AVATAR;
integer LIMIT = 100;
vector CHANGING_ROOM = <128,128, 25>;

default
{
    touch_start(integer n)
    {
        AVATAR = llDetectedKey(0);
        NAME = llKey2Name(AVATAR);
        osAgentSaveAppearance(AVATAR, NAME);
        llSetTimerEvent(5.0);
    }
   
    timer()
    {
        if (osGetNumberOfNotecardLines(NAME) < LIMIT)
        {
            llInstantMessage(AVATAR, "Possible wardrobe malfunction");
            osTeleportAgent(AVATAR, CHANGING_ROOM, ZERO_VECTOR);
           
        }
        llSetTimerEvent(0.0);
    }
}
Graham Mills
 
Posts: 860
Joined: Sun Dec 23, 2012 2:26 pm
Has liked: 517 times
Been liked: 646 times


Return to Scripting

Who is online

Users browsing this forum: No registered users and 7 guests