Don't click here unless you want to be banned.

LSL Wiki : DolusNaumova

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl427.us.archive.org
I occasionally do stuff. Once in a while I yell at things that don't work, or noobs with guns.



Snippets

//Gets the first name of the owner (faster string version)
string first = llGetSubString(llKey2Name(llGetOwner()),0,llSubStringIndex(llKey2Name(llGetOwner())," ") - 1);

//Gets the first name of the owner (list)
string first = llList2String(llParseString2List(llKey2Name(llGetOwner()),[" "],[]),0);

//XYText Word-wrap script. 
string wrapXYText(string text, integer chars){
    list t = llParseString2List(text,[" "],[]);
    integer i;
    integer l = llGetListLength(t);
    string out;
    string currline;
    for(i = 0; i < l; ++i){
        integer len = llStringLength(currline);
        integer wordlen = llStringLength(llList2String(t,i)+" ");
        if(len + wordlen > chars){
            integer j;
            integer k = chars - len;
            for(j = 0; j < k; ++j) currline += " ";
            out += currline;
            currline = llList2String(t,i)+" ";
        } else {
            currline += llList2String(t,i) + " ";
        }
    }
    out += currline;
    return out;
}

//Takes text and returns the appropriate scanner type
integer text2SensorType(string txt){
    if(llToLower(txt) == "agent") return AGENT;
    if(llToLower(txt) == "scripted") return SCRIPTED;
    if(llToLower(txt) == "passive") return PASSIVE;
    if(llToLower(txt) == "active") return ACTIVE;
    return -1;
}

//Date and time functions
string getClock(integer timezone){
    string am = "AM";
    integer t = (integer)llGetWallclock();
    integer hours = t / 3600;
    hours += 8;
    hours += timezone;
    if(hours > 12){
        hours -= 12;
        am = "PM";
    }
    integer minutes = (t % 3600) / 60;
    integer seconds = t % 60;
    
    string h = (string)hours;
    string m = (string)minutes;
    string s = (string)seconds;
    
    if(llStringLength(m) == 1){
        m = "0" + m;
    }
    if(llStringLength(s) == 1){
        s = "0" + s;
    }
    
    return h + ":" + m + ":" + s + " " + am;
}

integer getDate(string date){
    return (integer)llList2String(llParseString2List(date,["-"],[]),2);
}

integer getMonth(string date){
    return (integer)llList2String(llParseString2List(date,["-"],[]),1);
}

integer getYear(string date){
    return (integer)llList2String(llParseString2List(date,["-"],[]),0);
}

integer getDayNumber(string date){
    integer d = getDate(date);
    integer m = getMonth(date);
    integer y = getYear(date);
    
    y -= (14 - m) / 12;
    m += 12*((14 - m) / 12) - 2;
    
    return ((d + y + y/4 - y/100 + y/400 + (31*m)/12) % 7);
}

string getEaster(integer year){
    integer gNumber = (year % 19) + 1;
    integer century = year/100;
    integer H = (century - llRound(century / 4) - llRound((8 * century + 13) / 25) + 19 * gNumber + 15) % 30;
    integer I = H - llRound((H / 28)) * (1 - (llRound(29 / (H + 1))) * llRound((21 - gNumber) / 11));
    integer J = (year + llRound(year / 4) + I + 2 - century + llRound(century / 4)) % 7;
    
    integer L = I - J;
    integer month = 3 + llRound((L + 40) / 44);
    integer day = L + 28 - 31 * llRound(month / 4);
    
    return (string)day + "-" + (string)month + "-" + (string)year;
}

string getDayName(string date){
    list days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
    return llList2String(days,getDayNumber(date));
}

string getOrdinalDate(string date){
    string last = llGetSubString((string)getDate(date),-1,-1);
    if(last == "1") return "st";
    else if(last == "2") return "nd";
    else if(last == "3") return "rd";
    return "th";
}

string getMonthName(string date){
    list months = ["Smarch","January","February","March","April","May","June","July","August","September","October","November","December"];
    return llList2String(months,getMonth(date));
}

integer isEaster(string date){
    string easter = getEaster(getYear(date));
    if(easter == date)
        return TRUE;
    return FALSE;
}

