Code:
using System;
using System.Collections.Generic;
using System.Text;
using maddox.game;
using maddox.game.world;
//$reference parts/core/gamePlay.dll
public class Mission : AMission
{
public override void OnBattleInit()
{
base.OnBattleInit();
if (GamePlay is GameDef)
{
(GamePlay as GameDef).EventChat += new GameDef.Chat(Mission_EventChat);
}
}
void Mission_EventChat(IPlayer from, string msg)
{
if (msg.StartsWith("!help"))
{
Chat("Commands: !aircraft, !select#", from);
}
if (msg.StartsWith("!aircraft") || msg.StartsWith("!select"))
{
List<Tuple<AiAircraft, int>> aircraftPlaces = new List<Tuple<AiAircraft, int>>();
if (GamePlay.gpArmies() != null && GamePlay.gpArmies().Length > 0)
{
foreach (int army in GamePlay.gpArmies())
{
if (GamePlay.gpAirGroups(army) != null && GamePlay.gpAirGroups(army).Length > 0)
{
foreach (AiAirGroup airGroup in GamePlay.gpAirGroups(army))
{
if (airGroup.GetItems() != null && airGroup.GetItems().Length > 0)
{
foreach (AiActor actor in airGroup.GetItems())
{
if (actor is AiAircraft)
{
AiAircraft Aircraft = actor as AiAircraft;
for (int place = 0; place < Aircraft.Places(); place++)
{
aircraftPlaces.Add(new Tuple<AiAircraft, int>(Aircraft, place));
}
}
}
}
}
}
}
}
if (msg.StartsWith("!aircraft"))
{
int i = 0;
foreach (Tuple<AiAircraft, int> aircraftPlace in aircraftPlaces)
{
string playerName = "";
Player player = aircraftPlace.Item1.Player(aircraftPlace.Item2);
if (player != null)
{
playerName = " " + player.Name();
}
Chat("#" + i + ": " + aircraftPlace.Item1.Name() + " " + aircraftPlace.Item1.TypedName() + " " + aircraftPlace.Item1.CrewFunctionPlace(aircraftPlace.Item2) + " " + playerName, from);
i++;
}
}
else if (msg.StartsWith("!select"))
{
msg = msg.Replace("!select", "");
int i = -1;
if (int.TryParse(msg, out i) && i < aircraftPlaces.Count)
{
Tuple<AiAircraft, int> aircraftPlace = aircraftPlaces[i];
if (aircraftPlace.Item1.Player(aircraftPlace.Item2) == null)
{
from.PlaceEnter(aircraftPlace.Item1, aircraftPlace.Item2);
}
else
{
Chat("Place occupied.", from);
}
}
else
{
Chat("Please enter a valid aircraft number, e.g. !select0, !select1, !select2, ...", from);
}
}
}
}
public void Chat(string line, IPlayer to)
{
if (GamePlay is GameDef)
{
(GamePlay as GameDef).gameInterface.CmdExec("chat " + line + " TO " + to.Name());
}
}
}
using maddox.game;
using maddox.game.world;
using part;
using System.IO;
using System.Reflection;
using maddox.GP;
public class Mission : AMission
{
// perpetual vehicles movements
#region perpetual vehicles movements
bool PerpetualVehicles = true; // turn perpetual vehicle movements on/off
int CheckVehicleMovementEvery = 120; // seconds
#endregion
public override void OnTickGame()
{
base.OnTickGame();
#region Vehicles travel up & down waypoints endlessly in MP server missions
// ------------------------------------------------------------------------------------------------------
// Vehicles travel back & forth along waypoints endlessly in MP server missions just like on spline roads
// ------------------------------------------------------------------------------------------------------
// By: Salmo 6 Oct 2012 COPYRIGHT Lee Miles 2012 ALL RIGHTS RESERVED
// Purpose:
// A work-around for the broken spline roads/car.cpp script in multiplayer (server) missions.
// How it works:
// a. Place vehicles & waypoints as normal in FMB (one way only). do not attach to spline roads
// or use car.cpp script
// b. The script will detect when a vehicle has reached it's last waypoint & will
// send the vehicle off in the reverse direction. Works endlessly or until vehicle destroyed.
// Known issues:
// 1. Vehicles sometimes are a little erratic following their waypoint path, make sure there are not too many
// objects that could get in their way.
// 2. Vehicles will sometimes reverse or do a circle along their waypoint path.
// ------------------------------------------------------------------------------------------------------
if (PerpetualVehicles && Time.tickCounter() % (CheckVehicleMovementEvery * 32) == 0) // check ground group positions every 2 min
{
try
{
foreach(int army in GamePlay.gpArmies()) // do all armies
{
foreach (AiGroundGroup groundgroup in GamePlay.gpGroundGroups(army)) // every groundgroup in each army
{
if (groundgroup.GroupType() == AiGroundGroupType.Vehicle)
{
AiWayPoint[] way = groundgroup.GetWay(); // remember the ground groups waypoints
// should be able to use line below, but groundgroup.GetCurrentWayPoint() always returns zero (is broken), damn you dev's :(
// if (groundgroup.GetCurrentWayPoint() == way.GetLength(0)) // ground group has reached the end waypoint
// Let's use a work-around instead. See if groundgroup position is close to end waypoint
Point3d EndWayPoint = new Point3d();
EndWayPoint.x = way[way.GetLength(0) - 1].P.x;
EndWayPoint.y = way[way.GetLength(0) - 1].P.y;
EndWayPoint.z = groundgroup.Pos().z;
if (groundgroup.Pos().distance(ref EndWayPoint) < 50) // ground group is close to it's last waypoint
{
// reverse waypoints
for (int j = 0; j < way.GetLength(0) / 2; j++)
{
AiWayPoint tmp = way[j];
way[j] = way[way.GetLength(0) - j - 1];
way[way.GetLength(0) - j - 1] = tmp;
}
// give ground group new reversed waypoints
groundgroup.SetWay(way);
}
}
}
}
}
catch (Exception e)
{
//Console.WriteLine("Error: " + e.Message + " [OnTickGame]");
// nothing to print here, usually a 'object not set to instance of object' error
// if one of the armies does not have any ground groups
}
}
// ------------------------------ end of endless vehicles routine -----------------------------------
#endregion
Bookmarks