Difference between revisions of "Bot Playground/Commands/scanNearbyAvatars"

From SmartBots Developers Docs
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:{{SUBPAGENAME}}}} <onlyinclude>Scans current region for other avatars.</onlyinclude> <syntaxhighlight lang="javascript"> const result = await Bot.scanNearbyAva...")
 
 
(4 intermediate revisions by the same user not shown)
Line 13: Line 13:
 
{{API Variable Group|Output}}
 
{{API Variable Group|Output}}
 
{{API Return promise}}
 
{{API Return promise}}
{{API Variable|avatars|Array}} An array containing avatars on sim. Each entry is:
+
{{API Variable|avatars|Array}} An array containing avatars on sim. See "Response details" for more info.
<syntaxhighlight lang="javascript">
+
 
 +
{{API Variables Table End}}
 +
 
 +
== Response details ==
 +
 
 +
'avatars' field of the response is an array and contains the list of avatars our bot sees:
 +
 
 +
<syntaxhighlight lang="json">
 
{
 
{
 
   // Avatar name
 
   // Avatar name
   "Name": "GrrrillaBongo Resident",
+
   "name": "GrrrillaBongo Resident",
 
   // Avatar UUID
 
   // Avatar UUID
 
   "UUID": "d8e20552-ca84-4c42-b8d3-e8fa5fbdcc6b",
 
   "UUID": "d8e20552-ca84-4c42-b8d3-e8fa5fbdcc6b",
  
 
   // The parcel this avatar currently in
 
   // The parcel this avatar currently in
   "ParcelID": 177,
+
   "parcelID": 177,
  
 
   // If avatar is sitting on something
 
   // If avatar is sitting on something
   "Sitting": false
+
   "sitting": false,
  
 
   // Position of avatar in-world
 
   // Position of avatar in-world
   "Position": {
+
   "position": {
 
     "X": 110,
 
     "X": 110,
 
     "Y": 75,
 
     "Y": 75,
Line 34: Line 41:
 
   },
 
   },
 
   // Local position. If avatar is sitting this position is relative to sit parent
 
   // Local position. If avatar is sitting this position is relative to sit parent
   "LocalPosition": {
+
   "localPosition": {
 
     "X": 110,
 
     "X": 110,
 
     "Z": 32,
 
     "Z": 32,
Line 40: Line 47:
 
   },
 
   },
 
   // Avatar heading (the view direction)
 
   // Avatar heading (the view direction)
   "Heading": 0,
+
   "heading": 0,
 
   // Local heading (for sitting avatars)
 
   // Local heading (for sitting avatars)
   "LocalHeading": 0,
+
   "localHeading": 0,
  
 
   // The distance to this avatar
 
   // The distance to this avatar
   "Distance": 129.97195,
+
   "distance": 129.97195,
  
 
   // When we seen this avatar for first time (see Details)
 
   // When we seen this avatar for first time (see Details)
   "SeenSince": "2022-10-18T12:36:58.2626463Z",
+
   "seenSince": "2022-10-18T12:36:58.2626463Z",
 
   // How much seconds do we see this avatar
 
   // How much seconds do we see this avatar
   "SeenSeconds: 123,
+
   "seenSeconds": 123,
 
+
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
{{API Variables Table End}}
 
  
 
== Details ==
 
== Details ==
  
 +
'SeenSince' value shows when we saw the specific avatar for the first time ''when running scanNearbyAvatars''. For example:
 +
 +
# Bot logs on. Time passes (say, 1 hour).
 +
# Script sends 'scanNearbyAvatars' command
 +
# Bot sees one avatar, Guest1 and sets SeenSince to current time (say, "2022-10-18 13:00")
 +
# 5 minutes passes
 +
# Script sends 'scanNearbyAvatars' again
 +
# Now bot sees that another avatar arrived - Guest2. Its SeenSince will be "2022-10-18 13:05"
 +
 +
Thus, all further calls to 'scanNearbyAvatars' will return:
 +
* Guest1: SeenSince  = "2022-10-18 13:00"
 +
* Guest2: SeenSince = "2022-10-18 13:05"
 +
 +
SeenSeconds shows the number of seconds we see avatar (Now - SeenSince).
 +
 +
== Throttling ==
 +
 +
The maximum rate of calling scanNearbyAvatars is 2 calls per 10 seconds. Excessive calls will return "Frequent API requests throttled" error.
 +
 +
== Data size ==
 +
 +
The amount of data returned by this command can be pretty large (up to 10kb and more). Remember [[Bot_Playground/Built-in_Functions/console.log|console.log]] is unable to log more than 4kbytes.
 +
 +
If you need to trace scanNearbyAvatars response, use for(...of...) loop (as used in Examples below).
  
 
== Examples ==
 
== Examples ==
  
See the [[Bot_Playground/Examples/Listing_worn_items|Currently worn items]] scripts in our Playground Examples section.
+
See the [[https://www.mysmartbots.com/dev/docs/Bot_Playground/Examples/Scan_nearby_avatars|Scan nearby avatars]] scripts in our Playground Examples section.
  
 
{{NavMenu}}
 
{{NavMenu}}
 
__NOTOC__
 
__NOTOC__

Latest revision as of 15:32, 18 October 2022

Scans current region for other avatars.

const result = await Bot.scanNearbyAvatars();

Reference

This command accepts the following parameters:

Variable Required Description


Input:
Output:
Function returns a Promise with the following data:
success bool true if command completed successfully
error string error string if command has failed
avatars Array An array containing avatars on sim. See "Response details" for more info.

Response details

'avatars' field of the response is an array and contains the list of avatars our bot sees:

{
  // Avatar name
  "name": "GrrrillaBongo Resident",
  // Avatar UUID
  "UUID": "d8e20552-ca84-4c42-b8d3-e8fa5fbdcc6b",

  // The parcel this avatar currently in
  "parcelID": 177,

  // If avatar is sitting on something
  "sitting": false,

  // Position of avatar in-world
  "position": {
    "X": 110,
    "Y": 75,
    "Z": 32
  },
  // Local position. If avatar is sitting this position is relative to sit parent
  "localPosition": {
    "X": 110,
    "Z": 32,
    "Y": 75
  },
  // Avatar heading (the view direction)
  "heading": 0,
  // Local heading (for sitting avatars)
  "localHeading": 0,

  // The distance to this avatar
  "distance": 129.97195,

  // When we seen this avatar for first time (see Details)
  "seenSince": "2022-10-18T12:36:58.2626463Z",
  // How much seconds do we see this avatar
  "seenSeconds": 123,
}

Details

'SeenSince' value shows when we saw the specific avatar for the first time when running scanNearbyAvatars. For example:

  1. Bot logs on. Time passes (say, 1 hour).
  2. Script sends 'scanNearbyAvatars' command
  3. Bot sees one avatar, Guest1 and sets SeenSince to current time (say, "2022-10-18 13:00")
  4. 5 minutes passes
  5. Script sends 'scanNearbyAvatars' again
  6. Now bot sees that another avatar arrived - Guest2. Its SeenSince will be "2022-10-18 13:05"

Thus, all further calls to 'scanNearbyAvatars' will return:

  • Guest1: SeenSince = "2022-10-18 13:00"
  • Guest2: SeenSince = "2022-10-18 13:05"

SeenSeconds shows the number of seconds we see avatar (Now - SeenSince).

Throttling

The maximum rate of calling scanNearbyAvatars is 2 calls per 10 seconds. Excessive calls will return "Frequent API requests throttled" error.

Data size

The amount of data returned by this command can be pretty large (up to 10kb and more). Remember console.log is unable to log more than 4kbytes.

If you need to trace scanNearbyAvatars response, use for(...of...) loop (as used in Examples below).

Examples

See the [nearby avatars] scripts in our Playground Examples section.