integer isChristmas(string date){
    if(getDate(date) == 25 && getMonth(date) == 12)
        return TRUE;
    return FALSE;
}

integer isChristmasEve(string date){
    if(getDate(date) == 24 && getMonth(date) == 12)
        return TRUE;
    return FALSE;
}

integer isNewYearsEve(string date){
    if(getDate(date) == 31 && getMonth(date) == 12)
        return TRUE;
    return FALSE;
}

integer isNewYearsDay(string date){
    if(getDate(date) == 1 && getMonth(date) == 1)
        return TRUE;
    return FALSE;
}

I also make simple scripts and distribute them via a shoddy network vendor system I threw together. They're reprinted here for your convience.

Date and Time
[+/-] show/hide
float timezone = 0;


string clock(float timezone, integer military)
{
    integer raw = (integer)(llGetGMTclock() + (timezone * 3600));
    integer shiftraw = raw;
    
    if((timezone * 3600) + raw > 86400)
    {
        shiftraw = raw - 86400;
    }http://secondlife.com/badgeo/wakka.php?wakka=DolusNaumova/edit
Edit this page
    else if((timezone * 3600) + raw < 0)
    {
        shiftraw = raw + 86400;
    }
    
    integer hours = shiftraw / 3600;
    integer minutes = (shiftraw % 3600) / 60;
    integer seconds = shiftraw % 60;
    string ampm;
    
    //non-military time adjustments
    if(!military)
    {
        if(shiftraw < 43200)
        {
            ampm = " AM";
        }
        else
        {
            ampm = " PM";
            hours -= 12;
        }
    }
    
    string shours = (string)hours;
    string sminutes = (string)minutes;
    string sseconds = (string)seconds;
    
    //add zeros to single digit minutes/seconds
    if(llStringLength(sminutes) == 1)
    {
        sminutes = "0" + sminutes;
    }
    if(llStringLength(sseconds) == 1)
    {
        sseconds = "0" + sseconds;
    }
    
    string time = shours + ":" + sminutes + ":" + sseconds + ampm;
    
    return time;
}

default{
    state_entry(){
        llOwnerSay("Say 'date' for date, 'time' for time, and 'timezone' to set the timezone.");
        llListen(0,"",llGetOwner(),"");
    }
    on_rez(integer s){
        llResetScript();
    }
    listen(integer c, string n, key id, string msg){
        list m = llParseString2List(llToLower(msg),[" "],[]);
        string q = llList2String(m,0);
        if(q == "date"){
            llOwnerSay(llGetDate());
        }
        if(q == "time"){
            llOwnerSay(clock(timezone,0));
        }
        if(q == "timezone"){
            timezone = (float)llList2String(m,1);
        }
    }
}


A Simple Message Box
[+/-] show/hide
list _MESSAGES;
string spacer = "/?/";

default{
    state_entry(){
        llListen(10,"","","");
        llSetTimerEvent(600);
        llSetText("Messages can be left on channel ten.",<1,1,0>,1);
    }
    listen(integer channel, string name, key id, string message){
        if(id == llGetOwner()){
            if(message == "view"){
                integer i;
                integer l = llGetListLength(_MESSAGES);
                if(l == 0){ llOwnerSay("No messages"); return; }
                for(i; i < l; ++ i){
                    llOwnerSay(llList2String(_MESSAGES,i));
                }
            } else if(message == "backup"){ //For use with the hO Drive
                llMessageLinked(LINK_SET,0x20002,llDumpList2String(_MESSAGES,spacer),"save");
                llOwnerSay("Data backed up.");
            } else if(message == "restore"){ //For use with the hO Drive
                llMessageLinked(LINK_SET,0x20002,"","get");
            } else {
                _MESSAGES += "(" + llGetDate() + ") " + name + ": " + message;
            }
        } else {
            _MESSAGES += "(" + llGetDate() + ") " + name + ": " + message;
        }
    }
    timer(){//For use with the hO Drive
        llMessageLinked(LINK_SET,0x20002,llDumpList2String(_MESSAGES,spacer),"save");
    }
    link_message(integer sender, integer chan, string data, key extra){
        if(chan == 0x20002){
            _MESSAGES = llParseString2List(data,[spacer],[]);
            llOwnerSay("Data restored.");
        }
    }
}


Random Shape
[+/-] show/hide
(For use with a launcher)
float rand(float min, float max){
    float low;
    float high;
    if(min < 0){
        low = -llFrand(min);
        high = llFrand(max);
        if(llFrand(1) >= 0.5){
            return high;
        } else {
            return low;
        }
    } else {
        high = llFrand(max);
        return high;
    }
}

vector randVector(vector min, vector max){
    return <rand(min.x,max.x),rand(min.y,max.y),rand(min.z,max.z)>;
}

randParams(){
    integer i;
    integer l = llGetNumberOfSides();
    for(i = 0; i < l; ++i){
        llSetColor(randVector(<0,0,0>,<1,1,1>),i);
        llSetAlpha(rand(0,1),i);
    }
    float ecut = rand(0.2,1);
    float bcut = rand(0,ecut - 0.2);
    float ecutt = rand(0.2,1);
    float bcutt = rand(0,ecut - 0.2);
    llSetPrimitiveParams([PRIM_SIZE,randVector(<0.25,0.25,0.25>,<5,5,5>),
                                        PRIM_MATERIAL,llRound(rand(0,7)),
                                        PRIM_TYPE, llRound(rand(0,6)), 0, 
                                        <bcut, ecut, 0.0>, rand(0,.95), <rand(-180,180), rand(-180,180), 0.0>, 
                                        <rand(0.05,1), rand(0.05,1), 0.0>, <rand(0,0.5), rand(0,0.5), 0.0>, 
                                        <bcutt, ecutt, 0.0>, <rand(0,0.5), rand(0,0.5), 0.0>, rand(1,4), 0.0, 0.0]);
}

default{
    collision(integer d){
        llSetStatus(STATUS_PHYSICS,FALSE);
        randParams();
    }
    land_collision(vector p){
        llSetStatus(STATUS_PHYSICS,FALSE);
        randParams();
    }
    touch(integer d){
        randParams();
    }
}


Storage Box
[+/-] show/hide
Requires two prims and three scripts: One that sends a link message with "back" to the root, one that sends "next" to the root, and this one.
list _inventory;
integer _p = -1;

registerInventory(){
    integer i;
    integer l = llGetInventoryNumber(-1);
    for(i = 0; i < l; ++i){
        _inventory += llGetInventoryName(-1,i);
    }
}

string type2Name(integer type){
    if(type == 0){
        return "Texture";
    } else if(type == 1){
        return "Sound";
    } else if(type == 3){
        return "Landmark";
    } else if(type == 5){
        return "Clothing";
    } else if(type == 6){
        return "Object";
    } else if(type == 7){
        return "Notecard";
    } else if(type == INVENTORY_SCRIPT){
        return "Script";
    } else if(type == 13){
        return "Bodypart";
    } else if(type == 20){
        return "Animation";
    } else if(type == 21){
        return "Gesture";
    } else {
        return "Unknown";
    }
}

string mask2Name(integer mask){
    string o;
    if(mask == PERM_ALL){
        return "Move/Modify/Copy/Transfer";
    } else if(mask == PERM_COPY){
        o +=  "Copy/";
    } else if(mask == PERM_MODIFY){
        o +=  "Modify/";
    } else if(mask == PERM_TRANSFER){
        o +=  "Transfer/";
    } else if(mask == PERM_MOVE){
        o +=  "Move/";
    }
    o = llDeleteSubString(o,llStringLength(o) - 1,-1);
    return o;
}

