LlFlee debugging

From Second Life Wiki
Jump to: navigation, search

Note: you'll probably need to recompile the script after you add it to your object

<lsl>

float speed = 1.0; //speed the critter moves at float sensorRange = 3.0; //how far the critter can see, if it;s a bit myopic (lol) increase this numer vector wanderRange = <10.0, 10.0, 10.0>; //radius the critter wanders from the last place it was scared or rezzed/reset float minFleeDistance = 3.0; //how far from the critter the agent must be to make it run (ie, less than this number) float fleeDistance = 10; //the distance the critter will free from an avatar integer extraHard = FALSE; //if this is set to true the critter will wander when it gets near the flee distance instead of when it get to the end of the flee distance, making it harder to control and less predictable

// -- don't mod anything below this line

float var = 5.0; vector scale; vector basePos; vector scaryGiantPos;

debugMsg(string msg) {

   //llOwnerSay(msg); //comment this line out to turn off debug messages

}

setup() {

   llDeleteCharacter();
   llResetScript();

}

wander() {

   llSensorRepeat("", "", AGENT, 5.0, PI, sensorRange);
   basePos = llGetPos();
   llWanderWithin(basePos, wanderRange, []);

}

default {

   state_entry()
   {
       //if (llGetObjectDesc() != "0" && llGetObjectDesc() != "(No Description)") //should be zero if rezzed from inventory
       //{
       //    speed = (float)llGetSubString(llGetObjectDesc(), 0, 1);
       //    wanderRange = (float)llGetSubString(llGetObjectDesc(), 2, 3);
       //}
       llCreateCharacter([CHARACTER_DESIRED_SPEED, speed, CHARACTER_ORIENTATION, VERTICAL, CHARACTER_RADIUS, 0.2, CHARACTER_LENGTH, 0.5]);
       wander(); //either replace this with your functionality or replace the function doStuff()
   }
  
   //touch_start(integer total_number)
   //{
   //    setup(); //comment this handler line out when done testing unless touch events desired
   //}
  
   on_rez(integer start_param)
   {    
   //    llSetObjectDesc((string)start_param);
       setup();
   }
   
   sensor(integer num_detected)
   {
      
       string thisAgent = "";
       integer agentNum;
       for (agentNum=0; agentNum<num_detected; agentNum++)
       {
           key thisKey = llDetectedKey(agentNum);
           scaryGiantPos = llList2Vector(llGetObjectDetails(thisKey, [OBJECT_POS]), 0);
           float distance = llVecDist(llGetPos(), scaryGiantPos);
           debugMsg("detected at distance of " + (string)distance);
           if (distance < minFleeDistance)
           {
               debugMsg("I should be running");
               //llFleeFrom(scaryGiantPos, fleeDistance, []);
               llEvade(thisKey, []);
           }
           else wander();
       }
   }
  
   path_update(integer update, list none)
   {
       if (update == 0) //near goal
       {
           debugMsg("");
       }
       else if (update == 1) //goal reached
       {
           debugMsg("");
           wander();
       }
       else //errors
       {
           debugMsg("");
       }
   }

}