User Tools

Site Tools


lslsnips

This is an old revision of the document!


Create morsecode in LSL

🛠️ How It Works Listens on public chat (channel 0).

  • Converts each character to Morse using a lookup list.
  • Outputs Morse code with spaces between letters and slashes between words.
// Morse code mapping
list morseMap = [
    "A", ".-",    "B", "-...",  "C", "-.-.",  "D", "-..",   "E", ".",
    "F", "..-.",  "G", "--.",   "H", "....",  "I", "..",    "J", ".---",
    "K", "-.-",   "L", ".-..",  "M", "--",    "N", "-.",    "O", "---",
    "P", ".--.",  "Q", "--.-",  "R", ".-.",   "S", "...",   "T", "-",
    "U", "..-",   "V", "...-",  "W", ".--",   "X", "-..-",  "Y", "-.--",
    "Z", "--..",
    "0", "-----", "1", ".----", "2", "..---", "3", "...--", "4", "....-",
    "5", ".....", "6", "-....", "7", "--...", "8", "---..", "9", "----."
];
 
// Convert a string to Morse code
string toMorse(string input) {
    input = llToUpper(input);
    string result = "";
    integer i;
    for (i = 0; i < llStringLength(input); ++i) {
        string ch = llGetSubString(input, i, i);
        integer idx = llListFindList(morseMap, [ch]);
        if (idx != -1) {
            result += llList2String(morseMap, idx + 1) + " ";
        } else if (ch == " ") {
            result += "/ "; // Slash for space between words
        }
    }
    return result;
}
 
// Listen for chat and convert to Morse
default {
    state_entry() {
        llListen(0, "", NULL_KEY, "");
    }
 
    listen(integer channel, string name, key id, string message) {
        string morse = toMorse(message);
        llSay(0, "Morse: " + morse);
    }
}

SL to Telegram

string TELEGRAM_API_URL = "https://api.telegram.org/bot<YOUR-BOT-TOKEN>/sendMessage";
string chat_id = "<YOUR-CHAT-ID>";
string message = "Hello from Second Life!";

