#1
|
|||
|
|||
Feature Request: Despawn AI aircraft Command
I've been struggling to get to grips with the FMB. Not so much the placement of objects (I made many IL2 missions) but its the scripting and related subjects. I am only interested in MP and producing maps for MP servers and at the moment I am finding it difficult to get the desired effects and there is one majoy stumbling block for me (and I think many others): Removing unwanted AI objects, especially flying AI aircraft from the mission/server.
I have a simple request: I want to be able to set a command to an AI object or group (be it aircraft, vehicles or ships.... anything AI) that will automatically despawn it. This could after a set time and/or when it reaches a set waypoint. My preference would be that it would simply be one of the Options available in Properties>Waypoint>Action. So you would set the aircrafts route, target etc and when it reaches the final waypoint it simply despawns and is removed from the server. I would also ask for an additional setting which sets the maximum time that the AI object/group is alive for. This would be useful is an object doesn't reach its final waypoint (it might be damaged or its route blocked or another propblem) or say if you want an aircraft group to loiter until a set time. I understand that its possible to remove ground object via a script but not flying AI aircraft. I believe this would be a crucial and much welcomed addition to the FMB. Even with my limited knowledge of scripts (and in reality I borrow other people...thanks Ataros!) I can see the potential but at the moment the big handicap that I see is that we cannot reliably despawn AI objects once they are no longer useful. If we can have a working, reliable, trusted method of despawning AI then the potential for multiday unpredictable missions (utilising the sub-mission system with scripts) is huge. It would mean you could have essentially a massive mission spread over a wide are with multiple objectives, but with clever mission making the actual number of AI etc in game would be smaller than the whole. |
#2
|
|||
|
|||
+1
I hope one day we have this integrated into FMB. Another thing that we probably need is a sort of Mission Creation Toolkit including set of useful scripts for various purposes and then some add-ons that can be used to create a mission without knowledge of C#. Ideally a mission builder could just drop several script-files to his mission folder and add their names to a sort of mission.ini file and that is it. I remember how scary it was to open a C# file for the 1st time Very often C# programmers and mission designers happen to be different people If programmers can deliver such a Toolkit mission builders would quicker produce more interesting missions. Many people with knowledge of C# helped me a lot in creation of the script for Repka server. Thank you! |
#3
|
|||
|
|||
Quote:
I can tell you that this method is called when a Spitfire and a tank reach their final waypoints. Anyway, here's the script. This is the code that I wrote. You won't have this in your script, although you might have some code in the OnActorTaskCompleted() method. Code:
public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor) { base.OnActorTaskCompleted(missionNumber, shortName, actor); //destroy it if it's an aircraft damageAiControlledPlane(actor); //destroy it if it's a grond object destroyGroundActor(actor); } private void destroyGroundActor(AiActor actor) { //loop through all of the ground groups from both armies foreach (AiGroundGroup g in GamePlay.gpGroundGroups(1)) { //if we find our actor in the ground group... if (g.Name() == actor.Name()) { //Destroy them! Destroy them all! foreach (AiActor a in g.GetItems()) (a as AiGroundActor).Destroy(); } } foreach (AiGroundGroup g in GamePlay.gpGroundGroups(2)) { //if we find our actor in the ground group... if (g.Name() == actor.Name()) { //Destroy them! Destroy them all! foreach (AiActor a in g.GetItems()) (a as AiGroundActor).Destroy(); } } } http://forum.1cpublishing.eu/showpos...0&postcount=92 You probably already have this because this is the code people are using to destroy aircraft that players abandon. And finally, here's the script in it's entirety so you can see how it all fits together. Code:
using System; using System.Collections; using maddox.game; using maddox.game.world; using System.Diagnostics; public class Mission : AMission { public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor) { base.OnActorTaskCompleted(missionNumber, shortName, actor); //destroy it if it's an aircraft damageAiControlledPlane(actor); //destroy it if it's a grond object destroyGroundActor(actor); } private void destroyGroundActor(AiActor actor) { //loop through all of the ground groups from both armies foreach (AiGroundGroup g in GamePlay.gpGroundGroups(1)) { //if we find our actor in the ground group... if (g.Name() == actor.Name()) { //Destroy them! Destroy them all! foreach (AiActor a in g.GetItems()) (a as AiGroundActor).Destroy(); } } foreach (AiGroundGroup g in GamePlay.gpGroundGroups(2)) { //if we find our actor in the ground group... if (g.Name() == actor.Name()) { //Destroy them! Destroy them all! foreach (AiActor a in g.GetItems()) (a as AiGroundActor).Destroy(); } } } private bool isAiControlledPlane(AiAircraft aircraft) { if (aircraft == null) { return false; } Player[] players = GamePlay.gpRemotePlayers(); foreach (Player p in players) { if (p != null && (p.Place() is AiAircraft) && (p.Place() as AiAircraft) == aircraft) { return false; } } return true; } private void damageAiControlledPlane(AiActor actor) { if (actor == null || !(actor is AiAircraft)) { return; } AiAircraft aircraft = (actor as AiAircraft); if (!isAiControlledPlane(aircraft)) { return; } if (aircraft == null) { return; } aircraft.hitNamed(part.NamedDamageTypes.ControlsElevatorDisabled); aircraft.hitNamed(part.NamedDamageTypes.ControlsAileronsDisabled); aircraft.hitNamed(part.NamedDamageTypes.ControlsRudderDisabled); aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFailure); aircraft.hitNamed(part.NamedDamageTypes.Eng0TotalFailure); aircraft.hitNamed(part.NamedDamageTypes.Eng1TotalFailure); Timeout(300, () => { destroyPlane(aircraft); } ); } private void destroyPlane(AiAircraft aircraft) { if (aircraft != null) { aircraft.Destroy(); } } } |
#4
|
|||
|
|||
+1 for the despawn waypoint.
I currently have a major headache with the script Trigger-Action Commands. I need an AI ac to land and for that ac to spawn another AI to take off. That results (or would) in a unwanted ground object doing nothing and showing up on the map if icons are enabled (despawn would be nice and simple for me). It should be possible to do this using the 'Group' and Passthorugh (an area on the runway) to act as a trigger but there appears to be a bug in that anything that lands automatically taxis to the same spawn point needed for the newly spawned ac - so it doesn't spawn! If you place an object on the runway and destroy the ac on the runway - the new ac spawns. You can use group and all the other commands with 'passthrough' to spawn Airgroups except a 'group' with a landing waypoint! So, if there is a script please let me know or alternatively, can we also have a 're-arm' way point for AI ac to 'land - wait - and takeoff'! Having spent hours on this problem I selected every available ac to land and they all appear to use the same algorithm for landing irrrespective of the FM for that ac........which may explain why some go 'tits up' on landing and others are OK! If you want to spawn a new AI - use the Anson....it can't land without going 'arse over tip' and your new AI spawns in its Hanger (and the Anson despawns!)..... Last edited by SEE; 05-20-2011 at 03:34 AM. |
#5
|
|||
|
|||
I think you can destroy an AC onAircraftLanding or do some damage to it, e.g. kill engine preventing it taxiing to a parking slot.
|
#6
|
||||
|
||||
OnAircraftLanded() is called only after plane stops. In case of AI, plane stops only after it reaches parking spot.
|
#7
|
|||
|
|||
Quote:
But if you are using both that might help you find your solution. |
#8
|
|||
|
|||
Hi EnlightenedFLorist,
I will have a look at that, though I have no knowledge of C++ and so far my scripts consist of hacking up other peoples and hoping they work! Im really hoping 1C can include this Despawn idea as a setting in the FMB, it would be most helpful. Anyhoo, I will have a look, do some swearing, and will see what I can come up with. Cheers |
#9
|
|||
|
|||
Quote:
If you need help writing a script, you can post it on the forum and I'm sure there'll be plenty of people willing to help you out. Also, scripts are written in C#, not C++. C# is very much like Java and way easier to work with than C++. I don't want you to go learning C++ when you should be learning C#. Last edited by TheEnlightenedFlorist; 05-20-2011 at 09:15 AM. |
#10
|
|||
|
|||
Quote:
I will have a look at using triggers and actions within the script itself as some are quite useful. I did have a mission where if one plane was shot down another would spawn... lots of potential with that one. There is a lot to learn, but equally there is a lot we can do that is really interesting. I will post up my next daft script and see what people think later on when im home. Cheers! |
|
|