Second Life/Selfreplication: Unterschied zwischen den Versionen

aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Zur Navigation springenZur Suche springen
K
K (+kat.)
 
(4 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 1: Zeile 1:
// The ttl variable is a counter, decreased for each subsequent replication,
+
== sourcecode ==
// the child that get rezzed with a ttl value of zero will not procreate.
 
  
integer ttl = 3;
+
=== selfrep.lsl ===
  
 +
// Global variables
 +
integer gintGeneration;                    // The Generation we are. Iterates with each replication.
 +
integer gintMaxGeneration = 5;              // Maximum allowed Generations. Replication stops at this Generation-Count.
 +
   
 +
vector gvecStandardNull = <9.5,0,0>;        // Position to rez Object to.
 +
rotation grotStandardNull = <0,0,0,0.0>;    // Rotation to rez Object to.
 +
 
 +
rez_child()
 +
{
 +
    // Check if we're allowed to create any more offspring
 +
    //llSay(0, "ok, rez!");
 +
    if(gintGeneration < gintMaxGeneration)
 +
    {
 +
        // Satellite still over my land? 
 +
        if (llOverMyLand(llGetKey())) {
 +
            // if yes, rez the inventory-item at the distance of standardnull in front of us.
 +
            llRezObject("Metastasis Unit", (gvecStandardNull*llGetRot())+llGetPos(), ZERO_VECTOR, llGetRot(), gintGeneration+1);
 +
        }
 +
    }
 +
}
 +
 
 +
default
 +
{
 +
    // llRezObject throws event object_rez on the parent with the offspring as parameter 
 +
    object_rez(key child)
 +
    {
 +
        // Give copy of child to child
 +
        llGiveInventory(child, llKey2Name(child)); 
 +
    }
 +
   
 +
    // When rezzed, the event on_rez is called on me as the child
 +
    on_rez(integer pintGeneration)
 +
    {
 +
       
 +
        // Save child (this one) ttl;
 +
        gintGeneration = pintGeneration;
 +
       
 +
        // show the generation
 +
        llSetText((string)gintGeneration,<1,1,1>,1.0);
 +
        // llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
 +
    }
 +
 
 +
    link_message(integer sender_num, integer num, string msg, key id) {
 +
        if (msg == "replicate") {
 +
            rez_child();
 +
        }
 +
    }
 +
}
  
  
rez_child()
+
=== sensor.lsl ===
{
 
  // Check if we're allowed to create any more offspring
 
  if(ttl > 0)
 
  {
 
      // Offspring ttl should be one closer to zero
 
      integer ttl_child = ttl - 1;
 
      // Rez child one meter above me
 
      llRezObject("1000er", llGetPos()+<1.5,0,0>, <0,0,0>, llEuler2Rot(<0,90,0> * DEG_TO_RAD) , ttl_child);
 
  }
 
}
 
  
  
default
+
// boolean that keeps aggro/friendly mode.
{
+
integer intState = FALSE;
   // If you touch me, we'll have babies!
+
 
   touch_start(integer total_number)
+
// the index for the
   {
+
integer intListenPointer = 0;
      rez_child();
+
  }
+
// all needed rotations for a crystalline-form in an array
 
+
list glRotations = [
 
+
    // the six 2D-Plane rotations
  // llRezObject throws event object_rez on the parent with the offspring as parameter 
+
    <0,0,0>,
   object_rez(key child)  
+
    <0,0,60>,
  {  
+
    <0,0,120>,
      // Give copy of child to child
+
    <0,0,180>,
       llGiveInventory(child, llKey2Name(child));  
+
    <0,0,240>,
  }  
+
    <0,0,300>,
 +
   
 +
    // the three upper rotations
 +
  <35,315,45>,
 +
  <35,45,135>,
 +
  <305,0,270>,
 +
 
 +
   // the three lower rotations
 +
  <35,315,225>,
 +
  <35,45,315>,
 +
  <305,0,90>
 +
  ];
 +
   
 +
   
 +
// the rotation-function.
 +
// rotates the entity to object to the next position in the global Rotations-Array
 +
object_rotateby() {
 +
         
 +
    rotation rotDelta;
 +
    rotation new_rot;    
 +
    integer intZufall =  (integer)llFrand(11.9);
 +
   
 +
    rotDelta = llEuler2Rot( llList2Vector(glRotations,intZufall) *  DEG_TO_RAD );
 +
    new_rot = ZERO_ROTATION * rotDelta;
 +
    llSetRot(new_rot);
 +
     
 +
    intListenPointer = intListenPointer + 1;
 +
    if (intListenPointer >= 11) intListenPointer = 0;
 +
}
 +
   
 +
object_init(integer pintOldPointer) {
 +
    llSetStatus(STATUS_PHYSICS,FALSE);
 +
    llListenRemove(pintOldPointer);
 +
    intListenPointer = llListen(0, "", llGetOwner(), "");
 +
    llSetTimerEvent(15);
 +
}
 +
    
 +
default
 +
{
 +
 
 +
    state_entry()
 +
    {
 +
        object_init(intListenPointer);
 +
    }
 +
   
 +
    on_rez(integer pintGeneration)
 +
    {
 +
        object_init(intListenPointer);
 +
       
 +
        if (pintGeneration>0) {
 +
        // Children are aggro.
 +
              intState = TRUE;
 +
        }
 +
    }
 +
   
 +
    sensor(integer total_number) // total_number is the number of avatars detected.
 +
    {
 +
        //llWhisper(0, (string)total_number + " debris-items detected - rotate 60 degrees" );
 +
        //object_rotateby();
 +
    }
 +
    
 +
    no_sensor() {
 +
       
 +
        if (intState) {
 +
            //llSay(0, "No debris detected, replicate");
 +
          llMessageLinked(LINK_THIS, 0, "replicate", "");
 +
        }
 +
    }
 +
   
 +
    // Because of the script-delay we have to connect the grand-child rezzing
 +
    // to the 'changed' event, which happens when someone (the parent) has
 +
    // given me (as the child) something (a copy of myself)
 +
    changed(integer change)
 +
    {
 +
        if(change == CHANGED_INVENTORY)
 +
        {
 +
          // rez_child();        
 +
        }
 +
    }
 +
       
 +
    timer() {
 +
        if (intState) {
 +
            object_rotateby();  
 +
            llSensor("Metastasis Unit","", SCRIPTED, 12.5, PI_BY_TWO / 3);
 +
        }
 +
    }
 
    
 
    
 
+
    listen( integer channel, string name, key id, string message ){
   // When rezzed, the event on_rez is called on me as the child
+
       
  on_rez(integer ttl_in)
+
        if (message == "metastasis off") {
   {
+
            intState = FALSE;
      // Save child (this one) ttl;
+
            llSay(0, "Metastasis Unit offline: Service shutdown");
      ttl = ttl_in;
+
        } else if (message == "metastasis on") {
  }
+
            intState = TRUE;   
 +
            llSay(0, "Metastasis Unit online: Service up");
 +
        } else if (message == "metastasis fall") {
 +
            intState = FALSE;   
 +
            llSay(0, "Metastasis Unit physics enabled");
 +
            llSetStatus(STATUS_PHYSICS,TRUE);
 +
        } else if (message == "metastasis delete") {
 +
            intState = FALSE;    
 +
            llSay(0, "Metastasis Unit self suicide");
 +
            llDie();
 +
        }
 +
    }
 +
         
 +
    // another quite funny feature.
 +
    //collision_start( integer num_detected) {
 +
    //    
 +
    //   llSetStatus(STATUS_PHYSICS,TRUE);
 +
    //}
 +
                     
 +
}
  
  
  // Because of the script-delay we have to connect the grand-child rezzing
+
[[Kategorie:Gaming]]
  // to the 'changed' event, which happens when someone (the parent) has
 
  // given me (as the child) something (a copy of myself)
 
  changed(integer change)
 
  {
 
      if(change == CHANGED_INVENTORY)
 
      {
 
          rez_child();       
 
      }
 
  }
 
}
 

Aktuelle Version vom 26. April 2007, 03:58 Uhr

sourcecode

selfrep.lsl

// Global variables
integer gintGeneration;                     // The Generation we are. Iterates with each replication.
integer gintMaxGeneration = 5;              // Maximum allowed Generations. Replication stops at this Generation-Count.
   
vector gvecStandardNull = <9.5,0,0>;        // Position to rez Object to.
rotation grotStandardNull = <0,0,0,0.0>;    // Rotation to rez Object to.
 
rez_child()
{
   // Check if we're allowed to create any more offspring
   //llSay(0, "ok, rez!");
   if(gintGeneration < gintMaxGeneration)
   {
       // Satellite still over my land?  
       if (llOverMyLand(llGetKey())) {
           // if yes, rez the inventory-item at the distance of standardnull in front of us.
           llRezObject("Metastasis Unit", (gvecStandardNull*llGetRot())+llGetPos(), ZERO_VECTOR, llGetRot(), gintGeneration+1);
       }
   }
}
 
default
{
   // llRezObject throws event object_rez on the parent with the offspring as parameter   
   object_rez(key child) 
   { 
       // Give copy of child to child
       llGiveInventory(child, llKey2Name(child));  
   } 
    
   // When rezzed, the event on_rez is called on me as the child
   on_rez(integer pintGeneration)
   {
       
       // Save child (this one) ttl;
       gintGeneration = pintGeneration;
       
       // show the generation
       llSetText((string)gintGeneration,<1,1,1>,1.0);
       // llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
   }
 
   link_message(integer sender_num, integer num, string msg, key id) {
       if (msg == "replicate") {
            rez_child(); 
       }
   }
}


sensor.lsl

// boolean that keeps aggro/friendly mode.
integer intState = FALSE;
  
// the index for the 
integer intListenPointer = 0;

// all needed rotations for a crystalline-form in an array
list glRotations = [
   // the six 2D-Plane rotations
   <0,0,0>,
   <0,0,60>,
   <0,0,120>,
   <0,0,180>,
   <0,0,240>,
   <0,0,300>,
   
   // the three upper rotations
  <35,315,45>,
  <35,45,135>,
  <305,0,270>,
  
  // the three lower rotations
  <35,315,225>,
  <35,45,315>,
  <305,0,90>
  ];
   
    
// the rotation-function.
// rotates the entity to object to the next position in the global Rotations-Array
object_rotateby() {
         
   rotation rotDelta;
   rotation new_rot;    
   integer intZufall =  (integer)llFrand(11.9);
   
   rotDelta = llEuler2Rot( llList2Vector(glRotations,intZufall) *  DEG_TO_RAD );
   new_rot = ZERO_ROTATION * rotDelta;
   llSetRot(new_rot);
      
   intListenPointer = intListenPointer + 1;
   if (intListenPointer >= 11) intListenPointer = 0;
}
    
object_init(integer pintOldPointer) {
   llSetStatus(STATUS_PHYSICS,FALSE);
   llListenRemove(pintOldPointer);
   intListenPointer = llListen(0, "", llGetOwner(), "");
   llSetTimerEvent(15);
}
  
default
{
 
   state_entry()
   {
        object_init(intListenPointer);
   }
   
   on_rez(integer pintGeneration)
   {
        object_init(intListenPointer);
       
       if (pintGeneration>0) {
       // Children are aggro.
             intState = TRUE;  
       }
   }
   
   sensor(integer total_number) // total_number is the number of avatars detected.
   {
       //llWhisper(0, (string)total_number + " debris-items detected - rotate 60 degrees" );
       //object_rotateby();
   }
  
   no_sensor() {
       
       if (intState) {
           //llSay(0, "No debris detected, replicate");
          llMessageLinked(LINK_THIS, 0, "replicate", "");
       }
   }
   
   // Because of the script-delay we have to connect the grand-child rezzing 
   // to the 'changed' event, which happens when someone (the parent) has
   // given me (as the child) something (a copy of myself)
   changed(integer change)
   {
       if(change == CHANGED_INVENTORY)
       {
          // rez_child();        
       }
   }
       
   timer() {
       if (intState) {
           object_rotateby(); 
           llSensor("Metastasis Unit","", SCRIPTED, 12.5, PI_BY_TWO / 3);
       }
   }
  
   listen( integer channel, string name, key id, string message ){
       
       if (message == "metastasis off") {
           intState = FALSE;
           llSay(0, "Metastasis Unit offline: Service shutdown");
       } else if (message == "metastasis on") {
           intState = TRUE;    
           llSay(0, "Metastasis Unit online: Service up");
       } else if (message == "metastasis fall") {
           intState = FALSE;    
           llSay(0, "Metastasis Unit physics enabled");
           llSetStatus(STATUS_PHYSICS,TRUE);
       } else if (message == "metastasis delete") {
           intState = FALSE;    
           llSay(0, "Metastasis Unit self suicide");
           llDie();
       }
   }
         
   // another quite funny feature. 
   //collision_start( integer num_detected) {
   //    
   //    llSetStatus(STATUS_PHYSICS,TRUE);
   //}
                      
}