default
{
    state_entry()
    {
        // Construct the HTTP request payload
        string payload = "{\"chat_id\":\"" + chat_id + "\", \"text\":\"" + message + "\"}";

        // Send HTTP POST request to Telegram API
        llHTTPRequest(TELEGRAM_API_URL, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/json"], payload);
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
        // Handle the HTTP response
        if (status == 200)
        {
            llOwnerSay("Message sent successfully!");
        }
        else
        {
            llOwnerSay("Failed to send message. Status: " + (string)status + ", Response: " + body);
        }
    }
}

SL2Discord

string discord_web_hook = "wehhookURL"; // this is where your web hook url from discord goes

key http_send;
Send_Message(string message) // this is where the magic happens.
{
    string json_encode = llList2Json(JSON_OBJECT,["username",username,"content",message]);
    http_send = llHTTPRequest(discord_web_hook, [HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/json",HTTP_VERIFY_CERT,FALSE],json_encode);
}

string username = "Test User"; //var to set the name in your message

default
{
    state_entry()
    {
        
    }
    touch_start(integer total_number)
    {
        Send_Message(llGetDisplayName(llDetectedKey(0))  + " clicked me");
    }
    
}

Rezz at feet

integer canRezAt(vector pos) //can I rez at this place?
{
    integer parcelFlags = llGetParcelFlags(pos);
    list parcelDetails = llGetParcelDetails(pos, [PARCEL_DETAILS_OWNER, PARCEL_DETAILS_GROUP]);
    key parcelOwner = llList2Key(parcelDetails, 0);
    key parcelGroup = llList2Key(parcelDetails, 1);
    if (parcelFlags & PARCEL_FLAG_ALLOW_CREATE_OBJECTS) return TRUE;
    if (parcelOwner == llGetOwner()) return TRUE;
    if (!llSameGroup(parcelGroup)) return FALSE;
    if (parcelFlags & PARCEL_FLAG_ALLOW_CREATE_GROUP_OBJECTS) return TRUE;
    return FALSE;
}


/// rez the stuff to my feet
vector          size;
float           Zpos;
vector          rot = <90.00000, 0.00000, 0.00000>;

positioner() //get my size and locate my feet
{
    size = llGetAgentSize(llGetOwner());
    vector pos = llGetPos();Zpos = pos.z - (size.z / 2);
}

rezzer(string object) // do the rez!
{
    if(canRezAt(llGetPos())) //can I rez at this place?
    {
        positioner();
        vector pos = llGetPos()+(<2,0,-2>*llGetRot());
        rotation rot1 = llEuler2Rot(rot);
        pos.z = Zpos;llRezObject(object, pos, <0,0,0>,ZERO_ROTATION, 1);
    }
    else
    {
        llOwnerSay("Cant rez at current position!");
    }
}

Random giver

//gimme random
integer random_integer(integer min, integer max)
{
    return min + (integer)(llFrand(max - min + 1));
}

Find in List

// find stuff in my list or not

integer findinList(list src,list item){
    if(~llListFindList(src, (list)item))
    return TRUE;
    else  
    return FALSE;   
}

Find an avatar key on region

string getKey(string req)
{
    if(llStringLength(req) < 3)
    {
        return NULL_KEY;
    }
    req = llToLower(req);
    list keyNames;
    list temp;
    list agents = llGetAgentList(AGENT_LIST_REGION , []); 
    integer x = 0;
    integer y = llGetListLength(agents);
    while(x<y)
    {   
        list t = llParseString2List(llToLower(llKey2Name(llList2String(agents,x))),[" "],[]);
        temp = [llList2String(t,0) +"|"+ llList2String(agents,x) ] + temp;   
        ++x;
    }
    keyNames = llListSort(temp,1,TRUE); 
    x = 0;
    y = llGetListLength(keyNames);
    while(x<y) 
    {
        if(llSubStringIndex(llList2String(keyNames,x),req) != -1)
        {
            list a = llParseString2List(llList2String(keyNames,x), ["|"] ,[]);
            return llList2String(a,1); 
        }
        ++x;
    }
    return NULL_KEY; 
}

Check if object is original

integer checkOriginal(key id) {
 
    // Check if we have the original number of primitives.
    if(llGetNumberOfPrims() != 15) return FALSE;
    // Check if the creator of the object is Morgan LeFay.
    if(llGetCreator() != "1ad33407-a792-476d-a5e3-06007c0802bf") return FALSE;
    // Check the sizes and positions of all primitives.
    list size = [ <.032813, .015186, .022779>,<.018223, .015186, .015186>,<.015186, .075929, .015186>,<.018223, .015186, .015186>,<.015186, .015186, .015186>,<.016704, .076547, .046667>,<.046755, .010000, .010000>,<.018223, .030371, .030371>,<.020000, .013000, .010000>,<.010000, .010000, .046230>,<.030000, .030000, .030000>,<.030000, .030000, .030000>,<.010000, .014000, .010000>,<.012000, .016000, .010000>,<.016840, .076546, .073333> ];
    integer itra = 14;
    do {
        if((string)llList2Vector(llGetLinkPrimitiveParams(14-itra+1, [PRIM_SIZE]),0) != (string)llList2Vector(size, itra)) return FALSE;
        i += llList2Vector(llGetLinkPrimitiveParams(14-itra+1, [PRIM_SIZE]),0);
    } while(--itra>0);
 
    return llAbs((integer)((integer)(i.x*((integer)("0x"+llGetSubString((string)id,-8,-1)))) & (integer)(i.y*((integer)("0x"+llGetSubString((string)llGetCreator(),-8,-1)))) ^ (integer)(i.z*((integer)("0x"+llGetSubString("2358cb5c-578a-4b90-932f-54d01e36cfc8",-8,-1))))));
}

Shield effect

ShieldFade(integer link_num, float alpha_start, float alpha_end, float glow_start, float glow_end, float speed)
{
	integer complete = FALSE;
	do
	{
		if((alpha_start < alpha_end && alpha_start != alpha_end)||(alpha_start > alpha_end && alpha_start != alpha_end))
		{
			if(alpha_start < alpha_end && (alpha_start + speed) < alpha_end)
			{
				alpha_start += speed;
			}
			else if(alpha_start > alpha_end && (alpha_start - speed) > alpha_end)

			{
				alpha_start -= speed;
			}
			else
			{
				alpha_start = alpha_end;
			}
		}
		if((glow_start < glow_end && glow_start != glow_end)||(glow_start > glow_end && glow_start != glow_end))
		{
			if(glow_start < glow_end && (glow_start + speed) < glow_end)
			{
				glow_start += speed;
			}
			else if(glow_start > glow_end && (glow_start - speed) > glow_end)
			{
				glow_start -= speed;
			}
			else
			{
				glow_start = glow_end;
			}
		}
		vector color = <1,1,1>;
		llSetLinkPrimitiveParamsFast(link_num, [PRIM_GLOW, ALL_SIDES, glow_start, PRIM_COLOR, ALL_SIDES, color, alpha_start]);
		if(glow_start == glow_end && alpha_start == alpha_end)
		{
			complete = TRUE;
		}
	}while(complete == FALSE);
}

WarpPos

warpPos(vector destpos) {
    integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
    if (jumps > 411) jumps = 411;
    list rules = [PRIM_POSITION, destpos];
    integer count = 1;
    while ((count = count << 1) < jumps) {
        rules = (rules = []) + rules + rules;
    }
    llSetPrimitiveParams(rules + llList2List(rules, (count - jumps) << 1, count));
    if (llVecDist(llGetPos(), destpos) > 0.001) {
        while (--jumps) llSetPos(destpos);
    }
}

Binary converter


// Function to encode a string into a binary form using integers
list encodeToBinary(string data) {
    list binaryList = [];
    integer len = llStringLength(data);

    for (integer i = 0; i < len; ++i) {
        integer ch = llString2Key(llGetSubString(data, i, i));
        list bits = [];
        for (integer j = 0; j < 8; ++j) {
            bits += (ch & (1 << j)) ? 1 : 0;
        }
        binaryList += llList2String(bits, 0);
    }
    return binaryList;
}

// Function to decode a binary list back to a string
string decodeFromBinary(list binaryList) {
    string data = "";
    integer len = llGetListLength(binaryList);

    for (integer i = 0; i < len; ++i) {
        integer ch = 0;
        list bits = llParseString2List(llList2String(binaryList, i), [" "], []);
        for (integer j = 0; j < 8; ++j) {
            ch += (llList2Integer(bits, j) ? 1 : 0) << j;
        }
        data += (string)ch;
    }
    return data;
}

// Example usage
default {
    state_entry() {
        string originalData = "Hello";
        list binaryData = encodeToBinary(originalData);
        string decodedData = decodeFromBinary(binaryData);

        llSay(0, "Original Data: " + originalData);
        llSay(0, "Binary Data: " + llDumpList2String(binaryData, " "));
        llSay(0, "Decoded Data: " + decodedData);
    }
}

ENDLESS DIALOG

// Dynamisches Dialogskript in LSL mit Seiten
integer dialogChannel = -123456;
key user;
list options = ["Option 1", "Option 2", "Option 3", "Option 4", "Option 5", 
                "Option 6", "Option 7", "Option 8", "Option 9", "Option 10", 
                "Option 11", "Option 12"];
integer itemsPerPage = 5;
integer currentPage = 0;

// Funktion zum Anzeigen des Dialogs mit Seiten
showDialog(key userId, integer page) {
    integer start = page * itemsPerPage;
    integer end = start + itemsPerPage;
    list pageOptions = llList2List(options, start, end - 1);
    
    if (start > 0) {
        pageOptions += ["Vorherige"];
    }
    if (end < llGetListLength(options)) {
        pageOptions += ["Nächste"];
    }
    
    llDialog(userId, "Wähle eine Option:", pageOptions, dialogChannel);
}

// Ereignis, wenn das Skript zurückgesetzt wird
default {
    state_entry() {
        llListen(dialogChannel, "", NULL_KEY, ""); 
        llSay(0, "Dialogskript ist aktiv. Tippe '/100 menü' zum Starten.");
    }

    listen(integer channel, string name, key id, string message) {
        if (llToLower(message) == "menü") { 
            user = id;
            currentPage = 0;
            showDialog(user, currentPage);
        } else {
            llListenRemove(channel);
        }
        if (channel == dialogChannel) {
            if (message == "Vorherige") {
                currentPage--;
            } else if (message == "Nächste") {
                currentPage++;
            } else {
                llSay(0, "Du hast " + message + " gewählt.");
            }
            showDialog(user, currentPage);
        }
    }

    on_rez(integer start_param) {
        llResetScript();
    }

    touch_start(integer num) {
        user = llDetectedKey(0);
        currentPage = 0;
        showDialog(user, currentPage);
    }
}

Turn Avatar to Target / RLV

vector pointTo = targetpos - llGetPos();
float angleTo = llAtan2(pointTo.x, pointTo.y);
llOwnerSay("@setrot:" + (string)angleTo + "=force");

Key2Number

integer Key2Number(key objKey) {
  return -(integer)("0x8" + llGetSubString(llGetKey(), 0, 6));
}
/* 
    *DS* FloatLinkNumber by Daemonika Nightfire (daemonika.nightfire)
 
    Features:
    Nuetzlicher Helfer fuer Ersteller & Scripter
    Mit diesem Tool kannst du saemtliche Linknummern direkt als Hovertext ueber den Prims sehen
    Lege das Script einfach in den Root-Prim und klicke ihn zum ein/ausschalten des Hovertextes.
 
    Info:
    ein einzelner Prim zeigt LinkNumber 0 fuer den root
    in einem LINK_SET zeigt der root die LinkNumber 1
*/
 
integer text = 0;
 
// setze TRUE oder FALSE fuer mit oder ohne LinkName
integer name = TRUE;
 
Links()
{
    integer i;
    for(i = 0; i <= llGetNumberOfPrims(); i++)
    {
        if(text)
        {
            string num;
            if(i < 2)
            {
                num = (string)i + " (root)";
                if(name)
                {
                    num = (string)i + " (root)\n" + llGetLinkName(i);
                }
            }
            else if(i >= 2)
            {
                num = (string)i;
                if(name)
                {
                    num = (string)i + "\n" + llGetLinkName(i);
                }
            }
            llSetLinkPrimitiveParamsFast(i,[PRIM_TEXT, num, <1,1,0>, 1.0]);
        }
        else if(!text)
        {
            llSetLinkPrimitiveParamsFast(i,[PRIM_TEXT, "", ZERO_VECTOR, 0.0]);
        }
    }
}
 
default
{
    state_entry()
    {
        Links();
    }
 
    touch_start(integer num_detected)
    {
        // Zum ein/aus schalten, musst du den Root Prim klicken
        if(llDetectedKey(0) == llGetOwner() && llDetectedLinkNumber(0) < 2)
        {
            if(!text)
            {
                text = 1;
            }
            else if(text)
            {
                text = 0;
            }
            Links();
        }
    }
 
    on_rez(integer Dae)
    {
        llResetScript();
    }
}

GetPrimInfo

default
{
    touch_start(integer num_detected)
    {
        integer i;
        for(i=0; i<num_detected; ++i)
        {
            llOwnerSay("/me Creator: "  + (string)llKey2Name(llGetCreator()) +
            "\nCreatorKey: "            + (string)llGetCreator() +
            "\nObjectKey: "             + (string)llGetKey() +
            "\nObjectPrimCount: "       + (string)llGetNumberOfPrims() +
            "\nLinkNumber: "            + (string)llDetectedLinkNumber(i) +
            "\nLinkName: "              + (string)llGetLinkName(llDetectedLinkNumber(i)) +
            "\nLinkNumberKey: "         + (string)llGetLinkKey(llDetectedLinkNumber(i)) +
            "\nTouchFace: "             + (string)llDetectedTouchFace(i) +
            "\nTouchPos: "              + (string)llDetectedTouchST(i) +
            "\nScale (me): "            + (string)llGetScale() +
            "\nMass (object): "         + (string)llGetMass() +
            "\nLinkMass: "              + (string)llGetObjectMass(llGetLinkKey(llDetectedLinkNumber(i))) +
            "\nPos (root): "            + (string)llGetPos() +
            "\nRot (root): "            + (string)llGetRot() +
            "\nLocalPos (me): "         + (string)llGetLocalPos() +
            "\nLocalRot (me): "         + (string)llGetLocalRot() +
            "\nColor: "                 + (string)llGetColor(llDetectedTouchFace(i)) +
            "\nAlpha: "                 + (string)llGetAlpha(llDetectedTouchFace(i)));
        }
    }
}

RealEncryption

string xorSalted(string msg, string salt)
{
    // Derive a numeric key from the salt
    integer key = 0;
    integer i;
    integer slen = llStringLength(salt);

    for (i = 0; i < slen; ++i)
    {
        key = key ^ llOrd(salt, i);   // XOR all salt chars together
        key = (key * 31) & 0xFF;      // scramble it a bit
    }

    // Now XOR the message with the salted key
    string out = "";
    integer mlen = llStringLength(msg);

    for (i = 0; i < mlen; ++i)
    {
        integer c = llOrd(msg, i);
        c = c ^ key;                  // XOR with salted key
        out += llChar(c);
    }

    return out;
}

🧪 How to use it

string encrypted = xorSalted("Hello World", "mySalt123");

string decrypted = xorSalted(encrypted, "mySalt123");

🧠 Why this works The salt is turned into a derived key Even a small change in the salt produces a completely different output The cipher is reversible only if you know the salt It’s compact and fast enough for LSL This is the closest you can get to “real” salted encryption inside Second Life scripting.

lslsnips.1769584799.txt.gz · Last modified: by miko

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki