Mission to Destroy a Target
A common mission is to send the player out to destroy a target. Here is a basic example:
<MissionType unid="..."
...
>
<Properties>
<Constant id="targetCriteria">
"TAE +populated; -questTarget; -uncharted;"
</Constant>
<Data id="targetID"></Data>
</Properties>
<Events>
<OnCreate>
(block (targetObj)
; Pick a random target
(setq targetObj
(random
(sysFindObject
aOwnerObj
(msnGetProperty gSource 'targetCriteria)
)
)
)
; If we have a target, remember it
(if targetObj
(block ()
(msnRegisterForEvents gSource targetObj)
(msnSetProperty gSource 'targetID
(objGetID targetObj)
)
)
; Otherwise, no mission
(msnDestroy gSource)
)
)
</OnCreate>
<OnObjDestroyed>
(switch
; If our target was destroyed, then mission success
(= (objGetID aObjDestroyed)
(msnGetProperty gSource 'targetID)
)
(switch
aDestroy
(msnSuccess gSource)
; Otherwise, the target left the system or something.
; Check aDestroyReason to figure out what happened
; and deal with it accordingly.
...
)
)
</OnObjDestroyed>
</Events>
</MissionType>
A few notes on this code:
random
function to pick a random target from the criteria. Adjust this if necessary (e.g., if the target criteria returns a single object).msnRegisterForEvents
is required so that the mission object gets the <OnObjDestroyed>
event.<OnObjDestroyed>
and the mission will succeed, but the player will not be credited (because they did not accept).