default{
    state_entry(){
        registerInventory();
        llSetText("Current Inventory:\n"+llDumpList2String(_inventory,"\n")+"\n"+(string)llGetListLength(_inventory)+" total items.",<1,1,1>,1);
    }
    changed(integer c){
        if(c & CHANGED_INVENTORY){
            llResetScript();
        }
    }
    link_message(integer sender, integer num, string str, key id){
        if(str == "back"){
            --_p;
            if(_p == -1){
                _p = -2;
                llSetText("Current Inventory:\n"+llDumpList2String(_inventory,"\n")+"\n"+(string)llGetListLength(_inventory)+" total items.",<1,1,1>,1);
            } else if(_p < -1){
                _p = llGetListLength(_inventory) - 1;
                string perms;
                if(llGetCreator() == llGetOwner()){
                    perms = mask2Name(llGetInventoryPermMask(llList2String(_inventory,_p),1));
                } else {
                    perms = mask2Name(llGetInventoryPermMask(llList2String(_inventory,_p),1));
                }
                llSetText(llList2String(_inventory,_p) + "\n" + type2Name(llGetInventoryType(llList2String(_inventory,_p))) + "\n" + perms,<1,1,1>,1);
            } else {
                string perms;
                if(llGetCreator() == llGetOwner()){
                    perms = mask2Name(llGetInventoryPermMask(llList2String(_inventory,_p),1));
                } else {
                    perms = mask2Name(llGetInventoryPermMask(llList2String(_inventory,_p),1));
                }
                llSetText(llList2String(_inventory,_p) + "\n" + type2Name(llGetInventoryType(llList2String(_inventory,_p))) + "\n" + perms,<1,1,1>,1);
            }
        } else if(str == "next"){
            ++_p;
            if(_p >= llGetListLength(_inventory)){
                _p = -1;
                llSetText("Current Inventory:\n"+llDumpList2String(_inventory,"\n")+"\n"+(string)llGetListLength(_inventory)+" total items.",<1,1,1>,1);
            } else {
                string perms;
                if(llGetCreator() == llGetOwner()){
                    perms = mask2Name(llGetInventoryPermMask(llList2String(_inventory,_p),1));
                } else {
                    perms = mask2Name(llGetInventoryPermMask(llList2String(_inventory,_p),1));
                }
                llSetText(llList2String(_inventory,_p) + "\n" + type2Name(llGetInventoryType(llList2String(_inventory,_p))) + "\n" + perms,<1,1,1>,1);
            }
        }
    }
}





brace
CometAero
Contributors
DolusNaumova
eeped
ExampleHUDCommunication
forumreferences
HazVega
JimLinden
LibraryCameraFollower
LibraryVigenereCipher
RecursiveRezzing
RemovalPetition
ScriptLibrary
WikiFormatting
WikiUsers


<?php if(preg_match("/.+\n\{/i",$code)){ echo "Evil."; } ?>
Comments [Hide comments/form]
Um, once in a while I notice you make a change and don't actually make a change, is this accidental?
-- IceBrodie (2005-08-27 07:52:59)
Yes. Double-click editing, or I decide half-way through I don't actually need to.
-- DolusNaumova (2005-08-28 07:41:49)
For the parasite script, shouldn't
llSensorRepeat(,NULL_KEY, AGENT && SCRIPTED, sight, PI, 0.5);
be
llSensorRepeat(,NULL_KEY, AGENT|SCRIPTED, sight, PI, 0.5);
?
-- SchitsoMonkey (2005-08-28 08:16:02)
No, in fact, that won't work either way. I've compensated by using a collision_start() event.

Also, the script is slightly outdated. The most recent one is in-world, which I can't currently access.
-- DolusNaumova (2005-08-28 08:21:08)
Well, if you're trying to detect agents and objects, you could use:
llSensorRepeat("",NULL_KEY, AGENT|ACTIVE|PASSIVE, sight, PI, 0.5);
Unless you only want scripted objects to be detected, in which case you might be able to use two scripts with link messages?
-- SchitsoMonkey (2005-08-28 08:24:42)
Nope. That won't work. Check llSensorRepeat.
-- DolusNaumova (2005-08-28 08:27:27)
"August 24, 2005: Wrote and debugged the script. Lost three parasites, found them clinging onto some poor newbie." That's something I wish I'd seen. :D
-- CirrMarat (2005-09-04 10:52:13)
Dolus, how functional is the comm? Sorry I haven't been on SL much, GCSE Coursework -_-
-- SevenEightTwo (2005-09-21 02:38:19)
It works. All the features are completely functional (as far as I can tell), but like I said, the project is scrapped.

If you want the script, though, contact me in world.
-- DolusNaumova (2005-09-25 09:06:39)
Dolus, I would quite like that script too if that is OK with you? If you are online now i will IM you.
-- HazVega (2006-03-27 07:45:10)
Attach a comment to this page: