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 springenK (Die Seite wurde neu angelegt: // The ttl variable is a counter, decreased for each subsequent replication, // the child that get rezzed with a ttl value of zero will not procreate. integer ttl = 3;...) |
Pk (Diskussion | Beiträge) K (+kat.) |
||
(7 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
− | + | == sourcecode == | |
− | |||
− | + | === selfrep.lsl === | |
− | + | // Global variables | |
− | rez_child() | + | 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 | // Check if we're allowed to create any more offspring | ||
− | if( | + | //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 | + | default |
− | { | + | { |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
// llRezObject throws event object_rez on the parent with the offspring as parameter | // llRezObject throws event object_rez on the parent with the offspring as parameter | ||
object_rez(key child) | object_rez(key child) | ||
{ | { | ||
// Give copy of child to child | // Give copy of child to child | ||
− | llGiveInventory(child, llKey2Name(child)); | + | llGiveInventory(child, llKey2Name(child)); |
} | } | ||
− | + | ||
// When rezzed, the event on_rez is called on me as the child | // When rezzed, the event on_rez is called on me as the child | ||
− | on_rez(integer | + | on_rez(integer pintGeneration) |
{ | { | ||
+ | |||
// Save child (this one) ttl; | // 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 | // Because of the script-delay we have to connect the grand-child rezzing | ||
// to the 'changed' event, which happens when someone (the parent) has | // to the 'changed' event, which happens when someone (the parent) has | ||
Zeile 47: | Zeile 146: | ||
if(change == CHANGED_INVENTORY) | 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); | ||
+ | //} | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | [[Kategorie:Gaming]] |
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); //} }