Linden text version 2
{
LLEmbeddedItems version 1
{
count 0
}
Text length 17077
/* LAND EDITOR (OS Version) 2.1
   Based on the Second Life Land Leveller created by Jim Lanate
   and shared by Nebadon Izumi on the OSGrid Forums 
   (see https://forums.osgrid.org/viewtopic.php?t=364 )
   Revised by Laura Ess December 2019.
   See LAND EDITOR 2.1 NOTES for a list of updates and changes
   and LAND EDITOR 2.1 HELP  for help on how to use this tool
*/

integer CHANNEL; 
// Used only for first rezz & resets.
// Change for your own defaults
integer Action     = LAND_LEVEL;
string  ActionText = "NOT SET";
string  BrushText  = "Medium";
integer BrushSize  = 1;
integer PrimSize   = 4;
float   sideScale  = 0.5;
string  Mode       = "OFF";
string  SkinName   = "Colour"; 

integer InitDone   = FALSE; 
integer InitStyles = FALSE;
integer listen_handle;

// Used for ONCE mode.
integer Touched = TRUE;

// Used for MOVE mode
vector PositionOld;
vector PositionNew;
 
// Floating Title colour definitions
vector TitleOFF    = <1.000, 1.000, 1.000>;  // WHITE
vector TitleONCE   = <0.004, 1.000, 0.439>;  // LIME
vector TitleMOVE   = <1.000, 0.863, 0.000>;  // YELLOW
vector TitleON     = <1.000, 0.255, 0.212>;  // RED
vector TitleCOLOUR = <1.000, 1.000, 1.000>;
string TitleTEXT;

// Default/Current skin set (a copy of the Colour skin set)
string skin0Name    = "Colour";
key    skin0        = "e7cd870a-5064-420e-9f99-f888e2ea978f";
key    skin0Blank   = "e7cd870a-5064-420e-9f99-f888e2ea978f";
key    skin0Flatten = "4e8d9ddf-054e-4e15-97c0-6277ab530a70";
key    skin0Lower   = "3fe212d2-85d1-4f61-bd83-c211080819ba";
key    skin0Noise   = "0d39e78c-7884-496a-a738-0c1d02cd2186";
key    skin0Raise   = "a8fb08d1-4a8c-4506-b483-efac5c5ded38";
key    skin0Revert  = "3eac5786-10bd-426b-826d-1096fcc43443";
key    skin0Smooth  = "9eacb93e-ccee-4d06-a723-88f71ce725a7";

// UUIDs for Colour Skins (Default)
string skin1Name    = "Colour";
key    skin1        = "e7cd870a-5064-420e-9f99-f888e2ea978f";
key    skin1Blank   = "e7cd870a-5064-420e-9f99-f888e2ea978f";
key    skin1Flatten = "4e8d9ddf-054e-4e15-97c0-6277ab530a70";
key    skin1Lower   = "3fe212d2-85d1-4f61-bd83-c211080819ba";
key    skin1Noise   = "0d39e78c-7884-496a-a738-0c1d02cd2186";
key    skin1Raise   = "a8fb08d1-4a8c-4506-b483-efac5c5ded38";
key    skin1Revert  = "3eac5786-10bd-426b-826d-1096fcc43443";
key    skin1Smooth  = "9eacb93e-ccee-4d06-a723-88f71ce725a7";

// UUIDs for Symbol skins 
string skin2Name    = "Symbol";
key    skin2        = "72bf2d0c-abb2-43ac-abc6-68e2383d1cc8";
key    skin2Blank   = "72bf2d0c-abb2-43ac-abc6-68e2383d1cc8";
key    skin2Flatten = "8cfa3083-2e1c-4698-9a35-d58ecbbca25e";
key    skin2Lower   = "6f87ae57-a573-415f-b4c8-379e074c08ed";
key    skin2Noise   = "3abb0ce1-d061-4589-82f7-fd4256dd7075";
key    skin2Raise   = "5487f9aa-c07f-49ca-8bfd-81a94626603c";
key    skin2Revert  = "4b354694-2166-4de6-badd-15181d1b40fd";
key    skin2Smooth  = "0965b133-899c-4d5a-a3ce-b6bc2e4ffa9b";

// UUIDs for Mono skins 
string skin3Name    = "Mono";
key    skin3        = "be0631c8-2b12-4d0c-894a-155effe40e56";
key    skin3Blank   = "be0631c8-2b12-4d0c-894a-155effe40e56";
key    skin3Flatten = "65fe01da-b60e-4300-a3f8-e44e2a4d9263";
key    skin3Lower   = "30ddb2de-c67f-41e7-93ed-3b22c44505bd";
key    skin3Noise   = "79653e24-a1f6-484f-82ee-8aaa2f18358d";
key    skin3Raise   = "134adb57-1b47-42ac-a81a-84fc2beeaa82";
key    skin3Revert  = "b37e05b0-fdee-4f84-a76c-20414b164736";
key    skin3Smooth  = "f750a60f-12f8-414c-a1fb-cabdae28756e";

// Example for adding definitions for extra skin
// string skin4Name    = "-4-";
// key    skin4        = "";
// key    skin4Blank   = "";
// key    skin4Flatten = "";
// key    skin4Lower   = "";
// key    skin4Noise   = "";
// key    skin4Raise   = "";
// key    skin4Revert  = "";
// key    skin4Smooth  = "";

// MAIN MENU, bottom row to top row
string MainMenuString = "Pick an ACTION, MODE or SIZE";         
list   MainMenuList = [
    "OFF", "Ground", "(OPTIONS)",
    "ONCE","Lower",  "Revert",
    "MOVE","Flatten","Smooth",
    "ON",  "Raise",  "Noise"
        ];

// OPTIONS MENU
string OptionsMenuString = "Change the Land Editor's SIZE or SKIN,\n"+ 
                           "read User HELP, Release NOTES,\n" +
                           "or BACK to cancel";
// Standard six buttons
// The other 1 to 6 buttons are generated by skin themes. 
list       OptionsMenuList = [
            "Back", "User HELP", "Release INFO",
            "Small (2x2)", "Medium (4x4)","Large (8x8)"
        ];

// Round Decimals Function
string FormatDecimal(float number, integer precision)
    {    
        float roundingValue = llPow(10, -precision)*0.5;
        float rounded;
        if (number < 0) rounded = number - roundingValue;
        else           rounded = number + roundingValue;
        if (precision < 1) // Rounding integer value
        {
            integer intRounding = (integer)llPow(10, -precision);
            rounded = (integer)rounded/intRounding*intRounding;
            precision = -1; // Don't truncate integer value
        }
        string strNumber = (string)rounded;
        return llGetSubString(strNumber, 0, llSubStringIndex(strNumber, ".") + precision);
    }

// Update Floating Title Function
update_Title(string mode_type){
        float landHeight = llGround(ZERO_VECTOR);
        // Round pos to 4 decimal places
        string Xfour = FormatDecimal(PositionNew.x,4);
        string Yfour = FormatDecimal(PositionNew.y,4);
        string Zfour = FormatDecimal(PositionNew.z,4);
        string Lfour = FormatDecimal(landHeight,4);
        TitleTEXT =   "~~~~~~~~~~\n"
                    + ActionText + " (" + mode_type + ") " + BrushText +"\n" 
                    + "X: " + Xfour + "\n"
                    + "Y: " + Yfour + "\n"
                    + "Z: " + Zfour + "\n \n"
                    + "L: " + Lfour + "\n~~~~~~~~~~\n:";
        llSetText( TitleTEXT, TitleCOLOUR, 1.0 );     
    }

// Update Skin & Size Function
update_skin (key skin, string mode_type, integer size) {
    llSetPrimitiveParams([ 
        PRIM_SIZE, <size, size, 0.75>,
        PRIM_TEXTURE, 0, skin, <sideScale,sideScale,1>, <0,0,0>,0,
        PRIM_COLOR, 5, <0, 0, 0>, 1 
    ]);
    if (Mode == "OFF") {
        llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1, 1, 1>,0.5]);
    } else {
        llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1, 1, 1>,1.0]);
    }
    // Set sides of prim with current action skin
    integer faceLoop = 1;
    for(; faceLoop < 5; ++faceLoop)
        llSetPrimitiveParams([ PRIM_TEXTURE, faceLoop, skin, <sideScale,0.2,1>, <0,0,0>,0]);        
}

