Table of Contents

Events are a powerful way to create behaviour in ships and stations.

Events

The following info is taken from the OTF, here → http://neurohack.com/transcendence/forums/viewtopic.php?t=1997&highlight=events

<OnAIUpdate>

Populated variables:

  • gSource: object that carries the item
  • gItem: the item

The OnAIUpdate event for an item is called once every 30 ticks on every non-player ship that carries the item. Use this event to implement special behaviors. For example, an <OnAIUpdate> event on an armor patch item allows a non-player ship to use the armor patch when it is damaged. Use this event sparingly because it will impact performance.

<OnAttacked>

<OnAttackedByPlayer>

<OnContractGenerate>

<OnContractQuery>

<OnCreate>

For systems, stations, ships, at object creation.

<OnDamage>

Populated variables:

  • gSource: station object
  • aAttacker: object that attacked
  • aHitPos: vector position of hit
  • aHitDir: angle direction from which hit came
  • aDamageHP: hit points of damage
  • aDamageType: type of damage

This event is called when an object is hit by a weapon. The event must return the number of hit points of damage to do to the object. For example, imagine an object that takes half damage from the player (but full damage from all others). The event could check aAttacker and return half of aDamageHP if it is the player and full aDamageHP otherwise.

The event should avoid affecting other objects and should not destroy the station (e.g., by calling objDestroy). If necessary, the event could return a very large number to insure that the station is destroyed. (why is this. Does anyone know)

<OnDestroy>

Populated variables:

  • gSource: ship object
  • aDestroyer: object that caused destruction
  • aWreckObj: ship wreck left behind

The <OnDestroy> event now includes the aWreckObj parameter that allows you to access the wreck left behind by a ship. This parameter is sometimes Nil if the ship left no wreck.

<OnEnteredGate>

Populated variables:

  • gSource: station object
  • aGateObj: gate object

Version 0.99 uses aGateObj instead of aGate (as in previous versions) to be consistent with <OnObjEnteredGate>.

<OnGameEnd>

Found inside <AdventureDesc>

<OnGameStart>

Found inside <AdventureDesc>

<OnGlobalSystemCreated>

For systems, all instances executed whenever a system is created.

This event is called after a system is created (right after <OnCreate> for the system). You may use this event to create new objects in the system or to otherwise alter the system. Remember that there is no guarantee that other systems have been created at this point. Look at Huari.xml for an example of how this event is used.

Warning : multiple instances of this event can be created on multiple system types. They will ALL be called when ANY system is created, and their order can NOT be forecast.

<OnGlobalTopologyCreated>

For topology, once when the topology is created. This event is called at the beginning of the game right after the complete system topology has been generated. You may use this event to explore the topology and add data to topology nodes that may later be used inside systems. Remember that no systems have been created yet. You can only call functions that work on topology nodes.

For an example of how this event is used, look at Huari.xml.

<OnInvokedByPlayer>

<OnInit>

Used in dockscreens, when the dockscreen is shown.

<OnMining>

For asteroids.

<OnObjDestroyed>

Populated variables:

  • aWreckObj: the wreck left behind the destroyed object.

Like all <OnObj*> events, let an object know that something happenned to another object to which events it has previously registered. Is triggerred when an object A has registered for object B events and object B is destroyed. <OnDestroy> is fired on object B, and <OnObjDestroyed> is fired on object A. 0.99c: the <OnObjDestroyed> event now includes the aWreckObj parameter that allows you to access the wreck left behind by a ship. This parameter is sometimes Nil if the ship left no wreck.

See example on earth slaver.

<OnObjDocked>

Like all <OnObj*> events, let an object know that something happenned to another object to which events it has previously registered. This was primarily used before <OnOrdersCompleted>.

<OnObjEnteredGate>

Like all <OnObj*> events, let an object know that something happenned to another object to which events it has previously registered.

<OnObjJumped>

Like all <OnObj*> events, let an object know that something happenned to another object to which events it has previously registered.

<OnObjReconned>

Like all <OnObj*> events, let an object know that something happenned to another object to which events it has previously registered.

<OnOrderChanged>

<OnOrdersCompleted>

For ships, when all queued orders are completed.

<OnRefuel>

<OnShieldDown>

<OnShow>

When a communication menu messages is shown.

<OnUpdate>

Populated variables:

  • gSource: object that carries the item
  • gItem: the item

The OnUpdate event for an item is called once every 30 ticks on every object that carries the item. Use this event sparingly because it will impact performance.



Events and script

Some events are very particular about where they can be called from and what kind of functions can be run in them. The <OnCreate> function can be placed in ships or stations but dosn't like running some functions due to the fact that what it is looking for may not yet have been create. This event is best used to set timers for other events or register with a controller so it can be given orders at a later time.

There are a number of functions that are used in cunjuction with events such as:

(sysAddObjRecurringTimerEvent)
    ;; will fire a specific event every n ticks until (sysCancelTimerEvent) is called
 
(sysAddObjTimerEvent)
    ;; will fire a specific event after a delay only once
 
(sysCancelTimerEvent)
    ;; will cancel a timer event (obviously!)
 
(objFireEvent) 
    ;; will fire a specific event immediately
 
(objFireItemEvent)
    ;; will fire a specific event that is contained in an item immediately
 
(objRegisterForEvents)
    ;; creates a relationship between two objects so they can use eachother in events
    ;; Some events can only be called once they have been registered such as <onObjDocked>
 
(objUnregisterForEvents)
    ;; cancels the relationship between objects

You are not limited to these events, you can create any event you wish but it must be called from a function that you define.

	<Events>
		<OnCreate>
			(block Nil
		  	 (itmEnumTypes "*" itemType 
				(block  Nil
					(itmSetKnown itemType)
					(itmSetReference itemType)
					)
				)
			)
	        </OnCreate>
	</Events>

This little fella here is a great event to add to a ship that you use for debugging your mods. It will fire the even <OnCreate> when the game loads. <OnCreate> is a built in Event. If you put it on another ship or a station it will still run but it's effects will not be noticed by you unless it is on your player ship.

<Events>
    <OnDestroy>
        (block Nil
            (plyMessage gPlayer "You haven't seen the last of me!!!! BOOM!")
            (sysAddObjTimerEvent 100 gSource "Kaboom")
            )
    </OnDestroy>
    <Kaboom>
         (sysCreateEffect &vtPlasmaExplosion2; gSource (objGetPos gSource))
    </Kaboom>
</Events>

The <OnDestroy> event is called when ship or station that is holding this event is destroyed. When it is run, it sends a message to the player and sets a timer to run the event called “Kaboom” after 100 ticks have passed. The event <Kaboom> creates a little farewell fireworks display. The <OnDestroy> event is built-in so it is called when it's condition is met. In this case, when the object that has the event is destroyed. The event <Kaboom> is not built-in, so we must call it when we want it to run, in this case 100 ticks after it is destroyed.

Changes

* 06/01/09: Applied some wiki formatting to the content -alterecco

 
events.txt · Last modified: 2009/06/01 11:26 by alterecco
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki