Difference between revisions of "User:ANSI Soderstrom"

From Second Life Wiki
Jump to navigation Jump to search
Line 289: Line 289:
         LIST = PUT(LIST,[1234],["Second Value"]);     
         LIST = PUT(LIST,[1234],["Second Value"]);     
      
      
         llSay(0,llList2CSV(LIST));   // Output : 1234, First Value, 1234, Second Value
        test = llList2CSV(LIST);
         llSay(0,test);                 // Output : 1234, First Value, 1234, Second Value
          
          
         llSay(0,GET(LIST,["1234"])); // Output : First Value
         llSay(0,GET(LIST,["1234"])); // Output : First Value

Revision as of 19:28, 24 February 2010

i am alive ! ...and have for you :

A #Simple Copy Protection for your Scripts.

A #Simple LSL Array for your Scripts.
























Simple LSL Copy Protection for your Scripts (best give away as no mod) :

<lsl> // Simple Copy Protection for your Items // (C) 10/2009 ANSI Soderstrom

default {

   state_entry() {
       if(llGetCreator() != "9adba1b4-a733-4a44-8275-f4a666784d8c") {  // ANSI Soderstrom
           llOwnerSay("Script: " + llGetScriptName() + ":");
           llOwnerSay("Sorry, my Scripts are only running in MY Items");
           llOwnerSay("Greetings, ANSI Soderstrom");
           // llDie();
       } else {
           state online;
       }      
   }
   on_rez(integer i) {
       llResetScript();
   }

}

state online {

   state_entry() {
       // your Code
   }   
   
   on_rez(integer i) {
       llResetScript();
   }    

} </lsl>



Simple LSL Array for your Scripts :

<lsl> // Simple LSL Array for your Scripts (useful but slow) // (C) 02/2010 ANSI Soderstrom

list SOMELIST;

string GET(list ARRAY,list KEY) {

   if(!llGetListLength(KEY)>1) {
      // dont allow lists in lists
      return "-1";
   }
   integer position;
   do {
       position = llListFindList(ARRAY, KEY);
       if(position%2 && ~position && position) {
           ARRAY = llDeleteSubList(ARRAY,0,position);
       } 
   } while (~position  && position%2);
   if(~position) {
       return llList2String(ARRAY,position+1);
   } else {
       return "0";
   } 

}

list PUT(list ARRAY,list KEY, list VALUE) {

   if(llGetListLength(KEY)>1 || llGetListLength(VALUE)>1) {
       // dont allow lists in lists
       return [-1];
   }  
   integer position = llListFindList(ARRAY, KEY);
   list helparray = [];
   do {
       if(!~position) { 
           ARRAY += KEY;
           ARRAY += VALUE;
           return helparray + ARRAY;
       }        
       if(position%2 && ~position && position) {
           helparray += llList2List(ARRAY,0,position);
           ARRAY = llDeleteSubList(ARRAY,0,position);
       } 
       position = llListFindList(ARRAY, KEY);        
   } while (position%2);
   ARRAY = llListReplaceList(ARRAY, VALUE, position + 1, position + 1);
   return helparray + ARRAY;   

}

