PDA

View Full Version : Script damage aircraft



1lokos
May-12-2015, 00:53
How make this script work for AI aircraft?

BTW- Is nice to check Spitfire engine fire. :devilish:


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

public class Mission : AMission
{
private double nextMsgTime = 0;

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

if (Time.current() > nextMsgTime)
{
nextMsgTime = Time.current() + 60.0; // Time in seconds till the damage

if (GamePlay.gpPlayer() != null) // check if we have a player.
{
if (GamePlay.gpPlayer().Place() != null)
{
Player me = GamePlay.gpPlayer();
Player[] all = { me };

AiActor where = me.Place();
AiAircraft aircraft = (GamePlay.gpPlayer().Place() as AiAircraft);

GamePlay.gpLogServer(all, "Fire!!!", null);
GamePlay.gpLogServer(all, "Fire!!!", null);
aircraft.hitNamed(part.NamedDamageTypes.Eng0Cylind erHeadFire);
aircraft.hitNamed(part.NamedDamageTypes.FuelTank0F ire);

}
}
}
}
}
}

Salmo
May-12-2015, 04:01
This will damage a "random" aircraft (player aircraft or aiaircraft).



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

public class Mission : AMission
{
private double nextMsgTime = 0;
Random random = new Random(Guid.NewGuid().GetHashCode());

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

if (Time.current() > nextMsgTime)
{
nextMsgTime = Time.current() + 60.0; // Time in seconds till the damage

// make a list of ALL aircraft the game
List<int> armies = new List<int> (GamePlay.gpArmies());
List<AiAircraft> aircraft = new List<AiAircraft>();

for (int i = 0; i < armies.Count; i++) // for every army
{
List<AiAirGroup> airgroups = new List<AiAirGroup>(GamePlay.gpAirGroups(armies[i]));
for (int j = 0; j < airgroups.Count; j++) // for every airgroup
{
List<AiActor> actors = new List<AiActor>(airgroups[j].GetItems());
for (int k = 0; k < actors.Count; k++)
{
if (actors[k] is AiAircraft) aircraft.Add(actors[k] as AiAircraft);
}

// pick a random aircraft to damage (ai-aircraft or player aircraft)
if (aircraft.Count > 0)
{
int RandomAircraft = random.Next(aircraft.Count + 1);
DoRandomAircraftfDamage(aircraft[RandomAircraft]);
}
}

}
}
}
}

private void DoRandomAircraftfDamage(AiAircraft aircraft)
#region do some damage to named aircraft
{ // Script that triggered an accidental damage to the player plane
// Author: FG28_Kodiak Modified by: Salmo & Octocat
// Ref: http://forum.1cpublishing.eu/showthread.php?t=22184

if (aircraft == null || !(aircraft is AiAircraft)) return;
List<Player> player = new List<Player>(GamePlay.gpRemotePlayers()); // ALL players

switch (random.Next(1, 7 + 1))
{
// ===================================
// ---- Engine(s) failures ----
// ===================================
case 1:
int i = random.Next(0, GetNumberOfEngines(aircraft) + 1);

aircraft.hitNamed(part.NamedDamageTypes.Eng0TotalF ailure);
GamePlay.gpHUDLogCenter(player.ToArray(), "Engine failure", null, 3);
//sendChatMessageTo(aircraft.Army(), "Engine failure", null); // 1st msg to see if this works OK
//Timeout(10.0, () => GamePlay.gpHUDLogCenter("Engine Failure")); // wait 10 seconds for debugging
break;

case 2:
aircraft.hitNamed(part.NamedDamageTypes.Eng0OilSec ondariesFire);
GamePlay.gpHUDLogCenter(player.ToArray(), "Oil is on fire", null, 3);
//sendChatMessageTo(aircraft.Army(), "Oil is on fire", null);
//GamePlay.gpHUDLogCenter("Oil is on fire");
break;

// ===================================
// ---- Hydrolicss & cables failures ----
// ===================================
case 3:
if (random.Next(1, 2 + 1) == 1)
{
aircraft.hitNamed(part.NamedDamageTypes.Undercarri ageUpLockFailureL);
GamePlay.gpHUDLogCenter(player.ToArray(), "Undercarriage failure", null, 3);
//sendChatMessageTo(aircraft.Army(), "Undercarriage failure", null);
//GamePlay.gpHUDLogCenter("Undercarriage failure");
}
else
{
aircraft.hitNamed(part.NamedDamageTypes.Undercarri ageUpLockFailureR);
GamePlay.gpHUDLogCenter(player.ToArray(), "Undercarriage failure", null, 3);
//sendChatMessageTo(aircraft.Army(), "Undercarriage failure", null);
//GamePlay.gpHUDLogCenter("Undercarriage failure");
}
break;

case 4:
aircraft.hitNamed(part.NamedDamageTypes.Eng0Thrott leControlBroken);
GamePlay.gpHUDLogCenter(player.ToArray(), "Broken throttle cable", null, 3);
//sendChatMessageTo(aircraft.Army(), "Broken throttle cable", null);
//GamePlay.gpHUDLogCenter("Broken throttle cable");
break;

// ===================================
// ---- Flight surfaces failures ----
// ===================================
case 5:
aircraft.hitNamed(part.NamedDamageTypes.ControlsEl evatorDisabled);
GamePlay.gpHUDLogCenter(player.ToArray(), "Elevator jammed", null, 3);
//sendChatMessageTo(aircraft.Army(), "Elevator jammed", null);
//GamePlay.gpHUDLogCenter("Elevator jammed");
break;

case 6:
aircraft.hitNamed(part.NamedDamageTypes.ControlsAi leronsDisabled);
GamePlay.gpHUDLogCenter(player.ToArray(), "Ailerons jammed", null, 3);
//sendChatMessageTo(aircraft.Army(), "Ailerons jammed", null);
//GamePlay.gpHUDLogCenter("Ailerons jammed");
break;

case 7:
aircraft.hitNamed(part.NamedDamageTypes.ControlsRu dderDisabled);
GamePlay.gpHUDLogCenter(player.ToArray(), "Rudder jammed", null, 3);
//sendChatMessageTo(aircraft.Army(), "Rudder jammed", null);
//GamePlay.gpHUDLogCenter("Rudder jammed");
break;

default:
aircraft.hitNamed(part.NamedDamageTypes.Eng0TotalF ailure);
GamePlay.gpHUDLogCenter(player.ToArray(), "Engine Failure", null, 3);
//sendChatMessageTo(aircraft.Army(), "Engine Failure", null);
//GamePlay.gpHUDLogCenter("Engine Failure");
break;
}
}
#endregion

