Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

If you want to know when something you don't own is destroyed, or when map features (like trees) are destroyed, use the bind() function instead.

Avilability

Warzone 3.1 Beta 1 and above.

Excerpt

...

This event is triggered when one of your droids or structures ceases to exist due to being destroyed, recycled or demolished.

Triggered when a game object is destroyed...

 

Syntax

Code Block
theme

...

RDark
languagejavascript
linenumberstrue
function eventDestroyed(gameObject) {
  // do stuff
}

Parameters

ParameterTypeMandatoryDescriptionGame version
gameObject

...

Structure object

Feature object

(tick)

...

The droid, structure or feature that was just destroyed

...

Also, if a player picks up a barrel, artefact, or claims an oil resource, this event will be called with a feature object. Note, however, that regardless of who interacts with the artefact/resource the .player value will always be that of your script. So, you can detect when a barrel/artefact is picked up or when an oil resource is claimed but you can't determine who by.

(warning) This object will quickly be deleted from the game data so it must not be used in further API calls.

...

Return value

...

.

See "Notes" section below for important information.

3.1 Beta 1

Updated in Warzone 3.2

Return value

Warzone does not process the event handler's return value.

Notes

By the time the event is triggered, the gameObject will already have been removed from the map so you can't use it with any other JS API functions – it's for reference purposes only.

This event is unthrottled, it will be called whenever an object is destroyed – avoid complex or time consuming processing in your event handler.

In Warzone 3.1, the event is triggered when:

  • One of your droids is destroyed or recycled
  • One of your structures is destroyed or demolished
  • A barrel or artifact is picked up (note: gameObject.player is incorrectly reported as me on these objects)
  • An oil resource is claimed by any player (note: gameObject.player is incorrectly reported as me)

In Warzone 3.2 and above, the event is triggered when:

  • Same scenarios as above, but also...
  • Any droid or structure owned by any other player.

As such, it's vital to check which player the destroyed gameObject belongs to before deciding how to react, regardless of game version.

Example

Code Block
theme

...

RDark
languagejavascript
titleProcess the object differently based on it's type
linenumberstrue
function eventDestroyed(gameObject) {
  switch (gameObject.type) {
    case DROID: {
      // do stuff when a droid is destroyed
      // gameObject.order == DORDER_RECYCLE indicates droid was destroyed due to recycling
      break;
    }
    case STRUCTURE: {
      // do stuff when a structure is destroyed
      // gameObject.status !=

...

 

...

BUILT indicates structure was demolished by truck
      break;
    }
	case FEATURE: {
		// a feature was destroyed, picked up or claimed
	}
    default: {
      debug("eventDestroyed: Unknown object type: "+gameObject.type);
    }
  }
} 
Div
classbox
Availability
Status
colourGreen
title3.1 b1+

Requires:

  • Warzone 3.1 or above
  • Event scope changed in Warzone 3.2
Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

See also

Related articles:

  • bind() – monitor other players' objects (and even features) to get notified when they are destroyed
  • eventAttacked() – find out what's attacking your objects
  • eventGroupLoss() – triggered when an object is removed from a group