So with reference to the repaired OnBuildingKilled() script function and the usage of the following script:
Code:
public override void OnBuildingKilled(string title, Point3d pos, AiDamageInitiator initiator, int eventArgInt) {
string[] parts = title.Split(new string[] { SEPARATOR }, StringSplitOptions.None);
DateTime now = DateTime.Now;
long pk = writeDestroyed(DESTROYED_TYPE_BUILDING, parts[2], "", now);
if (initiator.Player != null) {
writeDestroyer(getInitiatorDescription(initiator), initiator.Player.Name() , pk);
} else {
writeDestroyer(getInitiatorDescription(initiator), initiator.Actor.Name(), pk);
}
}
It seems like there's code missing from a functioning method. When I add this code to our test mission I get the following on start up and the mission fails to continue loading properly:
Capture.JPG
Is the ATAG server showing this error on loading its missions? If not, can we please have the rest of the code related to using OnBuildingKilled() effectively in an MP mission? This would help mission and campaign designers immensely.
Could be that some namespaces aren't being used in the mission? Or that the overall ATAG script contains other functions referenced but were omitted (ex. writeDestroyer, writeDestroyed etc.).
The test mission file uses the following:
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using maddox.game;
using maddox.game.world;
using maddox.GP;
Is TF able to explain why the above ATAG code apparently works but the one I supplied doesn't? It's calling all the same data and seems actually be a lot simpler than the ATAG one since all it does is take the values from the OnBuildingKilled() method and display them when the code fires in the server messages. For reference:
Code:
public override void OnBuildingKilled(string title, Point3d pos, AiDamageInitiator initiator, int eventArgInt)
{
base.OnBuildingKilled(title, pos, initiator, eventArgInt);
string BuildingName = title;
string BuildingArmy = "";
string PlayerArmy = "";
string sectorTitle = "";
string sectorName = GamePlay.gpSectorName(pos.x, pos.y);
if (GamePlay.gpFrontArmy(pos.x, pos.y) == 1)
{
BuildingArmy = "England";
}
else if (GamePlay.gpFrontArmy(pos.x, pos.y) == 2)
{
BuildingArmy = "France";
}
else
{
BuildingArmy = "Neutral";
}
if (initiator.Player.Army() == 1)
{
PlayerArmy = "RAF";
}
else if (initiator.Player.Army() == 2)
{
PlayerArmy = "Luftwaffe";
}
else
{
PlayerArmy = "Unknown";
}
GamePlay.gpLogServer(null, "BUILDING:" + BuildingName + " in " + BuildingArmy + " was destroyed in sector " + sectorName + " by " + initiator.Player.Name() + " from the " + PlayerArmy + ".", new object[] { });
}
I'm missing an if statement in case the initiator isn't a player but simply an actor, but I don't think that is the problem. I'll add one and test it just to make sure.
EDIT: Additional testing done with a simple script including a switch for initiator.Actor. AI bombers will trigger this script on a dedicated server and notifications will appear for destroyed buildings of all types. The debug message for Actor NOT null is displayed. Player destroyed buildings still do not appear. There is no Player NOT null message. The OnBuildingKilled() called but NULL PLAYER & NULL ACTOR message is not displayed either, so it appears that the OnBuildingKilled() code is simply not called at all when a player destroyed a building in multiplayer if they are not the host of the mission. Full script used below:
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using maddox.game;
using maddox.game.world;
using maddox.GP;
public class Mission : AMission
{
public override void OnBattleStarted()
{
}
public override void OnBuildingKilled(string title, Point3d pos, AiDamageInitiator initiator, int eventArgInt)
{
base.OnBuildingKilled(title, pos, initiator, eventArgInt);
string BuildingName = title;
string BuildingArmy = "";
string PlayerArmy = "";
string sectorTitle = "";
string sectorName = GamePlay.gpSectorName(pos.x, pos.y);
if (GamePlay.gpFrontArmy(pos.x, pos.y) == 1)
{
BuildingArmy = "England";
}
else if (GamePlay.gpFrontArmy(pos.x, pos.y) == 2)
{
BuildingArmy = "France";
}
else
{
BuildingArmy = "Neutral";
}
if (initiator.Player != null)
{
if (initiator.Player.Army() == 1)
{
PlayerArmy = "RAF";
}
else if (initiator.Player.Army() == 2)
{
PlayerArmy = "Luftwaffe";
}
else
{
PlayerArmy = "Unknown";
}
GamePlay.gpLogServer(null, "TEST MESSAGE FOR DEBUG PURPOSE. Player NOT null", new object[] { });
GamePlay.gpLogServer(null, "BUILDING:" + BuildingName + " in " + BuildingArmy + " was destroyed in sector " + sectorName + " by " + initiator.Player.Name() + " from the " + PlayerArmy + ".", new object[] { });
}
else if (initiator.Actor != null)
{
if (initiator.Actor.Army() == 1)
{
PlayerArmy = "RAF";
}
else if (initiator.Actor.Army() == 2)
{
PlayerArmy = "Luftwaffe";
}
else
{
PlayerArmy = "Unknown";
}
GamePlay.gpLogServer(null, "TEST MESSAGE FOR DEBUG PURPOSE. Actor NOT null", new object[] { });
GamePlay.gpLogServer(null, "BUILDING:" + BuildingName + " in " + BuildingArmy + " was destroyed in sector " + sectorName + " by " + initiator.Actor.Name() + " from the " + PlayerArmy + ".", new object[] { });
}
else
{
GamePlay.gpLogServer(null, "TEST MESSAGE FOR DEBUG PURPOSE. OnBuildingKilled() called but NULL PLAYER & NULL ACTOR", new object[] { });
}
}
}
Bookmarks