public int GetNumberOfEngines(AiAircraft aircraft)
#region Get the number of engines a plane has
{ // --------------------------------------------------------
// Purpose: Get the number of engines a plane has
// Input: recieves parameter aircraft of the type AiAircraft
// Output: integer value
// Example syntax: GetNumberOfEngines(aircraft);
// --------------------------------------------------------
int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
return iNumOfEngines;
}
#endregion
}

ATAG_Lolsav
May-12-2015, 06:25
Made without testing:

A "Frankenscript" should be close to this:


ublic class Mission : AMission
{
private double nextMsgTime = 0;

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

if (Time.current() > nextMsgTime)
{
nextMsgTime = Time.current() + 60.0; // Time in seconds till the damage

// make a list of ALL aircraft the game
List<int> armies = new List<int> (GamePlay.gpArmies());
List<AiAircraft> aircraft = new List<AiAircraft>();

for (int i = 0; i < armies.Count; i++) // for every army
{
List<AiAirGroup> airgroups = new List<AiAirGroup>(GamePlay.gpAirGroups(armies[i]));
for (int j = 0; j < airgroups.Count; j++) // for every airgroup
{
List<AiActor> actors = new List<AiActor>(airgroups[j].GetItems());
for (int k = 0; k < actors.Count; k++)
{
if (actors[k] is AiAircraft) aircraft.Add(actors[k] as AiAircraft);
}

AiAircraft aircraft = (GamePlay.gpPlayer().Place() as AiAircraft);

GamePlay.gpLogServer(all, "Fire!!!", null);
GamePlay.gpLogServer(all, "Fire!!!", null);
aircraft.hitNamed(part.NamedDamageTypes.Eng0Cylind erHeadFire);
aircraft.hitNamed(part.NamedDamageTypes.FuelTank0F ire);
}
}

}
}

}
}

1lokos
May-12-2015, 12:00
Thank you guys.

The Salmo script work for player and AI aircraft - despite the console report various "missing" parameters. :thumbsup:

The Lolsav script dont work - I remove some space that appear in the damage lines - the console report "Not destroyed actor:56" and some "variables can't be used".

My ideas is create a AI accident on some SP mission. :D

ATAG_Lolsav
May-12-2015, 12:34
Yes you need to adjust the variables names accordingly i believe.

1lokos
May-12-2015, 12:48
That is the problem... :D

In default Campaign mission - "Shoot up a strangler.CS", has this scrip - part of big script - for damage in specific AI aircraft:


