De DigiWiki.
// llGetStaticPath() test script
// Reports the static path from the object's current position to the object owner's position
// Radius of character to test for
float character_radius = 1.0;
// All defined path_update codes; note that llGetStaticPath() can only return a few of these.
list path_update_codes = [
"PU_SLOWDOWN_DISTANCE_REACHED ",
"PU_GOAL_REACHED",
"PU_FAILURE_INVALID_START",
"PU_FAILURE_INVALID_GOAL",
"PU_FAILURE_UNREACHABLE",
"PU_FAILURE_TARGET_GONE",
"PU_FAILURE_NO_VALID_DESTINATION",
"PU_EVADE_HIDDEN",
"PU_EVADE_SPOTTED",
"PU_FAILURE_NO_NAVMESH",
"PU_FAILURE_DYNAMIC_PATHFINDING_DISABLED",
"PU_FAILURE_PARCEL_UNREACHABLE",
"PU_FAILURE_OTHER"
];
default
{
touch_start(integer detected)
{
vector agent_pos = llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_POS]), 0);
vector end_pos = llList2Vector(llGetClosestNavPoint(agent_pos, [GCNP_STATIC, TRUE]), 0);
vector start_pos = llList2Vector(llGetClosestNavPoint(llGetPos(), [GCNP_STATIC, TRUE]), 0);
if(end_pos == ZERO_VECTOR)
{
llOwnerSay("Error: end position undefined - the object owner is either offline or far away from the nav mesh."
+ "\nagent pos is " + (string)agent_pos);
}
else if(start_pos == ZERO_VECTOR)
{
llOwnerSay("Error: start position undefined - this object is far away from the nav mesh."
+ "\nobject pos is " + (string)llGetPos());
}
else
{
llOwnerSay("Finding path from " + (string)start_pos
+ " to " + (string)end_pos
+ " for a character of radius " + (string)character_radius);
list result = llGetStaticPath(start_pos, end_pos, character_radius, []);
integer result_code = llList2Integer(result, -1);
//llOwnerSay("Raw llGetStaticPath() result: " + llList2CSV(result));
// the last element in the list is just the return code;
// the preceding elements should be waypoint vectors
if(result_code == 0)
{
llOwnerSay("llGetStaticPath found a path: " + llList2CSV(llList2List(result, 0, -2)));
}
else
{
llOwnerSay("llGetStaticPath failed to find a path, with code " + (string)result_code
+ " (" + llList2String(path_update_codes, result_code) + ")");
}
}
}
}