Path update debugging

From Second Life Wiki
Jump to navigation Jump to search

It require 4 objects to work with this script. Name one prim "Red", another prim named "Green" and another as "Blue". These colored prim are used for tracking them.

One more prim named "hot" but is 2m x 2m x 0.1m cylinder to test it's avoiding range. place hot prim inside the a prim with the script, for rezzing.

It has listen command to do your bidding, useful for testing command conflicts.


<lsl>

key Green; key Blue; key Red;

vector PosTarget(key ID){

   return (llList2Vector(llGetObjectDetails(ID, [3]),0));

}


default {

   state_entry(){
       llCreateCharacter([CHARACTER_DESIRED_SPEED, 5.0]);
       llListen( 0, "", "", "");
       llSensor("","",(PASSIVE | ACTIVE ),96,PI);
   }
   
   sensor(integer Num){
       integer aNum;
       for (aNum=0; aNum<Num; aNum++){
           string Tar = llDetectedName(aNum);
           if (Tar == "Green"){Green=llDetectedKey(aNum);  llOwnerSay("Green found");}
           if (Tar == "Blue"){Blue=llDetectedKey(aNum);    llOwnerSay("Blue found");}
           if (Tar == "Red"){Red=llDetectedKey(aNum);      llOwnerSay("Red found");}
       }
   }
   listen( integer ch, string n, key id, string m ){
            if(m=="jump"){ llExecCharacterCmd( 1, [2.0] ); }
       else if(m=="stop"){ llExecCharacterCmd( 0, [] ); }
       else if(m=="wander"){ llWanderWithin( llGetPos(), 300.0, []); }
       else if(m=="evade"){ llEvade( Red, []); }
       else if(m=="chase"){ llPursue( Blue, []); }
       else if(m=="follow"){ llPursue( id, []); }
       else if(m=="hot"){ llFleeFrom( llGetPos(), 3, []); llRezObject( "hot", llGetPos(), <0,0,0>,<0,0,0,0>,0);}
       else if(m=="here"){ llNavigateTo( PosTarget(id), [FORCE_DIRECT_PATH, 0]); }
       else if(m=="now"){ llNavigateTo( PosTarget(id), [FORCE_DIRECT_PATH, 1]); }
       else if(m=="close"){ llGetClosestNavPoint( PosTarget(Green), []); }
   }
   path_update(integer typeUpdate, list reserved){
            if (typeUpdate == PU_SLOWDOWN_DISTANCE_REACHED   ){ llOwnerSay("Slowdown: Near Goal");               }
       else if (typeUpdate == PU_GOAL_REACHED                ){ llOwnerSay("Goal: Reached");                     }
       else if (typeUpdate == PU_FAILURE_INVALID_START       ){ llOwnerSay("Failure: Not connected to NavMesh"); }
       else if (typeUpdate == PU_FAILURE_INVALID_GOAL        ){ llOwnerSay("Failure: Goal not on NavMesh");      }
       else if (typeUpdate == PU_FAILURE_UNREACHABLE         ){ llOwnerSay("Failure: Unreachable");              }
       else if (typeUpdate == PU_FAILURE_TARGET_GONE         ){ llOwnerSay("Failure: Target Missing");           }
       else if (typeUpdate == PU_FAILURE_NO_VALID_DESTINATION){ llOwnerSay("Failure: No Valid Destination");     }
       else if (typeUpdate == PU_EVADE_HIDDEN                ){ llOwnerSay("Evade: Hidden");                     }
       else if (typeUpdate == PU_EVADE_SPOTTED               ){ llOwnerSay("Evade: Spotted");                    }
       else if (typeUpdate == PU_FAILURE_NO_NAVMESH          ){ llOwnerSay("Failure: No NavMesh");               }
       else if (typeUpdate == PU_FAILURE_OTHER               ){ llOwnerSay("Failure: Other");                    }
       else{   llOwnerSay("Unknown failure"); }
   }

}