AiActor a = GamePlay.gpActorByName("0:BoB_LW_KG27_II.200");
if (a is AiAircraft) {
AiAircraft airc = (AiAircraft)a;
airc.hitNamed(part.NamedDamageTypes.Eng0Plug00Fail ure);
airc.hitNamed(part.NamedDamageTypes.Eng0Plug01Fail ure);
airc.hitNamed(part.NamedDamageTypes.FuelTank0Large Leak);
airc.hitLimb(part.LimbNames.WingL2, -0.3);

}

But seems need somewhat before, related with "a"... :doh:

This "hitLimb" cause visual damage and need a value after the damage name, like -0,3 in the example, I try up to -9 but don't see (visual) difference.

Salmo
May-13-2015, 07:18
That is the problem... :D

In some Campaign mission, has this - part of big script - for damage in specific AI aircraft:


AiActor a = GamePlay.gpActorByName("0:BoB_LW_KG27_II.200");
if (a is AiAircraft) {
AiAircraft airc = (AiAircraft)a;
airc.hitNamed(part.NamedDamageTypes.Eng0Plug00Fail ure);
airc.hitNamed(part.NamedDamageTypes.Eng0Plug01Fail ure);
airc.hitNamed(part.NamedDamageTypes.FuelTank0Large Leak);
airc.hitLimb(part.LimbNames.WingL2, -0.3);

}

But seems need somewhat before, related with "a"... :doh:

This "hitLimb" cause visual damage and need a value after the damage name, like -0,3 in the example, I try up to -9 but don't see (visual) difference.

I think you'll find that the 'value' is a variable of type double in the range 0.0 to 1.0

No.401_Wolverine
May-13-2015, 13:02
Interesting idea. I wonder if this could ever be hard-coded into the game as part of an update along with a realism setting for 'random failures'.

Salmo
May-14-2015, 03:29
Interesting idea. I wonder if this could ever be hard-coded into the game as part of an update along with a realism setting for 'random failures'.

G'day Wolvie :) It's ceratinly possible to hard-code this into the aircraft takeoff event in the game code. However, not everyone would be happy with their aircraft systems randomly failing. Better to use mission-scripts to help us play in Oleg & Ilya's sandpit .......

Here's a script for random aircraft damage (http://theairtacticalassaultgroup.com/forum/showthread.php?t=17270&p=187976#post187976) on takeoff

[edit] BTW, there is already an engine failure probability built into the game's FM-engine file, but it's set to zero for all engines. So Oleg & Ilya were indeed far thnking in their development of the game.

1lokos
May-14-2015, 12:25
In the release version of CloD has a slider for "Physical weathering" (or something similar) that suppose allow the player set the probability of random failures, but was removed latter. I don't reminder if work as announced...

From 2009 Oleg's inteview:

* Random mechanical failure is modelled but can be switched off in the GUI

BTW - In game manual:



Physical Weathering. The flip side of the visual weathering setting, this slider allows you to set how well the aircraft’s systems operate. 0% means the plane is in perfect working order, and 100% means it’s an accident waiting to happen. The actual details of a higher Physical Weathering setting are determined randomly, including which systems are affected, how broken they are, and at what times they may completely break down.
While 100% physical weathering means on average a much higher chance of more things going wrong, the random nature of the failure model can mean that you’ll fly an uneventful mission in a 100% plane, and have a wing fall off on start-up in a 1% plane.
NOTE: This setting is not for the faint of heart. Even the more hardcore players often find it infuriating, reset it to 0 and never touch it again. You can only take so many missions in which your engine seizes in the middle of a heated dogfight and you float down helplessly waiting to get shot out of the sky.


Maybe that feature was killed by Banana's complains...

I see Bliss comments about turbulence in release version - although I dont remember. Find this "TX-Gunslinger's impressions of Il-2:CoD (SImHQ (http://simhq.com/forum/ubbthreads.php/topics/3249958#ixzz3a8Iqaijh
))" :

"Last great thing I noticed today is the spotty turbulence. At some altitudes you pass through, it will just shake your brains out. Dials jumping up and down - view shaking. Now ROF has pretty awesome turbulence - but the fluid-mechanics in this sim have to be experienced to be believed.

I dont' know exactly how the turbulence is implemented. Maybe it's altitude dependent - in layers. I'm starting to suspect that it might be range/altitude dependent however - as I seem to keep encountering it in patches. I pretty sure what I'm experiencing is not flutter as I was trimmed in yaw and diving when I hit the worst of it. Only more flying will tell."

No.401_Wolverine
May-20-2015, 10:31
Certainly features like this shouldn't be mandatory. It would be great as a new realism option potentially. Percentage of failures would need to be pretty low to avoid infuriation. Something like this is probably too niche to be widely used though. Maybe something to pursue later on when all other work is done. Until then, scripting shall prevail as you say Salmo.