PDA

View Full Version : How to remove Static4 Stationary.Environment objects


hc_wolf
10-15-2012, 03:57 AM
Hi all,

this used to work but now it is not. any ideas on how to fix?


Below code is in the .mis file that items the stationary objects i want to remove after 58 minutes.


[Stationary]
Static5 Stationary.Environment.FuelDrum_GER1_9 de 296598.06 217104.48 0.00
Static4 Stationary.Environment.FuelDrum_GER1_9 de 296582.91 217086.94 0.00
Static3 Stationary.Environment.FuelDrum_GER1_9 de 296562.56 217080.95 0.00
Static2 Stationary.Environment.FuelDrum_GER1_9 de 295859.16 217662.86 0.00
Static1 Stationary.Environment.FuelDrum_GER1_9 de 295877.09 217695.95 0.00
Static0 Stationary.Environment.FuelDrum_GER1_9 de 295899.00 217686.78 0.00



Below is the code I have in my .cs file that states ground objects to be removed after 58 minutes. This is not working. The barrels are not removing??


using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;
using System.Diagnostics;

public class Mission : AMission
{
Stopwatch MissionTimer1M1 = new Stopwatch();
bool ReStart = false;
public override void Init(ABattle battle, int missionNumber)
{
base.Init(battle, missionNumber);
GamePlay.gpLogServer(null, "Mission 1 Loaded ", new object[] { }); //test Message
//MissionNumberListener = -1;

MissionTimer1M1.Reset();
MissionTimer1M1.Start();
}

public override void OnTickGame()
{
base.OnTickGame();
if (Time.tickCounter() % (32 * 30 * 1) == 0) // every 30sec repeat, (32 ticks a sec x 60 sec * 1 mins)
{
if (MissionTimer1M1.Elapsed.Minutes >= 59)
MissionTimer1M1.Stop();
}
}


//Section to remove AI after 58 mins

public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
{
base.OnActorCreated(missionNumber, shortName, actor);

if (actor is AiGroundActor) // 3599 = 58 mins
Timeout(3599, () =>
{
if (actor != null)
{ (actor as AiGroundActor).Destroy(); }
});
}
}

FG28_Kodiak
10-15-2012, 04:43 AM
Stationaries are not Actors!

You can use


public static void RemoveStaticAt(double xPos, double yPos, double radius)
{

foreach (GroundStationary stationary in GamePlay.gpGroundStationarys(xPos, yPos, radius))
{
stationary.Destroy();
}

}


GamePlay.gpGroundStationarys is overloaded:
GamePlay.gpGroundStationarys(double x, double y, double radius)
GamePlay.gpGroundStationarys(string country)
GamePlay.gpGroundStationarys(string country, double y, double radius)

you get a Array of GroundStationary on a Position with a given radius, additional you can specify a country. Or you can get all Stationaries of a country you specify.

hc_wolf
10-15-2012, 08:35 AM
Sweet. Will test

salmo
10-15-2012, 10:19 AM
Sweet. Will test

Keep radius small to avoid accidently deleting other ground stationaries

hc_wolf
10-15-2012, 10:34 PM
Keep radius small to avoid accidently deleting other ground stationaries

Thanks Salmo I shall remember for other times.

But for this topic I don't to delete in a radius area, I want to delete every object I load in a sub mission.

Example, I load a bomber mission, the targets spawn at same time as bomnbers. Then 1 hour later if the bombers did not make it or if they did, all Ground objects that were spawned in on that submission are removed.

so maybe I use the below and place it in the sub mission .cs file



public static void RemoveStaticAt(string country)
{

foreach (GroundStationary stationary in GamePlay.gpGroundStationarys(country))
{
If country = de;
{
stationary.Destroy();
}
}

}

salmo
10-16-2012, 04:47 AM
OK, so if your loading from a sub-mission, I'll presume you know the mission number from which you want all the actor objects deleted. How about this ...

Code remove by author

FG28_Kodiak
10-16-2012, 05:34 AM
Not Actors :rolleyes: Stationaries


So

using System;
using System.Collections.Generic;
using maddox.GP;
using maddox.game;
using maddox.game.world;



public class Mission : AMission
{

Dictionary<GroundStationary,int> Stationaries = new Dictionary<GroundStationary, int>();

public override void OnBattleStarted()
{
base.OnBattleStarted();

MissionNumberListener = -1;
}


public override void OnMissionLoaded(int missionNumber)
{
base.OnMissionLoaded(missionNumber);

foreach (GroundStationary stationary in GamePlay.gpGroundStationarys())
{
if (!Stationaries.ContainsKey(stationary))
Stationaries[stationary] = missionNumber;
}
}


public void RemoveStationaries(int missionNumber)
{

List<GroundStationary> toRemove = new List<GroundStationary>();

foreach (KeyValuePair<GroundStationary, int> keyValuePair in Stationaries)
{
if (keyValuePair.Value == missionNumber)
{
toRemove.Add(keyValuePair.Key);
keyValuePair.Key.Destroy();
}
}

foreach (GroundStationary groundStationary in toRemove)
{
Stationaries.Remove(groundStationary);
}
}
}

hc_wolf
10-16-2012, 05:38 AM
Thanks Salmo, will test tonight. With regards to mission number.. well I can't say it is always mission 3 or mission 12. As the game goes on missions load and count in and the mission number can be mission 256

Anyways I will test that tonight. it is clean and looks like it will do the job.

My other way I looked at today was this but have not tested yet.

The below code removes all objects loaded in the mission that are from a country. example de



Dictionary<GroundStationary, int> StationaryMisRelation = new Dictionary<GroundStationary, int>();
//Section 1: Trigger Nachrichten

public override void OnTrigger(int missionNumber, string shortName, bool active)
{
base.OnTrigger(missionNumber, shortName, active);

if ("DeleteTrigger".Equals(shortName) && active) //Trigger 1 Nachricht
{
foreach (KeyValuePair<GroundStationary, int> kvp in StationaryMisRelation)
{
GamePlay.gpLogServer(null, "Stationary: {0}; MissNr.: {1}", new object[] { kvp.Key.Title, kvp.Value });
}
Timeout(20, () =>
{
GamePlay.gpGetTrigger(shortName).Enable = false;
});
}


}


// Destroy all [Stationary] objects for country de (germany)
public void RemoveStaticAt(string country) //not sure if this will work.
{


foreach (GroundStationary stationary in GamePlay.gpGroundStationarys(country))
{
country = de;
{
stationary.Destroy();
}
}
}

FG28_Kodiak
10-16-2012, 05:44 AM
salmos code wouldn't work for stationaries he uses AiActor but a GroundStantionary is not an Actor. So it's never registered in OnActorCreated,

salmo
10-16-2012, 05:55 AM
Wolfie, Kodiak's code is appropriate for groundStationaries. My code is for AiActors & as Kodiak says, won't work for stationaries (I had it for stationaries originally then changed it). You need to decide exactly what you want to do: delete groundstationaries for a given country? or stationaries from a given sub-mission?

In any event you will need to trap the mission number of the mission you want the stationaries deleted from.