default {

   state_entry() {        

       // --------------------------------------------------------------------------------
        
       SOMELIST = PUT(SOMELIST,["KEY"],["VALUE"]);
       SOMELIST = PUT(SOMELIST,[AGENT],[<1,1,1>]);
       SOMELIST = PUT(SOMELIST,["TEST"],["VALUE"]);
       SOMELIST = PUT(SOMELIST,["VALUE"],["TEST"]);

       llSay(0,GET(SOMELIST,["KEY"]));     // Output : VALUE
       llSay(0,GET(SOMELIST,[AGENT]));     // Output : <1.000000, 1.000000, 1.000000>
       llSay(0,GET(SOMELIST,["TEST"]));    // Output : VALUE
       llSay(0,GET(SOMELIST,["VALUE"]));   // Output : TEST
       
       // --------------------------------------------------------------------------------
       
       SOMELIST = PUT(SOMELIST,["KEY"],["9adba1b4-a733-4a44-8275-f4a666784d8c"]);
       SOMELIST = PUT(SOMELIST,[AGENT],["unknown"]);
       SOMELIST = PUT(SOMELIST,["TEST"],["TEST"]);
       SOMELIST = PUT(SOMELIST,["VALUE"],["VALUE"]);

       llSay(0,GET(SOMELIST,["KEY"]));     // Output : 9adba1b4-a733-4a44-8275-f4a666784d8c
       llSay(0,GET(SOMELIST,[AGENT]));     // Output : unknown
       llSay(0,GET(SOMELIST,["TEST"]));    // Output : TEST
       llSay(0,GET(SOMELIST,["VALUE"]));   // Output : VALUE      

       // --------------------------------------------------------------------------------
        
       // AGENT is a static integer with the value 1
       SOMELIST = PUT(SOMELIST,[1],["AGENT"]); 
       
       llSay(0,GET(SOMELIST,[AGENT]));     // Output : AGENT
               
       // --------------------------------------------------------------------------------        
         
       // "AGENT" and AGENT are different
       if(!(integer)GET(SOMELIST,["AGENT"])) {
           llSay(0,"Not in List");
       } else {
           llSay(0,"Found");
       }
       // Output : Not in List
       
       // --------------------------------------------------------------------------------
               
       // case sensitive KEY´s
       SOMELIST = PUT(SOMELIST,["AGENT"],[NULL_KEY]);
       SOMELIST = PUT(SOMELIST,[AGENT],[ZERO_ROTATION]);
        
       llSay(0,GET(SOMELIST,["agent"]));   // Output : 0
       llSay(0,GET(SOMELIST,["AGENT"]));   // Output : 00000000-0000-0000-0000-000000000000
       llSay(0,GET(SOMELIST,[AGENT]));     // Output : <0.000000, 0.000000, 0.000000, 1.000000>
       
       // --------------------------------------------------------------------------------        
       
       // Let us play...
       SOMELIST = PUT(SOMELIST,[AGENT],llGetObjectDetails(GET(SOMELIST,["KEY"]),([OBJECT_NAME])));   

       llSay(0,GET(SOMELIST,["KEY"])); // Output : 9adba1b4-a733-4a44-8275-f4a666784d8c
       llSay(0,GET(SOMELIST,[AGENT])); // Output : ANSI Soderstrom  

       // --------------------------------------------------------------------------------   
        
       llSay(0,GET(SOMELIST,["NotInList"])); 
       // Output : 0
       
       // --------------------------------------------------------------------------------           

       // Not in List is not in list
       if(!(integer)GET(SOMELIST,["Not In List"])) {
           llSay(0,"Not in List");
       } else {
           llSay(0,"Found");
       }
       // Output : Not in List
       
       // --------------------------------------------------------------------------------           

       // ANSI Soderstrom is not a KEY, only a VALUE
       if(!(integer)GET(SOMELIST,["ANSI Soderstrom"])) {
           llSay(0,"Not in List");
       } else {
           llSay(0,"Found");
       } 
       // Output : Not in List  
       
       // --------------------------------------------------------------------------------           
       
       // KEY is a KEY and have a VALUE
       if(!(integer)GET(SOMELIST,["KEY"])) {
           llSay(0,"Not in List");
       } else {
           llSay(0,"Found");
       } 
       // Output : Found        
       
       // -------------------------------------------------------------------------------- 
       
       llSay(0,llList2CSV(SOMELIST));
       /*
           Output :    KEY,    9adba1b4-a733-4a44-8275-f4a666784d8c, 
                       1,      ANSI Soderstrom, 
                       TEST,   TEST, 
                       VALUE,  VALUE, 
                       AGENT,  00000000-0000-0000-0000-000000000000  
       */    
       // -------------------------------------------------------------------------------- 
       // Extended behavior

       list WHITELIST;
       list BLACKLIST;
             
       WHITELIST = [   "1234","ANSI Soderstrom",
                       "4321","Other Name"
                   ];
                                                             
       BLACKLIST = [   "9876","Invisible Linden",
                       "6789","Visible Linden"
                   ];
       
       // Does NOTHING (no Target List)
       PUT(WHITELIST,["1234"],["Any Value"]);             
       
       // Dont touch the Blacklist...
       // Overwrite Whitelist with Blacklist AND CHANGE the Value of the given Name in the Whitelist
       // (because KEY is in Blacklist)        
       WHITELIST = PUT(BLACKLIST,["9876"],["Changed Name"]); 
       llOwnerSay(llList2CSV(WHITELIST));  // Whitelist : 9876, Changed Name, 6789, Visible Linden
       
       // Dont touch the Blacklist...
       // Overwrite Whitelist with Blacklist AND ADD the given KEY/VALUE to Whitelist
       // (because KEY is not in Blacklist)              
       WHITELIST = PUT(BLACKLIST,["1234"],["Any Value"]);
       llOwnerSay(llList2CSV(WHITELIST));  // Whitelist : 9876, Invisible Linden, 6789, Visible Linden, 1234, Any Value


       // -------------------------------------------------------------------------------- 
       // more complex...
       
       list LIST;  
       list TEST;
       string test;
       
       LIST = PUT(LIST,["1234"],["First Value"]);  
       LIST = PUT(LIST,[1234],["Second Value"]);     
   
       test = llList2CSV(LIST);
       llSay(0,test);                  // Output : 1234, First Value, 1234, Second Value
       
       llSay(0,GET(LIST,["1234"])); // Output : First Value
       llSay(0,GET(LIST,[1234]));   // Output : Second Value   
       
       TEST = llCSV2List(test);
       llSay(0,llList2CSV(TEST));      // Output ; 1234, First Value, 1234, Second Value
       
       // ARRAY BROKEN AFTER llList2CSV(); !!!
       llSay(0,GET(TEST,["1234"]));    // Output : First Value
       llSay(0,GET(TEST,[1234]));      // Output : 0   
       // -------------------------------------------------------------------------------- 
       /* 
       Now you can manage your Settings simple...
       list SETTINGS;
       SETTINGS = PUT(SETTINGS,["owner"],[llGetOwner()]);
       SETTINGS = PUT(SETTINGS,["POS"],[llGetPos()]);
       
       list API;
       API = PUT(API,["I_HAVE_THE_SETTINGS"],[-34234242]);
       llMessageLinked(LINK_SET,(integer)GET(API,["I_HAVE_THE_SETTINGS"]),llList2CSV(SETTINGS),llGetOwner());
       // -------------------------------------------------------------------------------- 
       list SETTINGS;
       list API;
       API = PUT(API,["I_HAVE_THE_SETTINGS"],[-34234242]);
       link_message(integer sender_num, integer num, string str, key id) {
           // receive a valid message for this state AND a further Copy Protection
           if(id==llGetCreator() && num==(integer)GET(API,["I_HAVE_THE_SETTINGS"]) {
               SETTINGS = llCSV2List(str);
           } // if     
       } // link_message  
     
       */
   } 

}

</lsl>