mission.php

From Galactineers
Jump to: navigation, search

The mission.php file contains the main mission script of the mission. It can define event handlers and use commands and properties to control the mission process.

File Definition

The basic mission.php file contents look like this:

<?php
    class Mission {   
        public function OnMissionInitialize() {
            global $MissionContext;

            /* implementation of the MissionInitialize event handler */
        }

        /* other event handlers */
    }
?>

It must contain a class called Mission. The mission instance will create one instance of your Mission class and call its event handler functions at certain events. The Mission class may have event handler functions according to the $MissionContext events reference. Via the global variable $MissionContext, you can access properties of the current mission state. All available properties can be found here: $MissionContext properties reference. The $MissionContext also provides the commands to control the mission process. All available commands can be found here: $MissionContext commands reference. You can define any sort of variable at function scope, or even at class scope.

Example

The following is a (shortened) version of the First Blood mission script:

<?php
    class Mission {   
        
        public function OnMissionInitialize() {
            global $MissionContext;
            
            $MissionContext->AddShip('PirateProbe', array(12, -10), 0, 'X');
            $MissionContext->AddShip('PirateProbe', array(5, 7), 0, 'X');           

            $MissionContext->SetMissionObjective('killEnemies',array('EN' => 'Defeat all enemies.', 
                                                                     'DE' => 'Besiegen Sie alle Feinde.'));
            $MissionContext->SetTimer('missionTimer', 600, true, array('EN' => 'Time remaining', 
                                                                       'DE' => 'Verbleibende Zeit'));
            $MissionContext->SetTimer('5minTimer', 300, false, null);
            $MissionContext->SetCounter('enemyCounter', $MissionContext->EnemiesShipList->Count, array('EN' => 'Remaining enemies', 
                                                                                                       'DE' => 'Verbleibende Feinde'));
        }
        
        public function OnTimerExpired($timerId) {
            global $MissionContext;
            
            if ($timerId == 'missionTimer') {
                $MissionContext->SetMissionFailed(array('EN' => 'Time is up', 
                                                        'DE' => 'Die Zeit ist abgelaufen'));
            } else if ($timerId == '5minTimer') {
                $MissionContext->SendSystemMessage(array('EN' => '5:00 minutes left...', 
                                                         'DE' => 'Noch 5:00 Minuten verbleiben...'));
            }
        }
        
        public function OnShipKilled($shipId) {
            global $MissionContext;
            
            if ($MissionContext->PlayersShipList->Count == 0) {
                $MissionContext->SetMissionFailed(array('EN' => 'All your ships have been defeated', 
                                                        'DE' => 'Alle eure Schiffe wurden besiegt'));
            } else {
                if ($MissionContext->EnemiesShipList->Count == 0) {
                    $MissionContext->SetMissionSuccessful(array('EN' => 'All enemy ships have been defeated', 
                                                                'DE' => 'Alle feindlichen Schiffe wurden besiegt'));
                } else {
                    $MissionContext->SetCounter('enemyCounter', $MissionContext->EnemiesShipList->Count, array('EN' => 'Remaining enemies', 
                                                                                                               'DE' => 'Verbleibende Feinde'));
                }
            }                
        }
    }
?>

The mission challenges the players with a 10 minutes time limit to defeat all enemy ships. The OnMissionInitialize event handler is used to setup the mission objectives, timers, a counter of the remaining enemies and adds the enemy ships to the map. The ship for the Id PiratesProbe is defined in the shipdefinitions.xml. The owner 'X' represents the enemy faction.

There are two events to happen, which change the state of the mission:

  • When the timer runs out, players lose the mission, so we handle the OnTimerExpired event.
  • When either the players or the enemies have no remaining ships, the mission ends with either a loss or a win. We can check that condition whenever the amount of remaining ships changes, so we use the On ShipKilled event.

The OnTimerExpired event handler is straight forward: It checks, if it's the mission timer which has expired, or the 5-minutes-remainder and either ends the mission or sends a chat message. The OnShipKilled event simply checks the amount of remaining ships by accessing the $MissionContext->PlayersShipList and $MissionContext->EnemiesShipList properties of the $MissionContext and evaluates their count. If one of these is empty, the mission ends with a loss or win. If none are empty, the counter with the Id enemyCounter, which has been defined in the OnMissionInitialize event handler, will be updated to show the remaining number of enemies to the players.

Pages in category "Modding:PVEMissions:mission.php"

The following 3 pages are in this category, out of 3 total.