default
{
    state_entry()    
    {
        if (InitDone == FALSE)
        {
            llSay(0, "Script Initialised");
            OptionsMenuList  += [ 
// Comment/Uncomment to hide/add Skins to the OPTIONS menu
                                skin1Name 
                                ,skin2Name 
                                ,skin3Name
                                //,skin4Name
                                //,skin5Name
                                //,skin6Name
                                ]; 
            InitStyles = TRUE;
            InitDone = TRUE;
            update_Title(Mode);
            update_skin (skin0, Mode, PrimSize);
        }

        CHANNEL = llFloor(llFrand(100000.0)) + 1000;
        llListen(CHANNEL, "", NULL_KEY, "");
    }

    touch_start(integer num_detected)
    {
        if (llDetectedOwner(0) == llGetOwner())
        {
            llDialog(llDetectedKey(0), MainMenuString, MainMenuList, CHANNEL);
        }
    }

    listen(integer CHANNEL, string name, key id, string message)
    {
        if (llListFindList(MainMenuList + OptionsMenuList, [message]) != -1) // verify dialog choice
        {
            if (message == "(OPTIONS)")
            {
                llDialog(id, OptionsMenuString, OptionsMenuList, CHANNEL);
            }

            if (message == "Flatten")
            {
                Action = LAND_LEVEL;
                ActionText ="Flatten";                
                skin0 = skin0Flatten;
                skin1 = skin1Flatten;
                skin2 = skin2Flatten;
                skin3 = skin3Flatten;
                // Example of adding code for extra skins
                // skin4 = skin4Flatten;
                // skin5 = skin5Flatten;
                // skin6 = skin6Flatten;
                update_Title(Mode);
                update_skin (skin0, Mode, PrimSize);
                Touched = TRUE;
                llSetTimerEvent(0.1);
            }

            if (message == "Raise")
            {
                Action = LAND_RAISE;
                ActionText ="Raise";
                skin0 = skin0Raise;
                skin1 = skin1Raise;
                skin2 = skin2Raise;
                skin3 = skin3Raise;
                update_Title(Mode);
                update_skin (skin0, Mode, PrimSize);
                Touched = TRUE;
                llSetTimerEvent(0.1);
            }

            if (message == "Lower")
            {
                Action = LAND_LOWER;
                ActionText ="Lower";
                skin0 = skin0Lower;
                skin1 = skin1Lower;
                skin2 = skin2Lower;
                skin3 = skin3Lower;
                update_Title(Mode);
                update_skin (skin0, Mode, PrimSize);
                Touched = TRUE;
                llSetTimerEvent(0.1);
            }

            if (message == "Smooth")
            {
                Action = LAND_SMOOTH;
                ActionText ="Smooth";
                skin0 = skin0Smooth;
                skin1 = skin1Smooth;
                skin2 = skin2Smooth;
                skin3 = skin3Smooth;
                update_Title(Mode);
                update_skin (skin0, Mode, PrimSize);
                Touched = TRUE;
                llSetTimerEvent(0.1);
            }

            if (message == "Noise")
            {
                Action = LAND_NOISE;
                ActionText ="Noise";
                skin0 = skin0Noise;
                skin1 = skin1Noise;
                skin2 = skin2Noise;
                skin3 = skin3Noise;
                update_Title(Mode);
                update_skin (skin0, Mode, PrimSize);
                Touched = TRUE;
                llSetTimerEvent(0.1);
            }

            if (message == "Revert")
            {
                Action = LAND_REVERT;
                ActionText ="Revert";
                skin0 = skin0Revert;
                skin1 = skin1Revert;
                skin2 = skin2Revert;
                skin3 = skin3Revert;
                update_Title(Mode);
                update_skin (skin0, Mode, PrimSize);
                Touched = TRUE;
                llSetTimerEvent(0.1);
            }

            if (message == "Small (2x2)")
            {
                // Brush       = LAND_SMALL_BRUSH;
                BrushText ="Small";
                BrushSize = 0;
                PrimSize  = 2;
                sideScale = 0.25;
                update_Title(Mode);
                update_skin (skin0, Mode, PrimSize);
            }
            
            if (message == "Medium (4x4)")
            {
                // Brush        = LAND_MEDIUM_BRUSH;
                BrushText = "Medium";
                BrushSize = 1;
                PrimSize  = 4;
                sideScale = 0.5;
                update_Title(Mode);
                update_skin (skin0, Mode, PrimSize);
            }

            if (message == "Large (8x8)")
            {
                // Brush        = LAND_LARGE_BRUSH;
                BrushText = "Large";
                BrushSize = 2;
                PrimSize  = 8;
                sideScale = 1.0;
                update_Title(Mode);
                update_skin (skin0, Mode, PrimSize);
            }

            // Change to skin1 (Colour Theme)
            if (message == skin1Name)
            {
                SkinName    = skin1Name;
                update_Title(Mode);
                skin0= skin1;
                update_skin (skin0, Mode, PrimSize);
                skin0Blank   = skin1Blank  ;
                skin0Flatten = skin1Flatten;
                skin0Lower   = skin1Lower  ;
                skin0Noise   = skin1Noise  ;
                skin0Raise   = skin1Raise  ;
                skin0Revert  = skin1Revert ;
                skin0Smooth  = skin1Smooth ;
            }

            // Change to Skin (Symbol Theme)
            if (message == skin2Name)
            {
                SkinName    = skin3Name;
                update_Title(Mode);
                skin0= skin3;
                update_skin (skin0, Mode, PrimSize);
                skin0Blank   = skin3Blank  ;
                skin0Flatten = skin3Flatten;
                skin0Lower   = skin3Lower  ;
                skin0Noise   = skin3Noise  ;
                skin0Raise   = skin3Raise  ;
                skin0Revert  = skin3Revert ;
                skin0Smooth  = skin3Smooth ;
            }

            // Change to skin3 (Mono Theme)
            if (message == skin3Name)
            {
                SkinName    = skin2Name;
                update_Title(Mode);
                skin0= skin2;
                update_skin (skin0, Mode, PrimSize);
                skin0Blank   = skin2Blank  ;
                skin0Flatten = skin2Flatten;
                skin0Lower   = skin2Lower  ;
                skin0Noise   = skin2Noise  ;
                skin0Raise   = skin2Raise  ;
                skin0Revert  = skin2Revert ;
                skin0Smooth  = skin2Smooth ;
            }

            // Change to Skin4 Blamk example
            // if (message == skin4Name)
            // {
            //     SkinName    = skin4Name;
            //     update_Title(Mode);
            //     skin0= skin4;
            //     update_skin (skin0, Mode, PrimSize);
            //     skin0Blank   = skin4Blank  ;
            //     skin0Flatten = skin4Flatten;
            //     skin0Lower   = skin4Lower  ;
            //     skin0Noise   = skin4Noise  ;
            //     skin0Raise   = skin4Raise  ;
            //     skin0Revert  = skin4Revert ;
            //     skin0Smooth  = skin4Smooth ;
            // }

            if (message == "User HELP")
            {
                llGiveInventory(id, "LAND EDITOR HELP");
            }            

            if (message == "Release INFO")
            {
                llGiveInventory(id, "LAND EDITOR NOTES");
            }            

            if (message == "OFF")
            {
                Mode        = "OFF";
                TitleCOLOUR = TitleOFF;
                update_Title(Mode);
                llSetPrimitiveParams([
                    PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
                    PRIM_COLOR, ALL_SIDES, <1, 1, 1>, 0.5 
                ]);
            }

            if (message == "ONCE")
            {
                Mode        = "ONCE";
                TitleCOLOUR = TitleONCE;
                update_Title(Mode);
                llSetPrimitiveParams([
                    PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
                    PRIM_COLOR, ALL_SIDES, <1, 1, 1>, 1 
                ]);
            }


            if (message == "MOVE")
            {
                Mode        = "MOVE";
                TitleCOLOUR = TitleMOVE;
                update_Title(Mode);
                vector PositionOld = llGetPos();
                vector PositionNew = llGetPos();
                llSetPrimitiveParams([
                    PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
                    PRIM_COLOR, ALL_SIDES, <1, 1, 1>, 1 
                ]);
            }

            if (message == "ON")
            {
                Mode        = "ON";
                TitleCOLOUR = TitleON;
                update_Title(Mode);
                llSetPrimitiveParams([ 
                    PRIM_FULLBRIGHT, ALL_SIDES, TRUE, 
                    PRIM_COLOR, ALL_SIDES, <1, 1, 1>, 1 
                ]);
            }

            if (message == "Ground")
            {
                // THIS PORTION BY STRIFE ONIZUKA //
                float height = llGround(ZERO_VECTOR);
                vector pos = llGetPos();
                integer count = llCeil(llFabs(height - pos.z) / 10.0);
                pos.z = height;
                //for(;count;--count)
                llSetPos(pos);
                // THANK YOU STRIFE! //
                llSetTimerEvent(0.1);
            }
        }
    }

    timer()
    {
        PositionOld = PositionNew;
        PositionNew = llGetPos();
            update_Title(Mode);

        if (Mode == "ON") {
            llModifyLand((integer)Action, (integer)BrushSize);
            llSetTimerEvent(0.1);
        };
        if (Mode == "MOVE" && PositionNew != PositionOld) {
                llModifyLand((integer)Action, (integer)BrushSize);
                llSetTimerEvent(0.1);
        };
        if (Mode == "ONCE" && Touched == TRUE) {
            llModifyLand((integer)Action, (integer)BrushSize);
            Touched = FALSE;
            llSetTimerEvent(0.1); 
        };
    }
}

// [END OF SCRIPT]
 }
 