backIndex

Xelagot action script

Events: ObjectAdd, ObjectDelete; (3.1) AllObjectsGone.

Refer to Events for general information.

The first 2 events, ObjectAdd and ObjectDelete, are triggered after an ongoing property query (survey) in live update receives a message from the world server to update the survey, and after the update has taken place: an object has been added or deleted by someone. The object added or deleted is always defined in this event, the source ('someone') may only be known by its session number if it is not in the bot's avatar database: test IfSourceDefined, IfSourceUndefined. If the source is known, this does not mean it is in the bot's perception field, it may have left it: in this case, the source's position is not up to date, but its name and other data will be valid. You can use the conditional statements for person to test this.

The third event, AllObjectsGone, is triggered when the world attributes sent to the bot announce that the world has no objects (left). It is only applicable to new 3.1 worlds as from build 28 of the world server. The bot does not need to be querying for this event to be triggered. It can be ignored in most cases, because a querying bot will detect this change and adjust the survey, but it can be usefull in some cases because it works as a warning. It has no meaningfull parameters which can be retrieved. For SDK programmers: it is related to AW_EVENT_WORLD_ATTRIBUTES, not to AW_CALLBACK_DELETE_ALL_OBJECTS_RESULT.

Note: In the event handlers for ObjectAdd and ObjectDelete, you must test whether the Source is defined or not, and exit if the Source is required but it is not available:
IfSourceUndefined Escape

Installer: OnObjectAddEvent <eventlabel>
Event type: 2200

Installer: OnObjectDeleteEvent <eventlabel>
Event type: 2300

Installer: OnAllObjectsGoneEvent <eventlabel>
Event type: 2400

Specific statements (must be inside this event handler):

GetEventType %a stores the event type code in variable %a
GetEventResult %a stores the event result code in variable %a. Is always 0.
GetSourceName $a The name of the avatar causing this event is stored in $a if the source is defined, otherwise $a will be an empty string (this can be used to test if the source is defined). Not for AllObjectsGone.
GetSourceSession %a The session number of the avatar causing this event is stored in %a. Valid even if the source is not defined. Not for AllObjectsGone.
GetSourcePerson &s The data of the avatar causing this event are stored in &s. This includes name and session number. Only valid if the source is defined. Not for AllObjectsGone.
GetTargetObject ~t The data of the object added or deleted are stored in ~t. Not for AllObjectsGone.
GetSourceTarget &s ~t The data of both the source person and the target object are stored in &s and ~t. Only valid if the source is defined. Not for AllObjectsGone.
IfSourceDefined statement1
[Else statement2]
tests whether the source avatar is defined. If defined, executes statement1. Otherwise, optionally, executes statement2. Not for AllObjectsGone.
IfSourceUndefined statement1
[Else statement2]
tests whether the source avatar is not defined. If not defined, executes statement1. Otherwise, optionally, executes statement2. Not for AllObjectsGone.

The following example expands the one I show in the Event handler QueryComplete. After the query is done, the bot is in live update, and any changes to objects will be noted by the bot.

[Head]
Type=Script
Version=2.0

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

[Script]
  OnQueryCompleteEvent QComplete
  OnWorldReconnectEvent ImBack
  OnObjectAddEvent ObjAdd
  OnObjectDeleteEvent ObjDel
Label QueryNow
  @a = 7n 5e
  %q = 1
  QueryAt @a
Label WaitForQuery
  IfInt %q = 1 Goto WaitForQuery

# the bot now finished querying,
# and receives any updates for the zone automatically
# ObjAdd and ObjDelete will detect any changes

Label MainLoop
  Goto MainLoop

End


Event QComplete
  %q = 0
EndEvent

Event ImBack
  ResetTo QueryNow
EndEvent

Event ObjAdd
  GetTargetObject ~t
  GetModel $m ~t
  GetSourceName $n
  GetSourceSession %s
  IfSourceDefined SayConcat $n " added object " $m " at " ~t
  Else SayConcat "Someone out of range (session # " %s ") added object " $m " at " ~t
  GetDescription $d ~t
  IfString $d <> "" SayConcat "Its description is: " $d
  GetAction $a ~t
  IfString $a <> "" SayConcat "Its action is: " $a
EndEvent

Event ObjDel
  GetTargetObject ~t
  GetModel $m ~t
  GetSourceName $n
  GetSourceSession %s
  IfSourceDefined SayConcat $n " deleted object " $m " at " ~t
  Else SayConcat "Someone out of range (session # " %s ") deleted object " $m " at " ~t
  GetDescription $d ~t
  IfString $d <> "" SayConcat "Its description was: " $d
  GetAction $a ~t
  IfString $a <> "" SayConcat "Its action was: " $a
EndEvent


backIndex