backIndex

Xelagot action script

Events: AvatarScan, AvatarScanComplete

Refer to Events for general information.

AvatarScan is triggered by the statement Scanav [%range] for each avatar present if the range condition is met. If %range is omitted, all avatar presents are included. The range must be specified in metres. Scanav may be called from the main script or from an event handler. In the main script, it interrupts the execution of the script and triggers the events; when called from an event handler, it is executed after the event handler exits.

AvatarScanComplete is triggered by the statement Scanav after all Avatars have been scanned.

Installer: OnAvatarScanEvent <eventlabel>
Event type: 350

Installer: OnAvatarScanCompleteEvent <eventlabel>
Event type: 351

Specific statements for AvatarScan event (AvatarScanComplete event has no meaningful values)(must be inside these event handlers):

GetEventType %a stores the event type code in variable %a
GetEventResult %a stores the event result code in variable %a. Is always 0 in this event. 0 means success, other positive codes are equivalent to the rc codes of the SDK and the Windows codes. See SDK Error Codes.
GetAvatarName $a The name of the avatar causing this event is stored in $a
GetAvatarSession %a The session number of the avatar causing this event is stored in %a
GetAvatarPerson &p The data of the avatar causing this event are stored in &p. This includes name and session number.

A story: Many months ago, JustIn made a bot script. In this script, the bot walked the streets of New York. JustIn wanted the bot to approach people near him as it walked passed them. The event handlers AvatarAdd and AvatarChange did not help much: the bot needed to initiate an action even if the avatars were not moving... So I invented this event. I never found out if JustIn used it in his script :)

This is one of the few events which the script can trigger whenever it needs to. It can be combined with another event: Timeout. The Timeout event can also be triggered by the script, at whatever inteval you want.

Here is an example of how this could work. I define 3 positions, @a, @b, and @c, and let the bot walk from one to the other. When it arrives at one of these positions, the bot triggers AvatarScan, looking for people within a radius of 5m: it gets the nearest one and whispers something to him/her and says something aloud. I do not use the Timeout event here, but I use a new statement introduced in version 2.9999952: EscapeTo, which disables the Wait statement, ends the processing of the event handler and jumps to a label in the Main section. %x acts as a flag: if it is < 0 no suitable avatar was found. Wait is used instead of looping while the scanning is going on, EscapeTo at the end of the scanning cancels it. To test this script, you will need a few people near the points you selected.

[Head]
Type=Script
Version=2.0

[Settings]
Origin=0.000n 0.000w 0.00a 0.0°

[Script]
  @a = 2n 2w 0a
  @b = 2n 0w 0a
  @c = 2n 1.5w 0a
  %r = 5.0
  Step 1.5
  OnAvatarScanEvent AvScan
  OnAvatarScanCompleteEvent AvScanned
Label Start

Label First
  $N = "Second"
  To @a
  %x = -1
  Scanav %r
  Wait 60
  
Label Second
  $N = "Third"
  To @b
  %x = -1
  Scanav %r
  Wait 60

Label Third
  $N = "First"
  To @c
  %x = -1
  Scanav %r
  Wait 60

  Goto Start

End

Event AvScan
  # the avatar
  GetAvatarPerson &p
  # the bot
  GetPerson &b
  # %d = distance between bot and avatar
  Distance %d &b &p
  IfReal %x < 0 Goto AvScan1
  Else IfReal %d < %x Goto AvScan1
EndEvent
Label AvScan1
  %x = %d
  &x = &p
EndEvent

Event AvScanned
  # no one meets requirement? carry on walking...
  IfInt %x < 0 SayConcat "No-one here..."
  IfInt %x < 0 EscapeTo $N
  # otherwise... bingo!
  GetName $x &x
  WhisperConcat &x $x ", you are very near me :)"
  StringFromReal $d %x 2
  SayConcat $x " is " $d " metres away from me!"
  EscapeTo $N
EndEvent

There is similar script, using Walk instead of To, on the WalkComplete event handler page.



backIndex